split out remote backends

This commit is contained in:
chrys 2018-09-09 19:08:18 +02:00
parent 79b4ac32fb
commit d991a94451
16 changed files with 170 additions and 110 deletions

View File

@ -188,10 +188,10 @@ highlight=False
[remote] [remote]
enable=True enable=True
# connection type # driver
# unix = unix sockets # unixDriver = unix sockets
# tcp = tcp (localhost only) # tcpDriver = tcp (localhost only)
method=unix driver=unixDriver
# tcp port # tcp port
port=22447 port=22447
# socket filepath # socket filepath

View File

@ -198,10 +198,10 @@ highlight=False
[remote] [remote]
enable=True enable=True
# connection type # driver
# unix = unix sockets # unixDriver = unix sockets
# tcp = tcp (localhost only) # tcpDriver = tcp (localhost only)
method=unix driver=unixDriver
# tcp port # tcp port
port=22447 port=22447
# socket filepath # socket filepath

View File

@ -198,10 +198,10 @@ highlight=False
[remote] [remote]
enable=True enable=True
# connection type # driver
# unix = unix sockets # unixDriver = unix sockets
# tcp = tcp (localhost only) # tcpDriver = tcp (localhost only)
method=unix driver=unixDriver
# tcp port # tcp port
port=22447 port=22447
# socket filepath # socket filepath

View File

@ -198,10 +198,10 @@ highlight=False
[remote] [remote]
enable=True enable=True
# connection type # driver
# unix = unix sockets # unixDriver = unix sockets
# tcp = tcp (localhost only) # tcpDriver = tcp (localhost only)
method=unix driver=unixDriver
# tcp port # tcp port
port=22447 port=22447
# socket filepath # socket filepath

View File

@ -199,10 +199,10 @@ highlight=False
[remote] [remote]
enable=True enable=True
# connection type # driver
# unix = unix sockets # unixDriver = unix sockets
# tcp = tcp (localhost only) # tcpDriver = tcp (localhost only)
method=unix driver=unixDriver
# tcp port # tcp port
port=22447 port=22447
# socket filepath # socket filepath

View File

@ -144,10 +144,10 @@ highlight=False
[remote] [remote]
enable=True enable=True
# connection type # driver
# unix = unix sockets # unixDriver = unix sockets
# tcp = tcp (localhost only) # tcpDriver = tcp (localhost only)
method=unix driver=unixDriver
# tcp port # tcp port
port=22447 port=22447
# socket filepath # socket filepath

View File

@ -198,10 +198,10 @@ highlight=False
[remote] [remote]
enable=True enable=True
# connection type # driver
# unix = unix sockets # unixDriver = unix sockets
# tcp = tcp (localhost only) # tcpDriver = tcp (localhost only)
method=unix driver=unixDriver
# tcp port # tcp port
port=22447 port=22447
# socket filepath # socket filepath

View File

@ -0,0 +1,16 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug
class remoteDriver():
def __init__(self):
self._isInitialized = False
def initialize(self, environment):
self.env = environment
self._isInitialized = True
def shutdown(self):
self._isInitialized = False

View File

@ -29,9 +29,6 @@ command interrupt
from fenrirscreenreader.core import debug from fenrirscreenreader.core import debug
from fenrirscreenreader.core.eventData import fenrirEventType from fenrirscreenreader.core.eventData import fenrirEventType
import time import time
import select
import socket
import os, os.path
class remoteManager(): class remoteManager():
def __init__(self): def __init__(self):
@ -48,83 +45,11 @@ class remoteManager():
self.resetSettingConst = 'RESET' self.resetSettingConst = 'RESET'
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
self.env['runtime']['settingsManager'].loadDriver(\
if self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enabled'): self.env['runtime']['settingsManager'].getSetting('remote', 'driver'), 'remoteDriver')
if self.env['runtime']['settingsManager'].getSetting('remote', 'method').upper() == 'UNIX':
self.env['runtime']['processManager'].addCustomEventThread(self.unixSocketWatchDog, multiprocess=True)
elif self.env['runtime']['settingsManager'].getSetting('remote', 'method').upper() == 'TCP':
self.env['runtime']['processManager'].addCustomEventThread(self.tcpWatchDog, multiprocess=True)
def shutdown(self): def shutdown(self):
if self.sock: self.env['runtime']['settingsManager'].shutdownDriver('remoteDriver')
self.sock.close()
self.sock = None
def unixSocketWatchDog(self, active, eventQueue):
# echo "command say this is a test" | socat - UNIX-CLIENT:/tmp/fenrirscreenreader-deamon.sock
if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver':
socketpath = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'socketpath') + 'fenrirscreenreader-deamon.sock'
else:
socketpath = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'socketpath') + 'fenrirscreenreader-' + str(os.getpid()) + '.sock'
if os.path.exists(socketpath):
os.remove(socketpath)
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.bind(socketpath)
self.sock.listen(1)
if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver':
os.chmod(socketpath, 0o222)
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().lstrip()
eventQueue.put({"Type":fenrirEventType.RemoteIncomming,
"Data": data
})
except:
pass
client_sock.close()
if os.path.exists(socketpath):
os.remove(socketpath)
if self.sock:
self.sock.close()
self.sock = None
def tcpWatchDog(self, active, eventQueue):
# echo "command say this is a test" | nc localhost 22447
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.host = '127.0.0.1'
self.port = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'port')
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().lstrip()
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): def handleSettingsChange(self, settingsText):
if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'):
return return
@ -200,6 +125,8 @@ class remoteManager():
if not eventData: if not eventData:
return return
upperEventData = eventData.upper() upperEventData = eventData.upper()
self.env['runtime']['debug'].writeDebugOut('remoteManager:handleRemoteIncomming: event: ' + str(eventData),debug.debugLevel.INFO)
if upperEventData.startswith(self.settingConst): if upperEventData.startswith(self.settingConst):
settingsText = eventData[len(self.settingConst):] settingsText = eventData[len(self.settingConst):]
self.handleSettingsChange(settingsText) self.handleSettingsChange(settingsText)

View File

@ -11,6 +11,7 @@ runtimeData = {
'screenDriver': None, 'screenDriver': None,
'soundDriver': None, 'soundDriver': None,
'inputDriver': None, 'inputDriver': None,
'remoteDriver': None,
'brailleDriver': None, 'brailleDriver': None,
'inputManager': None, 'inputManager': None,
'commandManager': None, 'commandManager': None,

View File

@ -82,7 +82,7 @@ settingsData = {
}, },
'remote':{ 'remote':{
'enabled': True, 'enabled': True,
'method': 'unix', 'driver': 'unixDriver',
'port': 22447, 'port': 22447,
'socketpath':'/tmp/', 'socketpath':'/tmp/',
'enableSettingsRemote': True, 'enableSettingsRemote': True,

View File

@ -0,0 +1,12 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug
from fenrirscreenreader.core.remoteDriver import remoteDriver
class driver(remoteDriver):
def __init__(self):
remoteDriver.__init__(self)

View File

@ -0,0 +1,47 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug
from fenrirscreenreader.core.remoteDriver import remoteDriver
from fenrirscreenreader.core.eventData import fenrirEventType
import select, socket, os, os.path
class driver(remoteDriver):
def __init__(self):
remoteDriver.__init__(self)
def initialize(self, environment):
self.env = environment
self.env['runtime']['processManager'].addCustomEventThread(self.watchDog, multiprocess=True)
def watchDog(self, active, eventQueue):
# echo "command say this is a test" | nc localhost 22447
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.host = '127.0.0.1'
self.port = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'port')
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().lstrip()
eventQueue.put({"Type":fenrirEventType.RemoteIncomming,
"Data": data
})
except:
pass
client_sock.close()
if self.sock:
self.sock.close()
self.sock = None

View File

@ -0,0 +1,57 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug
from fenrirscreenreader.core.remoteDriver import remoteDriver
from fenrirscreenreader.core.eventData import fenrirEventType
import select, socket, os, os.path
class driver(remoteDriver):
def __init__(self):
remoteDriver.__init__(self)
def initialize(self, environment):
self.env = environment
self.env['runtime']['processManager'].addCustomEventThread(self.watchDog, multiprocess=True)
def watchDog(self, active, eventQueue):
# echo "command say this is a test" | socat - UNIX-CLIENT:/tmp/fenrirscreenreader-deamon.sock
if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver':
socketpath = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'socketpath') + 'fenrirscreenreader-deamon.sock'
else:
socketpath = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'socketpath') + 'fenrirscreenreader-' + str(os.getpid()) + '.sock'
if os.path.exists(socketpath):
os.remove(socketpath)
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.bind(socketpath)
self.sock.listen(1)
if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver':
os.chmod(socketpath, 0o222)
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().lstrip()
eventQueue.put({"Type":fenrirEventType.RemoteIncomming,
"Data": data
})
except:
pass
client_sock.close()
if os.path.exists(socketpath):
os.remove(socketpath)
if self.sock:
self.sock.close()
self.sock = None