Commit 2d11d7ff authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Prepare support for shared libraries

parent c31afeb6
...@@ -17,6 +17,7 @@ import re ...@@ -17,6 +17,7 @@ import re
import logging import logging
import optparse import optparse
import time import time
from ctypes import CDLL
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
terminal_formatter = logging.Formatter( terminal_formatter = logging.Formatter(
...@@ -131,6 +132,8 @@ def gui(): ...@@ -131,6 +132,8 @@ def gui():
help='Display debug information') help='Display debug information')
parser.add_option('--udp', dest='udp', metavar='RemoteIP:inPort:outPort', parser.add_option('--udp', dest='udp', metavar='RemoteIP:inPort:outPort',
help='Use UDP sockets instead of message queues') help='Use UDP sockets instead of message queues')
parser.add_option('-l', '--shared_lib', action='store_true', default=False,
help='Use a shared library instead of msgQ or UDP')
parser.add_option('-r', '--reset', action='store_true', default=False, parser.add_option('-r', '--reset', action='store_true', default=False,
help='Do not try to restore windows layout') help='Do not try to restore windows layout')
parser.add_option('-i', '--ivpath', dest='ivpath', parser.add_option('-i', '--ivpath', dest='ivpath',
...@@ -151,10 +154,18 @@ def gui(): ...@@ -151,10 +154,18 @@ def gui():
log.error('You entered ' + options.udp) log.error('You entered ' + options.udp)
sys.exit(-1) sys.exit(-1)
try:
import datamodel
except ImportError:
log.error('Could not import project data')
return -1
msgQ = True msgQ = True
udp = None udp = None
dll = None
hasTM = False hasTM = False
if options.udp is None: if options.udp is None and options.shared_lib is None:
# Default: use message queue
try: try:
from PythonController import(OpenMsgQueueForReading, from PythonController import(OpenMsgQueueForReading,
GetMsgQueueBufferSize, DV, RetrieveMessageFromQueue) GetMsgQueueBufferSize, DV, RetrieveMessageFromQueue)
...@@ -162,7 +173,7 @@ def gui(): ...@@ -162,7 +173,7 @@ def gui():
except ImportError: except ImportError:
log.error('Python module "PythonController" is missing') log.error('Python module "PythonController" is missing')
return -1 return -1
else: elif options.udp:
msgQ = False msgQ = False
udpConfig = options.udp.split(':') udpConfig = options.udp.split(':')
log.debug('UDP with IP={cfg[0]} inPort={cfg[1]} outPort={cfg[2]}' log.debug('UDP with IP={cfg[0]} inPort={cfg[1]} outPort={cfg[2]}'
...@@ -175,12 +186,16 @@ def gui(): ...@@ -175,12 +186,16 @@ def gui():
except ImportError: except ImportError:
log.error('Python module "udpcontroller" is missing') log.error('Python module "udpcontroller" is missing')
return -1 return -1
elif options.options.shared_lib:
try: # Load and run the startup transition of the shared library (Ada only?)
import datamodel try:
except ImportError: dll = CDLL('./{}.so'.format(datamodel.FVname))
log.error('Could not import user-defined datamodel') dll_init = getattr(dll, 'lib{}init'.format(datamodel.FVname))
return -1 dll_init()
except OSError:
log.error('Shared library ./{}.so not found'
.format(datamodel.FVname))
return -1
# Define a Qt application (mandatory) # Define a Qt application (mandatory)
app = QApplication(sys.argv) app = QApplication(sys.argv)
...@@ -295,8 +310,10 @@ def gui(): ...@@ -295,8 +310,10 @@ def gui():
editor.msc.connect(msc.addToMsc) editor.msc.connect(msc.addToMsc)
if msgQ: if msgQ:
encoder_backend.setMsgQ() encoder_backend.setMsgQ()
else: elif udp:
encoder_backend.setUDP() encoder_backend.setUDP()
elif dll:
encoder_backend.setSharedLib(dll)
editor.backend = encoder_backend editor.backend = encoder_backend
editor.log = log editor.log = log
dockWidget = editor.parent() dockWidget = editor.parent()
...@@ -340,10 +357,13 @@ def gui(): ...@@ -340,10 +357,13 @@ def gui():
if isinstance(editor, asn1Viewer): if isinstance(editor, asn1Viewer):
pollingThread.tm.connect(editor.receivedTM) pollingThread.tm.connect(editor.receivedTM)
pollingThread.start() pollingThread.start()
else: # use UDP elif udp:
if hasTM: if hasTM:
udp.tmPool = g_tmPool udp.tmPool = g_tmPool
udp.start(hasTM) udp.start(hasTM)
elif dll:
# TODO Should register the TMs callbacks
pass
# Associate the plotter manager to the main app # Associate the plotter manager to the main app
myWidget.plotter = plotter myWidget.plotter = plotter
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment