initial watchdog for VCSA driver
This commit is contained in:
parent
b0604a9907
commit
a476e730c4
23
src/fenrir/core/eventData.py
Executable file
23
src/fenrir/core/eventData.py
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Fenrir TTY screen reader
|
||||||
|
# By Chrys, Storm Dragon, and contributers.
|
||||||
|
|
||||||
|
from core import debug
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
class fenrirEventType(Enum):
|
||||||
|
Ignore = 0
|
||||||
|
StopMainLoop = 1
|
||||||
|
ScreenUpdate = 2
|
||||||
|
KeyboardInput = 3
|
||||||
|
BrailleInput = 4
|
||||||
|
PlugInputDevice = 5
|
||||||
|
BrailleFlush = 6
|
||||||
|
ScreenChanged = 7
|
||||||
|
HeartBeat = 8 # for time based scheduling
|
||||||
|
def __int__(self):
|
||||||
|
return self.value
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
@ -5,29 +5,13 @@
|
|||||||
# By Chrys, Storm Dragon, and contributers.
|
# By Chrys, Storm Dragon, and contributers.
|
||||||
|
|
||||||
from core import debug
|
from core import debug
|
||||||
|
from core.eventData import fenrirEventType
|
||||||
from queue import Empty
|
from queue import Empty
|
||||||
import time
|
import time
|
||||||
from enum import Enum
|
|
||||||
from multiprocessing import Process, Queue
|
from multiprocessing import Process, Queue
|
||||||
from multiprocessing.sharedctypes import Value
|
from multiprocessing.sharedctypes import Value
|
||||||
from ctypes import c_bool
|
from ctypes import c_bool
|
||||||
|
|
||||||
class fenrirEventType(Enum):
|
|
||||||
Ignore = 0
|
|
||||||
StopMainLoop = 1
|
|
||||||
ScreenUpdate = 2
|
|
||||||
KeyboardInput = 3
|
|
||||||
BrailleInput = 4
|
|
||||||
PlugInputDevice = 5
|
|
||||||
BrailleFlush = 6
|
|
||||||
ScreenChanged = 7
|
|
||||||
HeartBeat = 8 # for time based scheduling
|
|
||||||
def __int__(self):
|
|
||||||
return self.value
|
|
||||||
def __str__(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
|
|
||||||
class eventManager():
|
class eventManager():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._mainLoopRunning = Value(c_bool, True)
|
self._mainLoopRunning = Value(c_bool, True)
|
||||||
@ -42,7 +26,7 @@ class eventManager():
|
|||||||
self.cleanEventQueue()
|
self.cleanEventQueue()
|
||||||
def timerProcess(self):
|
def timerProcess(self):
|
||||||
try:
|
try:
|
||||||
time.sleep(0.03)
|
time.sleep(1.3)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
#self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay')
|
#self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay')
|
||||||
@ -69,10 +53,13 @@ class eventManager():
|
|||||||
print('stop')
|
print('stop')
|
||||||
return
|
return
|
||||||
elif event['Type'] == fenrirEventType.ScreenUpdate:
|
elif event['Type'] == fenrirEventType.ScreenUpdate:
|
||||||
print('do an update')
|
self.env['runtime']['fenrirManager'].handleProcess()
|
||||||
pass
|
print(self._eventQueue.qsize())
|
||||||
|
print('ScreenUpdate')
|
||||||
elif event['Type'] == fenrirEventType.KeyboardInput:
|
elif event['Type'] == fenrirEventType.KeyboardInput:
|
||||||
pass
|
self.env['runtime']['fenrirManager'].handleProcess()
|
||||||
|
print(self._eventQueue.qsize())
|
||||||
|
print('KeyboardInput')
|
||||||
elif event['Type'] == fenrirEventType.BrailleInput:
|
elif event['Type'] == fenrirEventType.BrailleInput:
|
||||||
pass
|
pass
|
||||||
elif event['Type'] == fenrirEventType.PlugInputDevice:
|
elif event['Type'] == fenrirEventType.PlugInputDevice:
|
||||||
@ -80,14 +67,19 @@ class eventManager():
|
|||||||
elif event['Type'] == fenrirEventType.BrailleFlush:
|
elif event['Type'] == fenrirEventType.BrailleFlush:
|
||||||
pass
|
pass
|
||||||
elif event['Type'] == fenrirEventType.ScreenChanged:
|
elif event['Type'] == fenrirEventType.ScreenChanged:
|
||||||
pass
|
self.env['runtime']['fenrirManager'].handleProcess()
|
||||||
|
print(self._eventQueue.qsize())
|
||||||
|
print('ScreenChanged')
|
||||||
elif event['Type'] == fenrirEventType.HeartBeat:
|
elif event['Type'] == fenrirEventType.HeartBeat:
|
||||||
self.env['runtime']['fenrirManager'].handleProcess()
|
self.env['runtime']['fenrirManager'].handleProcess()
|
||||||
print(self._eventQueue.qsize())
|
print(self._eventQueue.qsize())
|
||||||
print('HeartBeat at ' + str(event['Type']) + ' ' +str(event['Data'] ))
|
print('HeartBeat at {0} {1}'.format(event['Type'], event['Data'] ))
|
||||||
|
|
||||||
|
def isMainEventLoopRunning(self):
|
||||||
|
return self._mainLoopRunning.value == 1
|
||||||
def startMainEventLoop(self):
|
def startMainEventLoop(self):
|
||||||
self._mainLoopRunning.value = 1
|
self._mainLoopRunning.value = 1
|
||||||
while(self._mainLoopRunning.value == 1):
|
while( self.isMainEventLoopRunning()):
|
||||||
st = time.time()
|
st = time.time()
|
||||||
self.proceedEventLoop()
|
self.proceedEventLoop()
|
||||||
print('ALL loop ' + str(time.time() - st))
|
print('ALL loop ' + str(time.time() - st))
|
||||||
@ -97,7 +89,7 @@ class eventManager():
|
|||||||
self._eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
self._eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
||||||
def addCustomEventThread(self, function):
|
def addCustomEventThread(self, function):
|
||||||
self._mainLoopRunning.value = 1
|
self._mainLoopRunning.value = 1
|
||||||
t = Process(target=self.eventWorkerThread, args=(q, function))
|
t = Process(target=self.customEventWorkerThread, args=(self._eventQueue, function))
|
||||||
self._eventProcesses.append(t)
|
self._eventProcesses.append(t)
|
||||||
t.start()
|
t.start()
|
||||||
def addSimpleEventThread(self, event, function):
|
def addSimpleEventThread(self, event, function):
|
||||||
@ -119,11 +111,11 @@ class eventManager():
|
|||||||
self._eventQueue.put({"Type":event,"Data":data})
|
self._eventQueue.put({"Type":event,"Data":data})
|
||||||
return True
|
return True
|
||||||
def customEventWorkerThread(self, eventQueue, function):
|
def customEventWorkerThread(self, eventQueue, function):
|
||||||
if not isinstance(eventQueue, Queue):
|
#if not isinstance(eventQueue, Queue):
|
||||||
return
|
# return
|
||||||
if not callable(function):
|
if not callable(function):
|
||||||
return
|
return
|
||||||
while self._mainLoopRunning.value:
|
while self.isMainEventLoopRunning():
|
||||||
try:
|
try:
|
||||||
function(eventQueue)
|
function(eventQueue)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -134,7 +126,7 @@ class eventManager():
|
|||||||
return
|
return
|
||||||
if not callable(function):
|
if not callable(function):
|
||||||
return
|
return
|
||||||
while self._mainLoopRunning.value == 1:
|
while self.isMainEventLoopRunning():
|
||||||
Data = None
|
Data = None
|
||||||
try:
|
try:
|
||||||
Data = function()
|
Data = function()
|
||||||
@ -144,20 +136,3 @@ class eventManager():
|
|||||||
self.putToEventQueue(event, Data)
|
self.putToEventQueue(event, Data)
|
||||||
if runOnce:
|
if runOnce:
|
||||||
break
|
break
|
||||||
'''
|
|
||||||
def p():
|
|
||||||
time.sleep(0.02)
|
|
||||||
return("p")
|
|
||||||
|
|
||||||
i = 1
|
|
||||||
e = eventManager()
|
|
||||||
e.addEventThread(fenrirEventType.ScreenUpdate,p)
|
|
||||||
e.addEventThread(fenrirEventType.BrailleInput,p)
|
|
||||||
e.addEventThread(fenrirEventType.PlugInputDevice,p)
|
|
||||||
e.addEventThread(fenrirEventType.ScreenChanged,p)
|
|
||||||
time.sleep(1.5)
|
|
||||||
e.addEventThread(fenrirEventType.StopMainLoop,e.stopMainEventLoop)
|
|
||||||
s = time.time()
|
|
||||||
e.startMainEventLoop()
|
|
||||||
print(time.time() - s )
|
|
||||||
'''
|
|
||||||
|
@ -10,8 +10,10 @@ import subprocess
|
|||||||
import fcntl
|
import fcntl
|
||||||
import termios
|
import termios
|
||||||
import time
|
import time
|
||||||
|
import select
|
||||||
import dbus
|
import dbus
|
||||||
from core import debug
|
from core import debug
|
||||||
|
from core.eventData import fenrirEventType
|
||||||
from utils import screen_utils
|
from utils import screen_utils
|
||||||
|
|
||||||
class driver():
|
class driver():
|
||||||
@ -20,6 +22,7 @@ class driver():
|
|||||||
self.ListSessions = None
|
self.ListSessions = None
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
|
self.env['runtime']['eventManager'].addCustomEventThread(self.updateWatchdog)
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
pass
|
pass
|
||||||
def getCurrScreen(self):
|
def getCurrScreen(self):
|
||||||
@ -93,7 +96,44 @@ class driver():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('getSessionInformation: Maybe no LoginD:' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('getSessionInformation: Maybe no LoginD:' + str(e),debug.debugLevel.ERROR)
|
||||||
self.env['screen']['autoIgnoreScreens'] = []
|
self.env['screen']['autoIgnoreScreens'] = []
|
||||||
|
|
||||||
|
def updateWatchdog(self,eventQueue):
|
||||||
|
print('init updateWatchdog')
|
||||||
|
currScreen = '2'
|
||||||
|
vcsa = {}
|
||||||
|
for i in range(1,7):
|
||||||
|
vcsa[str(i)] = open('/dev/vcsa'+str(i),'rb')
|
||||||
|
|
||||||
|
tty = open('/sys/devices/virtual/tty/tty0/active','r')
|
||||||
|
currScreen = str(tty.read()[3:-1])
|
||||||
|
oldScreen = currScreen
|
||||||
|
watchdog = select.epoll()
|
||||||
|
watchdog.register(vcsa[currScreen], select.EPOLLPRI)
|
||||||
|
watchdog.register(tty, select.EPOLLPRI)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
changes = watchdog.poll()
|
||||||
|
print('-----------------------------')
|
||||||
|
print(changes)
|
||||||
|
for change in changes:
|
||||||
|
fileno = change[0]
|
||||||
|
event = change[1]
|
||||||
|
print(change,fileno, tty.fileno())
|
||||||
|
if fileno == tty.fileno():
|
||||||
|
tty.seek(0)
|
||||||
|
currScreen = str(tty.read()[3:-1])
|
||||||
|
if currScreen != oldScreen:
|
||||||
|
watchdog.unregister(vcsa[ oldScreen ])
|
||||||
|
watchdog.register(vcsa[ currScreen ], select.EPOLLPRI)
|
||||||
|
oldScreen = currScreen
|
||||||
|
eventQueue.put({"Type":fenrirEventType.ScreenChanged,"Data":''})
|
||||||
|
print('new screen '+ currScreen)
|
||||||
|
else:
|
||||||
|
vcsa[currScreen].seek(0)
|
||||||
|
content = vcsa[currScreen].read()
|
||||||
|
eventQueue.put({"Type":fenrirEventType.ScreenUpdate,"Data":''})
|
||||||
|
print('update '+ str(time.time()))
|
||||||
|
|
||||||
def update(self, trigger='onUpdate'):
|
def update(self, trigger='onUpdate'):
|
||||||
newContentBytes = b''
|
newContentBytes = b''
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user