21 # You should have received a copy of the GNU General Public License |
21 # You should have received a copy of the GNU General Public License |
22 # along with this program; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 |
25 |
26 |
|
27 |
|
28 import sys |
26 import sys |
29 import traceback |
27 import traceback |
30 from functools import partial |
28 from functools import partial |
31 from threading import Thread, Event |
29 from threading import Thread, Event |
32 from six import text_type as text |
|
33 |
30 |
34 from twisted.internet import reactor, threads |
31 from twisted.internet import reactor, threads |
35 from autobahn.twisted import wamp |
32 from autobahn.twisted import wamp |
36 from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS |
33 from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS |
37 from autobahn.wamp import types |
34 from autobahn.wamp import types |
83 # start logging to console |
80 # start logging to console |
84 # log.startLogging(sys.stdout) |
81 # log.startLogging(sys.stdout) |
85 |
82 |
86 # create a WAMP application session factory |
83 # create a WAMP application session factory |
87 component_config = types.ComponentConfig( |
84 component_config = types.ComponentConfig( |
88 realm=text(realm), |
85 realm=str(realm), |
89 extra={"ID": ID}) |
86 extra={"ID": ID}) |
90 session_factory = wamp.ApplicationSessionFactory( |
87 session_factory = wamp.ApplicationSessionFactory( |
91 config=component_config) |
88 config=component_config) |
92 session_factory.session = cls |
89 session_factory.session = cls |
93 |
90 |
109 _WampConnection = RegisterWampClient() |
106 _WampConnection = RegisterWampClient() |
110 AddToDoBeforeQuit(reactor.stop) |
107 AddToDoBeforeQuit(reactor.stop) |
111 reactor.run(installSignalHandlers=False) |
108 reactor.run(installSignalHandlers=False) |
112 |
109 |
113 def WampSessionProcMapper(funcname): |
110 def WampSessionProcMapper(funcname): |
114 wampfuncname = text('.'.join((ID, funcname))) |
111 wampfuncname = str('.'.join((ID, funcname))) |
115 |
112 |
116 def catcher_func(*args, **kwargs): |
113 def catcher_func(*args, **kwargs): |
117 if _WampSession is not None: |
114 if _WampSession is not None: |
118 try: |
115 try: |
119 return threads.blockingCallFromThread( |
116 return threads.blockingCallFromThread( |