Dynamic signal addition in bridge
- DBus: new addSignal method - plugins XEP-0045: roomJoined is now a dynamically added signal
This commit is contained in:
parent
724a97b14d
commit
af23265ee0
2 changed files with 20 additions and 6 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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")', '<DBus bridge>','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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue