adding signal emission
authorFrederic PAUT <frederic.paut@linux.intel.com>
Thu, 28 Mar 2013 11:57:30 +0000 (12:57 +0100)
committerFrederic PAUT <frederic.paut@linux.intel.com>
Thu, 28 Mar 2013 11:57:30 +0000 (12:57 +0100)
cloudeebus/cloudeebus.js
cloudeebus/cloudeebus.py
doc/agent/client.html
doc/agent/server.html

index 6c01414..7e9d55c 100644 (file)
@@ -270,6 +270,16 @@ cloudeebus.Service.prototype.returnMethod = function(methodId, callIndex, succes
        this.wampSession.call("returnMethod", arglist).then(successCB, errorCB);
 };
 
+cloudeebus.Service.prototype.emitSignal = function(objectPath, signalName, result, successCB, errorCB) {
+       var arglist = [
+           objectPath,
+           signalName,
+           result
+           ];
+
+       this.wampSession.call("emitSignal", arglist).then(successCB, errorCB);
+};
+
 
 /*****************************************************************************/
 
index 2a75452..0f85747 100755 (executable)
@@ -229,6 +229,8 @@ class XmlCbParser: # The target object of the parser
                                                 attrib['type'])
                 return
             if (self.current == 'signal'):
+                if (attrib.has_key('name') == False):
+                    attrib['name'] = 'value'
                 self.dynDBusClass.add_signature(attrib['name'], 'in',
                                                 attrib['type'])
                 return
@@ -488,6 +490,21 @@ class CloudeebusService:
 
 
     @exportRpc
+    def emitSignal(self, list):
+        '''
+        arguments: agentObjectPath, signalName, result (to emit)
+        '''
+        objectPath = list[0]
+        className = re.sub('/', '_', objectPath[1:])
+        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)
index 977e84c..c4afa73 100644 (file)
@@ -45,11 +45,17 @@ function gotAddResult(aSum) {
 //  sampleProxy.Release();
 }
 
+function signalHandler(aSum) {
+  cloudeebus.log("signal 'ResultChanged': " + aSum);
+}
+
 function gotProxy(proxy) {
   logCB(proxy);
   for (var i=-10; i<10; i++)
     proxy.Add(i,i*2,gotAddResult,errorCB);
   sampleProxy = proxy;
+  sampleProxy.connectToSignal("org.cloudeebus.Sample", "ResultChanged", signalHandler);
+  
 }
 
 function connectSuccess() {
index d39022f..3d5e554 100644 (file)
@@ -17,7 +17,7 @@
    <body>
         <center><h1>cloudeebus</h1></center>
         <br>
-               <textarea style="width:80%" rows="32" id="script">var sampleXml= '<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"\n"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">\n<node><interface name="org.cloudeebus.Sample"><method name="Release"></method><method name="Add"><arg type="i" name="arg1"/><arg type="i" name="arg2"/><arg type="i" name="result" direction="out"/></method></interface></node>';
+               <textarea style="width:80%" rows="32" id="script">var sampleXml= '<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"\n"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">\n<node><interface name="org.cloudeebus.Sample"><method name="Release"></method><method name="Add"><arg type="i" name="arg1"/><arg type="i" name="arg2"/><arg type="i" name="result" direction="out"/></method><signal name="ResultChanged"><arg type="i" name="result"/></signal></interface></node>';
 cloudeebus.log = function(msg) {
   document.getElementById("log").innerHTML += msg + "\n";
 }
@@ -32,10 +32,14 @@ function errorCB(error) {
 
 function addCalled(args) {
   var methodId = arguments[0];
+  var objPath = methodId.split("#")[1];
   var callDict = JSON.parse(arguments[1]);
   cloudeebus.log("Method called: " + methodId);
-  cloudeebus.log("Add: " + callDict.args[0] + " + " + callDict.args[1] + " = " + (callDict.args[0] + callDict.args[1]));
-  cloudeebus.SessionBus().service.returnMethod(methodId, callDict.callIndex, true, callDict.args[0] + callDict.args[1]);
+  result = callDict.args[0] + callDict.args[1];
+  cloudeebus.log("Add: " + callDict.args[0] + " + " + callDict.args[1] + " = " + result);
+  cloudeebus.SessionBus().service.returnMethod(methodId, callDict.callIndex, true, result);
+  cloudeebus.log("Emit signal 'ResultChanged' with value " + result);
+  cloudeebus.SessionBus().service.emitSignal(objPath, "ResultChanged", result);
 }
 
 function releaseCalled() {