Add sample with variant (dictionary which is an array of string/variant)
authorFrederic PAUT <frederic.paut@linux.intel.com>
Thu, 16 May 2013 15:12:57 +0000 (17:12 +0200)
committerFrederic PAUT <frederic.paut@linux.intel.com>
Thu, 16 May 2013 15:12:57 +0000 (17:12 +0200)
note: for now, the variant could no be null nor an empty list

doc/agent/client.html
doc/agent/server.html

index 1b9b8a3..f87c484 100644 (file)
@@ -40,8 +40,20 @@ function errorCB(error) {
   cloudeebus.log(error.desc ? error.desc : error);
 }
 
+function gotDictResult(result) {
+  cloudeebus.log("gotDictResult: " + JSON.stringify(result));
+  cloudeebus.log("Name: " + result.Name);
+}
+
 function gotDivResult(result) {
   cloudeebus.log("gotDivResult: " + result);
+  var dictionary = {Name: "Mickey",
+                                Sisters: [""], 
+                                Married: true,
+                                Divorced: 0,
+                                Friends: ["Donald", "Dingo"],
+                                Others: [""]};
+  sampleProxy.Variant(dictionary,gotDictResult,errorCB);  
 //  sampleProxy.Release();
 }
 
@@ -56,12 +68,20 @@ function signalHandler(result) {
 }
 
 function gotProxy(proxy) {
-  logCB(proxy);
-  proxy.connectToSignal("org.cloudeebus.Sample1", "ResultChanged", signalHandler);
-  logCB('Addition');
-  for (var i=-10; i<10; i++)
-    proxy.Add(i,i*2,gotAddResult,errorCB);
-  sampleProxy = proxy;
+       sampleProxy = proxy;
+   logCB(sampleProxy);
+  if (0) {
+    proxy.Release();
+    return;
+   } else {
+         proxy.connectToSignal("org.cloudeebus.Sample1", "ResultChanged", signalHandler);
+         logCB('Addition');
+           proxy.Add(4,5,gotAddResult,errorCB);
+           return;
+         
+         for (var i=-10; i<10; i++)
+           proxy.Add(i,i*2,gotAddResult,errorCB);
+  }
   
 }
 
index 4351c27..849d1d2 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.Sample1"><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><method name="Variant"><arg type="d" name="arg1"/><arg type="d" name="result" direction="out"/></method><signal name="ResultChanged"><arg type="d" name="result"/></signal></interface><interface name="org.cloudeebus.Sample2"><method name="Div"><arg type="d" name="arg1"/><arg type="d" name="arg2"/><arg type="d" 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.Sample1"><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><method name="Variant"><arg type="a{sv}" name="arg1"/><arg type="a{sv}" name="result" direction="out"/></method><signal name="ResultChanged"><arg type="v" name="result"/></signal></interface><interface name="org.cloudeebus.Sample2"><method name="Div"><arg type="d" name="arg1"/><arg type="d" name="arg2"/><arg type="d" name="result" direction="out"/></method></interface></node>';
 cloudeebus.log = function(msg) {
   document.getElementById("log").innerHTML += msg + "\n";
 }
@@ -32,10 +32,12 @@ function errorCB(error) {
 
 sampleObjectHandler = {
   Add: function(a,b) {
+    cloudeebus.log("Add " + a + " + " + b);
     this.ResultChanged(a+b);
     return a+b;
   }, 
   Variant: function(a) {
+    cloudeebus.log("Get and return :" + JSON.stringify(a));
     return a;
   }, 
   Release: function() {
@@ -45,6 +47,7 @@ sampleObjectHandler = {
   interfaceProxies : {
     "org.cloudeebus.Sample2" : {
       Div: function(a,b) {
+        cloudeebus.log("Div " + a + " / " + b);
        this.ResultChanged(a/b);
         return a/b;
       }