@@ -66,6 +66,23 @@ typedef void (*ProcessEvent_t)(lp_id_t me, simtime_t now, unsigned event_type, c
6666 */
6767typedef bool (* CanEnd_t )(lp_id_t me , const void * snapshot );
6868
69+ /**
70+ * @brief Perform output operations.
71+ * @param me The logical process ID of the LP performing the output
72+ * @param output_type Numerical output type
73+ * @param output_content The output content
74+ * @param output_size The size (in bytes) of the output content
75+ *
76+ * This function is called by the simulation kernel whenever an event is committed, during the handling of which
77+ * an output operation had been scheduled by the simulation model using the ScheduleOutput() function.
78+ * This function will receive the same data that was passed to the ScheduleOutput() function.
79+ *
80+ * @warning The memory pointed by output_content is not a copy, and is owned by the simulation kernel. It will be
81+ * freed by the simulation kernel after the function returns.
82+ * @warning The function shall not perform any memory-managed allocation (e.g. using rs_malloc).
83+ */
84+ typedef void (* OutputCallback_t )(lp_id_t me , unsigned output_type , const void * output_content , unsigned output_size );
85+
6986/// @brief Internal event types used by the simulation kernel.
7087///
7188/// These event types are automatically scheduled to the model according to the following logic:
@@ -91,6 +108,19 @@ extern void ScheduleNewEvent(lp_id_t receiver, simtime_t timestamp, unsigned eve
91108
92109extern void SetState (void * new_state );
93110
111+ /**
112+ * @brief API to schedule a new output event to execute once the event being currently executed is committed
113+ *
114+ * This function makes a copy of the data in @p output_content , which stays owned by the caller.
115+ *
116+ * @param output_type Numerical output type to be passed to the output handling function
117+ * @param output_content The output content
118+ * @param output_size The size (in bytes) of the output content
119+ *
120+ * @warning This function shall not be called during the handling of LP_FINI events, as it will produce no output.
121+ */
122+ extern void ScheduleOutput (unsigned output_type , const void * output_content , unsigned output_size );
123+
94124/**
95125 * @brief Allocates rollbackable memory
96126 *
@@ -206,6 +236,8 @@ struct simulation_configuration {
206236 ProcessEvent_t dispatcher ;
207237 /// Function pointer to the termination detection function
208238 CanEnd_t committed ;
239+ /// Function pointer to the output handling function
240+ OutputCallback_t output_callback ;
209241};
210242
211243extern int RootsimInit (const struct simulation_configuration * conf );
0 commit comments