This repository has been archived on 2025-03-19. You can view files and clone it, but cannot push or open issues or pull requests.
gonetworkmanager/DeviceStatistics.go

68 lines
2 KiB
Go

package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus"
)
const (
DeviceStatisticsInterface = DeviceInterface + ".Statistics"
// Properties
DeviceStatisticsPropertyRefreshRateMs = DeviceStatisticsInterface + ".RefreshRateMs" // readwrite u
DeviceStatisticsPropertyTxBytes = DeviceStatisticsInterface + ".TxBytes" // readable t
DeviceStatisticsPropertyRxBytes = DeviceStatisticsInterface + ".RxBytes" // readable t
)
type DeviceStatistics interface {
GetPath() dbus.ObjectPath
// Refresh rate of the rest of properties of this interface. The properties are guaranteed to be refreshed each RefreshRateMs milliseconds in case the underlying counter has changed too. If zero, there is no guaranteed refresh rate of the properties.
GetPropertyRefreshRateMs() (uint32, error)
// Number of transmitted bytes
GetPropertyTxBytes() (uint64, error)
// Number of received bytes
GetPropertyRxBytes() (uint64, error)
}
func NewDeviceStatistics(objectPath dbus.ObjectPath) (DeviceStatistics, error) {
var d deviceStatistics
return &d, d.init(NetworkManagerInterface, objectPath)
}
type deviceStatistics struct {
dbusBase
}
func (d *deviceStatistics) GetPath() dbus.ObjectPath {
return d.obj.Path()
}
func (d *deviceStatistics) GetPropertyRefreshRateMs() (uint32, error) {
return d.getUint32Property(DeviceStatisticsPropertyRefreshRateMs)
}
func (d *deviceStatistics) GetPropertyTxBytes() (uint64, error) {
return d.getUint64Property(DeviceStatisticsPropertyTxBytes)
}
func (d *deviceStatistics) GetPropertyRxBytes() (uint64, error) {
return d.getUint64Property(DeviceStatisticsPropertyRxBytes)
}
func (d *deviceStatistics) marshalMap() map[string]interface{} {
return map[string]interface{}{}
}
func (d *deviceStatistics) MarshalJSON() ([]byte, error) {
m := make(map[string]interface{})
m["RefreshRateMs"], _ = d.GetPropertyRefreshRateMs()
m["TxBytes"], _ = d.GetPropertyTxBytes()
m["RxBytes"], _ = d.GetPropertyRxBytes()
return json.Marshal(m)
}