Refactor source tree and add packaging
authorChristophe Guiraud <christophe.guiraud@linux.intel.com>
Thu, 23 Aug 2012 11:59:31 +0000 (13:59 +0200)
committerChristophe Guiraud <christophe.guiraud@linux.intel.com>
Thu, 23 Aug 2012 12:12:26 +0000 (14:12 +0200)
19 files changed:
.gitignore [new file with mode: 0644]
AUTHORS [new file with mode: 0644]
README [deleted file]
README.md [new file with mode: 0644]
TODO
cloudeebus/__init__.py [new file with mode: 0644]
cloudeebus/cloudeebus.py [moved from cloudeebus/server.py with 75% similarity]
dbus-tools/autobahn.min.js [deleted file]
dbus-tools/dbus-register.html [deleted file]
dbus-tools/dbus-register.js [deleted file]
dbus-tools/dbus-register.py [deleted file]
dbus-tools/dbus-send.html [deleted file]
dbus-tools/dbus-send.js [deleted file]
dbus-tools/dbus-send.py [deleted file]
doc/dbus-tools/dbus-register.html [new file with mode: 0644]
doc/dbus-tools/dbus-send.html [new file with mode: 0644]
doc/sample/cloudeebus.html [moved from doc/cloudeebus.html with 99% similarity]
lib/autobahn.min.js [moved from doc/autobahn.min.js with 100% similarity]
setup.py [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..4109c3f
--- /dev/null
@@ -0,0 +1,3 @@
+*~
+build
+dist
diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..f48e975
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+Luc Yriarte <luc.yriarte@intel.com>
+Christophe Guiraud <christophe.guiraud@intel.com>
diff --git a/README b/README
deleted file mode 100644 (file)
index 57e48e8..0000000
--- a/README
+++ /dev/null
@@ -1,16 +0,0 @@
-Abstract:
----------
-
-Cloudeebus is a component which enables calling dbus methods and registering on dbus signals from Javascript.
-
-
-Example:
---------
-
-The dbus-tools folder contains a dbus-send and a dbus-register server, with corresponding test pages.
-Running a demo:
-
-python dbus-tools/dbus-send.py &
-python dbus-tools/dbus-register.py &
-firefox file://`pwd`/dbus-tools/dbus-send.html  file://`pwd`/dbus-tools/dbus-register.html &
-
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..a352d39
--- /dev/null
+++ b/README.md
@@ -0,0 +1,25 @@
+
+Cloudeebus
+==========
+
+Cloudeebus is a component which enables calling dbus methods and registering on dbus signals from Javascript.
+
+
+Example:
+--------
+
+The /doc/dbus-tools folder contains a dbus-send and a dbus-register server, with corresponding test pages.
+
+ * Running a demo: from the project root directory
+
+       python cloudeebus/cloudeebus.py &
+       firefox file://`pwd`/doc/docdbus-tools/dbus-send.html  file://`pwd`/doc/dbus-tools/dbus-register.html &
+
+
+Acknowledgements
+----------------
+
+Cloudeebus uses code from the following open-source projects
+
+  * [AutobahnJS](http://autobahn.ws/js)
+  * [AutobahnPython](http://autobahn.ws/python)
diff --git a/TODO b/TODO
index 2006ca5..4f8673e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -24,9 +24,3 @@ Proxy object properties:
 - create properties at introspection if "org.freedesktop.DBus.Properties" interface available.
 - add "onPropertiesChanged(successCB)" method to automatically update properties.
 
-
-Source reorg:
--------------
-- dbus-tools: html only (send / register)
-- doc: sample page only, move autobahn to /lib
-- server.py: rename cloudeebus.py
diff --git a/cloudeebus/__init__.py b/cloudeebus/__init__.py
new file mode 100644 (file)
index 0000000..6bafab5
--- /dev/null
@@ -0,0 +1,19 @@
+# Cloudeebus
+#
+# Copyright (C) 2012 Intel Corporation. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Luc Yriarte <luc.yriarte@intel.com>
+# Christophe Guiraud <christophe.guiraud@intel.com>
+#
similarity index 75%
rename from cloudeebus/server.py
rename to cloudeebus/cloudeebus.py
index 18a9f6b..201a19e 100644 (file)
@@ -1,12 +1,12 @@
 ###############################################################################
 # Copyright 2012 Intel Corporation.
-# 
+#
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
-# 
+#
 # http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -97,89 +97,89 @@ class DbusCallHandler:
 class CloudeebusService:
     def __init__(self):
         # dbus connexions
-       self.dbusConnexions = {}
+       self.dbusConnexions = {}
         # proxy objects
         self.proxyObjects = {}
         # proxy methods
         self.proxyMethods = {}
-       # signal handlers
-       self.signalHandlers = {}
+       # signal handlers
+       self.signalHandlers = {}
         # pending dbus calls
         self.pendingCalls = []
 
 
     def dbusConnexion(self, busName):
-       if not self.dbusConnexions.has_key(busName):
-               if busName == "session":
-                       self.dbusConnexions[busName] = dbus.SessionBus()
-               elif busName == "system":
-                       self.dbusConnexions[busName] = dbus.SystemBus()
-               else:
-                       raise Exception("Error: invalid bus: %s" % busName)
-       return self.dbusConnexions[busName]
+       if not self.dbusConnexions.has_key(busName):
+               if busName == "session":
+                       self.dbusConnexions[busName] = dbus.SessionBus()
+               elif busName == "system":
+                       self.dbusConnexions[busName] = dbus.SystemBus()
+               else:
+                       raise Exception("Error: invalid bus: %s" % busName)
+       return self.dbusConnexions[busName]
 
 
     def proxyObject(self, bus, serviceName, objectName):
-       id = hashId([serviceName, objectName])
-       if not self.proxyObjects.has_key(id):
-               self.proxyObjects[id] = bus.get_object(serviceName, objectName)
-       return self.proxyObjects[id]
+       id = hashId([serviceName, objectName])
+       if not self.proxyObjects.has_key(id):
+               self.proxyObjects[id] = bus.get_object(serviceName, objectName)
+       return self.proxyObjects[id]
 
 
     def proxyMethod(self, bus, serviceName, objectName, interfaceName, methodName):
-       id = hashId([serviceName, objectName, interfaceName, methodName])
-       if not self.proxyMethods.has_key(id):
-               obj = self.proxyObject(bus, serviceName, objectName)
-               self.proxyMethods[id] = obj.get_dbus_method(methodName, interfaceName)
-       return self.proxyMethods[id]
+       id = hashId([serviceName, objectName, interfaceName, methodName])
+       if not self.proxyMethods.has_key(id):
+               obj = self.proxyObject(bus, serviceName, objectName)
+               self.proxyMethods[id] = obj.get_dbus_method(methodName, interfaceName)
+       return self.proxyMethods[id]
 
 
     @exportRpc
     def dbusRegister(self, list):
-       # read arguments list by position
+       # read arguments list by position
         if len(list) < 5:
-               raise Exception("Error: expected arguments: bus, sender, object, interface, signal)")
-        
-       # check if a handler exists
+               raise Exception("Error: expected arguments: bus, sender, object, interface, signal)")
+
+       # check if a handler exists
         sigId = hashId(list[1:5])
         if self.signalHandlers.has_key(sigId):
-               return sigId
-       
+               return sigId
+
         # get dbus connexion
         bus = self.dbusConnexion(list[0])
-        
+
         # get dbus proxy
         object = self.proxyObject(bus, list[1], list[2])
-        
+
         # create a handler that will publish the signal
         dbusSignalHandler = DbusSignalHandler(bus, object, *list[1:5])
         self.signalHandlers[sigId] = dbusSignalHandler
-        
+
         return dbusSignalHandler.id
 
 
     @exportRpc
     def dbusSend(self, list):
-       # clear pending calls
-       for call in self.pendingCalls:
-               if not call.pending:
-                       self.pendingCalls.remove(call)
-       
-       # read arguments list by position
+       # clear pending calls
+       for call in self.pendingCalls:
+               if not call.pending:
+                       self.pendingCalls.remove(call)
+
+       # read arguments list by position
         if len(list) < 5:
-               raise Exception("Error: expected arguments: bus, destination, object, interface, message, [args])")
-        
+               raise Exception("Error: expected arguments: bus, destination, object, interface, message, [args])")
+
         # get dbus connexion
         bus = self.dbusConnexion(list[0])
-        
+
         # parse JSON arg list
         args = []
         if len(list) == 6:
-               args = json.loads(list[5])
-        
+               args = json.loads(list[5])
+
         # get dbus proxy
         method = self.proxyMethod(bus, *list[1:5])
-        
+
         # use a deferred call handler to manage dbus results
         dbusCallHandler = DbusCallHandler(method, args)
         self.pendingCalls.append(dbusCallHandler)
@@ -188,15 +188,15 @@ class CloudeebusService:
 
     @exportRpc
     def listNames(self, list):
-       # read arguments list by position
-       if len(list) < 1:
-               raise Exception("Error: expected arguments: bus)")
-        
+       # read arguments list by position
+       if len(list) < 1:
+               raise Exception("Error: expected arguments: bus)")
+
         # get dbus connexion
         bus = self.dbusConnexion(list[0])
-        
+
         # return bus names as json array
-        return json.dumps(bus.list_names())    
+        return json.dumps(bus.list_names())
 
 
 
@@ -229,4 +229,3 @@ if __name__ == '__main__':
        DBusGMainLoop(set_as_default=True)
 
        reactor.run()
-
diff --git a/dbus-tools/autobahn.min.js b/dbus-tools/autobahn.min.js
deleted file mode 100644 (file)
index 60350b1..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- AutobahnJS - http://autobahn.ws
-
- Copyright 2011, 2012 Tavendo GmbH.
- Licensed under the MIT License.
- See license text at http://www.opensource.org/licenses/mit-license.php
-
- AutobahnJS includes code from:
-
- when - http://cujojs.com
-
- (c) copyright B Cavalier & J Hann
- Licensed under the MIT License at:
- http://www.opensource.org/licenses/mit-license.php
-
- Crypto-JS - http://code.google.com/p/crypto-js/
-
- (c) 2009-2012 by Jeff Mott. All rights reserved.
- Licensed under the New BSD License at:
- http://code.google.com/p/crypto-js/wiki/License
-*/
-/*
- MIT License (c) copyright B Cavalier & J Hann */
-(function(a){a(function(){function a(){}function e(){}function d(a){var d=new e;d.then=function(d){f(arguments);var c;try{return d&&(c=d(a)),j(c===q?a:c)}catch(e){return b(e)}};return o(d)}function b(a){var d=new e;d.then=function(d,c){f(arguments);var e;try{return c?(e=c(a),j(e===q?a:e)):b(a)}catch(g){return b(g)}};return o(d)}function f(a){for(var b,d=a.length;d;)if(b=a[--d],null!=b&&"function"!=typeof b)throw Error("callback is not a function");}function h(){var a,c,g,m,i,j,k;g=[];m=[];i=function(a,
-b,d){f(arguments);var c=h();g.push(function(d){d.then(a,b).then(c.resolve,c.reject,c.progress)});d&&m.push(d);return c.promise};j=function(a){for(var d,b=0;d=m[b++];)d(a)};k=function(a){var d,b=0;i=a.then;k=j=function(){throw Error("already completed");};for(m=q;d=g[b++];)d(a);g=[]};a={};c=new e;c.then=a.then=function(a,d,b){return i(a,d,b)};a.promise=o(c);a.resolver=o({resolve:a.resolve=function(a){k(d(a))},reject:a.reject=function(a){k(b(a))},progress:a.progress=function(a){j(a)}});return a}function g(a){return a&&
-"function"===typeof a.then}function i(a,d,b,f){return j(a).then(d,b,f)}function j(a){var d;a instanceof e||(d=h(),g(a)?a.then(d.resolve,d.reject,d.progress):d.resolve(a),a=d.promise);return a}function k(d,b,f,e,g){function j(a){q(a)}function k(a){w(a)}function p(a){x(a)}var o,n,l,q,w,x,y;y=d.length>>>0;o=Math.max(0,Math.min(b,y));n=[];l=h();b=i(l,f,e,g);if(o){q=function(d){n.push(d);--o||(q=w=x=a,l.resolve(n))};w=function(d){q=w=x=a;l.reject(d)};x=l.progress;for(f=0;f<y;++f)f in d&&i(d[f],j,k,p)}else l.resolve(n);
-return b}function l(a,d,b){a[b]=d;return a}function n(a,d,b){var f,c;f=a.length;c=[function(a,b,c){return i(a,function(a){return i(b,function(b){return d(a,b,c,f)})})}];3<=arguments.length&&c.push(b);return j(p.apply(a,c))}var o,p,q;o=Object.freeze||function(a){return a};p=[].reduce||function(a){var d,b,f,c,e;e=0;d=Object(this);c=d.length>>>0;b=arguments;if(1>=b.length)for(;;){if(e in d){f=d[e++];break}if(++e>=c)throw new TypeError;}else f=b[1];for(;e<c;++e)e in d&&(f=a(f,d[e],e,d));return f};i.defer=
-h;i.isPromise=g;i.some=k;i.all=function(a,d,b,f){a=n(a,l,Array(a.length));return i(a,d,b,f)};i.any=function(a,d,b,f){return k(a,1,function(a){return d(a[0])},b,f)};i.reduce=n;i.map=function(a,d){var b,f;f=a.length;for(b=Array(f);0<=f;--f)f in a&&(b[f]=i(a[f],d));return n(b,l,b)};i.chain=function(a,d,f){var c=2<arguments.length;return i(a,function(a){c&&(a=f);d.resolve(a);return a},function(a){d.reject(a);return b(a)},d.progress)};return i})})("function"==typeof define?define:function(a){"undefined"!=
-typeof module?module.exports=a():this.when=a()});("undefined"==typeof Crypto||!Crypto.util)&&function(){var a=window.Crypto={},c=a.util={rotl:function(a,b){return a<<b|a>>>32-b},rotr:function(a,b){return a<<32-b|a>>>b},endian:function(a){if(a.constructor==Number)return c.rotl(a,8)&16711935|c.rotl(a,24)&4278255360;for(var b=0;b<a.length;b++)a[b]=c.endian(a[b]);return a},randomBytes:function(a){for(var b=[];0<a;a--)b.push(Math.floor(256*Math.random()));return b},bytesToWords:function(a){for(var b=[],f=0,c=0;f<a.length;f++,c+=8)b[c>>>5]|=(a[f]&255)<<
-24-c%32;return b},wordsToBytes:function(a){for(var b=[],f=0;f<32*a.length;f+=8)b.push(a[f>>>5]>>>24-f%32&255);return b},bytesToHex:function(a){for(var b=[],f=0;f<a.length;f++)b.push((a[f]>>>4).toString(16)),b.push((a[f]&15).toString(16));return b.join("")},hexToBytes:function(a){for(var b=[],f=0;f<a.length;f+=2)b.push(parseInt(a.substr(f,2),16));return b},bytesToBase64:function(a){if("function"==typeof btoa)return btoa(e.bytesToString(a));for(var b=[],f=0;f<a.length;f+=3)for(var c=a[f]<<16|a[f+1]<<
-8|a[f+2],g=0;4>g;g++)8*f+6*g<=8*a.length?b.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(c>>>6*(3-g)&63)):b.push("=");return b.join("")},base64ToBytes:function(a){if("function"==typeof atob)return e.stringToBytes(atob(a));for(var a=a.replace(/[^A-Z0-9+\/]/ig,""),b=[],f=0,c=0;f<a.length;c=++f%4)0!=c&&b.push(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a.charAt(f-1))&Math.pow(2,-2*c+8)-1)<<2*c|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a.charAt(f))>>>
-6-2*c);return b}},a=a.charenc={};a.UTF8={stringToBytes:function(a){return e.stringToBytes(unescape(encodeURIComponent(a)))},bytesToString:function(a){return decodeURIComponent(escape(e.bytesToString(a)))}};var e=a.Binary={stringToBytes:function(a){for(var b=[],f=0;f<a.length;f++)b.push(a.charCodeAt(f)&255);return b},bytesToString:function(a){for(var b=[],f=0;f<a.length;f++)b.push(String.fromCharCode(a[f]));return b.join("")}}}();("undefined"==typeof Crypto||!Crypto.util)&&function(){var a=window.Crypto={},c=a.util={rotl:function(a,b){return a<<b|a>>>32-b},rotr:function(a,b){return a<<32-b|a>>>b},endian:function(a){if(a.constructor==Number)return c.rotl(a,8)&16711935|c.rotl(a,24)&4278255360;for(var b=0;b<a.length;b++)a[b]=c.endian(a[b]);return a},randomBytes:function(a){for(var b=[];0<a;a--)b.push(Math.floor(256*Math.random()));return b},bytesToWords:function(a){for(var b=[],f=0,c=0;f<a.length;f++,c+=8)b[c>>>5]|=(a[f]&255)<<
-24-c%32;return b},wordsToBytes:function(a){for(var b=[],f=0;f<32*a.length;f+=8)b.push(a[f>>>5]>>>24-f%32&255);return b},bytesToHex:function(a){for(var b=[],f=0;f<a.length;f++)b.push((a[f]>>>4).toString(16)),b.push((a[f]&15).toString(16));return b.join("")},hexToBytes:function(a){for(var b=[],f=0;f<a.length;f+=2)b.push(parseInt(a.substr(f,2),16));return b},bytesToBase64:function(a){if("function"==typeof btoa)return btoa(e.bytesToString(a));for(var b=[],f=0;f<a.length;f+=3)for(var c=a[f]<<16|a[f+1]<<
-8|a[f+2],g=0;4>g;g++)8*f+6*g<=8*a.length?b.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(c>>>6*(3-g)&63)):b.push("=");return b.join("")},base64ToBytes:function(a){if("function"==typeof atob)return e.stringToBytes(atob(a));for(var a=a.replace(/[^A-Z0-9+\/]/ig,""),b=[],c=0,h=0;c<a.length;h=++c%4)0!=h&&b.push(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a.charAt(c-1))&Math.pow(2,-2*h+8)-1)<<2*h|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a.charAt(c))>>>
-6-2*h);return b}},a=a.charenc={};a.UTF8={stringToBytes:function(a){return e.stringToBytes(unescape(encodeURIComponent(a)))},bytesToString:function(a){return decodeURIComponent(escape(e.bytesToString(a)))}};var e=a.Binary={stringToBytes:function(a){for(var b=[],c=0;c<a.length;c++)b.push(a.charCodeAt(c)&255);return b},bytesToString:function(a){for(var b=[],c=0;c<a.length;c++)b.push(String.fromCharCode(a[c]));return b.join("")}}}();
-(function(){var a=Crypto,c=a.util,e=a.charenc,d=e.UTF8,b=e.Binary,f=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,
-2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],h=a.SHA256=function(a,f){var d=c.wordsToBytes(h._sha256(a));return f&&f.asBytes?d:f&&f.asString?b.bytesToString(d):c.bytesToHex(d)};h._sha256=function(a){a.constructor==String&&(a=d.stringToBytes(a));var b=c.bytesToWords(a),e=8*a.length,a=[1779033703,3144134277,
-1013904242,2773480762,1359893119,2600822924,528734635,1541459225],h=[],l,n,o,p,q,t,v,u,m,s,r;b[e>>5]|=128<<24-e%32;b[(e+64>>9<<4)+15]=e;for(u=0;u<b.length;u+=16){e=a[0];l=a[1];n=a[2];o=a[3];p=a[4];q=a[5];t=a[6];v=a[7];for(m=0;64>m;m++){16>m?h[m]=b[m+u]:(s=h[m-15],r=h[m-2],h[m]=((s<<25|s>>>7)^(s<<14|s>>>18)^s>>>3)+(h[m-7]>>>0)+((r<<15|r>>>17)^(r<<13|r>>>19)^r>>>10)+(h[m-16]>>>0));r=e&l^e&n^l&n;var z=(e<<30|e>>>2)^(e<<19|e>>>13)^(e<<10|e>>>22);s=(v>>>0)+((p<<26|p>>>6)^(p<<21|p>>>11)^(p<<7|p>>>25))+
-(p&q^~p&t)+f[m]+(h[m]>>>0);r=z+r;v=t;t=q;q=p;p=o+s>>>0;o=n;n=l;l=e;e=s+r>>>0}a[0]+=e;a[1]+=l;a[2]+=n;a[3]+=o;a[4]+=p;a[5]+=q;a[6]+=t;a[7]+=v}return a};h._blocksize=16;h._digestsize=32})();
-(function(){var a=Crypto,c=a.util,e=a.charenc,d=e.UTF8,b=e.Binary;a.HMAC=function(a,e,g,i){e.constructor==String&&(e=d.stringToBytes(e));g.constructor==String&&(g=d.stringToBytes(g));g.length>4*a._blocksize&&(g=a(g,{asBytes:!0}));for(var j=g.slice(0),g=g.slice(0),k=0;k<4*a._blocksize;k++)j[k]^=92,g[k]^=54;a=a(j.concat(a(g.concat(e),{asBytes:!0})),{asBytes:!0});return i&&i.asBytes?a:i&&i.asString?b.bytesToString(a):c.bytesToHex(a)}})();/*
- MIT License (c) 2011,2012 Copyright Tavendo GmbH. */
-var AUTOBAHNJS_VERSION="0.7.1",AUTOBAHNJS_DEBUG=!1,ab=window.ab={};ab._version=AUTOBAHNJS_VERSION;
-(function(){Array.prototype.indexOf||(Array.prototype.indexOf=function(a){if(null===this)throw new TypeError;var c=Object(this),e=c.length>>>0;if(0===e)return-1;var d=0;0<arguments.length&&(d=Number(arguments[1]),d!==d?d=0:0!==d&&Infinity!==d&&-Infinity!==d&&(d=(0<d||-1)*Math.floor(Math.abs(d))));if(d>=e)return-1;for(d=0<=d?d:Math.max(e-Math.abs(d),0);d<e;d++)if(d in c&&c[d]===a)return d;return-1});Array.prototype.forEach||(Array.prototype.forEach=function(a,c){var e,d;if(this===null)throw new TypeError(" this is null or not defined");
-var b=Object(this),f=b.length>>>0;if({}.toString.call(a)!=="[object Function]")throw new TypeError(a+" is not a function");c&&(e=c);for(d=0;d<f;){var h;if(d in b){h=b[d];a.call(e,h,d,b)}d++}})})();ab._sliceUserAgent=function(a,c,e){var d=[],b=navigator.userAgent,a=b.indexOf(a),c=b.indexOf(c,a);0>c&&(c=b.length);e=b.slice(a,c).split(e);b=e[1].split(".");for(c=0;c<b.length;++c)d.push(parseInt(b[c],10));return{name:e[0],version:d}};
-ab.getBrowser=function(){var a=navigator.userAgent;return-1<a.indexOf("Chrome")?ab._sliceUserAgent("Chrome"," ","/"):-1<a.indexOf("Safari")?ab._sliceUserAgent("Safari"," ","/"):-1<a.indexOf("Firefox")?ab._sliceUserAgent("Firefox"," ","/"):-1<a.indexOf("MSIE")?ab._sliceUserAgent("MSIE",";"," "):null};ab.browserNotSupportedMessage="Browser does not support WebSockets (RFC6455)";ab._idchars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";ab._idlen=16;ab._subprotocol="wamp";
-ab._newid=function(){for(var a="",c=0;c<ab._idlen;c+=1)a+=ab._idchars.charAt(Math.floor(Math.random()*ab._idchars.length));return a};ab.log=function(a){if(window.console&&console.log)if(1<arguments.length){console.group("Log Item");for(var c=0;c<arguments.length;c+=1)console.log(arguments[c]);console.groupEnd()}else console.log(arguments[0])};ab._debugrpc=!1;ab._debugpubsub=!1;ab._debugws=!1;
-ab.debug=function(a,c){if("console"in window)ab._debugrpc=a,ab._debugpubsub=a,ab._debugws=c;else throw"browser does not support console object";};ab.version=function(){return ab._version};ab.PrefixMap=function(){this._index={};this._rindex={}};ab.PrefixMap.prototype.get=function(a){return this._index[a]};ab.PrefixMap.prototype.set=function(a,c){this._index[a]=c;this._rindex[c]=a};ab.PrefixMap.prototype.setDefault=function(a){this._index[""]=a;this._rindex[a]=""};
-ab.PrefixMap.prototype.remove=function(a){var c=this._index[a];c&&(delete this._index[a],delete this._rindex[c])};ab.PrefixMap.prototype.resolve=function(a,c){var e=a.indexOf(":");if(0<=e){var d=a.substring(0,e);if(this._index[d])return this._index[d]+a.substring(e+1)}return!0==c?a:null};ab.PrefixMap.prototype.shrink=function(a,c){for(var e=a.length;0<e;e-=1){var d=this._rindex[a.substring(0,e)];if(d)return d+":"+a.substring(e)}return!0==c?a:null};ab._MESSAGE_TYPEID_WELCOME=0;
-ab._MESSAGE_TYPEID_PREFIX=1;ab._MESSAGE_TYPEID_CALL=2;ab._MESSAGE_TYPEID_CALL_RESULT=3;ab._MESSAGE_TYPEID_CALL_ERROR=4;ab._MESSAGE_TYPEID_SUBSCRIBE=5;ab._MESSAGE_TYPEID_UNSUBSCRIBE=6;ab._MESSAGE_TYPEID_PUBLISH=7;ab._MESSAGE_TYPEID_EVENT=8;ab.CONNECTION_CLOSED=0;ab.CONNECTION_LOST=1;ab.CONNECTION_RETRIES_EXCEEDED=2;ab.CONNECTION_UNREACHABLE=3;ab.CONNECTION_UNSUPPORTED=4;ab.CONNECTION_UNREACHABLE_SCHEDULED_RECONNECT=5;ab.CONNECTION_LOST_SCHEDULED_RECONNECT=6;ab._Deferred=when.defer;
-ab._construct=function(a,c){return"WebSocket"in window?new WebSocket(a,c):"MozWebSocket"in window?new MozWebSocket(a,c):null};
-ab.Session=function(a,c,e,d){var b=this;b._wsuri=a;b._options=d;b._websocket_onopen=c;b._websocket_onclose=e;b._websocket=null;b._websocket_connected=!1;b._session_id=null;b._wamp_version=null;b._server=null;b._calls={};b._subscriptions={};b._prefixes=new ab.PrefixMap;b._txcnt=0;b._rxcnt=0;b._websocket=ab._construct(b._wsuri,[ab._subprotocol]);if(!b._websocket){if(void 0!==e){e(ab.CONNECTION_UNSUPPORTED);return}throw ab.browserNotSupportedMessage;}b._websocket.onmessage=function(a){ab._debugws&&(b._rxcnt+=
-1,console.group("WS Receive"),console.info(b._wsuri+"  ["+b._session_id+"]"),console.log(b._rxcnt),console.log(a.data),console.groupEnd());a=JSON.parse(a.data);if(a[1]in b._calls){if(a[0]===ab._MESSAGE_TYPEID_CALL_RESULT){var c=b._calls[a[1]],d=a[2];if(ab._debugrpc&&void 0!==c._ab_callobj){console.group("WAMP Call",c._ab_callobj[2]);console.timeEnd(c._ab_tid);console.group("Arguments");for(var e=3;e<c._ab_callobj.length;e+=1){var j=c._ab_callobj[e];if(void 0!==j)console.log(j);else break}console.groupEnd();
-console.group("Result");console.log(d);console.groupEnd();console.groupEnd()}c.resolve(d)}else if(a[0]===ab._MESSAGE_TYPEID_CALL_ERROR){c=b._calls[a[1]];d=a[2];e=a[3];j=a[4];if(ab._debugrpc&&void 0!==c._ab_callobj){console.group("WAMP Call",c._ab_callobj[2]);console.timeEnd(c._ab_tid);console.group("Arguments");for(var k=3;k<c._ab_callobj.length;k+=1){var l=c._ab_callobj[k];if(void 0!==l)console.log(l);else break}console.groupEnd();console.group("Error");console.log(d);console.log(e);void 0!==j&&
-console.log(j);console.groupEnd();console.groupEnd()}void 0!==j?c.reject({uri:d,desc:e,detail:j}):c.reject({uri:d,desc:e})}delete b._calls[a[1]]}else if(a[0]===ab._MESSAGE_TYPEID_EVENT){if(c=b._prefixes.resolve(a[1],!0),c in b._subscriptions){var n=a[1],o=a[2];ab._debugpubsub&&(console.group("WAMP Event"),console.info(b._wsuri+"  ["+b._session_id+"]"),console.log(n),console.log(o),console.groupEnd());b._subscriptions[c].forEach(function(a){a(n,o)})}}else if(a[0]===ab._MESSAGE_TYPEID_WELCOME)if(null===
-b._session_id){b._session_id=a[1];b._wamp_version=a[2];b._server=a[3];if(ab._debugrpc||ab._debugpubsub)console.group("WAMP Welcome"),console.info(b._wsuri+"  ["+b._session_id+"]"),console.log(b._wamp_version),console.log(b._server),console.groupEnd();null!==b._websocket_onopen&&b._websocket_onopen()}else throw"protocol error (welcome message received more than once)";};b._websocket.onopen=function(){if(b._websocket.protocol!==ab._subprotocol)if("undefined"===typeof b._websocket.protocol)ab._debugws&&
-(console.group("WS Warning"),console.info(b._wsuri),console.log("WebSocket object has no protocol attribute: WAMP subprotocol check skipped!"),console.groupEnd());else if(b._options&&b._options.skipSubprotocolCheck)ab._debugws&&(console.group("WS Warning"),console.info(b._wsuri),console.log("Server does not speak WAMP, but subprotocol check disabled by option!"),console.log(b._websocket.protocol),console.groupEnd());else throw b._websocket.close(1E3,"server does not speak WAMP"),"server does not speak WAMP (but '"+
-b._websocket.protocol+"' !)";ab._debugws&&(console.group("WAMP Connect"),console.info(b._wsuri),console.log(b._websocket.protocol),console.groupEnd());b._websocket_connected=!0};b._websocket.onerror=function(){};b._websocket.onclose=function(a){ab._debugws&&(b._websocket_connected?console.log("Autobahn connection to "+b._wsuri+" lost (code "+a.code+", reason '"+a.reason+"', wasClean "+a.wasClean+")."):console.log("Autobahn could not connect to "+b._wsuri+" (code "+a.code+", reason '"+a.reason+"', wasClean "+
-a.wasClean+")."));void 0!==b._websocket_onclose&&(b._websocket_connected?a.wasClean?b._websocket_onclose(ab.CONNECTION_CLOSED):b._websocket_onclose(ab.CONNECTION_LOST):b._websocket_onclose(ab.CONNECTION_UNREACHABLE));b._websocket_connected=!1;b._wsuri=null;b._websocket_onopen=null;b._websocket_onclose=null;b._websocket=null}};
-ab.Session.prototype._send=function(a){if(!this._websocket_connected)throw"Autobahn not connected";a=JSON.stringify(a);this._websocket.send(a);this._txcnt+=1;ab._debugws&&(console.group("WS Send"),console.info(this._wsuri+"  ["+this._session_id+"]"),console.log(this._txcnt),console.log(a),console.groupEnd())};ab.Session.prototype.close=function(){this._websocket_connected&&this._websocket.close()};ab.Session.prototype.sessionid=function(){return this._session_id};
-ab.Session.prototype.shrink=function(a,c){void 0===c&&(c=!0);return this._prefixes.shrink(a,c)};ab.Session.prototype.resolve=function(a,c){void 0===c&&(c=!0);return this._prefixes.resolve(a,c)};ab.Session.prototype.prefix=function(a,c){this._prefixes.set(a,c);if(ab._debugrpc||ab._debugpubsub)console.group("WAMP Prefix"),console.info(this._wsuri+"  ["+this._session_id+"]"),console.log(a),console.log(c),console.groupEnd();this._send([ab._MESSAGE_TYPEID_PREFIX,a,c])};
-ab.Session.prototype.call=function(){for(var a=new ab._Deferred,c;!(c=ab._newid(),!(c in this._calls)););this._calls[c]=a;for(var e=this._prefixes.shrink(arguments[0],!0),e=[ab._MESSAGE_TYPEID_CALL,c,e],d=1;d<arguments.length;d+=1)e.push(arguments[d]);this._send(e);ab._debugrpc&&(a._ab_callobj=e,a._ab_tid=this._wsuri+"  ["+this._session_id+"]["+c+"]",console.time(a._ab_tid),console.info());return a};
-ab.Session.prototype.subscribe=function(a,c){var e=this._prefixes.resolve(a,!0);e in this._subscriptions||(ab._debugpubsub&&(console.group("WAMP Subscribe"),console.info(this._wsuri+"  ["+this._session_id+"]"),console.log(a),console.log(c),console.groupEnd()),this._send([ab._MESSAGE_TYPEID_SUBSCRIBE,a]),this._subscriptions[e]=[]);if(-1===this._subscriptions[e].indexOf(c))this._subscriptions[e].push(c);else throw"callback "+c+" already subscribed for topic "+e;};
-ab.Session.prototype.unsubscribe=function(a,c){var e=this._prefixes.resolve(a,!0);if(e in this._subscriptions){var d;if(void 0!==c){var b=this._subscriptions[e].indexOf(c);if(-1!==b)d=c,this._subscriptions[e].splice(b,1);else throw"no callback "+c+" subscribed on topic "+e;}else d=this._subscriptions[e].slice(),this._subscriptions[e]=[];0===this._subscriptions[e].length&&(delete this._subscriptions[e],ab._debugpubsub&&(console.group("WAMP Unsubscribe"),console.info(this._wsuri+"  ["+this._session_id+
-"]"),console.log(a),console.log(d),console.groupEnd()),this._send([ab._MESSAGE_TYPEID_UNSUBSCRIBE,a]))}else throw"not subscribed to topic "+e;};
-ab.Session.prototype.publish=function(){var a=arguments[0],c=arguments[1],e=null,d=null,b=null,f=null;if(3<arguments.length){if(!(arguments[2]instanceof Array))throw"invalid argument type(s)";if(!(arguments[3]instanceof Array))throw"invalid argument type(s)";d=arguments[2];b=arguments[3];f=[ab._MESSAGE_TYPEID_PUBLISH,a,c,d,b]}else if(2<arguments.length)if("boolean"===typeof arguments[2])e=arguments[2],f=[ab._MESSAGE_TYPEID_PUBLISH,a,c,e];else if(arguments[2]instanceof Array)d=arguments[2],f=[ab._MESSAGE_TYPEID_PUBLISH,
-a,c,d];else throw"invalid argument type(s)";else f=[ab._MESSAGE_TYPEID_PUBLISH,a,c];ab._debugpubsub&&(console.group("WAMP Publish"),console.info(this._wsuri+"  ["+this._session_id+"]"),console.log(a),console.log(c),null!==e?console.log(e):null!==d&&(console.log(d),null!==b&&console.log(b)),console.groupEnd());this._send(f)};ab.Session.prototype.authreq=function(a,c){return this.call("http://api.wamp.ws/procedure#authreq",a,c)};
-ab.Session.prototype.authsign=function(a,c){c||(c="");return Crypto.util.bytesToBase64(Crypto.HMAC(Crypto.SHA256,a,c,{asBytes:!0}))};ab.Session.prototype.auth=function(a){return this.call("http://api.wamp.ws/procedure#auth",a)};
-ab._connect=function(a){var c=new ab.Session(a.wsuri,function(){a.connects+=1;a.retryCount=0;a.onConnect(c)},function(c){switch(c){case ab.CONNECTION_CLOSED:a.onHangup(c,"Connection was closed properly - done.");break;case ab.CONNECTION_UNSUPPORTED:a.onHangup(c,"Browser does not support WebSocket.");break;case ab.CONNECTION_UNREACHABLE:a.retryCount+=1;if(0==a.connects)a.onHangup(c,"Connection could not be established.");else if(a.retryCount<=a.options.maxRetries)(c=a.onHangup(ab.CONNECTION_UNREACHABLE_SCHEDULED_RECONNECT,
-"Connection unreachable - scheduled reconnect to occur in "+a.options.retryDelay/1E3+" second(s).",{delay:a.options.retryDelay,retries:a.retryCount,maxretries:a.options.maxRetries}))?(console.log("Connection unreachable - retrying stopped by app"),a.onHangup(ab.CONNECTION_RETRIES_EXCEEDED,"Number of connection retries exceeded.")):(console.log("Connection unreachable - retrying ("+a.retryCount+") .."),window.setTimeout(ab._connect,a.options.retryDelay,a));else a.onHangup(ab.CONNECTION_RETRIES_EXCEEDED,
-"Number of connection retries exceeded.");break;case ab.CONNECTION_LOST:a.retryCount+=1;if(a.retryCount<=a.options.maxRetries)(c=a.onHangup(ab.CONNECTION_LOST_SCHEDULED_RECONNECT,"Connection lost - scheduled reconnect to occur in "+a.options.retryDelay/1E3+" second(s).",{delay:a.options.retryDelay,retries:a.retryCount,maxretries:a.options.maxRetries}))?(console.log("Connection lost - retrying stopped by app"),a.onHangup(ab.CONNECTION_RETRIES_EXCEEDED,"Connection lost.")):(console.log("Connection lost - retrying ("+
-a.retryCount+") .."),window.setTimeout(ab._connect,a.options.retryDelay,a));else a.onHangup(ab.CONNECTION_RETRIES_EXCEEDED,"Connection lost.");break;default:throw"unhandled close code in ab._connect";}},a.options)};
-ab.connect=function(a,c,e,d){peer={};peer.wsuri=a;peer.options=d?d:{};void 0==peer.options.retryDelay&&(peer.options.retryDelay=5E3);void 0==peer.options.maxRetries&&(peer.options.maxRetries=10);void 0==peer.options.skipSubprotocolCheck&&(peer.options.skipSubprotocolCheck=!1);if(c)peer.onConnect=c;else throw"onConnect handler required!";peer.onHangup=e?e:function(a,c){console.log(c)};peer.connects=0;peer.retryCount=0;ab._connect(peer)};ab._UA_FIREFOX=/.*Firefox\/([0-9+]*).*/;ab._UA_CHROME=/.*Chrome\/([0-9+]*).*/;ab._UA_CHROMEFRAME=/.*chromeframe\/([0-9]*).*/;ab._UA_WEBKIT=/.*AppleWebKit\/([0-9+.]*)w*.*/;ab._UA_WEBOS=/.*webOS\/([0-9+.]*)w*.*/;ab._matchRegex=function(a,c){var e=c.exec(a);return e?e[1]:e};
-ab.lookupWsSupport=function(){var a=navigator.userAgent;if(-1<a.indexOf("MSIE")){if(-1<a.indexOf("MSIE 10"))return[!0,!0,!0];if(-1<a.indexOf("chromeframe")){var c=parseInt(ab._matchRegex(a,ab._UA_CHROMEFRAME));return 14<=c?[!0,!1,!0]:[!1,!1,!1]}if(-1<a.indexOf("MSIE 8")||-1<a.indexOf("MSIE 9"))return[!0,!0,!0]}else{if(-1<a.indexOf("Firefox")){if(c=parseInt(ab._matchRegex(a,ab._UA_FIREFOX))){if(7<=c)return[!0,!1,!0];if(3<=c)return[!0,!0,!0]}return[!1,!1,!0]}if(-1<a.indexOf("Safari")&&-1==a.indexOf("Chrome")){if(c=
-ab._matchRegex(a,ab._UA_WEBKIT))return-1<a.indexOf("Windows")&&"534+"==c||-1<a.indexOf("Macintosh")&&(c=c.replace("+","").split("."),535==parseInt(c[0])&&24<=parseInt(c[1])||535<parseInt(c[0]))?[!0,!1,!0]:-1<a.indexOf("webOS")?(c=ab._matchRegex(a,ab._UA_WEBOS).split("."),2==parseInt(c[0])?[!1,!0,!0]:[!1,!1,!1]):[!0,!0,!0]}else if(-1<a.indexOf("Chrome")){if(c=parseInt(ab._matchRegex(a,ab._UA_CHROME)))return 14<=c?[!0,!1,!0]:4<=c?[!0,!0,!0]:[!1,!1,!0]}else if(-1<a.indexOf("Android")){if(-1<a.indexOf("Firefox")||
--1<a.indexOf("CrMo"))return[!0,!1,!0];if(-1<a.indexOf("Opera"))return[!1,!1,!0];if(-1<a.indexOf("CrMo"))return[!0,!0,!0]}else if(-1<a.indexOf("iPhone")||-1<a.indexOf("iPad")||-1<a.indexOf("iPod"))return[!1,!1,!0]}return[!1,!1,!1]};
diff --git a/dbus-tools/dbus-register.html b/dbus-tools/dbus-register.html
deleted file mode 100644 (file)
index 7acd52b..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-<!DOCTYPE html>
-<html>
-    <head>
-        <!-- include AutobahnJS .. that's all you need -->
-        <script src="./autobahn.min.js"></script>
-        <script src="./dbus-register.js"></script>
-    </head>
-   <body>
-        <center><h1>dbus-register</h1></center>
-        <br>
-        <table>
-        <tr><td>bus:</td>
-               <td>
-            <select id="bus">
-              <option value="session">session</option>
-              <option value="system">system</option>
-            </select>
-            </td>
-        </tr>
-        <tr><td>sender:</td>
-               <td>
-            <input type="text" size="40" id="sender" value="org.gnome.ScreenSaver"/>
-            </td>
-        </tr>
-        <tr><td>object:</td>
-               <td>
-            <input type="text" size="40" id="object" value="/org/gnome/ScreenSaver"/>
-            </td>
-        </tr>
-        <tr><td>interface:</td>
-               <td>
-            <input type="text" size="40" id="interface" value="org.gnome.ScreenSaver"/>
-            </td>
-        </tr>
-        <tr><td>signal:</td>
-               <td>
-            <input type="text" size="40" id="signal" value="ActiveChanged"/>
-            </td>
-        </tr>
-        <tr><td>
-            <input style="width:100%" type="button" value="register" onclick="dbus_register();"/>
-               </td>
-               <td>
-            <input type="text" size="40" id="uri" value="ws://localhost:9001"/>
-            </td>
-         </tr>
-        </table>
-               <br>
-               <input type="button" value="clear log" onclick="clear_log();"/>
-               <br>
-               <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre>
-    </body>
-</html>
diff --git a/dbus-tools/dbus-register.js b/dbus-tools/dbus-register.js
deleted file mode 100644 (file)
index 347b5f3..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-// WAMP session object
-var mSession = null;
-
-// HTML DOM elements
-var mLog, mBus, mSender, mObject, mInterface, mSignal, mArgs, mUri;
-
-window.onload = function() {
-
-    function onSessionConnectedCB(session) { // WAMP session was established
-        mSession = session;
-        log_append("Session successfully connected.");
-    }
-
-    function onSessionErrorCB(code, reason) { // WAMP session is gone
-        mSession = null;
-        if (code == ab.CONNECTION_UNSUPPORTED) {
-             log_append("Browser is not supported");
-        } else {
-            log_append("Failed to open session, code = " + code + ", reason = " + reason);
-        }
-    }
-    
-    mLog = document.getElementById('log');
-    mBus = document.getElementById('bus');
-    mSender = document.getElementById('sender');
-    mObject = document.getElementById('object');
-    mInterface = document.getElementById('interface');
-    mSignal = document.getElementById('signal');
-    mArgs = document.getElementById('args');
-    mUri = document.getElementById('uri');
-    
-    // Connect to WAMP server
-    ab.connect(mUri.value, onSessionConnectedCB, onSessionErrorCB);
-};
-
-function sigHandler(id, data)
-{
-    log_append("got signal: " + id);
-    log_append("data: " + data + "\n");
-}
-
-function dbus_register()
-{
-    // RPC success callback
-    function myAsyncFuncSuccessCB(res) {
-        log_append("subscribing to: " + res + "\n");
-        mSession.subscribe(res, sigHandler);
-    }
-     // RPC error callback
-    function myAsyncFuncErrorCB(error, desc) {
-        log_append("error: " + desc + "\n");
-    }
-    log_append("dbusRegister: "
-       + mBus.options[mBus.selectedIndex].value + "\n\t"
-       + mSender.value + "\n\t"
-       + mObject.value + "\n\t"
-       + mInterface.value + "\n\t"
-       + mSignal.value + "\n"
-               );
-    var arglist = [
-                       mBus.options[mBus.selectedIndex].value,
-                       mSender.value,
-                       mObject.value,
-                       mInterface.value,
-                       mSignal.value
-                       ]
-
-    // call dbusRegister with bus type, sender, object, and signal
-    mSession.call("dbusRegister", arglist).then(myAsyncFuncSuccessCB, myAsyncFuncErrorCB);
-};
-
-function log_append(message) {
-    mLog.innerHTML += message + '\n';
-    mLog.scrollTop = mLog.scrollHeight;
-};
-
-function clear_log() {
-    mLog.innerHTML = "";
-    mLog.scrollTop = mLog.scrollHeight;
-};
\ No newline at end of file
diff --git a/dbus-tools/dbus-register.py b/dbus-tools/dbus-register.py
deleted file mode 100644 (file)
index 2880ce5..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-###############################################################################
-# Copyright 2012 Intel Corporation.
-# 
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-# 
-# http://www.apache.org/licenses/LICENSE-2.0
-# 
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###############################################################################
-
-
-import sys, dbus, json
-
-from twisted.internet import glib2reactor
-# Configure the twisted mainloop to be run inside the glib mainloop.
-# This must be done before importing the other twisted modules
-glib2reactor.install()
-from twisted.internet import reactor, defer
-
-from autobahn.websocket import listenWS
-from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
-
-from dbus.mainloop.glib import DBusGMainLoop
-
-import gobject
-gobject.threads_init()
-
-from dbus import glib
-glib.init_threads()
-
-# enable debug log
-from twisted.python import log
-log.startLogging(sys.stdout)
-
-
-
-###############################################################################
-def hashId(senderName, objectName, interfaceName, signalName):
-       return senderName + "#" + objectName + "#" + interfaceName + "#" + signalName
-
-
-
-###############################################################################
-class DbusSignalHandler:
-       def __init__(self, bus, senderName, objectName, interfaceName, signalName):
-               # publish hash id
-               self.id = hashId(senderName, objectName, interfaceName, signalName)
-        # connect dbus proxy object to signal
-               self.object = bus.get_object(senderName, objectName)
-               self.object.connect_to_signal(signalName, self.handleSignal, interfaceName)
-
-
-       def handleSignal(self, *args):
-               # publish dbus args under topic hash id
-               factory.dispatch(self.id, json.dumps(args))
-
-
-
-###############################################################################
-class DbusRegisterService:
-    def __init__(self):
-       # signal handlers
-       self.signalHandlers = {}
-
-
-    @exportRpc
-    def dbusRegister(self, list):
-       # read arguments list by position
-        if len(list) < 5:
-               raise Exception("Error: expected arguments: bus, sender, object, interface, signal)")
-        
-       # check if a handler exists
-        sigId = hashId(list[1], list[2], list[3], list[4])
-        if self.signalHandlers.has_key(sigId):
-               return sigId
-       
-        if list[0] == "session":
-               bus = dbus.SessionBus()
-        elif list[0] == "system":
-               bus = dbus.SystemBus()
-        else:
-               raise Exception("Error: invalid bus: %s" % list[0])
-        
-        # create a handler that will publish the signal
-        dbusSignalHandler = DbusSignalHandler(bus, list[1], list[2], list[3], list[4])
-        self.signalHandlers[sigId] = dbusSignalHandler
-        
-        return dbusSignalHandler.id
-
-
-
-###############################################################################
-class DbusRegisterServerProtocol(WampServerProtocol):
-       def onSessionOpen(self):
-               # create dbus-register service instance
-               self.DbusRegisterService = DbusRegisterService()
-               # register it for RPC
-               self.registerForRpc(self.DbusRegisterService)
-               # register for Publish / Subscribe
-               self.registerForPubSub("", True)
-
-
-
-###############################################################################
-if __name__ == '__main__':
-       port = "9001"
-       if len(sys.argv) == 2:
-               port = sys.argv[1]
-
-       uri = "ws://localhost:" + port
-
-       factory = WampServerFactory(uri, debugWamp = True)
-       factory.protocol = DbusRegisterServerProtocol
-       factory.setProtocolOptions(allowHixie76 = True)
-
-       listenWS(factory)
-
-       DBusGMainLoop(set_as_default=True)
-
-       reactor.run()
-
diff --git a/dbus-tools/dbus-send.html b/dbus-tools/dbus-send.html
deleted file mode 100644 (file)
index b3a2a37..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-<!DOCTYPE html>
-<html>
-    <head>
-        <!-- include AutobahnJS .. that's all you need -->
-        <script src="./autobahn.min.js"></script>
-        <script src="./dbus-send.js"></script>
-    </head>
-   <body>
-        <center><h1>dbus-send</h1></center>
-        <br>
-        <table>
-        <tr><td>bus:</td>
-               <td>
-            <select id="bus">
-              <option value="session">session</option>
-              <option value="system">system</option>
-            </select>
-            </td>
-        </tr>
-        <tr><td>destination:</td>
-               <td>
-            <input type="text" size="40" id="destination" value="org.gnome.ScreenSaver"/>
-            </td>
-        </tr>
-        <tr><td>object:</td>
-               <td>
-            <input type="text" size="40" id="object" value="/"/>
-            </td>
-        </tr>
-        <tr><td>interface:</td>
-               <td>
-            <input type="text" size="40" id="interface" value="org.gnome.ScreenSaver"/>
-            </td>
-        </tr>
-        <tr><td>message:</td>
-               <td>
-            <input type="text" size="40" id="message" value="SetActive"/>
-            </td>
-        </tr>
-        <tr><td colspan="2" align="center">
-            <textarea cols="60" rows=6 id="args">[true]</textarea>
-        </td></tr>
-        <tr><td>
-            <input style="width:100%" type="button" value="send" onclick="dbus_send();"/>
-               </td>
-               <td>
-            <input type="text" size="40" id="uri" value="ws://localhost:9000"/>
-            </td>
-         </tr>
-        </table>
-               <br>
-               <input type="button" value="clear log" onclick="clear_log();"/>
-               <br>
-               <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre>
-    </body>
-</html>
diff --git a/dbus-tools/dbus-send.js b/dbus-tools/dbus-send.js
deleted file mode 100644 (file)
index b1bcab8..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-// WAMP session object
-var mSession = null;
-
-// HTML DOM elements
-var mLog, mBus, mDestination, mObject, mInterface, mMessage, mArgs, mUri;
-
-window.onload = function() {
-
-    function onSessionConnectedCB(session) { // WAMP session was established
-        mSession = session;
-        log_append("Session successfully connected.");
-    }
-
-    function onSessionErrorCB(code, reason) { // WAMP session is gone
-        mSession = null;
-        if (code == ab.CONNECTION_UNSUPPORTED) {
-             log_append("Browser is not supported");
-        } else {
-            log_append("Failed to open session, code = " + code + ", reason = " + reason);
-        }
-    }
-    
-    mLog = document.getElementById('log');
-    mBus = document.getElementById('bus');
-    mDestination = document.getElementById('destination');
-    mObject = document.getElementById('object');
-    mInterface = document.getElementById('interface');
-    mMessage = document.getElementById('message');
-    mArgs = document.getElementById('args');
-    mUri = document.getElementById('uri');
-    
-    // Connect to WAMP server
-    ab.connect(mUri.value, onSessionConnectedCB, onSessionErrorCB);
-};
-
-function dbus_send()
-{
-    // RPC success callback
-    function myAsyncFuncSuccessCB(res) {
-        log_append("got result: " + res + "\n");
-    }
-     // RPC error callback
-    function myAsyncFuncErrorCB(error, desc) {
-        log_append("error: " + desc + "\n");
-    }
-    log_append("dbusSend: "
-       + mBus.options[mBus.selectedIndex].value + "\n\t"
-       + mDestination.value + "\n\t"
-       + mObject.value + "\n\t"
-       + mInterface.value + "\n\t"
-       + mMessage.value + "\n\t"
-       + mArgs.value + "\n"
-               );
-    var arglist = [
-                       mBus.options[mBus.selectedIndex].value,
-                       mDestination.value,
-                       mObject.value,
-                       mInterface.value,
-                       mMessage.value
-                       ]
-    if (mArgs.value) {
-       arglist.push(mArgs.value);
-    }
-
-    // call dbusSend with bus type, destination, object, message and arguments
-    mSession.call("dbusSend", arglist).then(myAsyncFuncSuccessCB, myAsyncFuncErrorCB);
-};
-
-function log_append(message) {
-    mLog.innerHTML += message + '\n';
-    mLog.scrollTop = mLog.scrollHeight;
-};
-
-function clear_log() {
-    mLog.innerHTML = "";
-    mLog.scrollTop = mLog.scrollHeight;
-};
\ No newline at end of file
diff --git a/dbus-tools/dbus-send.py b/dbus-tools/dbus-send.py
deleted file mode 100644 (file)
index 749cd7d..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-###############################################################################
-# Copyright 2012 Intel Corporation.
-# 
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-# 
-# http://www.apache.org/licenses/LICENSE-2.0
-# 
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###############################################################################
-
-
-import sys, dbus, json
-
-from twisted.internet import glib2reactor
-# Configure the twisted mainloop to be run inside the glib mainloop.
-# This must be done before importing the other twisted modules
-glib2reactor.install()
-from twisted.internet import reactor, defer
-
-from autobahn.websocket import listenWS
-from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
-
-from dbus.mainloop.glib import DBusGMainLoop
-
-import gobject
-gobject.threads_init()
-
-from dbus import glib
-glib.init_threads()
-
-# enable debug log
-from twisted.python import log
-log.startLogging(sys.stdout)
-
-
-
-###############################################################################
-class DbusCallHandler:
-       def __init__(self, method, args):
-        # deferred reply to return dbus results
-               self.pending = False
-               self.request = defer.Deferred()
-               self.method = method
-               self.args = args
-
-
-       def callMethod(self):
-               # dbus method async call
-               self.pending = True
-               self.method(*self.args, reply_handler=self.dbusSuccess, error_handler=self.dbusError)
-               return self.request
-
-
-       def dbusSuccess(self, *result):
-               # return JSON string result array
-               self.request.callback(json.dumps(result))
-               self.pending = False
-
-
-       def dbusError(self, error):
-               # return dbus error message
-               self.request.errback(error.get_dbus_message())
-               self.pending = False
-
-
-
-###############################################################################
-class DbusSendService:
-    def __init__(self):
-        # pending dbus calls
-        self.pendingCalls = []
-
-
-    @exportRpc
-    def dbusSend(self, list):
-       # clear pending calls
-       for call in self.pendingCalls:
-               if not call.pending:
-                       self.pendingCalls.remove(call)
-       
-       # read arguments list by position
-        if len(list) < 5:
-               raise Exception("Error: expected arguments: bus, destination, object, interface, message, [args])")
-        if list[0] == "session":
-               bus = dbus.SessionBus()
-        elif list[0] == "system":
-               bus = dbus.SystemBus()
-        else:
-               raise Exception("Error: invalid bus: %s" % list[0])
-        
-        # parse JSON arg list
-        args = []
-        if len(list) == 6:
-               args = json.loads(list[5])
-        
-        # get dbus proxy
-        object = bus.get_object(list[1], list[2])
-        method = object.get_dbus_method(list[4], list[3])
-        
-        # use a deferred call handler to manage dbus results
-        dbusCallHandler = DbusCallHandler(method, args)
-        self.pendingCalls.append(dbusCallHandler)
-        return dbusCallHandler.callMethod()
-
-
-
-###############################################################################
-class DbusSendServerProtocol(WampServerProtocol):
-       def onSessionOpen(self):
-               # create dbus-send service instance and register it for RPC.
-               self.dbusSendService = DbusSendService()
-               self.registerForRpc(self.dbusSendService)
-
-
-
-###############################################################################
-if __name__ == '__main__':
-       port = "9000"
-       if len(sys.argv) == 2:
-               port = sys.argv[1]
-
-       uri = "ws://localhost:" + port
-
-       factory = WampServerFactory(uri, debugWamp = True)
-       factory.protocol = DbusSendServerProtocol
-       factory.setProtocolOptions(allowHixie76 = True)
-
-       listenWS(factory)
-
-       DBusGMainLoop(set_as_default=True)
-
-       reactor.run()
-
diff --git a/doc/dbus-tools/dbus-register.html b/doc/dbus-tools/dbus-register.html
new file mode 100644 (file)
index 0000000..5378562
--- /dev/null
@@ -0,0 +1,129 @@
+<!DOCTYPE html>
+<html>
+       <head>
+               <!-- include AutobahnJS .. that's all you need -->
+               <script src="../../lib/autobahn.min.js"></script>
+               <script language="javascript" type="text/javascript">
+               // WAMP session object
+               var mSession = null;
+
+               // HTML DOM elements
+               var mLog, mBus, mSender, mObject, mInterface, mSignal, mArgs, mUri;
+
+               window.onload = function() {
+
+                       function onSessionConnectedCB(session) { // WAMP session was established
+                               mSession = session;
+                               log_append("Session successfully connected.");
+                       }
+
+                       function onSessionErrorCB(code, reason) { // WAMP session is gone
+                               mSession = null;
+                               if (code == ab.CONNECTION_UNSUPPORTED) {
+                                       log_append("Browser is not supported");
+                               } else {
+                                       log_append("Failed to open session, code = " + code + ", reason = " + reason);
+                               }
+                       }
+
+                       mLog = document.getElementById('log');
+                       mBus = document.getElementById('bus');
+                       mSender = document.getElementById('sender');
+                       mObject = document.getElementById('object');
+                       mInterface = document.getElementById('interface');
+                       mSignal = document.getElementById('signal');
+                       mArgs = document.getElementById('args');
+                       mUri = document.getElementById('uri');
+
+                       // Connect to WAMP server
+                       ab.connect(mUri.value, onSessionConnectedCB, onSessionErrorCB);
+               };
+
+               function sigHandler(id, data) {
+                       log_append("got signal: " + id);
+                       log_append("data: " + data + "\n");
+               }
+
+               function dbus_register() {
+                       // RPC success callback
+                       function myAsyncFuncSuccessCB(res) {
+                               log_append("subscribing to: " + res + "\n");
+                               mSession.subscribe(res, sigHandler);
+                       }
+
+                       // RPC error callback
+                       function myAsyncFuncErrorCB(error, desc) {
+                               log_append("error: " + desc + "\n");
+                       }
+
+                       log_append("dbusRegister: "
+                               + mBus.options[mBus.selectedIndex].value + "\n\t"
+                               + mSender.value + "\n\t"
+                               + mObject.value + "\n\t"
+                               + mInterface.value + "\n\t"
+                               + mSignal.value + "\n"
+                               );
+
+                       var arglist = [
+                               mBus.options[mBus.selectedIndex].value,
+                               mSender.value,
+                               mObject.value,
+                               mInterface.value,
+                               mSignal.value
+                               ]
+
+                       // call dbusRegister with bus type, sender, object, and signal
+                       mSession.call("dbusRegister", arglist).then(myAsyncFuncSuccessCB, myAsyncFuncErrorCB);
+               };
+
+               function log_append(message) {
+                   mLog.innerHTML += message + '\n';
+                   mLog.scrollTop = mLog.scrollHeight;
+               };
+
+               function clear_log() {
+               mLog.innerHTML = "";
+               mLog.scrollTop = mLog.scrollHeight;
+               };
+               </script>
+       </head>
+       <body>
+               <center><h1>dbus-register</h1></center>
+               <br>
+               <table>
+                       <tr>
+                               <td>bus:</td>
+                               <td>
+                                       <select id="bus">
+                                               <option value="session">session</option>
+                                               <option value="system">system</option>
+                                       </select>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td>sender:</td>
+                               <td><input type="text" size="40" id="sender" value="org.gnome.ScreenSaver"/></td>
+                       </tr>
+                       <tr>
+                               <td>object:</td>
+                               <td><input type="text" size="40" id="object" value="/org/gnome/ScreenSaver"/></td>
+                       </tr>
+                       <tr>
+                               <td>interface:</td>
+                               <td><input type="text" size="40" id="interface" value="org.gnome.ScreenSaver"/></td>
+                       </tr>
+                       <tr>
+                               <td>signal:</td>
+                               <td><input type="text" size="40" id="signal" value="ActiveChanged"/></td>
+                       </tr>
+                       <tr>
+                               <td><input style="width:100%" type="button" value="register" onclick="dbus_register();"/></td>
+                               <td><input type="text" size="40" id="uri" value="ws://localhost:9000"/></td>
+                       </tr>
+               </table>
+               <br>
+               <input type="button" value="clear log" onclick="clear_log();"/>
+               <br>
+               <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre>
+       </body>
+</html>
diff --git a/doc/dbus-tools/dbus-send.html b/doc/dbus-tools/dbus-send.html
new file mode 100644 (file)
index 0000000..007dcea
--- /dev/null
@@ -0,0 +1,131 @@
+<!DOCTYPE html>
+<html>
+       <head>
+               <!-- include AutobahnJS .. that's all you need -->
+               <script src="../../lib/autobahn.min.js"></script>
+               <script language="javascript" type="text/javascript">
+               // WAMP session object
+               var mSession = null;
+
+               // HTML DOM elements
+               var mLog, mBus, mDestination, mObject, mInterface, mMessage, mArgs, mUri;
+
+               window.onload = function() {
+
+                       function onSessionConnectedCB(session) { // WAMP session was established
+                               mSession = session;
+                               log_append("Session successfully connected.");
+                       }
+
+                       function onSessionErrorCB(code, reason) { // WAMP session is gone
+                               mSession = null;
+                               if (code == ab.CONNECTION_UNSUPPORTED) {
+                                       log_append("Browser is not supported");
+                               } else {
+                                       log_append("Failed to open session, code = " + code + ", reason = " + reason);
+                               }
+                       }
+
+                       mLog = document.getElementById('log');
+                       mBus = document.getElementById('bus');
+                       mDestination = document.getElementById('destination');
+                       mObject = document.getElementById('object');
+                       mInterface = document.getElementById('interface');
+                       mMessage = document.getElementById('message');
+                       mArgs = document.getElementById('args');
+                       mUri = document.getElementById('uri');
+
+                       // Connect to WAMP server
+                       ab.connect(mUri.value, onSessionConnectedCB, onSessionErrorCB);
+               };
+
+               function dbus_send()
+               {
+                       // RPC success callback
+                       function myAsyncFuncSuccessCB(res) {
+                               log_append("got result: " + res + "\n");
+                       }
+
+                       // RPC error callback
+                       function myAsyncFuncErrorCB(error, desc) {
+                               log_append("error: " + desc + "\n");
+                       }
+
+                       log_append("dbusSend: "
+                               + mBus.options[mBus.selectedIndex].value + "\n\t"
+                               + mDestination.value + "\n\t"
+                               + mObject.value + "\n\t"
+                               + mInterface.value + "\n\t"
+                               + mMessage.value + "\n\t"
+                               + mArgs.value + "\n"
+                               );
+
+                       var arglist = [
+                               mBus.options[mBus.selectedIndex].value,
+                               mDestination.value,
+                               mObject.value,
+                               mInterface.value,
+                               mMessage.value
+                               ]
+                       if (mArgs.value) {
+                               arglist.push(mArgs.value);
+                       }
+
+                       // Call dbusSend with bus type, destination, object, message and arguments
+                       mSession.call("dbusSend", arglist).then(myAsyncFuncSuccessCB, myAsyncFuncErrorCB);
+               };
+
+               function log_append(message) {
+                       mLog.innerHTML += message + '\n';
+                       mLog.scrollTop = mLog.scrollHeight;
+               };
+
+               function clear_log() {
+                       mLog.innerHTML = "";
+                       mLog.scrollTop = mLog.scrollHeight;
+               };
+               </script>
+       </head>
+       <body>
+               <center><h1>dbus-send</h1></center>
+               <br>
+               <table>
+                       <tr>
+                               <td>bus:</td>
+                               <td>
+                                       <select id="bus">
+                                               <option value="session">session</option>
+                                               <option value="system">system</option>
+                                       </select>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td>destination:</td>
+                               <td><input type="text" size="40" id="destination" value="org.gnome.ScreenSaver"/></td>
+                       </tr>
+                       <tr>
+                               <td>object:</td>
+                               <td><input type="text" size="40" id="object" value="/"/></td>
+                       </tr>
+                       <tr>
+                               <td>interface:</td>
+                               <td><input type="text" size="40" id="interface" value="org.gnome.ScreenSaver"/></td>
+                       </tr>
+                       <tr>
+                               <td>message:</td>
+                               <td><input type="text" size="40" id="message" value="SetActive"/></td>
+                       </tr>
+                       <tr>
+                               <td colspan="2" align="center"><textarea cols="60" rows=6 id="args">[true]</textarea></td>
+                       </tr>
+                       <tr>
+                               <td><input style="width:100%" type="button" value="send" onclick="dbus_send();"/></td>
+                               <td><input type="text" size="40" id="uri" value="ws://localhost:9000"/></td>
+                       </tr>
+               </table>
+               <br>
+               <input type="button" value="clear log" onclick="clear_log();"/>
+               <br>
+               <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre>
+       </body>
+</html>
similarity index 99%
rename from doc/cloudeebus.html
rename to doc/sample/cloudeebus.html
index 83f66f6..2928b95 100644 (file)
@@ -58,4 +58,3 @@ cloudeebus.connect("ws://localhost:9000", connectSuccess, errorCB);
                <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre>
    </body>
 </html>
-
similarity index 100%
rename from doc/autobahn.min.js
rename to lib/autobahn.min.js
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..017b8fa
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+# Cloudeebus
+#
+# Copyright (C) 2012 Intel Corporation. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Luc Yriarte <luc.yriarte@intel.com>
+# Christophe Guiraud <christophe.guiraud@intel.com>
+#
+
+from setuptools import setup
+
+setup(name = "cloudeebus",
+       version = "0.0.1",
+       description = "Javascript-DBus bridge",
+       author = "Luc Yriarte, Christophe Guiraud",
+       author_email = "luc.yriarte@intel.com, christophe.guiraud@intel.com",
+       url = "https://01.org/cloudeebus/about",
+       license = "http://www.apache.org/licenses/LICENSE-2.0",
+       scripts = ["cloudeebus/cloudeebus.py"],
+       packages = ["cloudeebus"],
+       data_files = [("cloudeebus" ,["AUTHORS", "README.md", "LICENSE"])],
+       platforms = ("Any"),
+       install_requires = ["setuptools", "autobahn>=0.5.6"],
+       classifiers = ["License :: OSI Approved :: Apache Software License",
+                 "Development Status :: 3 - Alpha",
+                 "Environment :: Console",
+                 "Framework :: Autobahn",
+                 "Intended Audience :: Developers",
+                 "Operating System :: OS Independent",
+                 "Programming Language :: Python",
+                 "Topic :: Internet",
+                 "Topic :: Software Development :: Libraries"],
+       keywords = "cloudeebus autobahn websocket dbus javascript bridge")