8 import dbus.mainloop.glib
10 def make_bytes_readable(bytes):
11 SUFFIXES = [ 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB' ]
17 for suffix in SUFFIXES:
18 if bytes > size * 1024:
22 return '%.1f %s' % (bytes / float(size), suffix)
26 def print_stats(stats):
32 str = " %s = %s" % (key, val)
34 if key in ["RX.Bytes", "TX.Bytes"]:
35 hstr = make_bytes_readable(val)
37 str = "%s (%s)" % (str, hstr)
41 class Counter(dbus.service.Object):
42 @dbus.service.method("net.connman.Counter",
43 in_signature='', out_signature='')
48 @dbus.service.method("net.connman.Counter",
49 in_signature='oa{sv}a{sv}', out_signature='')
50 def Usage(self, path, home, roaming):
60 if __name__ == '__main__':
61 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
63 bus = dbus.SystemBus()
64 manager = dbus.Interface(bus.get_object('net.connman', "/"),
65 'net.connman.Manager')
71 path = "/test/counter%s" % period
72 object = Counter(bus, path)
74 manager.RegisterCounter(path, dbus.UInt32(10), dbus.UInt32(period))
76 mainloop = gobject.MainLoop()
79 #manager.UnregisterCounter(path)