speed up dbus logind interface creation
This commit is contained in:
parent
92691d5ae4
commit
4075cd78b4
@ -35,8 +35,8 @@ class fenrir():
|
|||||||
self.shutdown()
|
self.shutdown()
|
||||||
|
|
||||||
def handleProcess(self):
|
def handleProcess(self):
|
||||||
#startTime = time.time()
|
|
||||||
eventReceived = self.environment['runtime']['inputManager'].getInputEvent()
|
eventReceived = self.environment['runtime']['inputManager'].getInputEvent()
|
||||||
|
startTime = time.time()
|
||||||
if eventReceived:
|
if eventReceived:
|
||||||
self.prepareCommand()
|
self.prepareCommand()
|
||||||
if not (self.wasCommand or self.environment['generalInformation']['tutorialMode']) or self.environment['runtime']['screenManager'].isSuspendingScreen():
|
if not (self.wasCommand or self.environment['generalInformation']['tutorialMode']) or self.environment['runtime']['screenManager'].isSuspendingScreen():
|
||||||
@ -65,7 +65,7 @@ class fenrir():
|
|||||||
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenUpdate')
|
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenUpdate')
|
||||||
#self.environment['runtime']['outputManager'].brailleText(flush=False)
|
#self.environment['runtime']['outputManager'].brailleText(flush=False)
|
||||||
self.handleCommands()
|
self.handleCommands()
|
||||||
#print(time.time()-startTime)
|
print(time.time()-startTime)
|
||||||
|
|
||||||
def prepareCommand(self):
|
def prepareCommand(self):
|
||||||
if self.environment['runtime']['screenManager'].isSuspendingScreen():
|
if self.environment['runtime']['screenManager'].isSuspendingScreen():
|
||||||
@ -84,7 +84,6 @@ class fenrir():
|
|||||||
|
|
||||||
self.environment['runtime']['commandManager'].queueCommand(command)
|
self.environment['runtime']['commandManager'].queueCommand(command)
|
||||||
|
|
||||||
|
|
||||||
def handleCommands(self):
|
def handleCommands(self):
|
||||||
if not self.environment['runtime']['commandManager'].isCommandQueued():
|
if not self.environment['runtime']['commandManager'].isCommandQueued():
|
||||||
return
|
return
|
||||||
|
@ -36,14 +36,13 @@ class driver():
|
|||||||
self.getInputDevices()
|
self.getInputDevices()
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
pass
|
|
||||||
def getInputEvent(self):
|
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
time.sleep(0.005) # dont flood CPU
|
return
|
||||||
return None
|
self.releaseDevices()
|
||||||
if not self.iDevices:
|
def getInputEvent(self):
|
||||||
return None
|
|
||||||
if self.iDevices == {}:
|
if not self.hasIDevices():
|
||||||
|
time.sleep(0.008) # dont flood CPU
|
||||||
return None
|
return None
|
||||||
|
|
||||||
event = None
|
event = None
|
||||||
@ -54,7 +53,7 @@ class driver():
|
|||||||
event = self.iDevices[fd].read_one()
|
event = self.iDevices[fd].read_one()
|
||||||
except:
|
except:
|
||||||
#print('jow')
|
#print('jow')
|
||||||
del(self.iDevices[fd])
|
self.removeDevice(fd)
|
||||||
return None
|
return None
|
||||||
foreward = False
|
foreward = False
|
||||||
while(event):
|
while(event):
|
||||||
@ -146,7 +145,7 @@ class driver():
|
|||||||
|
|
||||||
def getLedState(self, led = 0):
|
def getLedState(self, led = 0):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return None
|
return False
|
||||||
# 0 = Numlock
|
# 0 = Numlock
|
||||||
# 1 = Capslock
|
# 1 = Capslock
|
||||||
# 2 = Rollen
|
# 2 = Rollen
|
||||||
@ -168,7 +167,7 @@ class driver():
|
|||||||
self.ledDevices[i].set_led(led , 1)
|
self.ledDevices[i].set_led(led , 1)
|
||||||
def grabDevices(self):
|
def grabDevices(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return None
|
return
|
||||||
for fd in self.iDevices:
|
for fd in self.iDevices:
|
||||||
try:
|
try:
|
||||||
self.uDevices[fd] = UInput.from_device(self.iDevices[fd].fn)
|
self.uDevices[fd] = UInput.from_device(self.iDevices[fd].fn)
|
||||||
@ -204,11 +203,7 @@ class driver():
|
|||||||
# #'/dev/uinput'
|
# #'/dev/uinput'
|
||||||
# )
|
# )
|
||||||
# dev.grab()
|
# dev.grab()
|
||||||
|
def removeDevice(self,fd):
|
||||||
def releaseDevices(self):
|
|
||||||
if not self._initialized:
|
|
||||||
return None
|
|
||||||
for fd in self.iDevices:
|
|
||||||
try:
|
try:
|
||||||
self.iDevices[fd].ungrab()
|
self.iDevices[fd].ungrab()
|
||||||
except:
|
except:
|
||||||
@ -221,13 +216,26 @@ class driver():
|
|||||||
self.uDevices[fd].close()
|
self.uDevices[fd].close()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
def hasIDevices(self):
|
||||||
|
if not self._initialized:
|
||||||
|
return False
|
||||||
|
if not self.iDevices:
|
||||||
|
return False
|
||||||
|
if len(self.iDevices) == 0:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def releaseDevices(self):
|
||||||
|
if not self.hasIDevices():
|
||||||
|
return
|
||||||
|
for fd in self.iDevices:
|
||||||
|
self.removeDevice(fd)
|
||||||
self.iDevices.clear()
|
self.iDevices.clear()
|
||||||
self.uDevices.clear()
|
self.uDevices.clear()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return None
|
return
|
||||||
self.releaseDevices()
|
self.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ from utils import screen_utils
|
|||||||
class driver():
|
class driver():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.vcsaDevicePath = '/dev/vcsa'
|
self.vcsaDevicePath = '/dev/vcsa'
|
||||||
|
self.ListSessions = None
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
@ -62,24 +63,18 @@ class driver():
|
|||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||||
return
|
|
||||||
|
|
||||||
def getSessionInformation(self):
|
def getSessionInformation(self):
|
||||||
progname = 'org.freedesktop.login1'
|
|
||||||
objpath = '/org/freedesktop/login1'
|
|
||||||
intfname = 'org.freedesktop.login1.Manager'
|
|
||||||
methname = 'ListSessions'
|
|
||||||
|
|
||||||
bus = dbus.SystemBus()
|
bus = dbus.SystemBus()
|
||||||
|
if not self.ListSessions:
|
||||||
|
obj = bus.get_object('org.freedesktop.login1', '/org/freedesktop/login1')
|
||||||
|
inf = dbus.Interface(obj, 'org.freedesktop.login1.Manager')
|
||||||
|
self.ListSessions = inf.get_dbus_method('ListSessions')
|
||||||
|
|
||||||
obj = bus.get_object(progname, objpath)
|
sessions = self.ListSessions()
|
||||||
inf = dbus.Interface(obj, intfname)
|
|
||||||
meth = inf.get_dbus_method(methname)
|
|
||||||
|
|
||||||
sessions = meth()
|
|
||||||
self.env['screenData']['autoIgnoreScreens'] = []
|
self.env['screenData']['autoIgnoreScreens'] = []
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
obj = bus.get_object(progname, session[4])
|
obj = bus.get_object('org.freedesktop.login1', session[4])
|
||||||
inf = dbus.Interface(obj, 'org.freedesktop.DBus.Properties')
|
inf = dbus.Interface(obj, 'org.freedesktop.DBus.Properties')
|
||||||
sessionType = inf.Get('org.freedesktop.login1.Session', 'Type')
|
sessionType = inf.Get('org.freedesktop.login1.Session', 'Type')
|
||||||
screen = str(inf.Get('org.freedesktop.login1.Session', 'TTY'))
|
screen = str(inf.Get('org.freedesktop.login1.Session', 'TTY'))
|
||||||
|
Loading…
Reference in New Issue
Block a user