Commit 33f02e01 authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Jérome Perrin

minor changes to ConditionalBuffer haveToDispose()

parent 79a73ba1
...@@ -51,39 +51,44 @@ class ConditionalBuffer(QueuePreemptive): ...@@ -51,39 +51,44 @@ class ConditionalBuffer(QueuePreemptive):
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
thecaller = callerObject thecaller = callerObject
# assert that the callerObject is not None
assert thecaller!=None, 'the caller object of the ConditionalBuffer should not be None'
# -------------------------------------------------------------------
# check the length of the activeObjectQueue # check the length of the activeObjectQueue
# if the length is zero then no componentType or entity.type can be read # if the length is zero then no componentType or entity.type can be read
# in this case return zero # in this case return zero
if len(activeObjectQueue)==0: if len(activeObjectQueue)==0:
return False return False
# read the entity to be disposed
activeEntity = activeObjectQueue[0] activeEntity = activeObjectQueue[0]
# assert that the entity.type is OrderComponent # assert that the entity.type is OrderComponent
assert activeEntity.type=='OrderComponent',\ assert activeEntity.type=='OrderComponent',\
"the entity to be disposed is not of type OrderComponent" "the entity to be disposed is not of type OrderComponent"
# -------------------------------------------------------------------
# if the type of the component is Secondary then verify that the basics of the same Order # if the type of the component is Secondary then verify that the basics of the same Order
# are already processed before disposing them to the next object # are already processed before disposing them to the next object
if activeEntity.componentType=='Secondary'\ if activeEntity.componentType=='Secondary'\
and (not activeEntity.order.basicsEnded): and (not activeEntity.order.basicsEnded):
return False return False
# -------------------------------------------------------------------
#if we have only one possible receiver just check if the receiver is the caller #if we have only one possible receiver just check if the receiver is the caller
if(len(activeObject.next)==1 or callerObject==None): if(len(activeObject.next)==1 or callerObject==None):
activeObject.receiver=activeObject.next[0] activeObject.receiver=activeObject.next[0]
return thecaller==activeObject.receiver return thecaller==activeObject.receiver
# -------------------------------------------------------------------
#give the entity to the possible receiver that is waiting for the most time. #give the entity to the possible receiver that is waiting for the most time.
#plant does not do this in every occasion! #plant does not do this in every occasion!
maxTimeWaiting=0 maxTimeWaiting=0
# loop through the object in the successor list # loop through the object in the successor list
for object in activeObject.next: for object in activeObject.next:
if(object.canAccept(activeObject)): # if the object can accept # if the object can accept
timeWaiting=now()-object.timeLastEntityLeft # compare the time that it has been waiting if(object.canAccept(activeObject)):
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):# with the others' timeWaiting=now()-object.timeLastEntityLeft
# compare the time that it has been waiting with the others'
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):
maxTimeWaiting=timeWaiting maxTimeWaiting=timeWaiting
self.receiver=object # and update the receiver to the index of this object # and update the receiver to the index of this object
self.receiver=object
#return True if the Queue caller is the receiver #return True if the Queue caller is the receiver
return thecaller is self.receiver return thecaller is self.receiver
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment