From af23265ee0fe6660d44e910748e3a0130758d7b4 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 22 Mar 2010 14:21:57 +1100 Subject: [PATCH] Dynamic signal addition in bridge - DBus: new addSignal method - plugins XEP-0045: roomJoined is now a dynamically added signal --- plugins/plugin_xep_0045.py | 1 + sat_bridge/DBus.py | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/plugins/plugin_xep_0045.py b/plugins/plugin_xep_0045.py index fbce342c..640a8787 100755 --- a/plugins/plugin_xep_0045.py +++ b/plugins/plugin_xep_0045.py @@ -69,6 +69,7 @@ class XEP_0045(): self.host = host self.clients={} host.bridge.addMethod("joinMUC", ".communication", in_sign='ssss', out_sign='', method=self.join) + host.bridge.addSignal("roomJoined", ".communication", signature='ssasss') #args: room_id, room_service, room_nicks, user_nick, profile def __check_profile(self, profile): if not profile or not self.clients.has_key(profile) or not self.host.isConnected(profile): diff --git a/sat_bridge/DBus.py b/sat_bridge/DBus.py index b7f228be..c74c55af 100755 --- a/sat_bridge/DBus.py +++ b/sat_bridge/DBus.py @@ -68,11 +68,6 @@ class DbusObject(dbus.service.Object): def presenceUpdate(self, entity, show, priority, statuses, profile): debug("presence update signal (from:%s show:%s priority:%d statuses:%s profile:%s) sended" , entity, show, priority, statuses, profile) - @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, - signature='ssasss') - def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile): - debug("room joined signal: id:%(room_id)s service:%(room_service)s nicks:%(room_nicks)s user:%(user_nick)s profile=%(profile)s" % {'room_id':room_id, 'room_service':room_service, 'room_nicks':room_nicks, 'user_nick':user_nick, 'profile':profile}) - @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, signature='sss') def subscribe(self, type, entity, profile): @@ -265,7 +260,11 @@ class DbusObject(dbus.service.Object): idx+=1 if in_sign[i] == 'a': - while (True): + i+=1 + if in_sign[i]!='{' and in_sign[i]!='(': #FIXME: gof: must manage tuples out of arrays + i+=1 + continue #we have a simple type for the array + while (True): #we have a dict or a list of tuples i+=1 if i>=len(in_sign): raise Exception #FIXME: create an exception here (the '}' is not presend) @@ -286,6 +285,17 @@ class DbusObject(dbus.service.Object): method = locals()[name] setattr(DbusObject, name, dbus.service.method( const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign)(method)) + + def addSignal(self, name, int_suffix, signature): + """Dynamically add a signal to Dbus Bridge""" + #FIXME: Better way ??? + attributes = self.__attribute_string(signature) + + code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '','exec') + exec (code) + signal = locals()[name] + setattr(DbusObject, name, dbus.service.signal( + const_INT_PREFIX+int_suffix, signature=signature)(signal)) class DBusBridge(Bridge): def __init__(self): @@ -350,3 +360,6 @@ class DBusBridge(Bridge): self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign) self.register(name, method) + def addSignal(self, name, int_suffix, signature): + self.dbus_bridge.addSignal(name, int_suffix, signature) +