added some data for node events to have a source field to help distinguish what originates from the gui or not

This commit is contained in:
Blake Harnden 2019-11-27 12:55:39 -08:00
parent 354d227cb3
commit d1db5e4b4e
7 changed files with 32 additions and 20 deletions

View file

@ -141,15 +141,19 @@ class CoreClient:
else: else:
logging.warning("unknown session event: %s", session_event) logging.warning("unknown session event: %s", session_event)
elif event.HasField("node_event"): elif event.HasField("node_event"):
node_event = event.node_event self.handle_node_event(event.node_event)
node_id = node_event.node.id
x = node_event.node.position.x
y = node_event.node.position.y
canvas_node = self.canvas_nodes[node_id]
canvas_node.move(x, y)
else: else:
logging.info("unhandled event: %s", event) logging.info("unhandled event: %s", event)
def handle_node_event(self, event):
if event.source == "gui":
return
node_id = event.node.id
x = event.node.position.x
y = event.node.position.y
canvas_node = self.canvas_nodes[node_id]
canvas_node.move(x, y)
def handle_throughputs(self, event): def handle_throughputs(self, event):
interface_throughputs = event.interface_throughputs interface_throughputs = event.interface_throughputs
for i in interface_throughputs: for i in interface_throughputs:
@ -164,9 +168,6 @@ class CoreClient:
) )
def join_session(self, session_id, query_location=True): def join_session(self, session_id, query_location=True):
# self.master.config(cursor="watch")
# self.master.update()
# update session and title # update session and title
self.session_id = session_id self.session_id = session_id
self.master.title(f"CORE Session({self.session_id})") self.master.title(f"CORE Session({self.session_id})")
@ -253,7 +254,6 @@ class CoreClient:
self.app.toolbar.runtime_frame.tkraise() self.app.toolbar.runtime_frame.tkraise()
else: else:
self.app.toolbar.design_frame.tkraise() self.app.toolbar.design_frame.tkraise()
# self.master.config(cursor="")
self.app.statusbar.progress_bar.stop() self.app.statusbar.progress_bar.stop()
def is_runtime(self): def is_runtime(self):
@ -321,8 +321,7 @@ class CoreClient:
def edit_node(self, node_id, x, y): def edit_node(self, node_id, x, y):
position = core_pb2.Position(x=x, y=y) position = core_pb2.Position(x=x, y=y)
response = self.client.edit_node(self.session_id, node_id, position) self.client.edit_node(self.session_id, node_id, position, source="gui")
logging.info("updated node id %s: %s", node_id, response)
def start_session(self): def start_session(self):
nodes = [x.core_node for x in self.canvas_nodes.values()] nodes = [x.core_node for x in self.canvas_nodes.values()]

View file

@ -600,6 +600,9 @@ class CanvasNode:
y_offset = y - old_y y_offset = y - old_y
self.core_node.position.x = x self.core_node.position.x = x
self.core_node.position.y = y self.core_node.position.y = y
self.canvas.move(self.id, x_offset, y_offset)
self.canvas.move(self.text_id, x_offset, y_offset)
self.antenna_draw.update_antennas_position(x_offset, y_offset)
for edge in self.edges: for edge in self.edges:
x1, y1, x2, y2 = self.canvas.coords(edge.id) x1, y1, x2, y2 = self.canvas.coords(edge.id)
if edge.src == self.id: if edge.src == self.id:
@ -608,9 +611,6 @@ class CanvasNode:
self.canvas.coords(edge.id, x1, y1, x_offset, y_offset) self.canvas.coords(edge.id, x1, y1, x_offset, y_offset)
edge.link_info.recalculate_info() edge.link_info.recalculate_info()
self.canvas.helper.update_wlan_connection(old_x, old_y, x, y, self.wlans) self.canvas.helper.update_wlan_connection(old_x, old_y, x, y, self.wlans)
self.canvas.move(self.id, x_offset, y_offset)
self.canvas.move(self.text_id, x_offset, y_offset)
self.antenna_draw.update_antennas_position(x_offset, y_offset)
def on_enter(self, event): def on_enter(self, event):
if self.app.core.is_runtime() and self.app.core.observer: if self.app.core.is_runtime() and self.app.core.observer:

View file

@ -428,7 +428,7 @@ class CoreGrpcClient:
request = core_pb2.GetNodeRequest(session_id=session_id, node_id=node_id) request = core_pb2.GetNodeRequest(session_id=session_id, node_id=node_id)
return self.stub.GetNode(request) return self.stub.GetNode(request)
def edit_node(self, session_id, node_id, position, icon=None): def edit_node(self, session_id, node_id, position, icon=None, source=None):
""" """
Edit a node, currently only changes position. Edit a node, currently only changes position.
@ -436,12 +436,17 @@ class CoreGrpcClient:
:param int node_id: node id :param int node_id: node id
:param core_pb2.Position position: position to set node to :param core_pb2.Position position: position to set node to
:param str icon: path to icon for gui to use for node :param str icon: path to icon for gui to use for node
:param str source: application source editing node
:return: response with result of success or failure :return: response with result of success or failure
:rtype: core_pb2.EditNodeResponse :rtype: core_pb2.EditNodeResponse
:raises grpc.RpcError: when session or node doesn't exist :raises grpc.RpcError: when session or node doesn't exist
""" """
request = core_pb2.EditNodeRequest( request = core_pb2.EditNodeRequest(
session_id=session_id, node_id=node_id, position=position, icon=icon session_id=session_id,
node_id=node_id,
position=position,
icon=icon,
source=source,
) )
return self.stub.EditNode(request) return self.stub.EditNode(request)

View file

@ -504,7 +504,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
position=position, position=position,
services=services, services=services,
) )
return core_pb2.NodeEvent(node=node_proto) return core_pb2.NodeEvent(node=node_proto, source=event.source)
def _handle_link_event(self, event): def _handle_link_event(self, event):
""" """
@ -800,7 +800,10 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
result = True result = True
try: try:
session.edit_node(node.id, options) session.edit_node(node.id, options)
node_data = node.data(0) source = None
if request.source:
source = request.source
node_data = node.data(0, source=source)
session.broadcast_node(node_data) session.broadcast_node(node_data)
except CoreError: except CoreError:
result = False result = False

View file

@ -76,6 +76,7 @@ NodeData = collections.namedtuple(
"altitude", "altitude",
"icon", "icon",
"opaque", "opaque",
"source",
], ],
) )
NodeData.__new__.__defaults__ = (None,) * len(NodeData._fields) NodeData.__new__.__defaults__ = (None,) * len(NodeData._fields)

View file

@ -176,7 +176,7 @@ class NodeBase:
self.ifindex += 1 self.ifindex += 1
return ifindex return ifindex
def data(self, message_type, lat=None, lon=None, alt=None): def data(self, message_type, lat=None, lon=None, alt=None, source=None):
""" """
Build a data object for this node. Build a data object for this node.
@ -184,6 +184,7 @@ class NodeBase:
:param str lat: latitude :param str lat: latitude
:param str lon: longitude :param str lon: longitude
:param str alt: altitude :param str alt: altitude
:param str source: source of node data
:return: node data object :return: node data object
:rtype: core.emulator.data.NodeData :rtype: core.emulator.data.NodeData
""" """
@ -217,6 +218,7 @@ class NodeBase:
model=model, model=model,
server=server, server=server,
services=services, services=services,
source=source,
) )
return node_data return node_data

View file

@ -298,6 +298,7 @@ message Event {
message NodeEvent { message NodeEvent {
Node node = 1; Node node = 1;
string source = 2;
} }
message LinkEvent { message LinkEvent {
@ -378,6 +379,7 @@ message EditNodeRequest {
int32 node_id = 2; int32 node_id = 2;
Position position = 3; Position position = 3;
string icon = 4; string icon = 4;
string source = 5;
} }
message EditNodeResponse { message EditNodeResponse {