chiark / gitweb /
svc/conntrack.in: Monitor class for ConnMan.
[tripe] / svc / conntrack.in
index 8564a6195fd7c96fc19f175be3f22cafcbc08a8a..6ada45d73950e68f6ca1d1c4419c08c6718de579 100644 (file)
@@ -398,6 +398,38 @@ class NetworkManagerMonitor (object):
     if props.get('Default', False):
       netupdown(True, ['nm', 'default-connection-change'])
 
     if props.get('Default', False):
       netupdown(True, ['nm', 'default-connection-change'])
 
+##--------------------------------------------------------------------------
+### Connman monitor.
+
+CM_NAME = 'net.connman'
+CM_PATH = '/'
+CM_IFACE = 'net.connman.Manager'
+
+class ConnManMonitor (object):
+  """
+  Watch ConnMan signls for changes in network state.
+  """
+
+  ## Strategy.  Everything seems to be usefully encoded in the `State'
+  ## property.  If it's `offline', `idle' or `ready' then we don't expect a
+  ## network connection.  During handover from one network to another, the
+  ## property passes through `ready' to `online'.
+
+  def attach(me, bus):
+    try:
+      cm = bus.get_object(CM_NAME, CM_PATH)
+      props = cm.GetProperties(dbus_interface = CM_IFACE)
+      state = props['State']
+      netupdown(state == 'online', ['connman', 'initially-%s' % state])
+    except D.DBusException:
+      pass
+    bus.add_signal_receiver(me._cm_state, 'PropertyChanged',
+                            CM_IFACE, CM_NAME, CM_PATH)
+
+  def _cm_state(me, prop, value):
+    if prop != 'State': return
+    netupdown(value == 'online', ['connman', value])
+
 ###--------------------------------------------------------------------------
 ### Maemo monitor.
 
 ###--------------------------------------------------------------------------
 ### Maemo monitor.
 
@@ -549,6 +581,7 @@ def init():
   T.Coroutine(kickpeers, name = 'kickpeers').switch()
   DBM = DBusMonitor()
   DBM.addmon(NetworkManagerMonitor())
   T.Coroutine(kickpeers, name = 'kickpeers').switch()
   DBM = DBusMonitor()
   DBM.addmon(NetworkManagerMonitor())
+  DBM.addmon(ConnManMonitor())
   DBM.addmon(MaemoICdMonitor())
   G.timeout_add_seconds(30, lambda: (netupdown(True, ['interval-timer'])
                                      or True))
   DBM.addmon(MaemoICdMonitor())
   G.timeout_add_seconds(30, lambda: (netupdown(True, ['interval-timer'])
                                      or True))