runtime/WampClient.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 22 Sep 2017 10:54:42 +0300
changeset 1826 91796f408540
parent 1782 5b6ad7a7fd9d
child 1832 0f1081928d65
permissions -rw-r--r--
fix usage of python2-only print statement
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
     3
1667
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
     4
# This file is part of Beremiz runtime.
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
     5
#
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
     6
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
     7
#
1667
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
     8
# See COPYING.Runtime file for copyrights details.
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
     9
#
1667
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    10
# This library is free software; you can redistribute it and/or
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    11
# modify it under the terms of the GNU Lesser General Public
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    12
# License as published by the Free Software Foundation; either
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    13
# version 2.1 of the License, or (at your option) any later version.
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    14
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    15
# This library is distributed in the hope that it will be useful,
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
    16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1667
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    18
# Lesser General Public License for more details.
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    19
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    20
# You should have received a copy of the GNU Lesser General Public
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    21
# License along with this library; if not, write to the Free Software
cefc9219bb48 runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1511
diff changeset
    22
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
1511
91538d0c242c add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1446
diff changeset
    23
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    24
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    25
from __future__ import print_function
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    26
import sys
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    27
from autobahn.twisted import wamp
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    28
from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    29
from twisted.internet.defer import inlineCallbacks
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    30
from autobahn.wamp import types
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    31
from autobahn.wamp.serializer import MsgPackSerializer
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    32
from twisted.internet.protocol import ReconnectingClientFactory
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    33
import json
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    34
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    35
_WampSession = None
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    36
_PySrv = None
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    37
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    38
ExposedCalls = ["StartPLC",
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    39
                "StopPLC",
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    40
                "ForceReload",
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    41
                "GetPLCstatus",
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    42
                "NewPLC",
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    43
                "MatchMD5",
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    44
                "SetTraceVariablesList",
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    45
                "GetTraceVariables",
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    46
                "RemoteExec",
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    47
                "GetLogMessage",
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    48
                "ResetLogCount",
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    49
                ]
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    50
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    51
SubscribedEvents = []
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    52
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    53
DoOnJoin = []
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    54
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
    55
1445
e25479e3fe11 More versatile registering of wamp callees
Edouard Tisserant
parents: 1443
diff changeset
    56
def GetCallee(name):
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    57
    """ Get Callee or Subscriber corresponding to '.' spearated object path """
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    58
    global _PySrv
1445
e25479e3fe11 More versatile registering of wamp callees
Edouard Tisserant
parents: 1443
diff changeset
    59
    names = name.split('.')
e25479e3fe11 More versatile registering of wamp callees
Edouard Tisserant
parents: 1443
diff changeset
    60
    obj = _PySrv.plcobj
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
    61
    while names:
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
    62
        obj = getattr(obj, names.pop(0))
1445
e25479e3fe11 More versatile registering of wamp callees
Edouard Tisserant
parents: 1443
diff changeset
    63
    return obj
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    64
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
    65
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    66
class WampSession(wamp.ApplicationSession):
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    67
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    68
    @inlineCallbacks
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    69
    def onJoin(self, details):
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    70
        global _WampSession
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    71
        _WampSession = self
1443
ff8a22d45c44 WAMP : prefix callee names with given ID so that multiple PLC and IDE can join the same realm
Edouard Tisserant
parents: 1441
diff changeset
    72
        ID = self.config.extra["ID"]
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    73
        print('WAMP session joined by :', ID)
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
    74
        for name in ExposedCalls:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
    75
            reg = yield self.register(GetCallee(name), '.'.join((ID, name)))
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    76
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    77
        for name in SubscribedEvents:
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    78
            reg = yield self.subscribe(GetCallee(name), name)
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    79
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    80
        for func in DoOnJoin:
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    81
            yield func(self)
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    82
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    83
    def onLeave(self, details):
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    84
        global _WampSession
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    85
        _WampSession = None
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    86
        print('WAMP session left')
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
    87
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
    88
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    89
class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory):
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    90
    def clientConnectionFailed(self, connector, reason):
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    91
        print("WAMP Client connection failed .. retrying ..")
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    92
        self.retry(connector)
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1748
diff changeset
    93
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    94
    def clientConnectionLost(self, connector, reason):
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    95
        print("WAMP Client connection lost .. retrying ..")
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    96
        self.retry(connector)
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    97
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
    98
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
    99
def LoadWampClientConf(wampconf):
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
   100
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
   101
    WSClientConf = json.load(open(wampconf))
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
   102
    return WSClientConf
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
   103
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
   104
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   105
def RegisterWampClient(wampconf):
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   106
1446
4963e3816641 Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents: 1445
diff changeset
   107
    WSClientConf = LoadWampClientConf(wampconf)
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   108
1753
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1751
diff changeset
   109
    # start logging to console
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
   110
    # log.startLogging(sys.stdout)
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   111
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
   112
    # create a WAMP application session factory
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   113
    component_config = types.ComponentConfig(
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   114
        realm=WSClientConf["realm"],
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   115
        extra={"ID": WSClientConf["ID"]})
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   116
    session_factory = wamp.ApplicationSessionFactory(
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   117
        config=component_config)
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   118
    session_factory.session = WampSession
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   119
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
   120
    # create a WAMP-over-WebSocket transport client factory
1441
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
   121
    transport_factory = ReconnectingWampWebSocketClientFactory(
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   122
        session_factory,
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   123
        url=WSClientConf["url"],
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   124
        serializers=[MsgPackSerializer()],
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   125
        debug=False,
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
   126
        debug_wamp=False)
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   127
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents: 1439
diff changeset
   128
    # start the client from a Twisted endpoint
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   129
    conn = connectWS(transport_factory)
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   130
    print("WAMP client connecting to :", WSClientConf["url"])
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   131
    return conn
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   132
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
   133
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   134
def GetSession():
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   135
    global _WampSession
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   136
    return _WampSession
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   137
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1667
diff changeset
   138
1439
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   139
def SetServer(pysrv):
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   140
    global _PySrv
a68cd4253259 Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff changeset
   141
    _PySrv = pysrv