mirror of
https://gitlab.com/manzerbredes/esds.git
synced 2025-04-07 02:26:28 +02:00
Debug plugins system
This commit is contained in:
parent
0db52b3e83
commit
721801012a
3 changed files with 21 additions and 21 deletions
38
esds/node.py
38
esds/node.py
|
@ -22,11 +22,6 @@ class Node:
|
||||||
def plugin_register(self,plugin):
|
def plugin_register(self,plugin):
|
||||||
self.plugins.append(plugin)
|
self.plugins.append(plugin)
|
||||||
|
|
||||||
def plugin_handle_requests(self):
|
|
||||||
# Take plugins notification into account
|
|
||||||
for key in list(self["plugin_notify"]):
|
|
||||||
self.plugin_notify(key,self["plugin_notify"].pop(key))
|
|
||||||
|
|
||||||
def plugin_notify(self,reason,args):
|
def plugin_notify(self,reason,args):
|
||||||
"""
|
"""
|
||||||
This function strives to avoid using Python specific features
|
This function strives to avoid using Python specific features
|
||||||
|
@ -145,15 +140,17 @@ class Node:
|
||||||
self["request"]="send"
|
self["request"]="send"
|
||||||
self["state"]="call_blocking"
|
self["state"]="call_blocking"
|
||||||
ack=self.wait_ack(["send","timeout","send_cancel"])
|
ack=self.wait_ack(["send","timeout","send_cancel"])
|
||||||
|
status=-1
|
||||||
if ack[0] == "timeout":
|
if ack[0] == "timeout":
|
||||||
self["request"]="send_cancel"
|
self["request"]="send_cancel"
|
||||||
self["state"]="call_non_blocking"
|
self["state"]="call_non_blocking"
|
||||||
self.wait_ack(["send_cancel"])
|
self.wait_ack(["send_cancel"])
|
||||||
return -1
|
else:
|
||||||
self["request"]="timeout_remove"
|
self["request"]="timeout_remove"
|
||||||
self["state"]="call_non_blocking"
|
self["state"]="call_non_blocking"
|
||||||
self.wait_ack(["timeout_remove"])
|
self.wait_ack(["timeout_remove"])
|
||||||
return ack[1]
|
status=ack[1]
|
||||||
|
return status
|
||||||
|
|
||||||
def receive(self,interface):
|
def receive(self,interface):
|
||||||
if interface not in self["interfaces"]:
|
if interface not in self["interfaces"]:
|
||||||
|
@ -185,14 +182,15 @@ class Node:
|
||||||
self.rargs=interface
|
self.rargs=interface
|
||||||
self["state"]="call_blocking"
|
self["state"]="call_blocking"
|
||||||
ack=self.wait_ack(["receive","timeout"])
|
ack=self.wait_ack(["receive","timeout"])
|
||||||
if ack[0] == "timeout":
|
result=(-1,None)
|
||||||
return (-1,None)
|
if ack[0] != "timeout":
|
||||||
self["request"]="timeout_remove"
|
self["request"]="timeout_remove"
|
||||||
self["state"]="call_non_blocking"
|
self["state"]="call_non_blocking"
|
||||||
self.wait_ack(["timeout_remove"])
|
self.wait_ack(["timeout_remove"])
|
||||||
data,start_at,end_at=self["interfaces"][interface].get()
|
data,start_at,end_at=self["interfaces"][interface].get()
|
||||||
self.plugin_notify("receivet_return",(interface,data,start_at,end_at))
|
self.plugin_notify("receivet_return",(interface,data,start_at,end_at))
|
||||||
return (0,data)
|
result=(0,data)
|
||||||
|
return result
|
||||||
|
|
||||||
def wait_ack(self, ack_types):
|
def wait_ack(self, ack_types):
|
||||||
"""
|
"""
|
||||||
|
@ -202,7 +200,9 @@ class Node:
|
||||||
ack=None
|
ack=None
|
||||||
while True:
|
while True:
|
||||||
ack=self.rqueue.get() # Wait for simulator acknowledgments
|
ack=self.rqueue.get() # Wait for simulator acknowledgments
|
||||||
if ack[0] not in ack_types:
|
if ack[0] == "plugin_notify":
|
||||||
|
self.plugin_notify(ack[1],ack[2]) # TODO: what is ack_types received before "plugin_notify" ?
|
||||||
|
elif ack[0] not in ack_types:
|
||||||
ack_buffer.append(ack)
|
ack_buffer.append(ack)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
|
@ -25,7 +25,7 @@ class NodePlugin:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_communication_end(self,interface,data,start_at,end_at,aborted_at):
|
def on_communication_end(self,interface,data,start_at,end_at,aborted_at):
|
||||||
self.log("hello world")
|
pass
|
||||||
|
|
||||||
def log(self,msg):
|
def log(self,msg):
|
||||||
self.api.log(self.plugin_name+"(NP) "+msg)
|
self.api.log(self.plugin_name+"(NP) "+msg)
|
||||||
|
|
|
@ -199,7 +199,7 @@ class Simulator:
|
||||||
selector_wireless.append(False)
|
selector_wireless.append(False)
|
||||||
if event[2][9]: # Check if should be cancel on turn_off (receiver_required)
|
if event[2][9]: # Check if should be cancel on turn_off (receiver_required)
|
||||||
selector_wired.append(True)
|
selector_wired.append(True)
|
||||||
self.notify_node_plugin(event[2][1],"on_communication_end",("eth0",0,0,0,0))
|
self.nodes[int(event[2][1])].rqueue.put(("plugin_notify","on_communication_end",("eth0",0,0,0,0)))
|
||||||
else:
|
else:
|
||||||
selector_wired.append(False)
|
selector_wired.append(False)
|
||||||
event[2][8]=False # So set delivery to False!!
|
event[2][8]=False # So set delivery to False!!
|
||||||
|
|
Loading…
Add table
Reference in a new issue