Package SmootLight :: Package operationscore :: Module Input
[hide private]
[frames] | no frames]

Source Code for Module SmootLight.operationscore.Input

 1  import threading,time 
 2  from logger import main_log, exception_log 
 3  from operationscore.ThreadedSmootCoreObject import ThreadedSmootCoreObject 
 4  import pdb 
5 -class Input(ThreadedSmootCoreObject):
6 """Abstract class for inputs. Inheriting classes should call "respond" to raise 7 their event. Inheriting classes MUST define sensingLoop. Called at the 8 interval specified in RefreshInterval while the input is active. For example, if you are writing 9 webserver, this is where the loop should go. 10 Inheriting classes MAY define inputInit. This is called before the loop 11 begins."""
12 - def init(self):
13 self.eventQueue = [] 14 if not 'RefreshInterval' in self.argDict: 15 self.argDict['RefreshInterval'] = 500 16 self.parentScope = self.argDict['parentScope'] 17 self.inputInit()
18
19 - def respond(self, eventDict):
20 eventDict['InputId'] = self['Id'] 21 self.parentScope.lock.acquire() 22 self.parentScope.processResponse(self.argDict, eventDict) 23 self.parentScope.lock.release() 24 time.sleep(.001)
25
26 - def parentAlive(self):
27 try: 28 parentAlive = self.parentScope.alive() 29 return parentAlive 30 except: 31 return False
32
33 - def run(self):
34 while 1: 35 try: 36 die = self.parentAlive() 37 except: 38 break 39 time.sleep(self.argDict['RefreshInterval']/float(1000)) 40 self.acquireLock() 41 self.sensingLoop() 42 self.releaseLock()
43
44 - def sensingLoop(self):
45 pass
46
47 - def inputInit(self):
48 pass
49