summaryrefslogtreecommitdiff
path: root/voctocore/lib/controlserver.py
diff options
context:
space:
mode:
authorMaZderMind <git@mazdermind.de>2015-09-02 15:08:49 +0200
committerMaZderMind <git@mazdermind.de>2015-09-02 15:08:49 +0200
commitc61fe2b667079168387376da1c09823967476b21 (patch)
tree4e281f520c228b0525df403706903962d6c84da9 /voctocore/lib/controlserver.py
parent46aace37db5c035a6d6b432db261dc7c417456f4 (diff)
refactor commands and notify code
Diffstat (limited to 'voctocore/lib/controlserver.py')
-rw-r--r--voctocore/lib/controlserver.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/voctocore/lib/controlserver.py b/voctocore/lib/controlserver.py
index 4e95e46..e0632fc 100644
--- a/voctocore/lib/controlserver.py
+++ b/voctocore/lib/controlserver.py
@@ -5,6 +5,7 @@ from gi.repository import GObject
from lib.commands import ControlServerCommands
from lib.tcpmulticonnection import TCPMultiConnection
+from lib.response import NotifyResponse, OkResponse
class ControlServer(TCPMultiConnection):
def __init__(self, pipeline):
@@ -73,21 +74,29 @@ class ControlServer(TCPMultiConnection):
args = words[1:]
try:
- f = self.commands.fetch(command)
- message, send_signals = f(*args)
- response = "ok %s\n" % message
+ command_function = self.commands.__class__.__dict__[command]
- except Exception as e:
- message = str(e) or "<no message>"
- response = "error %s\n" % message
+ except KeyError as e:
+ response = "error unknown command %s\n" % command
else:
- if send_signals:
- signal = "signal %s\n" % line
- for conn, queue in self.currentConnections.items():
- if conn == requestor:
- continue
- queue.put(signal)
+ try:
+ responseObject = command_function(self.commands, *args)
+
+ except Exception as e:
+ message = str(e) or "<no message>"
+ response = "error %s\n" % message
+
+ else:
+ if isinstance(responseObject, NotifyResponse):
+ signal = "%s\n" % str(responseObject)
+ for conn, queue in self.currentConnections.items():
+ if conn == requestor:
+ continue
+
+ queue.put(signal)
+
+ response = "%s\n" % str(responseObject)
finally:
self.currentConnections[requestor].put(response)