initial use of eventManager using heartbeat
This commit is contained in:
parent
df834ca372
commit
461e9bb5b3
@ -4,7 +4,7 @@
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
|
||||
#from core import debug
|
||||
from core import debug
|
||||
from queue import Empty
|
||||
import time
|
||||
from enum import Enum
|
||||
@ -21,6 +21,7 @@ class fenrirEventType(Enum):
|
||||
PlugInputDevice = 5
|
||||
BrailleFlush = 6
|
||||
ScreenChanged = 7
|
||||
HeartBeat = 8 # for time based scheduling
|
||||
def __int__(self):
|
||||
return self.value
|
||||
def __str__(self):
|
||||
@ -34,10 +35,14 @@ class eventManager():
|
||||
self._eventQueue = Queue() # multiprocessing.Queue()
|
||||
self.cleanEventQueue()
|
||||
def initialize(self, environment):
|
||||
self.env = environment
|
||||
self.env = environment
|
||||
self.addSimpleEventThread(fenrirEventType.HeartBeat, self.timerProcess)
|
||||
def shutdown(self):
|
||||
self.terminateAllProcesses()
|
||||
self.cleanEventQueue()
|
||||
def timerProcess(self):
|
||||
time.sleep(0.005)
|
||||
return time.time()
|
||||
def terminateAllProcesses(self):
|
||||
for proc in self._eventProcesses:
|
||||
try:
|
||||
@ -68,6 +73,9 @@ class eventManager():
|
||||
pass
|
||||
elif event['Type'] == fenrirEventType.ScreenChanged:
|
||||
pass
|
||||
elif event['Type'] == fenrirEventType.HeartBeat:
|
||||
self.env['runtime']['fenrirManager'].handleProcess()
|
||||
print('HeartBeat at ' + str(event['Type']) + ' ' +str(event['Data'] ))
|
||||
def startMainEventLoop(self):
|
||||
self._mainLoopRunning.value = True
|
||||
while(self._mainLoopRunning.value):
|
||||
@ -83,7 +91,7 @@ class eventManager():
|
||||
t.start()
|
||||
def addSimpleEventThread(self, event, function):
|
||||
self._mainLoopRunning.value = True
|
||||
t = Process(target=self.SimpleEventWorkerThread, args=(event, function))
|
||||
t = Process(target=self.simpleEventWorkerThread, args=(event, function))
|
||||
self._eventProcesses.append(t)
|
||||
t.start()
|
||||
def cleanEventQueue(self):
|
||||
|
@ -22,7 +22,7 @@ class fenrirManager():
|
||||
if not cliArgs:
|
||||
return
|
||||
try:
|
||||
self.environment = settingsManager.settingsManager().initFenrirConfig(cliArgs)
|
||||
self.environment = settingsManager.settingsManager().initFenrirConfig(cliArgs, self)
|
||||
if not self.environment:
|
||||
raise RuntimeError('Cannot Initialize. Maybe the configfile is not available or not parseable')
|
||||
except RuntimeError:
|
||||
@ -46,11 +46,8 @@ class fenrirManager():
|
||||
def proceed(self):
|
||||
if not self.initialized:
|
||||
return
|
||||
while(self.environment['general']['running']):
|
||||
try:
|
||||
self.handleProcess()
|
||||
except Exception as e:
|
||||
self.environment['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
self.environment['runtime']['eventManager'].startMainEventLoop()
|
||||
|
||||
self.shutdown()
|
||||
|
||||
def handleProcess(self):
|
||||
@ -118,7 +115,10 @@ class fenrirManager():
|
||||
self.shutdownRequest()
|
||||
|
||||
def shutdown(self):
|
||||
self.environment['eventManager'].stopMainEventLoop()
|
||||
self.environment['runtime']['outputManager'].presentText(_("Quit Fenrir"), soundIcon='ScreenReaderOff', interrupt=True)
|
||||
self.environment['eventManager'].cleanEventQueue()
|
||||
self.environment['eventManager'].stopMainEventLoop(True)
|
||||
for currManager in self.environment['general']['managerList']:
|
||||
if self.environment['runtime'][currManager]:
|
||||
self.environment['runtime'][currManager].shutdown()
|
||||
|
@ -242,7 +242,7 @@ class settingsManager():
|
||||
optionArgDict[section] = {}
|
||||
optionArgDict[section][option] = str(value)
|
||||
return optionArgDict
|
||||
def initFenrirConfig(self, cliArgs, environment = environment.environment):
|
||||
def initFenrirConfig(self, cliArgs, fenrirManager = None, environment = environment.environment):
|
||||
settingsRoot = '/etc/fenrir/'
|
||||
settingsFile = cliArgs.setting
|
||||
soundRoot = '/usr/share/sounds/fenrir/'
|
||||
@ -304,6 +304,8 @@ class settingsManager():
|
||||
else:
|
||||
environment['runtime']['settingsManager'].loadDicts(self.getSetting('general','punctuationProfile'))
|
||||
|
||||
if fenrirManager:
|
||||
environment['runtime']['fenrirManager'] = fenrirManager
|
||||
environment['runtime']['eventManager'] = eventManager.eventManager()
|
||||
environment['runtime']['eventManager'].initialize(environment)
|
||||
environment['runtime']['inputManager'] = inputManager.inputManager()
|
||||
|
Loading…
Reference in New Issue
Block a user