+ signalName = list[1]
+ result = list[2]
+ if (self.serviceAgents.has_key(className) == True):
+ exe_str = "self.serviceAgents['"+ className +"']."+ signalName + "(" + str(result) + ")"
+ eval(exe_str, self.globalCtx, self.localCtx)
+ else:
+ raise Exception("No object path " + objectPath)
+
+ @exportRpc
+ def returnMethod(self, list):
+ '''
+ arguments: methodId, callIndex, success (=true, error otherwise), result (to return)
+ '''
+ methodId = list[0]
+ callIndex = list[1]
+ success = list[2]
+ result = list[3]
+ if (self.servicePendingCalls.has_key(methodId)):
+ cb = self.servicePendingCalls[methodId]['calls'][callIndex]
+ if cb is None:
+ raise Exception("No pending call " + str(callIndex) + " for methodID " + methodId)
+ if (success):
+ successCB = cb["successCB"]
+ if (result != None):
+ successCB(result)
+ else:
+ successCB()
+ else:
+ errorCB = cb["errorCB"]
+ if (result != None):
+ errorCB(result)
+ else:
+ errorCB()
+ self.servicePendingCalls[methodId]['calls'][callIndex] = None
+ self.servicePendingCalls[methodId]['count'] = self.servicePendingCalls[methodId]['count'] - 1
+ if self.servicePendingCalls[methodId]['count'] == 0:
+ del self.servicePendingCalls[methodId]
+ else:
+ raise Exception("No methodID " + methodId)
+
+ def srvCB(self, name, objPath, ifName, async_succes_cb, async_error_cb, *args):
+ methodId = self.srvName + "#" + objPath + "#" + ifName + "#" + name
+ cb = { 'successCB': async_succes_cb,
+ 'errorCB': async_error_cb}
+ if methodId not in self.servicePendingCalls:
+ self.servicePendingCalls[methodId] = {'count': 0, 'calls': []}
+
+ try:
+ pendingCallStr = json.dumps({'callIndex': len(self.servicePendingCalls[methodId]['calls']), 'args': args})
+ except Exception, e:
+ args = eval( str(args).replace("dbus.Byte", "dbus.Int16") )
+ pendingCallStr = json.dumps({'callIndex': len(self.servicePendingCalls[methodId]['calls']), 'args': args})
+
+ self.servicePendingCalls[methodId]['calls'].append(cb)
+ self.servicePendingCalls[methodId]['count'] = self.servicePendingCalls[methodId]['count'] + 1
+ factory.dispatch(methodId, pendingCallStr)
+
+ @exportRpc
+ def serviceAdd(self, list):
+ '''
+ arguments: busName, srvName
+ '''
+ busName = list[0]
+ self.bus = cache.dbusConnexion( busName )
+ self.srvName = list[1]
+ if not OPENDOOR and (SERVICELIST == [] or SERVICELIST != [] and self.permissions['services'] == None):
+ SERVICELIST.index(self.srvName)
+
+ if (self.services.has_key(self.srvName) == False):
+ self.services[self.srvName] = dbus.service.BusName(name = self.srvName, bus = self.bus)
+ return self.srvName
+
+ @exportRpc
+ def serviceRelease(self, list):
+ '''
+ arguments: busName, srvName
+ '''
+ self.srvName = list[0]
+ if (self.services.has_key(self.srvName) == True):
+ self.services.pop(self.srvName)
+ return self.srvName
+ else:
+ raise Exception(self.srvName + " does not exist")
+
+ @exportRpc
+ def serviceAddAgent(self, list):
+ '''
+ arguments: objectPath, xmlTemplate
+ '''
+ self.agentObjectPath = list[0]
+ xmlTemplate = list[1]
+ className = createClassName(self.agentObjectPath)
+ if (self.dynDBusClasses.has_key(className) == False):
+ self.dynDBusClasses[className] = DynDBusClass(className, self.globalCtx, self.localCtx)
+ self.dynDBusClasses[className].createDBusServiceFromXML(xmlTemplate)
+ self.dynDBusClasses[className].declare()
+
+ ## Class already exist, instanciate it if not already instanciated
+ if (self.serviceAgents.has_key(className) == False):
+ self.serviceAgents[className] = eval(className + "(self.bus, callback=self.srvCB, objPath=self.agentObjectPath, busName=self.srvName)", self.globalCtx, self.localCtx)
+
+ self.serviceAgents[className].add_to_connection()
+ return (self.agentObjectPath)
+
+ @exportRpc
+ def serviceDelAgent(self, list):
+ '''
+ arguments: objectPath, xmlTemplate
+ '''
+ agentObjectPath = list[0]
+ className = createClassName(agentObjectPath)
+
+ print 'PY Try to remove ' + className
+
+ if (self.serviceAgents.has_key(className)):
+ self.serviceAgents[className].remove_from_connection()
+ self.serviceAgents.pop(className)
+ else:
+ raise Exception(agentObjectPath + " doesn't exist!")
+
+ return (agentObjectPath)