agent server sample: un-comment autobahn and cloudeebus scripts inclusion
[contrib/cloudeebus.git] / doc / agent / server.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <!-- Do not load autobahn or cloudeebus if already provided by Crosswalk browser extensions. -->
5         <script type="text/javascript">
6           typeof cloudeebus != 'undefined' ||
7           document.write(unescape('%3Cscript src=%27../../lib/autobahn.min.js%27%3E %3C/script%3E %3Cscript src=%27../../cloudeebus/cloudeebus.js%27%3E%3C/script%3E'));
8         </script>
9         <script type="text/javascript">
10                 function evalScript(field) {
11                         eval(
12                                 "var lambda = function() {" +
13                                         document.getElementById(field).value +
14                                 "};" + 
15                                 "lambda();"
16                         );
17                 }
18         </script>
19     </head>
20    <body>
21         <center><h1>cloudeebus</h1></center>
22         <br>
23                 <textarea style="width:80%" rows="32" id="script">
24 var manifest = {
25         name: "cloudeebus",
26         key: "secret",
27         services: [
28                 "org.cloudeebus.Sample"
29         ]
30 };
31
32
33 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="Add"><arg type="i" name="arg1"/><arg type="i" name="arg2"/><arg type="i" name="result" direction="out"/></method><method name="Div"><arg type="d" name="arg1"/><arg type="d" name="arg2"/><arg type="d" 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></node>';
34
35 cloudeebus.log = function(msg) {
36   document.getElementById("log").innerHTML += msg + "\n";
37 }
38
39 function logCB(result) {
40   cloudeebus.log(JSON.stringify(result));
41 }
42
43 function errorCB(error) {
44   cloudeebus.log(cloudeebus.getError(error));
45 }
46
47 sampleObjectHandler = {
48   Add: function(a,b) {
49     cloudeebus.log("Add " + a + " + " + b);
50     this.ResultChanged(a+b);
51     return a+b;
52   }, 
53   Variant: function(a) {
54     cloudeebus.log("Get and return :" + JSON.stringify(a));
55     return a;
56   }, 
57   Div: function(a,b) {
58     cloudeebus.log("Div " + a + " / " + b);
59         this.ResultChanged(a/b);
60     return a/b;
61   }
62 };
63
64 function addAgent(service) {
65   window.gService = service;
66   var agent = new cloudeebus.Agent("/org/cloudeebus/Sample", sampleObjectHandler, sampleXml);
67   cloudeebus.log("Adding agent " + agent.objectPath + " on " + service.name + ", mapped on Javascript object: 'sampleObjectHandler");
68   service.addAgent(agent).then(logCB, errorCB);
69   window.gAgent = agent;
70 }
71
72 function connectSuccess() {
73   cloudeebus.SessionBus().addService("org.cloudeebus.Sample").then(addAgent, errorCB);
74 }
75
76 if (!window.gService)
77   cloudeebus.connect("ws://localhost:9003", manifest, connectSuccess, errorCB);
78 </textarea>
79                 <br>
80 -               <input type="button" value="run script" onclick="evalScript('script')"/>
81                 <input type="button" value="clear log" onclick="document.getElementById('log').innerHTML='';"/>
82                 <br>
83 <textarea style="width:80%" rows="7" id="removeCmd">
84 function removeService() {
85         window.gService.remove();
86     cloudeebus.log("Service removed");
87         window.gService = null;
88 }
89
90 window.gService.removeAgent(window.gAgent).then(removeService, null);
91 </textarea>
92                 <br>
93                 <input type="button" value="Unregister service" onclick="evalScript('removeCmd')"/>
94                 <br>
95                 <pre id="log" style="height: 20em; overflow-x: auto; overflow-y: auto; background-color: #faa;"></pre>
96    </body>
97 </html>