# HG changeset patch # User Goffi # Date 1269228117 -39600 # Node ID 9d113b5471e6c49716d088c7da3525dc7409fd57 # Parent f271fff3a713a0963e1f349d4e0d304b3e498560 Dynamic signal addition in bridge - DBus: new addSignal method - plugins XEP-0045: roomJoined is now a dynamically added signal diff -r f271fff3a713 -r 9d113b5471e6 plugins/plugin_xep_0045.py --- a/plugins/plugin_xep_0045.py Sun Mar 21 10:28:55 2010 +1100 +++ b/plugins/plugin_xep_0045.py Mon Mar 22 14:21:57 2010 +1100 @@ -69,6 +69,7 @@ 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 -r f271fff3a713 -r 9d113b5471e6 sat_bridge/DBus.py --- a/sat_bridge/DBus.py Sun Mar 21 10:28:55 2010 +1100 +++ b/sat_bridge/DBus.py Mon Mar 22 14:21:57 2010 +1100 @@ -69,11 +69,6 @@ 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): debug("subscribe (type: [%s] from:[%s] profile:[%s])" , type, entity, profile) @@ -265,7 +260,11 @@ 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 @@ 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 @@ 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) +