agent client/server doc: create a service, delete it on method call
[contrib/cloudeebus.git] / doc / agent / server.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <script src="../../lib/autobahn.min.js"></script>
5         <script src="../../cloudeebus/cloudeebus.js"></script>
6         <script type="text/javascript">
7                 function evalScript() {
8                         eval(
9                                 "var lambda = function() {" +
10                                         document.getElementById('script').value +
11                                 "};" + 
12                                 "lambda();"
13                         );
14                 }
15         </script>
16     </head>
17    <body>
18         <center><h1>cloudeebus</h1></center>
19         <br>
20                 <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></interface></node>';
21 cloudeebus.log = function(msg) {
22   document.getElementById("log").innerHTML += msg + "\n";
23 }
24
25 function logCB(result) {
26   cloudeebus.log(JSON.stringify(result));
27 }
28
29 function errorCB(error) {
30   cloudeebus.log(error.desc ? error.desc : error);
31 }
32
33 function releaseCalled() {
34   cloudeebus.log("Release method called");
35   cloudeebus.SessionBus().service.returnMethod("org.cloudeebus.Sample#/org/cloudeebus/Sample#Release", true, null);
36   cloudeebus.SessionBus().service.delAgent("/org/cloudeebus/Sample", logCB, errorCB);
37   cloudeebus.SessionBus().service.remove(logCB, errorCB);
38 }
39
40 function serviceAdded(servName) {
41   cloudeebus.SessionBus().service.registerMethod("org.cloudeebus.Sample#/org/cloudeebus/Sample#Release",releaseCalled);
42   cloudeebus.SessionBus().service.addAgent("/org/cloudeebus/Sample", sampleXml, logCB, errorCB);
43 }
44
45 function connectSuccess() {
46   cloudeebus.SessionBus().addService("org.cloudeebus.Sample", serviceAdded, errorCB);
47 }
48
49 cloudeebus.connect("ws://localhost:9003", null, connectSuccess, errorCB);
50 </textarea>
51                 <br>
52                 <input type="button" value="run script" onclick="evalScript()"/>
53                 <input type="button" value="clear log" onclick="document.getElementById('log').innerHTML='';"/>
54                 <br>
55                 <pre id="log" style="height: 20em; overflow-x: auto; overflow-y: auto; background-color: #faa;"></pre>
56    </body>
57 </html>