connectors/WAMP/__init__.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 26 Apr 2024 09:24:26 +0200
changeset 3938 fc4af5685aa3
parent 3884 34da877021d5
permissions -rw-r--r--
merge
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
     3
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
     6
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
     8
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
     9
# See COPYING file for copyrights details.
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    10
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
    11
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
    12
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
    13
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
    14
# of the License, or (at your option) any later version.
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    15
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
    16
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
    19
# GNU General Public License for more details.
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    20
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
    21
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
    22
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1443
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    24
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    25
2006
c4ba142bf3fb #2476 Separate connectors dialogs from connectors module.
dporopat <denis.poropat@smarteh.si>
parents: 2005
diff changeset
    26
import sys
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1595
diff changeset
    27
import traceback
2472
897687a3c982 Allow easier monkey patching of WAMP connector Session class
Edouard Tisserant
parents: 2470
diff changeset
    28
from functools import partial
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1826
diff changeset
    29
from threading import Thread, Event
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1826
diff changeset
    30
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    31
from twisted.internet import reactor, threads
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    32
from autobahn.twisted import wamp
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    33
from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    34
from autobahn.wamp import types
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    35
from autobahn.wamp.exception import TransportLost
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    36
from autobahn.wamp.serializer import MsgPackSerializer
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1826
diff changeset
    37
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    38
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    39
_WampSession = None
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
    40
_WampConnection = None
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    41
_WampSessionEvent = Event()
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    42
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    43
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    44
class WampSession(wamp.ApplicationSession):
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    45
    def onJoin(self, details):
1841
9fd29e8b1393 fix pylint warning '(global-variable-not-assigned) Using global for 'X' but no assignment is done'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    46
        global _WampSession
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    47
        _WampSession = self
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    48
        _WampSessionEvent.set()
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    49
        print('WAMP session joined for :', self.config.extra["ID"])
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    50
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    51
    def onLeave(self, details):
1841
9fd29e8b1393 fix pylint warning '(global-variable-not-assigned) Using global for 'X' but no assignment is done'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    52
        global _WampSession
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    53
        _WampSessionEvent.clear()
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    54
        _WampSession = None
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
    55
        print('WAMP session left')
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    56
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1748
diff changeset
    57
2472
897687a3c982 Allow easier monkey patching of WAMP connector Session class
Edouard Tisserant
parents: 2470
diff changeset
    58
def _WAMP_connector_factory(cls, uri, confnodesroot):
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    59
    """
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    60
    WAMP://127.0.0.1:12345/path#realm#ID
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    61
    WAMPS://127.0.0.1:12345/path#realm#ID
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    62
    """
2338
2c3222433244 Renaming servicetype into scheme.
Edouard Tisserant
parents: 2006
diff changeset
    63
    scheme, location = uri.split("://")
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    64
    urlpath, realm, ID = location.split('#')
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
    65
    urlprefix = {"WAMP":  "ws",
2338
2c3222433244 Renaming servicetype into scheme.
Edouard Tisserant
parents: 2006
diff changeset
    66
                 "WAMPS": "wss"}[scheme]
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    67
    url = urlprefix+"://"+urlpath
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    68
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    69
    def RegisterWampClient():
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    70
1753
19f19c66b67e clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1750
diff changeset
    71
        # start logging to console
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    72
        # log.startLogging(sys.stdout)
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    73
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    74
        # create a WAMP application session factory
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    75
        component_config = types.ComponentConfig(
3752
9f6f46dbe3ae removed Python2 modules
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
    76
            realm=str(realm),
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1740
diff changeset
    77
            extra={"ID": ID})
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    78
        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
    79
            config=component_config)
2472
897687a3c982 Allow easier monkey patching of WAMP connector Session class
Edouard Tisserant
parents: 2470
diff changeset
    80
        session_factory.session = cls
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    81
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    82
        # create a WAMP-over-WebSocket transport client factory
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    83
        transport_factory = WampWebSocketClientFactory(
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    84
            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
    85
            url=url,
1894
f224383cc883 Fixed changes from dporopat and agregorcic about WAMP CRA and config.
Edouard Tisserant
parents: 1881
diff changeset
    86
            serializers=[MsgPackSerializer()])
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    87
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    88
        # start the client from a Twisted endpoint
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    89
        conn = connectWS(transport_factory)
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
    90
        confnodesroot.logger.write(_("WAMP connecting to URL : %s\n") % url)
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    91
        return conn
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
    92
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
    93
    AddToDoBeforeQuit = confnodesroot.AppFrame.AddToDoBeforeQuit
1750
acf02488f37f clean-up: fix PEP8 E306 expected 1 blank line before a nested definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
    94
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
    95
    def ThreadProc():
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
        global _WampConnection
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
        _WampConnection = RegisterWampClient()
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    98
        AddToDoBeforeQuit(reactor.stop)
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
    99
        reactor.run(installSignalHandlers=False)
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
   100
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   101
    class WampPLCObjectProxy(object):
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   102
        def __init__(self):
1841
9fd29e8b1393 fix pylint warning '(global-variable-not-assigned) Using global for 'X' but no assignment is done'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   103
            global _WampConnection
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   104
            if not reactor.running:
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   105
                Thread(target=ThreadProc).start()
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   106
            else:
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
   107
                _WampConnection = threads.blockingCallFromThread(
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   108
                    reactor, RegisterWampClient)
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   109
            if not _WampSessionEvent.wait(5):
1872
866fb3ab8778 fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1846
diff changeset
   110
                _WampConnection.stopConnecting()
1765
ccf59c1f0b45 clean-up: fix PEP8 W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
   111
                raise Exception(_("WAMP connection timeout"))
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   112
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   113
        def __del__(self):
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
   114
            _WampConnection.disconnect()
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
   115
            #
826730e60407 Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents: 1440
diff changeset
   116
            # reactor.stop()
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   117
3861
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   118
        def WampSessionProcMapper(self, funcname):
3881
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3752 3861
diff changeset
   119
            wampfuncname = str('.'.join((ID, funcname)))
3861
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   120
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   121
            def catcher_func(*args, **kwargs):
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   122
                if _WampSession is not None:
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   123
                    try:
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   124
                        return threads.blockingCallFromThread(
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   125
                            reactor, _WampSession.call, wampfuncname,
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   126
                            *args, **kwargs)
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   127
                    except TransportLost:
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   128
                        confnodesroot.logger.write_error(_("Connection lost!\n"))
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   129
                        confnodesroot._SetConnector(None)
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   130
                    except Exception:
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   131
                        errmess = traceback.format_exc()
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   132
                        confnodesroot.logger.write_error(errmess+"\n")
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   133
                        print(errmess)
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   134
                        # confnodesroot._SetConnector(None)
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   135
                return self.PLCObjDefaults.get(funcname)
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   136
            return catcher_func
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   137
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   138
        def __getattr__(self, attrName):
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   139
            member = self.__dict__.get(attrName, None)
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   140
            if member is None:
3861
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 2492
diff changeset
   141
                member = self.WampSessionProcMapper(attrName)
1440
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   142
                self.__dict__[attrName] = member
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   143
            return member
e8daabf2c438 Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
diff changeset
   144
2339
48b4eba13064 IDManager : refactored a bit, moved some code into PSKManagement.py. Now captures URI and PSK on new PYRO(S) and propose them when editing URI. Import/export still to be implemented.
Edouard Tisserant
parents: 2338
diff changeset
   145
    # TODO : GetPLCID()
48b4eba13064 IDManager : refactored a bit, moved some code into PSKManagement.py. Now captures URI and PSK on new PYRO(S) and propose them when editing URI. Import/export still to be implemented.
Edouard Tisserant
parents: 2338
diff changeset
   146
    # TODO : PSK.UpdateID()
48b4eba13064 IDManager : refactored a bit, moved some code into PSKManagement.py. Now captures URI and PSK on new PYRO(S) and propose them when editing URI. Import/export still to be implemented.
Edouard Tisserant
parents: 2338
diff changeset
   147
3884
34da877021d5 Replace PYRO with ERPC. Work In Progress.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3881
diff changeset
   148
    return WampPLCObjectProxy()
2472
897687a3c982 Allow easier monkey patching of WAMP connector Session class
Edouard Tisserant
parents: 2470
diff changeset
   149
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2472
diff changeset
   150
2472
897687a3c982 Allow easier monkey patching of WAMP connector Session class
Edouard Tisserant
parents: 2470
diff changeset
   151
WAMP_connector_factory = partial(_WAMP_connector_factory, WampSession)