@@ -15,9 +15,11 @@ use std::time::Duration;
1515
1616use kyron:: runtime:: * ;
1717use kyron_foundation:: prelude:: * ;
18- use logging_tracing:: TracingLibraryBuilder ;
18+ use logging_tracing:: LogAndTraceBuilder ;
1919use orchestration:: {
20- actions:: { invoke:: Invoke , sequence:: SequenceBuilder , sync:: SyncBuilder , trigger:: TriggerBuilder } ,
20+ actions:: {
21+ invoke:: Invoke , sequence:: SequenceBuilder , sync:: SyncBuilder , trigger:: TriggerBuilder ,
22+ } ,
2123 api:: { design:: Design , Orchestration } ,
2224 common:: DesignConfig ,
2325 prelude:: InvokeResult ,
@@ -34,7 +36,6 @@ use rust_kvs::prelude::*;
3436// which starts the object detection component. Persistency is demonstrated using a key-value store during shutdown.
3537// The orchestration is run using the Kyron async runtime, and the program chains are executed concurrently.
3638
37-
3839const CAMERA_IMG_READY : & str = "CameraImageReadyEvent" ;
3940const CAMERA_IMG_PROCESSED : & str = "CameraImageProcessedEvent" ;
4041
@@ -56,8 +57,8 @@ async fn on_shutdown() -> InvokeResult {
5657 // Instance ID for KVS object instances.
5758 let instance_id = InstanceId ( 0 ) ;
5859 let builder = KvsBuilder :: new ( instance_id)
59- . dir ( "./" )
60- . kvs_load ( KvsLoad :: Optional ) ;
60+ . dir ( "./" )
61+ . kvs_load ( KvsLoad :: Optional ) ;
6162 let kvs = builder. build ( ) . unwrap ( ) ;
6263
6364 kvs. set_value ( "number" , 123.0 ) . unwrap ( ) ;
@@ -74,41 +75,61 @@ fn camera_processing_component_design() -> Result<Design, CommonErrors> {
7475 // Register events and invoke actions in design so it knows how to build task chains
7576 design. register_event ( CAMERA_IMG_READY . into ( ) ) ?;
7677 design. register_event ( CAMERA_IMG_PROCESSED . into ( ) ) ?;
77- let on_camera_image_ready_tag = design. register_invoke_async ( "on_camera_image_ready" . into ( ) , on_camera_image_ready) ?;
78+ let on_camera_image_ready_tag =
79+ design. register_invoke_async ( "on_camera_image_ready" . into ( ) , on_camera_image_ready) ?;
7880
7981 // Create a program describing task chain
80- design. add_program ( "CameraProcessingProgram" , move |design_instance, builder| {
81- builder. with_run_action (
82- SequenceBuilder :: new ( )
83- . with_step ( SyncBuilder :: from_design ( CAMERA_IMG_READY , design_instance) )
84- . with_step ( Invoke :: from_tag ( & on_camera_image_ready_tag, design_instance. config ( ) ) )
85- . with_step ( TriggerBuilder :: from_design ( CAMERA_IMG_PROCESSED , design_instance) )
86- . build ( ) ,
87- ) ;
88- Ok ( ( ) )
89- } ) ;
82+ design. add_program (
83+ "CameraProcessingProgram" ,
84+ move |design_instance, builder| {
85+ builder. with_run_action (
86+ SequenceBuilder :: new ( )
87+ . with_step ( SyncBuilder :: from_design ( CAMERA_IMG_READY , design_instance) )
88+ . with_step ( Invoke :: from_tag (
89+ & on_camera_image_ready_tag,
90+ design_instance. config ( ) ,
91+ ) )
92+ . with_step ( TriggerBuilder :: from_design (
93+ CAMERA_IMG_PROCESSED ,
94+ design_instance,
95+ ) )
96+ . build ( ) ,
97+ ) ;
98+ Ok ( ( ) )
99+ } ,
100+ ) ;
90101
91102 Ok ( design)
92103}
93104
94105fn detect_object_component_design ( ) -> Result < Design , CommonErrors > {
95106 let mut design = Design :: new ( "DetectObjectDesign" . into ( ) , DesignConfig :: default ( ) ) ;
96107
97- // Register events and invoke actions in design so it knows how to build task chains
108+ // Register events and invoke actions in design so it knows how to build task chains
98109 design. register_event ( CAMERA_IMG_PROCESSED . into ( ) ) ?;
99- let detect_objects_tag = design. register_invoke_async ( "detect_objects" . into ( ) , detect_objects) ?;
110+ let detect_objects_tag =
111+ design. register_invoke_async ( "detect_objects" . into ( ) , detect_objects) ?;
100112 let on_shutdown_tag = design. register_invoke_async ( "on_shutdown" . into ( ) , on_shutdown) ?;
101113
102114 // Create a program describing task chain
103115 design. add_program ( "DetectObjectProgram" , move |design_instance, builder| {
104- builder. with_run_action (
105- SequenceBuilder :: new ( )
106- . with_step ( SyncBuilder :: from_design ( CAMERA_IMG_PROCESSED , design_instance) )
107- . with_step ( Invoke :: from_tag ( & detect_objects_tag, design_instance. config ( ) ) )
108- . build ( ) ,
109- ) . with_stop_action (
110- Invoke :: from_tag ( & on_shutdown_tag, design_instance. config ( ) ) , Duration :: from_secs ( 2 )
111- ) ;
116+ builder
117+ . with_run_action (
118+ SequenceBuilder :: new ( )
119+ . with_step ( SyncBuilder :: from_design (
120+ CAMERA_IMG_PROCESSED ,
121+ design_instance,
122+ ) )
123+ . with_step ( Invoke :: from_tag (
124+ & detect_objects_tag,
125+ design_instance. config ( ) ,
126+ ) )
127+ . build ( ) ,
128+ )
129+ . with_stop_action (
130+ Invoke :: from_tag ( & on_shutdown_tag, design_instance. config ( ) ) ,
131+ Duration :: from_secs ( 2 ) ,
132+ ) ;
112133 Ok ( ( ) )
113134 } ) ;
114135
@@ -117,18 +138,30 @@ fn detect_object_component_design() -> Result<Design, CommonErrors> {
117138
118139fn main ( ) {
119140 // Setup any logging framework you want to use.
120- let mut logger = TracingLibraryBuilder :: new ( ) . global_log_level ( Level :: INFO ) . enable_logging ( true ) . build ( ) ;
121-
122- logger. init_log_trace ( ) ;
141+ let logger = LogAndTraceBuilder :: new ( )
142+ . global_log_level ( logging_tracing:: Level :: INFO )
143+ . enable_logging ( true )
144+ . build ( ) ;
145+ // logger.init_log_trace();
123146
124147 // Create runtime
125- let ( builder, _engine_id) = kyron:: runtime:: RuntimeBuilder :: new ( ) . with_engine ( ExecutionEngineBuilder :: new ( ) . task_queue_size ( 256 ) . workers ( 2 ) ) ;
148+ let ( builder, _engine_id) = kyron:: runtime:: RuntimeBuilder :: new ( ) . with_engine (
149+ ExecutionEngineBuilder :: new ( )
150+ . task_queue_size ( 256 )
151+ . workers ( 2 ) ,
152+ ) ;
126153 let mut runtime = builder. build ( ) . unwrap ( ) ;
127154
128155 // Build Orchestration
129156 let mut orch = Orchestration :: new ( )
130- . add_design ( camera_processing_component_design ( ) . expect ( "Failed to create camera_processing_component_design" ) )
131- . add_design ( detect_object_component_design ( ) . expect ( "Failed to create detect_object_component_design" ) )
157+ . add_design (
158+ camera_processing_component_design ( )
159+ . expect ( "Failed to create camera_processing_component_design" ) ,
160+ )
161+ . add_design (
162+ detect_object_component_design ( )
163+ . expect ( "Failed to create detect_object_component_design" ) ,
164+ )
132165 . design_done ( ) ;
133166
134167 // Specify deployment information, ie. which event is local, which timer etc
0 commit comments