Commit 77883e3e authored by Michael Büsch's avatar Michael Büsch

Add connection timeout to project

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent 891f0d0f
[AWLSIM_PROJECT]
file_version=0
date=2014-12-18 13:31:27.166506
date=2014-12-24 12:00:55.945552
[CPU]
awl_0=T1JHQU5JWkFUSU9OX0JMT0NLIE9CIDENCkJFR0lODQoNCglDQUxMCUZDIDENCglDQUxMCUZDIDINCglDQUxMCUZCIDEsIERCIDIgKA0KCQlJTlBVVF9WQVIgOj0gMQ0KCSkNCg0KCUFVRglEQiAxDQoJTAlEQkQgMg0KCVQJTUQgMTYNCg0KRU5EX09SR0FOSVpBVElPTl9CTE9DSw0K
......@@ -31,6 +31,7 @@ spawn_local_port_range=4151:8246
spawn_local_interpreters=cHlweTM7IHB5cHk7ICRDVVJSRU5UOyBweXRob24zOyBweXRob24yOyBweXRob247IHB5
connect_host=bG9jYWxob3N0
connect_port=4151
connect_timeout_ms=3000
[GUI]
editor_autoindent=1
......
......@@ -200,12 +200,14 @@ class CoreLinkSettings(object):
spawnLocalInterpreters="pypy3; pypy; $CURRENT; "\
"python3; python2; python; py",
connectHost="localhost",
connectPort=4151):
connectPort=4151,
connectTimeoutMs=3000):
self.setSpawnLocalEn(spawnLocalEn)
self.setSpawnLocalPortRange(spawnLocalPortRange)
self.setSpawnLocalInterpreters(spawnLocalInterpreters),
self.setConnectHost(connectHost)
self.setConnectPort(connectPort)
self.setConnectTimeoutMs(connectTimeoutMs)
def setSpawnLocalEn(self, spawnLocalEn):
self.spawnLocalEn = spawnLocalEn
......@@ -247,6 +249,12 @@ class CoreLinkSettings(object):
def getConnectPort(self):
return self.connectPort
def setConnectTimeoutMs(self, connectTimeoutMs):
self.connectTimeoutMs = connectTimeoutMs
def getConnectTimeoutMs(self):
return self.connectTimeoutMs
class Project(object):
def __init__(self, projectFile,
awlSources=[],
......@@ -507,6 +515,9 @@ class Project(object):
if p.has_option("CORE_LINK", "connect_port"):
port = p.getint("CORE_LINK", "connect_port")
linkSettings.setConnectPort(port)
if p.has_option("CORE_LINK", "connect_timeout_ms"):
timeout = p.getint("CORE_LINK", "connect_timeout_ms")
linkSettings.setConnectTimeoutMs(timeout)
# GUI section
if p.has_option("GUI", "editor_autoindent"):
......@@ -629,7 +640,10 @@ class Project(object):
host = host.encode("utf-8", "ignore")
host = base64.b64encode(host).decode("ascii")
lines.append("connect_host=%s" % host)
lines.append("connect_port=%d" % int(linkSettings.getConnectPort()))
lines.append("connect_port=%d" %\
int(linkSettings.getConnectPort()))
lines.append("connect_timeout_ms=%d" %\
int(linkSettings.getConnectTimeoutMs()))
lines.append("")
lines.append("[GUI]")
......
......@@ -109,7 +109,7 @@ class GuiAwlSimClient(AwlSimClient, QObject):
self.shutdownTransceiver()
self.__setMode(self.MODE_OFFLINE)
def setMode_ONLINE(self, host, port):
def setMode_ONLINE(self, host, port, timeout=3.0):
if self.__mode == self.MODE_ONLINE:
if self.__host == host and\
self.__port == port:
......@@ -119,7 +119,9 @@ class GuiAwlSimClient(AwlSimClient, QObject):
self.__interpreterList = None
self.shutdown()
try:
self.connectToServer(host = host, port = port)
self.connectToServer(host = host,
port = port,
timeout = timeout)
except AwlSimError as e:
CALL_NOEX(self.shutdown)
raise e
......
......@@ -461,7 +461,10 @@ class CpuWidget(QWidget):
else:
host = linkConfig.getConnectHost()
port = linkConfig.getConnectPort()
client.setMode_ONLINE(host = host, port = port)
timeout = linkConfig.getConnectTimeoutMs() / 1000.0
client.setMode_ONLINE(host = host,
port = port,
timeout = timeout)
self.state.setCoreDetails(spawned = linkConfig.getSpawnLocalEn(),
host = host,
......
......@@ -101,6 +101,18 @@ class _ConnectConfigWidget(QGroupBox):
self.port.setToolTip(toolTip)
self.layout().addWidget(self.port, 1, 1)
toolTip = "Connection timeout."
label = QLabel("Timeout:", self)
label.setToolTip(toolTip)
self.layout().addWidget(label, 2, 0)
self.timeout = QDoubleSpinBox(self)
self.timeout.setRange(0.5, 60.0)
self.timeout.setSingleStep(0.5)
self.timeout.setDecimals(1)
self.timeout.setSuffix(" s")
self.timeout.setToolTip(toolTip)
self.layout().addWidget(self.timeout, 2, 1)
class LinkConfigDialog(QDialog):
# Signal: Emitted, if any content changed.
contentChanged = Signal()
......@@ -212,6 +224,8 @@ class LinkConfigDialog(QDialog):
self.connConfig.host.setText(linkSettings.getConnectHost())
self.connConfig.port.setValue(linkSettings.getConnectPort())
self.connConfig.timeout.setValue(
linkSettings.getConnectTimeoutMs() / 1000.0)
def __handleAccepted(self):
linkSettings = self.__project.getCoreLinkSettings()
......@@ -239,6 +253,10 @@ class LinkConfigDialog(QDialog):
if port != linkSettings.getConnectPort():
linkSettings.setConnectPort(port)
changed = True
timeout = int(round(self.connConfig.timeout.value() * 1000))
if timeout != linkSettings.getConnectTimeoutMs():
linkSettings.setConnectTimeoutMs(timeout)
changed = True
if changed:
self.contentChanged.emit()
Markdown is supported
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