Allow to have more than one notification type in Service
[gregoa/zavai.git] / zavai / gps.py
index f0d11f244f81d0f34235be16363b1c1499829612..bb551097979ec2eb3a247c8c593a3ddb73461c37 100755 (executable)
@@ -25,7 +25,7 @@ import zavai
 
 class GPSMonitor(zavai.Service):
     def __init__(self, gps):
-        super(GPSMonitor, self).__init__()
+        super(GPSMonitor, self).__init__(["satellites"])
 
         self.gps = gps
         self.gps_ubx = gps.gps_ubx
@@ -69,10 +69,10 @@ class GPSMonitor(zavai.Service):
 
     def on_ubxdebug_packet(self, clid, length, data):
         zavai.info("gps monitor: UBX debug packet")
-        self.notify(clid, length, data)
+        self.notify("satellites", clid, length, data)
 
     def start(self):
-        self.gps.request(self)
+        self.gps.connect("gps", self)
         # TODO: find out how come sometimes these events are not sent
         self.gps.bus.add_signal_receiver(
             self.on_satellites_changed, 'SatellitesChanged', 'org.freedesktop.Gypsy.Satellite',
@@ -89,19 +89,20 @@ class GPSMonitor(zavai.Service):
         self.gps.bus.remove_signal_receiver(
             self.on_ubxdebug_packet, 'DebugPacket', 'org.freesmartphone.GPS.UBX',
             'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
-        self.gps.release(self)
+        self.gps.disconnect("gps", self)
 
 
 class GPSPosition(zavai.Service):
     def __init__(self, gps):
+        super(GPSPosition, self).__init__(["position"])
         self.gps = gps
 
     def on_position_changed(self, fields, tstamp, lat, lon, alt):
         zavai.info("gps position: position changed")
-        self.notify(fields, tstamp, lat, lon, alt)
+        self.notify("position", fields, tstamp, lat, lon, alt)
 
     def start(self):
-        self.gps.request(self)
+        self.gps.connect("gps", self)
         self.gps.bus.add_signal_receiver(
             self.on_position_changed, 'PositionChanged', 'org.freedesktop.Gypsy.Position',
             'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
@@ -110,12 +111,12 @@ class GPSPosition(zavai.Service):
         self.gps.bus.remove_signal_receiver(
             self.on_position_changed, 'PositionChanged', 'org.freedesktop.Gypsy.Position',
             'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
-        self.gps.release(self)
+        self.gps.disconnect("gps", self)
 
 # For a list of dbus services, look in /etc/dbus-1/system.d/
 class GPS(zavai.Service):
     def __init__(self, registry, name):
-        super(GPS, self).__init__()
+        super(GPS, self).__init__(["gps"])
 
         self.bus = registry.resource("dbus.system_bus")
 
@@ -199,6 +200,7 @@ class GPS(zavai.Service):
 class GPX(zavai.Service):
     "Write GPX track and waypoint files"
     def __init__(self, registry, name):
+        super(GPX, self).__init__(["gpx"])
         self.registry = registry
         self.trk = None
         self.wpt = None
@@ -223,13 +225,13 @@ class GPX(zavai.Service):
         zavai.info("Starting GPX trace subsystem")
         self.started = True
         gps = self.registry.resource("gps")
-        gps.position.connect(self.on_position_changed)
+        gps.position.connect("gps", self.on_position_changed)
 
     def stop(self):
         if not self.started: return
         zavai.info("Stopping GPX trace subsystem")
         gps = self.registry.resource("gps")
-        gps.position.disconnect(self.on_position_changed)
+        gps.position.disconnect("gps", self.on_position_changed)
         self.stop_track()
         self.started = False