add VCSA watchdog prototype

This commit is contained in:
chrys 2017-06-22 01:27:31 +02:00
parent 42ade1fbf8
commit b0604a9907

View File

@ -3,39 +3,35 @@
import select import select
import time import time
currScreen = '2'
vcsa = {} vcsa = {}
for i in range(1,7): for i in range(1,7):
vcsa[str(i)] = open('/dev/vcs'+str(i),'rb') vcsa[str(i)] = open('/dev/vcs'+str(i),'rb')
vcsa[str(i)].read()
tty = open('/sys/devices/virtual/tty/tty0/active','r') tty = open('/sys/devices/virtual/tty/tty0/active','r')
currScreen = str(tty.read()[3:-1])
oldTty = str(tty.read()[3:-1]) oldScreen = currScreen
watchdog = select.poll() watchdog = select.epoll()
watchdog.register(vcsa[currScreen], select.EPOLLPRI)
watchdog.register(tty, select.EPOLLPRI) watchdog.register(tty, select.EPOLLPRI)
watchdog.register(vcsa[ oldTty ], select.EPOLLPRI)
while True: while True:
changed = watchdog.poll() changes = watchdog.poll()
print('-----------------------------') print('-----------------------------')
print(changed,tty.fileno()) print(changes)
for fileno, event in changed: for change in changes:
if tty.fileno() == fileno: fileno = change[0]
currTty = tty.seek(0) event = change[1]
#b = open('/sys/devices/virtual/tty/tty0/active','r') print(change,fileno, tty.fileno())
currTty = str(tty.read()[3:-1]) if fileno == tty.fileno():
print('|'+currTty+'|'+oldTty+'|') tty.seek(0)
if currTty != oldTty: currScreen = str(tty.read()[3:-1])
watchdog.register(vcsa[ currTty ].fileno(), select.EPOLLPRI) if currScreen != oldScreen:
watchdog.unregister(vcsa[ oldTty ].fileno()) watchdog.unregister(vcsa[ oldScreen ])
oldTty = currTty watchdog.register(vcsa[ currScreen ], select.EPOLLPRI)
print('new screen ' + currTty) oldScreen = currScreen
print('new screen '+ currScreen)
else: else:
print('update '+ currTty + ' ' + str(fileno)) vcsa[currScreen].seek(0)
vcsa[currTty].seek(0) content = vcsa[currScreen].read()
b = vcsa[currTty].read() print('update '+ str(time.time()))
#print(b)
time.sleep(0.5)