Skip to content

Commit 0268f25

Browse files
committed
Add hooks for frame complete and stream destroy
1 parent 70a022b commit 0268f25

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "aiko_services"
3-
version = "0.6.post22"
3+
version = "0.6.post25"
44
readme = "ReadMe.md"
55
description = "Distributed embedded service framework for A.I and robotics"
66
requires-python = ">=3.9.0,<=3.13.7"

src/aiko_services/main/hook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def remove_hook_handler(self, hook_name, hook_function):
105105
pass
106106

107107
@abstractmethod
108-
def run_hook(self, hook_name):
108+
def run_hook(self, hook_name, variables=None):
109109
pass
110110

111111
@abstractmethod

src/aiko_services/main/pipeline.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@
202202
_PIPELINE_HOOK_PROCESS_ELEMENT_POST = PIPELINE_HOOK_PROCESS_ELEMENT_POST+"0"
203203
PIPELINE_HOOK_PROCESS_FRAME = "pipeline.process_frame:"
204204
_PIPELINE_HOOK_PROCESS_FRAME = PIPELINE_HOOK_PROCESS_FRAME+"0"
205+
PIPELINE_HOOK_PROCESS_FRAME_COMPLETE = "pipeline.process_frame_complete:"
206+
_PIPELINE_HOOK_PROCESS_FRAME_COMPLETE = PIPELINE_HOOK_PROCESS_FRAME_COMPLETE+"0"
207+
PIPELINE_HOOK_DESTROY_STREAM = "pipeline.destroy_stream:"
208+
_PIPELINE_HOOK_DESTROY_STREAM = PIPELINE_HOOK_DESTROY_STREAM+"0"
205209

206210
_GRACE_TIME = 60 # seconds
207211
_LOGGER = aiko.logger(__name__)
@@ -697,6 +701,8 @@ def __init__(self, context):
697701
self.add_hook(_PIPELINE_HOOK_PROCESS_ELEMENT)
698702
self.add_hook(_PIPELINE_HOOK_PROCESS_ELEMENT_POST)
699703
self.add_hook(_PIPELINE_HOOK_PROCESS_FRAME)
704+
self.add_hook(_PIPELINE_HOOK_PROCESS_FRAME_COMPLETE)
705+
self.add_hook(_PIPELINE_HOOK_DESTROY_STREAM)
700706

701707
self.pipeline_graph = self._create_pipeline_graph(context.definition)
702708
self.share["element_count"] = self.pipeline_graph.element_count
@@ -1094,13 +1100,15 @@ def destroy_stream(self, stream_id,
10941100
stream.state = StreamState.ERROR
10951101

10961102
# Notify listeners that the stream has stopped
1097-
stop_state = stream.state
1098-
if stop_state >= StreamState.RUN:
1099-
stop_state = StreamState.STOP
1103+
if stream.state >= StreamState.RUN:
1104+
stream.state = StreamState.STOP
1105+
self.run_hook(_PIPELINE_HOOK_DESTROY_STREAM,
1106+
lambda: {"stream": stream,
1107+
"diagnostic": diagnostic})
11001108
stream_info = {
11011109
"stream_id": stream.stream_id,
11021110
"frame_id": stream.frame_id,
1103-
"state": stop_state}
1111+
"state": stream.state}
11041112
if stream.queue_response:
11051113
stream.queue_response.put((stream_info, diagnostic))
11061114
if stream.topic_response:
@@ -1393,6 +1401,10 @@ def _process_frame_common(self, stream_dict, frame_data_in, new_frame) \
13931401
"stream_id": stream.stream_id,
13941402
"frame_id": stream.frame_id,
13951403
"state": stream.state}
1404+
self.run_hook(_PIPELINE_HOOK_PROCESS_FRAME_COMPLETE,
1405+
lambda: {
1406+
"stream": stream,
1407+
"frame_data_out": frame_data_out})
13961408
if stream.queue_response:
13971409
stream.queue_response.put((stream_info, frame_data_out))
13981410
elif stream.topic_response:

0 commit comments

Comments
 (0)