improve dbus api
authorHelmut Grohne <helmut@subdivi.de>
Sun, 16 Jun 2013 21:51:09 +0000 (23:51 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Sun, 16 Jun 2013 21:51:09 +0000 (23:51 +0200)
 * rename state signal to changestate
 * provide a state method returning the current state

dbus_client.py
dbus_service.py

index 1ad846f..2af2a77 100755 (executable)
@@ -32,14 +32,14 @@ def main():
         s2.close()
         if st != ST_ACTIVE:
             print("state is %d waiting for signal" % st)
-            st = wait_for_signal(proxy, "state")
+            st = wait_for_signal(proxy, "changestate")
             print("new state is %d" % st)
         os.execvp(sys.argv[1], sys.argv[1:])
     else:
         st = proxy.activatetime(10)
         if st != ST_ACTIVE:
             print("state is %d waiting for signal" % st)
-            st = wait_for_signal(proxy, "state")
+            st = wait_for_signal(proxy, "changestate")
             print("new state is %d" % st)
 
 if __name__ == "__main__":
index a00b0df..7bb0b37 100755 (executable)
@@ -20,10 +20,14 @@ class OnoffControl(dbus.service.Object):
         self.curstate = 0 # empty bitmask
 
     @dbus.service.signal(domain, signature="q")
-    def state(self, st):
+    def changestate(self, st):
         print("emitting state %d" % st)
         self.curstate = st
 
+    @dbus.service.method(domain, out_signature="q")
+    def state(self):
+        return self.curstate
+
     @dbus.service.method(domain, in_signature="q", out_signature="q")
     def activatetime(self, duration):
         print("called with duration %d" % duration)
@@ -31,9 +35,9 @@ class OnoffControl(dbus.service.Object):
         GObject.timeout_add(duration * 1000, self.unuse)
         if self.usecount > 1:
             return self.curstate
-        self.state(ST_ACTIVE|ST_TRANSITION)
+        self.changestate(ST_ACTIVE|ST_TRANSITION)
         def finish():
-            self.state(ST_ACTIVE)
+            self.changestate(ST_ACTIVE)
         GObject.timeout_add(200, finish)
         return self.curstate
 
@@ -48,13 +52,13 @@ class OnoffControl(dbus.service.Object):
             GObject.timeout_add(duration * 1000, self.unuse)
             return False
         GObject.io_add_watch(fd, GObject.IO_HUP|GObject.IO_ERR, callback)
-        self.state(ST_ACTIVE)
+        self.changestate(ST_ACTIVE)
         return self.curstate
 
     def unuse(self):
         self.usecount -= 1
         if not self.usecount:
-            self.state(0)
+            self.changestate(0)
         else:
             print("%d users left" % self.usecount)
         return False