Commit d06b9bed authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Sebastien Robin

canAccept updated so that it does not require to identify the caller. Now it...

canAccept updated so that it does not require to identify the caller. Now it is passed as an argument
parent 10308468
......@@ -126,12 +126,16 @@ class Assembly(CoreObject):
startBlockageTime=now()
self.completedJobs+=1 #Assembly completed a job
self.waitToDispose=True #since all the frame is full
yield waituntil, self, self.next[0].canAccept #wait until the next object is free
while 1:
yield waituntil, self, self.next[0].canAccept #wait until the next object is free
if self.next[0].previous[self.next[0].predecessorIndex]==self: #if the free object can accept from this Assembly
#break. Else continue
break
self.totalBlockageTime+=now()-startBlockageTime #add the blockage time
#checks if the Assembly can accept an entity
def canAccept(self):
def canAccept(self, callerObject=None):
return len(self.Res.activeQ)==0
#checks if the Assembly can accept an entity and there is a Frame waiting for it
......
......@@ -161,7 +161,7 @@ class Conveyer(CoreObject):
#is considered as working time
#checks if the Conveyer can accept an entity
def canAccept(self):
def canAccept(self, callerObject=None):
#if there is no object in the predecessor just return false and set the current requested length to zero
if len(self.previous[0].Res.activeQ)==0:
self.currentRequestedLength=0
......@@ -187,7 +187,7 @@ class Conveyer(CoreObject):
#checks if the Conveyer can accept an entity and there is a Frame waiting for it
def canAcceptAndIsRequested(self):
return self.canAccept() and self.previous[0].haveToDispose()
return self.canAccept(self) and self.previous[0].haveToDispose()
#gets an entity from the predecessor
def getEntity(self):
......
......@@ -105,7 +105,7 @@ class CoreObject(Process):
pass
#checks if the Object can accept an entity
def canAccept(self):
def canAccept(self, callerObject=None):
pass
#takes the array and checks if all its values are identical (returns false) or not (returns true)
......
......@@ -130,7 +130,7 @@ class Dismantle(CoreObject):
return len(self.Res.activeQ)==0 and self.previous[0].haveToDispose()
#checks if the Dismantle can accept an entity
def canAccept(self):
def canAccept(self, callerObject=None):
return len(self.Res.activeQ)==0
#defines where parts and frames go after they leave the object
......
......@@ -97,7 +97,7 @@ class Exit(CoreObject):
self.previous=p
#checks if the Exit can accept an entity
def canAccept(self):
def canAccept(self, callerObject=None):
return True #the exit always can accept an entity
#checks if the Exit can accept an entity and there is an entity waiting for it
......
......@@ -194,23 +194,17 @@ class Machine(CoreObject):
#checks if the Machine can accept an entity
#it checks also who called it and returns TRUE only to the predecessor that will give the entity.
def canAccept(self):
def canAccept(self, callerObject=None):
#if we have only one predecessor just check if there is a place and the machine is up
if(len(self.previous)==1):
if(len(self.previous)==1 or callerObject==None):
return self.Up and len(self.Res.activeQ)==0
#if the machine is busy return False immediately
if len(self.Res.activeQ)==self.capacity:
return False
#identify the caller method
frame = sys._getframe(1)
arguments = frame.f_code.co_argcount
if arguments == 0:
print "Not called from a method"
return
caller_calls_self = frame.f_code.co_varnames[0]
thecaller = frame.f_locals[caller_calls_self]
thecaller=callerObject
#return true only to the predecessor from which the queue will take
flag=False
......@@ -245,7 +239,7 @@ class Machine(CoreObject):
#checks if the machine down or it can dispose the object
def ifCanDisposeOrHaveFailure(self):
return self.Up==False or self.next[0].canAccept() or len(self.Res.activeQ)==0 #the last part is added so that it is not removed and stack
return self.Up==False or self.next[0].canAccept(self) or len(self.Res.activeQ)==0 #the last part is added so that it is not removed and stack
#gotta think of it again
#removes an entity from the Machine
......@@ -279,7 +273,7 @@ class Machine(CoreObject):
#plant does not do this in every occasion!
maxTimeWaiting=0
for i in range(len(self.next)):
if(self.next[i].canAccept()):
if(self.next[i].canAccept(self)):
timeWaiting=now()-self.next[i].timeLastEntityLeft
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):
maxTimeWaiting=timeWaiting
......
......@@ -92,22 +92,15 @@ class Queue(CoreObject):
#checks if the Queue can accept an entity
#it checks also who called it and returns TRUE only to the predecessor that will give the entity.
def canAccept(self):
def canAccept(self, callerObject=None):
#if we have only one predecessor just check if there is a place available
if(len(self.previous)==1):
if(len(self.previous)==1 or callerObject==None):
return len(self.Res.activeQ)<self.capacity
if len(self.Res.activeQ)==self.capacity:
return False
#identify the caller method
frame = sys._getframe(1)
arguments = frame.f_code.co_argcount
if arguments == 0:
print "Not called from a method"
return
caller_calls_self = frame.f_code.co_varnames[0]
thecaller = frame.f_locals[caller_calls_self]
thecaller=callerObject
#return true only to the predecessor from which the queue will take
flag=False
......
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