diff --git a/config/settings/espeak.settings.conf b/config/settings/espeak.settings.conf index 3fd09f86..5b2b5250 100644 --- a/config/settings/espeak.settings.conf +++ b/config/settings/espeak.settings.conf @@ -188,7 +188,7 @@ cursor=True highlight=False [remote] -enable=True +enabled=True # connection type # unix = unix sockets method=unix diff --git a/config/settings/settings.conf.example b/config/settings/settings.conf.example index fd65bf79..8754aa14 100644 --- a/config/settings/settings.conf.example +++ b/config/settings/settings.conf.example @@ -199,7 +199,7 @@ cursor=True highlight=False [remote] -enable=True +enabled=True # connection type # unix = unix sockets method=unix diff --git a/config/settings/settings.conf.storm b/config/settings/settings.conf.storm index ebb18c49..e9bc09be 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -144,7 +144,7 @@ cursor=True highlight=False [remote] -enable=True +enabled=True # connection type # unix = unix sockets method=unix diff --git a/config/settings/speech-dispatcher.settings.conf b/config/settings/speech-dispatcher.settings.conf index e8c315da..b4fb40af 100644 --- a/config/settings/speech-dispatcher.settings.conf +++ b/config/settings/speech-dispatcher.settings.conf @@ -198,7 +198,7 @@ cursor=True highlight=False [remote] -enable=True +enabled=True # connection type # unix = unix sockets method=unix diff --git a/src/fenrirscreenreader/core/byteManager.py b/src/fenrirscreenreader/core/byteManager.py index 777ebaba..ebf57fcb 100644 --- a/src/fenrirscreenreader/core/byteManager.py +++ b/src/fenrirscreenreader/core/byteManager.py @@ -35,17 +35,17 @@ class byteManager(): if eventData == b'': return - convertedEscapeSequence = self.unifyEscapeSeq(eventData) + convertedEscapeSequence = self.unifyEscapeSeq(eventData) if self.switchCtrlModeOnce > 0: - self.switchCtrlModeOnce -= 1 - + self.switchCtrlModeOnce -= 1 + isControlMode = False if self.controlMode and not self.switchCtrlModeOnce == 1 or\ not self.controlMode: isControlMode = self.handleControlMode(eventData) - isCommand = False + isCommand = False if self.controlMode and not self.switchCtrlModeOnce == 1 or\ not self.controlMode and self.switchCtrlModeOnce == 1: if self.lastByteKey == convertedEscapeSequence: @@ -53,16 +53,16 @@ class byteManager(): self.repeat += 1 shortcutData = b'' for i in range(self.repeat): - shortcutData = shortcutData + convertedEscapeSequence + shortcutData = shortcutData + convertedEscapeSequence isCommand = self.detectByteCommand(shortcutData) # fall back to single stroke - do we want this? if not isCommand: isCommand = self.detectByteCommand(convertedEscapeSequence) - self.repeat = 1 + self.repeat = 1 if not (isCommand or isControlMode): self.env['runtime']['screenManager'].injectTextToScreen(eventData) if not isCommand: - self.repeat = 1 + self.repeat = 1 self.lastByteKey = convertedEscapeSequence self.lastInputTime = time.time() def getLastByteKey(self): diff --git a/src/fenrirscreenreader/core/eventManager.py b/src/fenrirscreenreader/core/eventManager.py index 82e55b7c..49185474 100644 --- a/src/fenrirscreenreader/core/eventManager.py +++ b/src/fenrirscreenreader/core/eventManager.py @@ -29,7 +29,7 @@ class eventManager(): #print('NET loop ' + str(time.time() - st)) def eventDispatcher(self, event): self.env['runtime']['debug'].writeDebugOut('eventManager:eventDispatcher:start: event: ' + str(event['Type']),debug.debugLevel.INFO) - + if not event: return if not event['Type']: @@ -79,9 +79,9 @@ class eventManager(): except Empty: pass def getEventQueue(self): - return self._eventQueue + return self._eventQueue def getRunning(self): - return self.running + return self.running def putToEventQueue(self,event, data): if not isinstance(event, fenrirEventType): return False diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index e6ef192f..51613544 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -6,16 +6,102 @@ from fenrirscreenreader.core import debug from fenrirscreenreader.core.eventData import fenrirEventType +import time +import select class remoteManager(): def __init__(self): pass def initialize(self, environment): - self.env = environment + self.env = environment + self.env['runtime']['processManager'].addCustomEventThread(self.tcpWatchDog, multiprocess=True) + return + if self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enabled'): + if self.env['runtime']['settingsManager'].getSetting('remote', 'method') == 'unix': + self.env['runtime']['processManager'].addCustomEventThread(self.unixSocketWatchDog, multiprocess=True) + elif self.env['runtime']['settingsManager'].getSetting('remote', 'method') == 'tcp': + self.env['runtime']['processManager'].addCustomEventThread(self.tcpWatchDog, multiprocess=True) def shutdown(self): - pass - def unixSocketWatchDog(): - pass + if self.sock: + self.sock.close() + self.sock = None + def unixSocketWatchDog(self, active, eventQueue): + while active.value == 1: + eventQueue.put({"Type":fenrirEventType.RemoteIncomming, + "Data":'#!#command##say##this is a test' + }) + eventQueue.put({"Type":fenrirEventType.RemoteIncomming, + "Data":'#!#command##interrupt' + }) + def tcpWatchDog(self, active, eventQueue): + import socket + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.host = '0.0.0.0' + self.port = 22447 + self.sock.bind((self.host, self.port)) + self.sock.listen(1) + while active.value == 1: + client_sock, client_addr = self.sock.accept() + if client_sock: + # Check if the client is still connected and if data is available: + try: + r, w, e = select.select([client_sock,], [], []) + except select.error: + return + if len(r) > 0: + rawdata = client_sock.recv(8129) + try: + data = rawdata.decode("utf-8").rstrip() + if data.startswith('#!#'): + eventQueue.put({"Type":fenrirEventType.RemoteIncomming, + "Data": data + }) + except: + pass + client_sock.close() + if self.sock: + self.sock.close() + self.sock = None + def handleSettingsChange(self, settingsText): + if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'): + return + if settingsText.startswith('set##'): + parameterText = settingsText[len('set##'):] + self.setSettings(parameterText) + if settingsText.startswith('reset'): + self.resetSettings() + def handleCommandExecution(self, commandText): + if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'): + return + if commandText.startswith('exec#say##'): + parameterText = commandText[len('exec#say##'):] + self.execSay(parameterText) + if commandText.startswith('cancel##say'): + self.execInterruptSpeech() + def execSay(self, text): + self.env['runtime']['outputManager'].speakText(text) + def execInterruptSpeech(self): + self.env['runtime']['outputManager'].interruptOutput() + def resetSettings(self): + self.env['runtime']['settingsManager'].resetSettingArgDict() + def setSettings(self, settingsArgs): + self.env['runtime']['settingsManager'].parseSettingArgs(settingsArgs) def handleRemoteIncomming(self, eventData): if not eventData: return + # settings: + # #!#settings##set##section#setting=value[,section#setting=value] + # #!#settings##set##speech#voice=de + # #!#settings##reset + # execute command: + # #!#command##exec#say##this is a test + # #!#command##cancel##say + if not eventData.startswith('#!#'): + return + if eventData.startswith('#!#settings##'): + settingsText = eventData[len('#!#settings##'):] + self.handleSettingsChange(settingsText) + elif eventData.startswith('#!#command##'): + commandText = eventData[len('#!#command##'):] + self.handleCommandExecution(commandText) diff --git a/src/fenrirscreenreader/core/settingsData.py b/src/fenrirscreenreader/core/settingsData.py index 7cacaa36..12e206f0 100644 --- a/src/fenrirscreenreader/core/settingsData.py +++ b/src/fenrirscreenreader/core/settingsData.py @@ -82,7 +82,7 @@ settingsData = { 'highlight': False, }, 'remote':{ - 'enable': True, + 'enabled': True, 'method': 'unix', 'enableSettingsRemote': True, 'allowSettings': 'barrier#enabled', diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index 4821813c..a7ddad2b 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -174,6 +174,8 @@ class settingsManager(): for key in keyList: if not key in self.env['input']['scriptKey']: self.env['input']['scriptKey'].append(key) + def resetSettingArgDict(self): + self.settingArgDict = {} def setOptionArgDict(self, section, option, value): section = section.lower() option = option.lower()