Skip to content

Commit

Permalink
Update struct names to use exported types
Browse files Browse the repository at this point in the history
The struct names in various files were updated to start with a capital letter which makes them exported and usable in other packages. This change allows these types to be used directly (declaration, parameters, return type).

Types that need initialization (and have a pseudo-constructor) and are exported through interfaces were not modified.
  • Loading branch information
mullerch committed Dec 5, 2023
1 parent 8420f1b commit fb50944
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 123 deletions.
28 changes: 14 additions & 14 deletions Bearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type Bearer interface {
// Additional items which are only applicable when using the MM_BEARER_IP_METHOD_STATIC method are:
// address, prefix, dns1, dns2, dns3 and gateway
// This property may also include the following items when such information is available: mtu
GetIp4Config() (bearerIpConfig, error)
GetIp4Config() (BearerIpConfig, error)

// If the bearer was configured for IPv6 addressing, upon activation this property contains the addressing
// details for assignment to the data interface.
Expand All @@ -84,12 +84,12 @@ type Bearer interface {
// Additional items which are usually only applicable when using the MM_BEARER_IP_METHOD_STATIC method are:
// address, prefix, dns1, dns2, dns3 and gateway
// This property may also include the following items when such information is available: mtu
GetIp6Config() (bearerIpConfig, error)
GetIp6Config() (BearerIpConfig, error)

// If the modem supports it, this property will show statistics of the ongoing connection.
// When the connection is disconnected automatically or explicitly by the user, the values in this
// property will show the last values cached. The statistics are reset
GetStats() (bearerStats, error)
GetStats() (BearerStats, error)

// Maximum time to wait for a successful IP establishment, when PPP is used.
GetIpTimeout() (uint32, error)
Expand Down Expand Up @@ -125,8 +125,8 @@ type bearer struct {
sigChan chan *dbus.Signal
}

// bearerIpConfig represents all available ip configuration properties
type bearerIpConfig struct {
// BearerIpConfig represents all available ip configuration properties
type BearerIpConfig struct {
Method MMBearerIpMethod `json:"method"` // Mandatory: A MMBearerIpMethod, given as an unsigned integer value (signature "u").
Address string `json:"address"` // IP address, given as a string value (signature "s").
Prefix uint32 `json:"prefix"` // Numeric CIDR network prefix (ie, 24, 32, etc), given as an unsigned integer value (signature "u").
Expand All @@ -139,7 +139,7 @@ type bearerIpConfig struct {
}

// MarshalJSON returns a byte array
func (bc bearerIpConfig) MarshalJSON() ([]byte, error) {
func (bc BearerIpConfig) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Method": fmt.Sprint(bc.Method),
"Address": bc.Address,
Expand All @@ -152,7 +152,7 @@ func (bc bearerIpConfig) MarshalJSON() ([]byte, error) {
"IpFamily: ": fmt.Sprint(bc.IpFamily)})
}

func (bc bearerIpConfig) String() string {
func (bc BearerIpConfig) String() string {
return "Method: " + fmt.Sprint(bc.Method) +
", Address: " + bc.Address +
", Prefix: " + fmt.Sprint(bc.Prefix) +
Expand Down Expand Up @@ -201,22 +201,22 @@ func (bp BearerProperty) String() string {
", Number: " + bp.Number
}

// bearerStats represents all stats according to the bearer
type bearerStats struct {
// BearerStats represents all stats according to the bearer
type BearerStats struct {
RxBytes uint64 `json:"rx-bytes"` // Number of bytes received without error, given as an unsigned 64-bit integer value (signature "t").
TxBytes uint64 `json:"tx-bytes"` // Number bytes transmitted without error, given as an unsigned 64-bit integer value (signature "t").
Duration uint32 `json:"duration"` // Duration of the connection, in seconds, given as an unsigned integer value (signature "u").
}

// MarshalJSON returns a byte array
func (bs bearerStats) MarshalJSON() ([]byte, error) {
func (bs BearerStats) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"RxBytes": bs.RxBytes,
"TxBytes": bs.TxBytes,
"Duration": bs.Duration,
})
}
func (bs bearerStats) String() string {
func (bs BearerStats) String() string {
return "RxBytes: " + fmt.Sprint(bs.RxBytes) +
", TxBytes: " + fmt.Sprint(bs.TxBytes) +
", Duration: " + fmt.Sprint(bs.Duration)
Expand Down Expand Up @@ -245,7 +245,7 @@ func (be bearer) GetSuspended() (bool, error) {
return be.getBoolProperty(BearerPropertySuspended)
}

func (be bearer) GetIp4Config() (bi bearerIpConfig, err error) {
func (be bearer) GetIp4Config() (bi BearerIpConfig, err error) {
tmpMap, err := be.getMapStringVariantProperty(BearerPropertyIp4Config)
if err != nil {
return bi, err
Expand Down Expand Up @@ -300,7 +300,7 @@ func (be bearer) GetIp4Config() (bi bearerIpConfig, err error) {
return
}

func (be bearer) GetIp6Config() (bi bearerIpConfig, err error) {
func (be bearer) GetIp6Config() (bi BearerIpConfig, err error) {
tmpMap, err := be.getMapStringVariantProperty(BearerPropertyIp6Config)
if err != nil {
return bi, err
Expand Down Expand Up @@ -354,7 +354,7 @@ func (be bearer) GetIp6Config() (bi bearerIpConfig, err error) {
return
}

func (be bearer) GetStats() (br bearerStats, err error) {
func (be bearer) GetStats() (br BearerStats, err error) {
tmpMap, err := be.getMapStringVariantProperty(BearerPropertyStats)
if err != nil {
return br, err
Expand Down
10 changes: 5 additions & 5 deletions Call.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type Call interface {
GetAudioPort() (string, error)

// If call audio is routed via the host, a description of the audio format supported by the audio port.
GetAudioFormat() (audioFormat, error)
GetAudioFormat() (AudioFormat, error)

/* SIGNALS */

Expand Down Expand Up @@ -146,21 +146,21 @@ type call struct {
sigChan chan *dbus.Signal
}

type audioFormat struct {
type AudioFormat struct {
Encoding string `json:"encoding"` // The audio encoding format. For example, "pcm" for PCM audio.
Resolution string `json:"resolution"` // The sampling precision and its encoding format. For example, "s16le" for signed 16-bit little-endian samples
Rate uint32 `json:"rate"` // The sampling rate as an unsigned integer. For example, 8000 for 8000hz.
}

// MarshalJSON returns a byte array
func (af audioFormat) MarshalJSON() ([]byte, error) {
func (af AudioFormat) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Encoding": af.Encoding,
"Resolution": af.Resolution,
"Rate": af.Rate,
})
}
func (af audioFormat) String() string {
func (af AudioFormat) String() string {
return returnString(af)

}
Expand Down Expand Up @@ -233,7 +233,7 @@ func (ca call) GetAudioPort() (string, error) {
return ca.getStringProperty(CallPropertyAudioPort)
}

func (ca call) GetAudioFormat() (af audioFormat, err error) {
func (ca call) GetAudioFormat() (af AudioFormat, err error) {
tmpMap, err := ca.getMapStringVariantProperty(CallPropertyAudioFormat)
if err != nil {
return af, err
Expand Down
10 changes: 5 additions & 5 deletions Modem.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ type Modem interface {

// The list of ports in the modem, given as an array of string and unsigned integer pairs.
// The string is the port name or path, and the integer is the port type given as a MMModemPortType value.
GetPorts() ([]port, error)
GetPorts() ([]Port, error)

// The identity of the device. This will be the IMEI number for GSM devices and the hex-format ESN/MEID for CDMA devices.
GetEquipmentIdentifier() (string, error)
Expand Down Expand Up @@ -318,13 +318,13 @@ type modem struct {
}

// Represents the modem port (name and type)
type port struct {
type Port struct {
PortName string // Port Name or Path
PortType MMModemPortType // Modem Port Type
}

// MarshalJSON returns a byte array
func (po port) MarshalJSON() ([]byte, error) {
func (po Port) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"PortName": po.PortName,
"PortType ": po.PortType,
Expand Down Expand Up @@ -561,7 +561,7 @@ func (m modem) GetPrimaryPort() (string, error) {
return m.getStringProperty(ModemPropertyPrimaryPort)
}

func (m modem) GetPorts() (ports []port, err error) {
func (m modem) GetPorts() (ports []Port, err error) {
res, err := m.getSliceSlicePairProperty(ModemPropertyPorts)
if err != nil {
return nil, err
Expand All @@ -576,7 +576,7 @@ func (m modem) GetPorts() (ports []port, err error) {

return nil, errors.New("wrong type != uin32")
}
ports = append(ports, port{PortName: newA, PortType: MMModemPortType(newB)})
ports = append(ports, Port{PortName: newA, PortType: MMModemPortType(newB)})
}
return
}
Expand Down
44 changes: 22 additions & 22 deletions Modem3gpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ type Modem3gpp interface {

// results is an array of dictionaries with each array element describing a mobile network found in the scan.
// takes up to 1 min
Scan() (networks []network3Gpp, err error)
Scan() (networks []Network3Gpp, err error)

// Request a network scan (async)
RequestScan()

// Get latest scan result
GetScanResults() (networkScanResult, error)
GetScanResults() (NetworkScanResult, error)

// Sets the UE mode of operation for EPS.
SetEpsUeModeOperation(mode MMModem3gppEpsUeModeOperation) error
Expand Down Expand Up @@ -95,7 +95,7 @@ type Modem3gpp interface {
// - The flag that indicates whether the PCO data contains the complete PCO structure received from the network, given as a boolean value (signature"b").
// - The raw PCO data, given as an array of bytes (signature "ay").
// Currently it's only implemented for MBIM modems that support "Microsoft Basic Connect Extensions" and for the Altair LTE plugin
GetPco() ([]rawPcoData, error)
GetPco() ([]RawPcoData, error)

// The object path for the initial default EPS bearer.
GetInitialEpsBearer() (Bearer, error)
Expand All @@ -111,24 +111,24 @@ type Modem3gpp interface {
// NewModem3gpp returns new Modem3gppInterface
func NewModem3gpp(objectPath dbus.ObjectPath) (Modem3gpp, error) {
var m3gpp modem3gpp
scanResults = networkScanResult{Recent: false}
scanResults = NetworkScanResult{Recent: false}
return &m3gpp, m3gpp.init(ModemManagerInterface, objectPath)
}

type modem3gpp struct {
dbusBase
}

// networkScanResult represents the results of a scanned network
type networkScanResult struct {
Networks []network3Gpp
// NetworkScanResult represents the results of a scanned network
type NetworkScanResult struct {
Networks []Network3Gpp
LastScan time.Time
ScanDuration float64
Recent bool
}

// MarshalJSON returns a byte array
func (nsr networkScanResult) MarshalJSON() ([]byte, error) {
func (nsr NetworkScanResult) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Networks": fmt.Sprint(nsr.Networks),
"LastScan ": nsr.LastScan,
Expand All @@ -137,15 +137,15 @@ func (nsr networkScanResult) MarshalJSON() ([]byte, error) {
})
}

func (nsr networkScanResult) String() string {
func (nsr NetworkScanResult) String() string {
return "Networks: " + fmt.Sprint(nsr.Networks) +
", LastScan: " + fmt.Sprint(nsr.LastScan) +
", ScanDuration: " + fmt.Sprint(nsr.ScanDuration) +
", Recent: " + fmt.Sprint(nsr.Recent)
}

// network3Gpp describes a mobile network found in the scan
type network3Gpp struct {
// Network3Gpp describes a mobile network found in the scan
type Network3Gpp struct {
Status MMModem3gppNetworkAvailability `json:"status"` // A MMModem3gppNetworkAvailability value representing network availability status, given as an unsigned integer (signature "u"). This key will always be present.
OperatorLong string `json:"operator-long"` // Long-format name of operator, given as a string value (signature "s"). If the name is unknown, this field should not be present.
OperatorShort string `json:"operator-short"` // Short-format name of operator, given as a string value (signature "s"). If the name is unknown, this field should not be present.
Expand All @@ -156,7 +156,7 @@ type network3Gpp struct {
}

// MarshalJSON returns a byte array
func (n network3Gpp) MarshalJSON() ([]byte, error) {
func (n Network3Gpp) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Status": fmt.Sprint(n.Status),
"OperatorLong ": n.OperatorLong,
Expand All @@ -168,7 +168,7 @@ func (n network3Gpp) MarshalJSON() ([]byte, error) {
})
}

func (n network3Gpp) String() string {
func (n Network3Gpp) String() string {
return "Status: " + fmt.Sprint(n.Status) +
", OperatorLong: " + n.OperatorLong +
", OperatorShort: " + n.OperatorShort +
Expand All @@ -178,14 +178,14 @@ func (n network3Gpp) String() string {
", AccessTechnology: " + fmt.Sprint(n.AccessTechnology)
}

type rawPcoData struct {
type RawPcoData struct {
SessionId uint32 // The session ID associated with the PCO, given as an unsigned integer value (signature "u").
Complete bool // The flag that indicates whether the PCO data contains the complete PCO structure received from the network, given as a boolean value (signature"b").
RawData []byte // The raw PCO data, given as an array of bytes (signature "ay").
}

// MarshalJSON returns a byte array
func (r rawPcoData) MarshalJSON() ([]byte, error) {
func (r RawPcoData) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"SessionId": r.SessionId,
"Complete ": r.Complete,
Expand All @@ -205,9 +205,9 @@ func (m modem3gpp) Register(operatorId string) error {
return m.call(Modem3gppRegister, operatorId)
}

var scanResults networkScanResult
var scanResults NetworkScanResult

func (m modem3gpp) Scan() (networks []network3Gpp, err error) {
func (m modem3gpp) Scan() (networks []Network3Gpp, err error) {
// takes < 1min
start := time.Now()
var tmpRes interface{}
Expand All @@ -218,7 +218,7 @@ func (m modem3gpp) Scan() (networks []network3Gpp, err error) {
scanResMap, ok := tmpRes.([]map[string]dbus.Variant)
if ok {
for _, el := range scanResMap {
var network network3Gpp
var network Network3Gpp
for key, element := range el {
switch key {
case "status":
Expand Down Expand Up @@ -260,7 +260,7 @@ func (m modem3gpp) Scan() (networks []network3Gpp, err error) {
}
}
duration := time.Since(start).Seconds()
scanResults = networkScanResult{Recent: true, LastScan: time.Now(), ScanDuration: duration, Networks: networks}
scanResults = NetworkScanResult{Recent: true, LastScan: time.Now(), ScanDuration: duration, Networks: networks}

return networks, nil
}
Expand All @@ -277,7 +277,7 @@ func (m modem3gpp) RequestScan() {
}()
}

func (m modem3gpp) GetScanResults() (res networkScanResult, err error) {
func (m modem3gpp) GetScanResults() (res NetworkScanResult, err error) {
if scanResults.Recent {
return scanResults, nil
}
Expand Down Expand Up @@ -375,7 +375,7 @@ func (m modem3gpp) GetEpsUeModeOperation() (MMModem3gppEpsUeModeOperation, error
return MMModem3gppEpsUeModeOperation(res), nil
}

func (m modem3gpp) GetPco() (data []rawPcoData, err error) {
func (m modem3gpp) GetPco() (data []RawPcoData, err error) {
// todo untested
tmpRes, err := m.getInterfaceProperty(Modem3gppPropertyPco)
if err != nil {
Expand All @@ -391,7 +391,7 @@ func (m modem3gpp) GetPco() (data []rawPcoData, err error) {
if ok {
rawData, ok := seq[2].([]byte)
if ok {
data = append(data, rawPcoData{SessionId: sessionId, Complete: complete, RawData: rawData})
data = append(data, RawPcoData{SessionId: sessionId, Complete: complete, RawData: rawData})
}
}
}
Expand Down
Loading

0 comments on commit fb50944

Please sign in to comment.