fixed how hooks get created and sent to grpc StartSession, also query hooks when joining a session
This commit is contained in:
parent
c947d8c6c2
commit
8c1b70822e
2 changed files with 32 additions and 26 deletions
|
@ -71,6 +71,7 @@ class CoreClient:
|
|||
# data for managing the current session
|
||||
self.nodes = {}
|
||||
self.edges = {}
|
||||
self.hooks = {}
|
||||
self.id = 1
|
||||
self.reusable = []
|
||||
self.preexisting = set()
|
||||
|
@ -97,19 +98,30 @@ class CoreClient:
|
|||
)
|
||||
|
||||
def join_session(self, session_id):
|
||||
# query session and set as current session
|
||||
# update session and title
|
||||
self.session_id = session_id
|
||||
response = self.client.get_session(self.session_id)
|
||||
logging.info("joining session(%s): %s", self.session_id, response)
|
||||
self.client.events(self.session_id, self.handle_events)
|
||||
|
||||
# set title to session
|
||||
self.master.title(f"CORE Session({self.session_id})")
|
||||
|
||||
# determine next node id and reusable nodes
|
||||
session = response.session
|
||||
# clear session data
|
||||
self.reusable.clear()
|
||||
self.preexisting.clear()
|
||||
self.nodes.clear()
|
||||
self.edges.clear()
|
||||
self.hooks.clear()
|
||||
|
||||
# get session data
|
||||
response = self.client.get_session(self.session_id)
|
||||
logging.info("joining session(%s): %s", self.session_id, response)
|
||||
session = response.session
|
||||
self.client.events(self.session_id, self.handle_events)
|
||||
|
||||
# get hooks
|
||||
response = self.client.get_hooks(self.session_id)
|
||||
logging.info("joined session hooks: %s", response)
|
||||
for hook in response.hooks:
|
||||
self.hooks[hook.file] = hook
|
||||
|
||||
# determine next node id and reusable nodes
|
||||
max_id = 1
|
||||
for node in session.nodes:
|
||||
if node.id > max_id:
|
||||
|
@ -262,9 +274,10 @@ class CoreClient:
|
|||
mobility_configs=None,
|
||||
):
|
||||
response = self.client.start_session(
|
||||
session_id=self.session_id,
|
||||
nodes=nodes,
|
||||
links=links,
|
||||
self.session_id,
|
||||
nodes,
|
||||
links,
|
||||
hooks=list(self.hooks.values()),
|
||||
wlan_configs=wlan_configs,
|
||||
)
|
||||
logging.debug("Start session %s, result: %s", self.session_id, response.result)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import logging
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
|
@ -11,7 +10,7 @@ class HookDialog(Dialog):
|
|||
super().__init__(master, app, "Hook", modal=True)
|
||||
self.name = tk.StringVar()
|
||||
self.data = None
|
||||
self.hook = None
|
||||
self.hook = core_pb2.Hook()
|
||||
self.state = tk.StringVar()
|
||||
self.draw()
|
||||
|
||||
|
@ -82,11 +81,9 @@ class HookDialog(Dialog):
|
|||
def save(self):
|
||||
data = self.data.get("1.0", tk.END).strip()
|
||||
state_value = core_pb2.SessionState.Enum.Value(self.state.get())
|
||||
self.hook = core_pb2.Hook(state=state_value, file=self.name.get(), data=data)
|
||||
response = self.app.core.client.add_hook(
|
||||
self.app.core.session_id, self.hook.state, self.hook.file, self.hook.data
|
||||
)
|
||||
logging.info("add hook: %s", response)
|
||||
self.hook.file = self.name.get()
|
||||
self.hook.data = data
|
||||
self.hook.state = state_value
|
||||
self.destroy()
|
||||
|
||||
|
||||
|
@ -97,20 +94,16 @@ class HooksDialog(Dialog):
|
|||
self.edit_button = None
|
||||
self.delete_button = None
|
||||
self.selected = None
|
||||
self.hooks = {}
|
||||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
response = self.app.core.client.get_hooks(self.app.core.session_id)
|
||||
logging.info("get hooks: %s", response)
|
||||
self.columnconfigure(0, weight=1)
|
||||
self.rowconfigure(0, weight=1)
|
||||
self.listbox = tk.Listbox(self)
|
||||
self.listbox.grid(row=0, sticky="nsew")
|
||||
self.listbox.bind("<<ListboxSelect>>", self.select)
|
||||
for hook in response.hooks:
|
||||
self.hooks[hook.file] = hook
|
||||
self.listbox.insert(tk.END, hook.file)
|
||||
for hook_file in self.app.core.hooks:
|
||||
self.listbox.insert(tk.END, hook_file)
|
||||
frame = tk.Frame(self)
|
||||
frame.grid(row=1, sticky="ew")
|
||||
for i in range(4):
|
||||
|
@ -131,11 +124,11 @@ class HooksDialog(Dialog):
|
|||
dialog.show()
|
||||
hook = dialog.hook
|
||||
if hook:
|
||||
self.hooks[hook.file] = hook
|
||||
self.app.core.hooks[hook.file] = hook
|
||||
self.listbox.insert(tk.END, hook.file)
|
||||
|
||||
def click_edit(self):
|
||||
hook = self.hooks[self.selected]
|
||||
hook = self.app.core.hooks[self.selected]
|
||||
dialog = HookDialog(self, self.app)
|
||||
dialog.set(hook)
|
||||
dialog.show()
|
||||
|
|
Loading…
Reference in a new issue