Code optimization and bug fixes. Removed the broken, partial atspi driver implementation.
This commit is contained in:
@ -58,9 +58,8 @@ class driver(screenDriver):
|
||||
def getCurrScreen(self):
|
||||
self.env['screen']['oldTTY'] = self.env['screen']['newTTY']
|
||||
try:
|
||||
currScreenFile = open('/sys/devices/virtual/tty/tty0/active','r')
|
||||
self.env['screen']['newTTY'] = str(currScreenFile.read()[3:-1])
|
||||
currScreenFile.close()
|
||||
with open('/sys/devices/virtual/tty/tty0/active','r') as currScreenFile:
|
||||
self.env['screen']['newTTY'] = str(currScreenFile.read()[3:-1])
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
def injectTextToScreen(self, text, screen = None):
|
||||
@ -118,26 +117,35 @@ class driver(screenDriver):
|
||||
break
|
||||
return d
|
||||
def updateWatchdog(self, active , eventQueue):
|
||||
vcsa = {}
|
||||
vcsu = {}
|
||||
tty = None
|
||||
watchdog = None
|
||||
try:
|
||||
useVCSU = os.access('/dev/vcsu', os.R_OK)
|
||||
vcsa = {}
|
||||
vcsaDevices = glob.glob('/dev/vcsa*')
|
||||
vcsu = {}
|
||||
vcsuDevices = None
|
||||
lastScreenContent = b''
|
||||
|
||||
# Open TTY file with proper cleanup
|
||||
tty = open('/sys/devices/virtual/tty/tty0/active','r')
|
||||
currScreen = str(tty.read()[3:-1])
|
||||
oldScreen = currScreen
|
||||
|
||||
# Open VCSA devices with proper cleanup tracking
|
||||
for vcsaDev in vcsaDevices:
|
||||
index = str(vcsaDev[9:])
|
||||
vcsa[index] = open(vcsaDev,'rb')
|
||||
if index == currScreen:
|
||||
lastScreenContent = self.readFile(vcsa[index])
|
||||
|
||||
# Open VCSU devices if available
|
||||
if useVCSU:
|
||||
vcsuDevices = glob.glob('/dev/vcsu*')
|
||||
for vcsuDev in vcsuDevices:
|
||||
index = str(vcsuDev[9:])
|
||||
vcsu[index] = open(vcsuDev,'rb')
|
||||
|
||||
self.updateCharMap(currScreen)
|
||||
watchdog = select.epoll()
|
||||
watchdog.register(vcsa[currScreen], select.POLLPRI | select.POLLERR)
|
||||
@ -220,6 +228,28 @@ class driver(screenDriver):
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut('VCSA:updateWatchdog:' + str(e),debug.debugLevel.ERROR)
|
||||
time.sleep(0.2)
|
||||
finally:
|
||||
# Clean up all file handles
|
||||
try:
|
||||
if watchdog:
|
||||
watchdog.close()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if tty:
|
||||
tty.close()
|
||||
except:
|
||||
pass
|
||||
for handle in vcsa.values():
|
||||
try:
|
||||
handle.close()
|
||||
except:
|
||||
pass
|
||||
for handle in vcsu.values():
|
||||
try:
|
||||
handle.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
def createScreenEventData(self, screen, vcsaContent, vcsuContent = None):
|
||||
eventData = {
|
||||
@ -252,27 +282,26 @@ class driver(screenDriver):
|
||||
def updateCharMap(self, screen):
|
||||
self.charmap = {}
|
||||
try:
|
||||
tty = open('/dev/tty' + screen, 'rb')
|
||||
with open('/dev/tty' + screen, 'rb') as tty:
|
||||
GIO_UNIMAP = 0x4B66
|
||||
VT_GETHIFONTMASK = 0x560D
|
||||
himask = array("H", (0,))
|
||||
ioctl(tty, VT_GETHIFONTMASK, himask)
|
||||
self.hichar, = unpack_from("@H", himask)
|
||||
sz = 512
|
||||
line = ''
|
||||
while True:
|
||||
try:
|
||||
unipairs = array("H", [0]*(2*sz))
|
||||
unimapdesc = array("B", pack("@HP", sz, unipairs.buffer_info()[0]))
|
||||
ioctl(tty.fileno(), GIO_UNIMAP, unimapdesc)
|
||||
break
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut('VCSA:updateCharMap:scaling up sz=' + str(sz) + ' ' + str(e),debug.debugLevel.WARNING)
|
||||
sz *= 2
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut('VCSA:updateCharMap:' + str(e),debug.debugLevel.ERROR)
|
||||
return
|
||||
GIO_UNIMAP = 0x4B66
|
||||
VT_GETHIFONTMASK = 0x560D
|
||||
himask = array("H", (0,))
|
||||
ioctl(tty, VT_GETHIFONTMASK, himask)
|
||||
self.hichar, = unpack_from("@H", himask)
|
||||
sz = 512
|
||||
line = ''
|
||||
while True:
|
||||
try:
|
||||
unipairs = array("H", [0]*(2*sz))
|
||||
unimapdesc = array("B", pack("@HP", sz, unipairs.buffer_info()[0]))
|
||||
ioctl(tty.fileno(), GIO_UNIMAP, unimapdesc)
|
||||
break
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut('VCSA:updateCharMap:scaling up sz=' + str(sz) + ' ' + str(e),debug.debugLevel.WARNING)
|
||||
sz *= 2
|
||||
tty.close()
|
||||
ncodes, = unpack_from("@H", unimapdesc)
|
||||
utable = unpack_from("@%dH" % (2*ncodes), unipairs)
|
||||
for u, b in zip(utable[::2], utable[1::2]):
|
||||
|
Reference in New Issue
Block a user