DBus bridge: using new generated bridge
This commit is contained in:
parent
7cd5b2ee6f
commit
3baae43808
1 changed files with 18 additions and 13 deletions
|
|
@ -296,18 +296,18 @@ class DbusObject(dbus.service.Object):
|
|||
return self.cb["subscription"](unicode(sub_type), unicode(entity), unicode(profile_key))
|
||||
|
||||
|
||||
def __attribute_string(self, in_sign):
|
||||
def __attributes(self, in_sign):
|
||||
"""Return arguments to user given a in_sign
|
||||
@param in_sign: in_sign in the short form (using s,a,i,b etc)
|
||||
@return: list of arguments that correspond to a in_sign (e.g.: "sss" return "arg1, arg2, arg3")"""
|
||||
i=0
|
||||
idx=0
|
||||
attr_string=""
|
||||
attr=[]
|
||||
while i<len(in_sign):
|
||||
if in_sign[i] not in ['b','y','n','i','x','q','u','t','d','s','a']:
|
||||
raise ParseError("Unmanaged attribute type [%c]" % in_sign[i])
|
||||
|
||||
attr_string += ("" if idx==0 else ", ") + ("arg_%i" % idx)
|
||||
attr.append("arg_%i" % idx)
|
||||
idx+=1
|
||||
|
||||
if in_sign[i] == 'a':
|
||||
|
|
@ -330,26 +330,31 @@ class DbusObject(dbus.service.Object):
|
|||
if opening_count == 0:
|
||||
break
|
||||
i+=1
|
||||
return attr_string
|
||||
return attr
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, doc={}):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, async=False, doc={}):
|
||||
"""Dynamically add a method to Dbus Bridge"""
|
||||
#FIXME: Better way ???
|
||||
attributes = self.__attribute_string(in_sign)
|
||||
_attributes = self.__attributes(in_sign)
|
||||
|
||||
if async:
|
||||
_attributes.extend(['callback','errback'])
|
||||
|
||||
attributes = ', '.join(_attributes)
|
||||
|
||||
code = compile ('def '+name+' (self,'+attributes+'): return self.cb["'+name+'"]('+attributes+')', '<DBus bridge>','exec')
|
||||
exec (code)
|
||||
method = locals()[name]
|
||||
async_callbacks = ('callback', 'errback') if async else None
|
||||
setattr(DbusObject, name, dbus.service.method(
|
||||
const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign)(method))
|
||||
const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign,
|
||||
async_callbacks=async_callbacks)(method))
|
||||
function = getattr(self, name)
|
||||
func_table = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__][function._dbus_interface]
|
||||
func_table[function.__name__] = function #Needed for introspection
|
||||
|
||||
def addSignal(self, name, int_suffix, signature, doc={}):
|
||||
"""Dynamically add a signal to Dbus Bridge"""
|
||||
#FIXME: Better way ???
|
||||
attributes = self.__attribute_string(signature)
|
||||
attributes = ', '.join(self.__attributes(signature))
|
||||
|
||||
code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '<DBus bridge>','exec')
|
||||
exec (code)
|
||||
|
|
@ -416,12 +421,12 @@ class DBusBridge(Bridge):
|
|||
debug("registering DBus bridge method [%s]", name)
|
||||
self.dbus_bridge.register(name, callback)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, doc={}):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}):
|
||||
"""Dynamically add a method to Dbus Bridge"""
|
||||
print ("Adding method [%s] to DBus bridge" % name)
|
||||
self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign)
|
||||
self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, async, doc)
|
||||
self.register(name, method)
|
||||
|
||||
def addSignal(self, name, int_suffix, signature, doc={}):
|
||||
self.dbus_bridge.addSignal(name, int_suffix, signature)
|
||||
self.dbus_bridge.addSignal(name, int_suffix, signature, doc)
|
||||
setattr(DBusBridge, name, getattr(self.dbus_bridge, name))
|
||||
|
|
|
|||
Loading…
Reference in a new issue