diff options
Diffstat (limited to 'operationscore')
-rw-r--r-- | operationscore/Behavior.py | 12 | ||||
-rw-r--r-- | operationscore/Input.py | 2 | ||||
-rw-r--r-- | operationscore/SmootCoreObject.py | 13 |
3 files changed, 20 insertions, 7 deletions
diff --git a/operationscore/Behavior.py b/operationscore/Behavior.py index 6424842..7090a23 100644 --- a/operationscore/Behavior.py +++ b/operationscore/Behavior.py @@ -1,9 +1,6 @@ - import pdb from operationscore.SmootCoreObject import * from logger import main_log -#timeStep is called on every iteration of the LightInstallation -#addInput is called on each individual input received, and the inputs queue class Behavior(SmootCoreObject): """Abstract class for a behavior. On every time step, the behavior is passed the inputs from all sensors it is bound to as well as any recursive inputs that it @@ -22,6 +19,7 @@ class Behavior(SmootCoreObject): self.recursiveResponseQueue = [] self.sensorResponseQueue = [] self.outGoingQueue = [] + self.lastState = None self.behaviorInit() def behaviorInit(self): pass @@ -44,6 +42,13 @@ class Behavior(SmootCoreObject): else: self.addInput(sensorInputs) #private + def getLastOutput(self): + return self.lastState + def setLastOutput(self, output): + """Override to modify state. For example: if you are using a behavior that does uses + strings for location specification, you will want to override this to point to a single + location. Make sure you keep lastState as a [] of {}. (List of dicts)""" + self.lastState = output def addMapperToResponse(self, responses): if self['Mapper'] != None: if type(responses) == type(tuple): @@ -59,5 +64,6 @@ class Behavior(SmootCoreObject): self.recursiveResponseQueue) self.sensorResponseQueue = [] self.recursiveResponseQueue = recursions + self.setLastOutput(outputs) main_log.debug(self['Id'] + ' Ouputs ' + str(outputs)) return self.addMapperToResponse(outputs) diff --git a/operationscore/Input.py b/operationscore/Input.py index d3d5644..5a835ec 100644 --- a/operationscore/Input.py +++ b/operationscore/Input.py @@ -17,7 +17,7 @@ class Input(ThreadedSmootCoreObject): self.inputInit() def respond(self, eventDict): - #if eventDict != []: + eventDict['InputId'] = self['Id'] self.parentScope.lock.acquire() self.parentScope.processResponse(self.argDict, eventDict) self.parentScope.lock.release() diff --git a/operationscore/SmootCoreObject.py b/operationscore/SmootCoreObject.py index 0d32773..6addb9c 100644 --- a/operationscore/SmootCoreObject.py +++ b/operationscore/SmootCoreObject.py @@ -2,6 +2,7 @@ import pdb import threading import thread import util.Config as configGetter +import types class SmootCoreObject(object): """SmootCoreObject is essentially a super-object class which grants us some niceties. It allows @@ -34,9 +35,15 @@ class SmootCoreObject(object): def __setitem__(self,k, item): self.argDict[k] = item - def __getitem__(self, item): - if item in self.argDict: - return self.argDict[item] + def __getitem__(self, key): + if key in self.argDict: + item = self.argDict[key] + if isinstance(item, types.FunctionType): + return item(self.argDict) #resolve the lambda function, if it exists + #elif isinstance(item, list): #if its a list of items + # pass #TODO: consider doing resolution of lambda funcs for items in lists + else: + return item else: return None def __contains__(self, item): |