split out remote backends
This commit is contained in:
parent
79b4ac32fb
commit
d991a94451
@ -188,10 +188,10 @@ highlight=False
|
||||
|
||||
[remote]
|
||||
enable=True
|
||||
# connection type
|
||||
# unix = unix sockets
|
||||
# tcp = tcp (localhost only)
|
||||
method=unix
|
||||
# driver
|
||||
# unixDriver = unix sockets
|
||||
# tcpDriver = tcp (localhost only)
|
||||
driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
|
@ -198,10 +198,10 @@ highlight=False
|
||||
|
||||
[remote]
|
||||
enable=True
|
||||
# connection type
|
||||
# unix = unix sockets
|
||||
# tcp = tcp (localhost only)
|
||||
method=unix
|
||||
# driver
|
||||
# unixDriver = unix sockets
|
||||
# tcpDriver = tcp (localhost only)
|
||||
driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
|
@ -198,10 +198,10 @@ highlight=False
|
||||
|
||||
[remote]
|
||||
enable=True
|
||||
# connection type
|
||||
# unix = unix sockets
|
||||
# tcp = tcp (localhost only)
|
||||
method=unix
|
||||
# driver
|
||||
# unixDriver = unix sockets
|
||||
# tcpDriver = tcp (localhost only)
|
||||
driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
|
@ -198,10 +198,10 @@ highlight=False
|
||||
|
||||
[remote]
|
||||
enable=True
|
||||
# connection type
|
||||
# unix = unix sockets
|
||||
# tcp = tcp (localhost only)
|
||||
method=unix
|
||||
# driver
|
||||
# unixDriver = unix sockets
|
||||
# tcpDriver = tcp (localhost only)
|
||||
driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
|
@ -199,10 +199,10 @@ highlight=False
|
||||
|
||||
[remote]
|
||||
enable=True
|
||||
# connection type
|
||||
# unix = unix sockets
|
||||
# tcp = tcp (localhost only)
|
||||
method=unix
|
||||
# driver
|
||||
# unixDriver = unix sockets
|
||||
# tcpDriver = tcp (localhost only)
|
||||
driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
|
@ -144,10 +144,10 @@ highlight=False
|
||||
|
||||
[remote]
|
||||
enable=True
|
||||
# connection type
|
||||
# unix = unix sockets
|
||||
# tcp = tcp (localhost only)
|
||||
method=unix
|
||||
# driver
|
||||
# unixDriver = unix sockets
|
||||
# tcpDriver = tcp (localhost only)
|
||||
driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
|
@ -198,10 +198,10 @@ highlight=False
|
||||
|
||||
[remote]
|
||||
enable=True
|
||||
# connection type
|
||||
# unix = unix sockets
|
||||
# tcp = tcp (localhost only)
|
||||
method=unix
|
||||
# driver
|
||||
# unixDriver = unix sockets
|
||||
# tcpDriver = tcp (localhost only)
|
||||
driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
|
16
src/fenrirscreenreader/core/remoteDriver.py
Normal file
16
src/fenrirscreenreader/core/remoteDriver.py
Normal 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
|
@ -29,9 +29,6 @@ command interrupt
|
||||
from fenrirscreenreader.core import debug
|
||||
from fenrirscreenreader.core.eventData import fenrirEventType
|
||||
import time
|
||||
import select
|
||||
import socket
|
||||
import os, os.path
|
||||
|
||||
class remoteManager():
|
||||
def __init__(self):
|
||||
@ -48,83 +45,11 @@ class remoteManager():
|
||||
self.resetSettingConst = 'RESET'
|
||||
def initialize(self, environment):
|
||||
self.env = environment
|
||||
|
||||
if self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enabled'):
|
||||
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)
|
||||
self.env['runtime']['settingsManager'].loadDriver(\
|
||||
self.env['runtime']['settingsManager'].getSetting('remote', 'driver'), 'remoteDriver')
|
||||
def shutdown(self):
|
||||
if self.sock:
|
||||
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
|
||||
self.env['runtime']['settingsManager'].shutdownDriver('remoteDriver')
|
||||
|
||||
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):
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'):
|
||||
return
|
||||
@ -200,6 +125,8 @@ class remoteManager():
|
||||
if not eventData:
|
||||
return
|
||||
upperEventData = eventData.upper()
|
||||
self.env['runtime']['debug'].writeDebugOut('remoteManager:handleRemoteIncomming: event: ' + str(eventData),debug.debugLevel.INFO)
|
||||
|
||||
if upperEventData.startswith(self.settingConst):
|
||||
settingsText = eventData[len(self.settingConst):]
|
||||
self.handleSettingsChange(settingsText)
|
||||
|
@ -11,6 +11,7 @@ runtimeData = {
|
||||
'screenDriver': None,
|
||||
'soundDriver': None,
|
||||
'inputDriver': None,
|
||||
'remoteDriver': None,
|
||||
'brailleDriver': None,
|
||||
'inputManager': None,
|
||||
'commandManager': None,
|
||||
|
@ -82,7 +82,7 @@ settingsData = {
|
||||
},
|
||||
'remote':{
|
||||
'enabled': True,
|
||||
'method': 'unix',
|
||||
'driver': 'unixDriver',
|
||||
'port': 22447,
|
||||
'socketpath':'/tmp/',
|
||||
'enableSettingsRemote': True,
|
||||
|
0
src/fenrirscreenreader/remoteDriver/__init__.py
Executable file
0
src/fenrirscreenreader/remoteDriver/__init__.py
Executable file
12
src/fenrirscreenreader/remoteDriver/dummyDriver.py
Normal file
12
src/fenrirscreenreader/remoteDriver/dummyDriver.py
Normal 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)
|
47
src/fenrirscreenreader/remoteDriver/tcpDriver.py
Normal file
47
src/fenrirscreenreader/remoteDriver/tcpDriver.py
Normal 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
|
57
src/fenrirscreenreader/remoteDriver/unixDriver.py
Normal file
57
src/fenrirscreenreader/remoteDriver/unixDriver.py
Normal 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
|
Loading…
Reference in New Issue
Block a user