Skip to content

Commit 4ffabf0

Browse files
committed
Add Zenoh component
1 parent 14bf639 commit 4ffabf0

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# r: compas_eve>=2.1.1
2+
"""
3+
Initialize a Zenoh transport.
4+
"""
5+
6+
from threading import Event
7+
8+
import Grasshopper
9+
from compas_ghpython import create_id
10+
from scriptcontext import sticky as st
11+
12+
from compas_eve.zenoh import ZenohTransport
13+
14+
15+
class ZenohConnectComponent(Grasshopper.Kernel.GH_ScriptInstance):
16+
def RunScript(self, connect: bool):
17+
zenoh_transport = None
18+
19+
key = create_id(ghenv.Component, "zenoh_transport") # noqa: F821
20+
zenoh_transport = st.get(key, None)
21+
22+
if zenoh_transport:
23+
st[key].close()
24+
25+
if connect:
26+
event = Event()
27+
transport = ZenohTransport()
28+
transport.on_ready(event.set)
29+
30+
if not event.wait(5):
31+
raise Exception("Failed to initialize Zenoh router transport.")
32+
33+
st[key] = transport
34+
35+
zenoh_transport = st.get(key, None)
36+
is_connected = zenoh_transport._is_connected if zenoh_transport else False
37+
return (zenoh_transport, is_connected)
1.74 KB
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "Zenoh Transport",
3+
"nickname": "Zenoh",
4+
"category": "COMPAS EVE",
5+
"subcategory": "Events",
6+
"description": "Initialize a Zenoh transport.",
7+
"exposure": 2,
8+
9+
"ghpython": {
10+
"isAdvancedMode": true,
11+
"iconDisplay": 2,
12+
"inputParameters": [
13+
{
14+
"name": "connect",
15+
"description": "If True, initializes a Zenoh transport. If False, removes it. Defaults to False.",
16+
"typeHintID": "bool"
17+
}
18+
],
19+
"outputParameters": [
20+
{
21+
"name": "zenoh_transport",
22+
"description": "The Zenoh transport instance."
23+
},
24+
{
25+
"name": "is_connected",
26+
"description": "True if initialization has been processed."
27+
}
28+
]
29+
}
30+
}

0 commit comments

Comments
 (0)