summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2010-05-26 20:11:04 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2010-06-03 17:08:09 +0200
commit98dc57df83f315e1dc5a7f8d8577f920d89761d6 (patch)
tree740542b9f8560c0646c6852b3aa0ed18d3e0eede
parentc300e4f566602b1569372003f4ceaa9953b0f06f (diff)
downloadjson-dbus-bridge-98dc57df83f315e1dc5a7f8d8577f920d89761d6.tar.gz
json-dbus-bridge-98dc57df83f315e1dc5a7f8d8577f920d89761d6.tar.xz
[html] demo first steps
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r--demo/Makefile.am2
-rw-r--r--demo/helper.js24
-rw-r--r--demo/index.html88
3 files changed, 114 insertions, 0 deletions
diff --git a/demo/Makefile.am b/demo/Makefile.am
index 76b1e68..364b895 100644
--- a/demo/Makefile.am
+++ b/demo/Makefile.am
@@ -7,5 +7,7 @@ MAINTAINERCLEANFILES = \
EXTRA_DIST = \
dbus-python-service.py \
+ helper.js \
+ index.html \
simple-test.sh
diff --git a/demo/helper.js b/demo/helper.js
new file mode 100644
index 0000000..cd3c226
--- /dev/null
+++ b/demo/helper.js
@@ -0,0 +1,24 @@
+
+function Rpc(url, service) {
+ this.url = url;
+ this.service = service;
+ this.id = 0;
+ this.callAsync = function(method, data, dataFunc, errFunc) {
+ this.id = this.id+1;
+ var d = {
+ "service": this.service,
+ "method": method,
+ "id": this.id,
+ "params": data
+ };
+ var ds = JSON.stringify(d);
+ $.post(this.url, ds, function(data) {
+ if (data.error == null)
+ dataFunc(data.id, data.result);
+ else if (errFunc)
+ errFunc(data.id, data.error);
+ }, "json");
+ return this.id;
+ }
+}
+
diff --git a/demo/index.html b/demo/index.html
new file mode 100644
index 0000000..00847d9
--- /dev/null
+++ b/demo/index.html
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <style>img{ height: 100px; float: left; }</style>
+ <script src="http://code.jquery.com/jquery-latest.min.js"></script>
+ <script src="helper.js"></script>
+</head>
+<body>
+
+<table border="1" cellpadding="5">
+<tr><th>function</th><th>send</th><th>receive</><tr>
+<tr><td>com.pengutronix.devel.SystemInfo.Ping</td><td id="echo-send">foobar</td><td id="echo-receive"></td></tr>
+<tr><td>com.pengutronix.devel.SystemInfo.Date</td><td id="date-send"></td><td id="date-receive"></td></tr>
+<tr><td>org.freedesktop.DBus.Introspectable.Introspect</td><td id="introspect-send"></td><td id="introspect-receive"></td></tr>
+<tr><td>com.pengutronix.devel.Data.Dump</td><td id="dump-send"></td><td id="dump-receive"></td></tr>
+</table>
+
+<script>
+var rpc = new Rpc("http://localhost:8080/rpc","com.pengutronix.devel.simpleinfo|/");
+
+rpc.callAsync(
+ "com.pengutronix.devel.SystemInfo.Ping",
+ ["s", $('#echo-send').text()],
+ function(id, data){
+ $('#echo-receive').html(data)
+ });
+
+window.setInterval('tick()', 1000);
+
+function tick() {
+ rpc.callAsync(
+ "com.pengutronix.devel.SystemInfo.Date",
+ [],
+ function(id, data){
+ var d = new Date(data*1000);
+ $('#date-receive').html(d.toString())
+ });
+}
+
+rpc.callAsync(
+ "org.freedesktop.DBus.Introspectable.Introspect",
+ [],
+ function(id, data){
+ var parser = new DOMParser();
+ var doc = parser.parseFromString(data, "text/xml");
+ var txt = "";
+ var ifaces = doc.getElementsByTagName("interface");
+ for (var i = 0; i < ifaces.length; i++) {
+ var iface = ifaces[i].getAttribute("name")
+ var methods = ifaces[i].getElementsByTagName("method");
+ for (var j = 0; j < methods.length; j++) {
+ txt += iface + "." + methods[j].getAttribute("name") + "<br/>";
+ }
+ txt += "<br/>";
+ }
+ $('#introspect-receive').html(txt);
+ });
+
+var rpc2 = new Rpc("http://localhost:8080/rpc","com.pengutronix.devel.demo1|/");
+
+rpc2.callAsync(
+ "com.pengutronix.devel.Data.Dump",
+ [],
+ function(id, data){
+ var table = document.createElement("table");
+ table.setAttribute("border", "1");
+ table.setAttribute("cellpadding", "2");
+ for (var key in data) {
+ var row = document.createElement("tr");
+ var cell = document.createElement("td");
+ cell.appendChild(document.createTextNode(key));
+ row.appendChild(cell);
+ var ll = data[key];
+ for (var i = 0; i < ll.length; i++) {
+ var cell = document.createElement("td");
+ cell.appendChild(document.createTextNode(String(ll[i])));
+ row.appendChild(cell);
+ }
+ table.appendChild(row);
+ }
+ $('#dump-receive').append(table);
+ var x = $('#dump-receive');
+ });
+
+
+</script>
+</body>
+</html>