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,16 +36,15 @@ 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 == {}:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
if not self.hasIDevices():
|
||||||
|
time.sleep(0.008) # dont flood CPU
|
||||||
|
return None
|
||||||
|
|
||||||
event = None
|
event = None
|
||||||
r, w, x = select(self.iDevices, [], [], self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay'))
|
r, w, x = select(self.iDevices, [], [], self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay'))
|
||||||
if r != []:
|
if r != []:
|
||||||
@ -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,30 +203,39 @@ class driver():
|
|||||||
# #'/dev/uinput'
|
# #'/dev/uinput'
|
||||||
# )
|
# )
|
||||||
# dev.grab()
|
# dev.grab()
|
||||||
|
def removeDevice(self,fd):
|
||||||
def releaseDevices(self):
|
try:
|
||||||
|
self.iDevices[fd].ungrab()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
self.iDevices[fd].close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
self.uDevices[fd].close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
def hasIDevices(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return None
|
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:
|
for fd in self.iDevices:
|
||||||
try:
|
self.removeDevice(fd)
|
||||||
self.iDevices[fd].ungrab()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
self.iDevices[fd].close()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
self.uDevices[fd].close()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
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(progname, objpath)
|
obj = bus.get_object('org.freedesktop.login1', '/org/freedesktop/login1')
|
||||||
inf = dbus.Interface(obj, intfname)
|
inf = dbus.Interface(obj, 'org.freedesktop.login1.Manager')
|
||||||
meth = inf.get_dbus_method(methname)
|
self.ListSessions = inf.get_dbus_method('ListSessions')
|
||||||
|
|
||||||
sessions = meth()
|
sessions = self.ListSessions()
|
||||||
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