From f0d15a552676afc247f6aafd6fd0cfba910fba13 Mon Sep 17 00:00:00 2001 From: tanneberger Date: Fri, 31 Oct 2025 13:02:28 +0100 Subject: [PATCH] new clang-format --- .clang-format | 7 +- include/reactor-uc/action.h | 26 +- include/reactor-uc/builtin_triggers.h | 6 +- include/reactor-uc/clock_synchronization.h | 12 +- include/reactor-uc/connection.h | 26 +- include/reactor-uc/coordinator.h | 6 +- include/reactor-uc/environment.h | 44 ++-- .../environments/federated_environment.h | 16 +- include/reactor-uc/event.h | 20 +- include/reactor-uc/federated.h | 42 ++-- include/reactor-uc/logging.h | 2 +- include/reactor-uc/macros_api.h | 20 +- include/reactor-uc/macros_internal.h | 236 +++++++++--------- include/reactor-uc/network_channel.h | 22 +- include/reactor-uc/physical_clock.h | 12 +- include/reactor-uc/platform.h | 22 +- .../reactor-uc/platform/flexpret/flexpret.h | 2 +- include/reactor-uc/platform/patmos/patmos.h | 2 +- .../reactor-uc/platform/pico/uart_channel.h | 8 +- .../platform/posix/tcp_ip_channel.h | 8 +- .../platform/riot/coap_udp_ip_channel.h | 6 +- .../reactor-uc/platform/riot/uart_channel.h | 8 +- include/reactor-uc/port.h | 22 +- include/reactor-uc/queues.h | 28 +-- include/reactor-uc/reaction.h | 20 +- include/reactor-uc/reactor-c.h | 4 +- include/reactor-uc/reactor.h | 22 +- include/reactor-uc/scheduler.h | 26 +- .../reactor-uc/schedulers/dynamic/scheduler.h | 20 +- .../schedulers/static/instructions.h | 54 ++-- .../reactor-uc/schedulers/static/scheduler.h | 10 +- .../static/scheduler_instructions.h | 8 +- include/reactor-uc/serialization.h | 8 +- include/reactor-uc/startup_coordinator.h | 14 +- include/reactor-uc/tag.h | 10 +- include/reactor-uc/timer.h | 4 +- include/reactor-uc/trigger.h | 20 +- include/reactor-uc/util.h | 6 +- src/action.c | 52 ++-- src/builtin_triggers.c | 12 +- src/clock_synchronization.c | 94 +++---- src/connection.c | 50 ++-- src/environment.c | 8 +- src/environments/federated_environment.c | 42 ++-- src/environments/unfederated_environment.c | 30 +-- src/event.c | 8 +- src/federated.c | 80 +++--- src/logging.c | 6 +- src/network_channel.c | 2 +- src/physical_clock.c | 14 +- src/platform/aducm355/aducm355.c | 38 ++- src/platform/flexpret/flexpret.c | 42 ++-- src/platform/patmos/patmos.c | 50 ++-- src/platform/pico/pico.c | 42 ++-- src/platform/pico/uart_channel.c | 42 ++-- src/platform/posix/posix.c | 49 ++-- src/platform/posix/tcp_ip_channel.c | 74 +++--- src/platform/riot/coap_udp_ip_channel.c | 92 +++---- src/platform/riot/riot.c | 38 ++- src/platform/riot/uart_channel.c | 44 ++-- src/platform/zephyr/zephyr.c | 40 ++- src/port.c | 18 +- src/queues.c | 28 +-- src/reaction.c | 30 +-- src/reactor.c | 30 +-- src/schedulers/dynamic/scheduler.c | 110 ++++---- src/schedulers/static/instructions.c | 100 ++++---- src/schedulers/static/scheduler.c | 10 +- src/serialization.c | 8 +- src/startup_coordinator.c | 86 +++---- src/timer.c | 18 +- src/trigger.c | 4 +- src/util.c | 6 +- test/unit/action_empty_test.c | 7 +- test/unit/action_microstep_test.c | 7 +- test/unit/action_overwrite_test.c | 7 +- test/unit/action_test.c | 7 +- test/unit/delayed_conn_test.c | 4 +- test/unit/event_payload_pool_test.c | 22 +- test/unit/event_queue_test.c | 2 +- test/unit/mock.c | 6 +- test/unit/nanopb_test.c | 10 +- test/unit/physical_clock_test.c | 4 +- test/unit/port_test.c | 4 +- test/unit/reaction_queue_test.c | 14 +- test/unit/request_shutdown_test.c | 4 +- test/unit/startup_test.c | 4 +- test/unit/tcp_channel_test.c | 32 +-- 88 files changed, 1144 insertions(+), 1216 deletions(-) diff --git a/.clang-format b/.clang-format index 5030019ed..cc97b76e7 100644 --- a/.clang-format +++ b/.clang-format @@ -2,7 +2,8 @@ BasedOnStyle: LLVM Language: Cpp IndentWidth: 2 +BreakConstructorInitializersBeforeComma: 'true' +PointerAlignment: Left +IncludeBlocks: Preserve +SortIncludes: false ColumnLimit: 120 -AllowShortIfStatementsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -SortIncludes: false \ No newline at end of file diff --git a/include/reactor-uc/action.h b/include/reactor-uc/action.h index 44b3d757a..1ba33e7af 100644 --- a/include/reactor-uc/action.h +++ b/include/reactor-uc/action.h @@ -18,7 +18,7 @@ struct Action { interval_t min_offset; // The minimum offset from the current time that an event can be scheduled on this action. interval_t min_spacing; // The minimum spacing between two events scheduled on this action. instant_t last_event_time; // Logical time of most recent event scheduled on this action. - void *value_ptr; // Pointer to the value associated with this action at the current logical tag. + void* value_ptr; // Pointer to the value associated with this action at the current logical tag. TriggerEffects effects; // The reactions triggered by this Action. TriggerSources sources; // The reactions that can write to this Action. TriggerObservers observers; // The reactions that can observe this Action. @@ -33,30 +33,30 @@ struct Action { * @param offset The tag of the scheduled event will be the current tag plus the min_offset plus this offset. * @param value A pointer to the value which should be scheduled with the event. */ - lf_ret_t (*schedule)(Action *self, interval_t offset, const void *value); + lf_ret_t (*schedule)(Action* self, interval_t offset, const void* value); }; -void Action_ctor(Action *self, ActionType type, interval_t min_offset, interval_t min_spacing, Reactor *parent, - Reaction **sources, size_t sources_size, Reaction **effects, size_t effects_size, Reaction **observers, - size_t observers_size, void *value_ptr, size_t value_size, void *payload_buf, bool *payload_used_buf, +void Action_ctor(Action* self, ActionType type, interval_t min_offset, interval_t min_spacing, Reactor* parent, + Reaction** sources, size_t sources_size, Reaction** effects, size_t effects_size, Reaction** observers, + size_t observers_size, void* value_ptr, size_t value_size, void* payload_buf, bool* payload_used_buf, size_t event_bound); struct LogicalAction { Action super; }; -void LogicalAction_ctor(LogicalAction *self, interval_t min_offset, interval_t min_spacing, Reactor *parent, - Reaction **sources, size_t sources_size, Reaction **effects, size_t effects_size, - Reaction **observers, size_t observers_size, void *value_ptr, size_t value_size, - void *payload_buf, bool *payload_used_buf, size_t event_bound); +void LogicalAction_ctor(LogicalAction* self, interval_t min_offset, interval_t min_spacing, Reactor* parent, + Reaction** sources, size_t sources_size, Reaction** effects, size_t effects_size, + Reaction** observers, size_t observers_size, void* value_ptr, size_t value_size, + void* payload_buf, bool* payload_used_buf, size_t event_bound); struct PhysicalAction { Action super; MUTEX_T mutex; }; -void PhysicalAction_ctor(PhysicalAction *self, interval_t min_offset, interval_t min_spacing, Reactor *parent, - Reaction **sources, size_t sources_size, Reaction **effects, size_t effects_size, - Reaction **observers, size_t observers_size, void *value_ptr, size_t value_size, - void *payload_buf, bool *payload_used_buf, size_t event_bound); +void PhysicalAction_ctor(PhysicalAction* self, interval_t min_offset, interval_t min_spacing, Reactor* parent, + Reaction** sources, size_t sources_size, Reaction** effects, size_t effects_size, + Reaction** observers, size_t observers_size, void* value_ptr, size_t value_size, + void* payload_buf, bool* payload_used_buf, size_t event_bound); #endif diff --git a/include/reactor-uc/builtin_triggers.h b/include/reactor-uc/builtin_triggers.h index 88880adf2..d0ee64e8a 100644 --- a/include/reactor-uc/builtin_triggers.h +++ b/include/reactor-uc/builtin_triggers.h @@ -11,10 +11,10 @@ struct BuiltinTrigger { Trigger super; TriggerEffects effects; TriggerObservers observers; - BuiltinTrigger *next; + BuiltinTrigger* next; }; -void BuiltinTrigger_ctor(BuiltinTrigger *self, TriggerType type, Reactor *parent, Reaction **effects, - size_t effects_size, Reaction **observers, size_t observers_size); +void BuiltinTrigger_ctor(BuiltinTrigger* self, TriggerType type, Reactor* parent, Reaction** effects, + size_t effects_size, Reaction** observers, size_t observers_size); #endif diff --git a/include/reactor-uc/clock_synchronization.h b/include/reactor-uc/clock_synchronization.h index 605705acb..5c6480962 100644 --- a/include/reactor-uc/clock_synchronization.h +++ b/include/reactor-uc/clock_synchronization.h @@ -44,8 +44,8 @@ typedef struct { struct ClockSynchronization { SystemEventHandler super; // ClockSynchronization is a subclass of SystemEventHandler - Environment *env; - NeighborClock *neighbor_clock; // Pointer to an array of neighbor clocks, one for each neighbor. + Environment* env; + NeighborClock* neighbor_clock; // Pointer to an array of neighbor clocks, one for each neighbor. size_t num_neighbours; // Number of neighbors, length of the neighbor_clock array. bool is_grandmaster; // Whether this node is the grandmaster. bool has_initial_sync; // Whether the initial sync has been completed. @@ -55,12 +55,12 @@ struct ClockSynchronization { interval_t period; // The period between sync request messages are sent to the neighbor master. ClockSyncTimestamps timestamps; // The timestamps used to compute clock offset. ClockServo servo; // The PID controller - void (*handle_message_callback)(ClockSynchronization *self, const ClockSyncMessage *msg, size_t bundle_idx); + void (*handle_message_callback)(ClockSynchronization* self, const ClockSyncMessage* msg, size_t bundle_idx); }; -void ClockSynchronization_ctor(ClockSynchronization *self, Environment *env, NeighborClock *neighbor_clock, - size_t num_neighbors, bool is_grandmaster, size_t payload_size, void *payload_buf, - bool *payload_used_buf, size_t payload_buf_capacity, interval_t period, +void ClockSynchronization_ctor(ClockSynchronization* self, Environment* env, NeighborClock* neighbor_clock, + size_t num_neighbors, bool is_grandmaster, size_t payload_size, void* payload_buf, + bool* payload_used_buf, size_t payload_buf_capacity, interval_t period, interval_t max_adj, float servo_kp, float servo_ki); #endif // REACTOR_UC_CLOCK_SYNCHRONIZATION_H diff --git a/include/reactor-uc/connection.h b/include/reactor-uc/connection.h index be6de2b66..1746467a3 100644 --- a/include/reactor-uc/connection.h +++ b/include/reactor-uc/connection.h @@ -19,35 +19,35 @@ typedef enum { LOGICAL_CONNECTION, PHYSICAL_CONNECTION } ConnectionType; struct Connection { Trigger super; - Port *upstream; // Single upstream port - Port **downstreams; // Pointer to array of pointers of downstream ports + Port* upstream; // Single upstream port + Port** downstreams; // Pointer to array of pointers of downstream ports size_t downstreams_size; // Size of downstreams array size_t downstreams_registered; // Number of downstreams currently registered - void (*register_downstream)(Connection *, Port *); - Port *(*get_final_upstream)(Connection *); - void (*trigger_downstreams)(Connection *, const void *value_ptr, size_t value_size); + void (*register_downstream)(Connection*, Port*); + Port* (*get_final_upstream)(Connection*); + void (*trigger_downstreams)(Connection*, const void* value_ptr, size_t value_size); }; -void Connection_ctor(Connection *self, TriggerType type, Reactor *parent, Port **downstreams, size_t num_downstreams, - EventPayloadPool *payload_pool, void (*prepare)(Trigger *, Event *), void (*cleanup)(Trigger *), - void (*trigger_downstreams)(Connection *, const void *, size_t)); +void Connection_ctor(Connection* self, TriggerType type, Reactor* parent, Port** downstreams, size_t num_downstreams, + EventPayloadPool* payload_pool, void (*prepare)(Trigger*, Event*), void (*cleanup)(Trigger*), + void (*trigger_downstreams)(Connection*, const void*, size_t)); struct LogicalConnection { Connection super; }; -void LogicalConnection_ctor(LogicalConnection *self, Reactor *parent, Port **downstreams, size_t num_downstreams); +void LogicalConnection_ctor(LogicalConnection* self, Reactor* parent, Port** downstreams, size_t num_downstreams); struct DelayedConnection { Connection super; interval_t delay; ConnectionType type; EventPayloadPool payload_pool; - void *staged_payload_ptr; + void* staged_payload_ptr; }; -void DelayedConnection_ctor(DelayedConnection *self, Reactor *parent, Port **downstreams, size_t num_downstreams, - interval_t delay, ConnectionType type, size_t payload_size, void *payload_buf, - bool *payload_used_buf, size_t payload_buf_capacity); +void DelayedConnection_ctor(DelayedConnection* self, Reactor* parent, Port** downstreams, size_t num_downstreams, + interval_t delay, ConnectionType type, size_t payload_size, void* payload_buf, + bool* payload_used_buf, size_t payload_buf_capacity); #endif diff --git a/include/reactor-uc/coordinator.h b/include/reactor-uc/coordinator.h index 6f06511f7..5f2529843 100644 --- a/include/reactor-uc/coordinator.h +++ b/include/reactor-uc/coordinator.h @@ -9,10 +9,10 @@ typedef struct Coordinator Coordinator; struct Coordinator { SystemEventHandler super; - Environment *env; + Environment* env; - void (*logical_tag_complete)(Coordinator *self, tag_t next_local_event_tag); - void (*handle_message_callback)(Coordinator *self, const void *msg, size_t bundle_idx); + void (*logical_tag_complete)(Coordinator* self, tag_t next_local_event_tag); + void (*handle_message_callback)(Coordinator* self, const void* msg, size_t bundle_idx); }; #endif // REACTOR_UC_COORDINATOR_H \ No newline at end of file diff --git a/include/reactor-uc/environment.h b/include/reactor-uc/environment.h index 566a3c01d..c418663be 100644 --- a/include/reactor-uc/environment.h +++ b/include/reactor-uc/environment.h @@ -16,29 +16,29 @@ typedef struct Platform Platform; typedef struct Environment Environment; -extern Environment *_lf_environment; // NOLINT +extern Environment* _lf_environment; // NOLINT struct Environment { - Reactor *main; // The top-level reactor of the program. - Scheduler *scheduler; // The scheduler in charge of executing the reactions. - Platform *platform; + Reactor* main; // The top-level reactor of the program. + Scheduler* scheduler; // The scheduler in charge of executing the reactions. + Platform* platform; bool has_async_events; // Whether the program has multiple execution contexts and can receive async events and thus // need critical sections. bool fast_mode; // Whether the program is executing in fast mode where we do not wait for physical time to elapse // before handling events. - BuiltinTrigger *startup; // A pointer to a startup trigger, if the program has one. - BuiltinTrigger *shutdown; // A pointer to a chain of shutdown triggers, if the program has one. + BuiltinTrigger* startup; // A pointer to a startup trigger, if the program has one. + BuiltinTrigger* shutdown; // A pointer to a chain of shutdown triggers, if the program has one. /** * @private * @brief Assemble the program by computing levels for each reaction and setting up the scheduler. */ - void (*assemble)(Environment *self); + void (*assemble)(Environment* self); /** * @private * @brief Start the program. */ - void (*start)(Environment *self); + void (*start)(Environment* self); /** * @private @@ -50,7 +50,7 @@ struct Environment { * This function must be called from a critical section. * */ - lf_ret_t (*wait_until)(Environment *self, instant_t wakeup_time); + lf_ret_t (*wait_until)(Environment* self, instant_t wakeup_time); /** * @brief Sleep for a duration. @@ -58,7 +58,7 @@ struct Environment { * @param wait_time The time duration to wait * */ - lf_ret_t (*wait_for)(Environment *self, interval_t wait_time); + lf_ret_t (*wait_for)(Environment* self, interval_t wait_time); /** * @brief Get the elapsed logical time since the start of the program. @@ -69,7 +69,7 @@ struct Environment { * @returns The elapsed logical time. */ - interval_t (*get_elapsed_logical_time)(Environment *self); + interval_t (*get_elapsed_logical_time)(Environment* self); /** * @brief Get the current logical time of the program.AbstractEvent @@ -79,7 +79,7 @@ struct Environment { * * @returns The current logical time. */ - instant_t (*get_logical_time)(Environment *self); + instant_t (*get_logical_time)(Environment* self); /** * @brief Get the elapsed physical time since the start of the program. @@ -90,7 +90,7 @@ struct Environment { * * @returns The elapsed physical time. */ - interval_t (*get_elapsed_physical_time)(Environment *self); + interval_t (*get_elapsed_physical_time)(Environment* self); /** * @brief Get the current physical time. @@ -101,7 +101,7 @@ struct Environment { * * @returns The current physical time. */ - instant_t (*get_physical_time)(Environment *self); + instant_t (*get_physical_time)(Environment* self); /** * @brief Get the current lag. @@ -111,7 +111,7 @@ struct Environment { * current logical time. Deadlines are bounds on the release lag of a reaction. * */ - interval_t (*get_lag)(Environment *self); + interval_t (*get_lag)(Environment* self); /** * @brief Request the termination of the program. @@ -122,7 +122,7 @@ struct Environment { * If the program is not federated, then the shutdown will occur at the next microstep. * If the program is federated, then the shutdown tag will be negotiated with the other federates. */ - void (*request_shutdown)(Environment *self); + void (*request_shutdown)(Environment* self); /** * @private @@ -134,7 +134,7 @@ struct Environment { * In a federated setting, we might have to wait before doing this. We might * wait for a STA offset or send out a coordination message to the upstream. */ - lf_ret_t (*acquire_tag)(Environment *self, tag_t tag); + lf_ret_t (*acquire_tag)(Environment* self, tag_t tag); /** * @private @@ -144,13 +144,13 @@ struct Environment { * This function should only be supplied in a federated environment. It should * poll all the PolledNetworkChannels that the federate has. */ - lf_ret_t (*poll_network_channels)(Environment *self); + lf_ret_t (*poll_network_channels)(Environment* self); }; -void Environment_ctor(Environment *self, Reactor *main, Scheduler *scheduler, bool fast_mode); -void Environment_free(Environment *self); +void Environment_ctor(Environment* self, Reactor* main, Scheduler* scheduler, bool fast_mode); +void Environment_free(Environment* self); -void Environment_schedule_startups(const Environment *self, tag_t start_tag); -void Environment_schedule_timers(Environment *self, const Reactor *reactor, tag_t start_tag); +void Environment_schedule_startups(const Environment* self, tag_t start_tag); +void Environment_schedule_timers(Environment* self, const Reactor* reactor, tag_t start_tag); #endif diff --git a/include/reactor-uc/environments/federated_environment.h b/include/reactor-uc/environments/federated_environment.h index b945ee71c..2efab0e3f 100644 --- a/include/reactor-uc/environments/federated_environment.h +++ b/include/reactor-uc/environments/federated_environment.h @@ -8,23 +8,23 @@ #include "reactor-uc/physical_clock.h" typedef struct FederatedEnvironment FederatedEnvironment; -extern Environment *_lf_environment; // NOLINT +extern Environment* _lf_environment; // NOLINT struct FederatedEnvironment { Environment super; PhysicalClock clock; // The physical clock that provides the physical time. bool do_clock_sync; - FederatedConnectionBundle **net_bundles; // A pointer to an array of NetworkChannel pointers that are used to + FederatedConnectionBundle** net_bundles; // A pointer to an array of NetworkChannel pointers that are used to // communicate with other federates running in different environments. size_t net_bundles_size; // The number of NetworkChannels in the net_channels array. size_t federation_longest_path; // The longest path in the federation. - StartupCoordinator *startup_coordinator; // A pointer to the startup coordinator, if the program has one. - ClockSynchronization *clock_sync; // A pointer to the clock synchronization module, if the program has one. + StartupCoordinator* startup_coordinator; // A pointer to the startup coordinator, if the program has one. + ClockSynchronization* clock_sync; // A pointer to the clock synchronization module, if the program has one. }; -void FederatedEnvironment_ctor(FederatedEnvironment *self, Reactor *main, Scheduler *scheduler, bool fast_mode, - FederatedConnectionBundle **net_bundles, size_t net_bundles_size, - StartupCoordinator *startup_coordinator, ClockSynchronization *clock_sync); -void FederatedEnvironment_free(FederatedEnvironment *self); +void FederatedEnvironment_ctor(FederatedEnvironment* self, Reactor* main, Scheduler* scheduler, bool fast_mode, + FederatedConnectionBundle** net_bundles, size_t net_bundles_size, + StartupCoordinator* startup_coordinator, ClockSynchronization* clock_sync); +void FederatedEnvironment_free(FederatedEnvironment* self); #endif diff --git a/include/reactor-uc/event.h b/include/reactor-uc/event.h index b734525e2..ae3e50f5b 100644 --- a/include/reactor-uc/event.h +++ b/include/reactor-uc/event.h @@ -22,20 +22,20 @@ typedef enum { EVENT, SYSTEM_EVENT } EventType; typedef struct { EventType type; tag_t tag; - void *payload; + void* payload; } AbstractEvent; /** Normal reactor event. */ typedef struct { AbstractEvent super; tag_t intended_tag; // Intended tag used to catch STP violations in federated setting. - Trigger *trigger; + Trigger* trigger; } Event; /** System events used to schedule system activities that are unordered wrt reactor events. */ typedef struct { AbstractEvent super; - SystemEventHandler *handler; + SystemEventHandler* handler; } SystemEvent; /** Arbitrary event is a structure with enough memory to hold any type of event.*/ @@ -47,8 +47,8 @@ typedef struct { } ArbitraryEvent; struct EventPayloadPool { - char *buffer; - bool *used; + char* buffer; + bool* used; /** Number of bytes per payload */ size_t payload_size; /** Max number of allocated payloads*/ @@ -59,19 +59,19 @@ struct EventPayloadPool { MUTEX_T mutex; /** Allocate a payload from the pool. */ - lf_ret_t (*allocate)(EventPayloadPool *self, void **payload); - lf_ret_t (*allocate_reserved)(EventPayloadPool *self, void **payload); + lf_ret_t (*allocate)(EventPayloadPool* self, void** payload); + lf_ret_t (*allocate_reserved)(EventPayloadPool* self, void** payload); /** Free a payload. */ - lf_ret_t (*free)(EventPayloadPool *self, void *payload); + lf_ret_t (*free)(EventPayloadPool* self, void* payload); }; /** Abstract base class for objects that can handle SystemEvents such as ClockSync and StartupCoordinator. */ struct SystemEventHandler { - void (*handle)(SystemEventHandler *self, SystemEvent *event); + void (*handle)(SystemEventHandler* self, SystemEvent* event); EventPayloadPool payload_pool; }; -void EventPayloadPool_ctor(EventPayloadPool *self, char *buffer, bool *used, size_t element_size, size_t capacity, +void EventPayloadPool_ctor(EventPayloadPool* self, char* buffer, bool* used, size_t element_size, size_t capacity, size_t reserved); #endif diff --git a/include/reactor-uc/federated.h b/include/reactor-uc/federated.h index 59618b2bd..44537e91d 100644 --- a/include/reactor-uc/federated.h +++ b/include/reactor-uc/federated.h @@ -21,7 +21,7 @@ typedef struct NetworkChannel NetworkChannel; * @param msg_buffer A pointer to the buffer to write the serialized message to * @return The size of the serialized message */ -typedef int (*serialize_hook)(const void *user_struct, size_t user_struct_size, unsigned char *msg_buffer); +typedef int (*serialize_hook)(const void* user_struct, size_t user_struct_size, unsigned char* msg_buffer); /** * @brief A function type for deserializers that takes a message buffer and deserializes them to a port value. @@ -34,7 +34,7 @@ typedef int (*serialize_hook)(const void *user_struct, size_t user_struct_size, * @param msg_size The size of the serialized message * @return Whether the deserialization was successful */ -typedef lf_ret_t (*deserialize_hook)(void *user_struct, const unsigned char *msg_buffer, size_t msg_size); +typedef lf_ret_t (*deserialize_hook)(void* user_struct, const unsigned char* msg_buffer, size_t msg_size); /** * @brief A FederatedConnectionBundle is a collection of input and output connections to a single other federate. @@ -43,26 +43,26 @@ typedef lf_ret_t (*deserialize_hook)(void *user_struct, const unsigned char *msg * the serializers and deserializers for each connection. */ struct FederatedConnectionBundle { - Reactor *parent; // Pointer to the federate - NetworkChannel *net_channel; // Pointer to the network super doing the actual I/O + Reactor* parent; // Pointer to the federate + NetworkChannel* net_channel; // Pointer to the network super doing the actual I/O // Pointer to an array of input connections which should live in the derived struct. - FederatedInputConnection **inputs; - deserialize_hook *deserialize_hooks; + FederatedInputConnection** inputs; + deserialize_hook* deserialize_hooks; size_t inputs_size; // Pointer to an array of output connections which should live in the derived struct. FederateMessage send_msg; - FederatedOutputConnection **outputs; - serialize_hook *serialize_hooks; + FederatedOutputConnection** outputs; + serialize_hook* serialize_hooks; size_t outputs_size; bool server; // Does this federate work as server or client size_t index; // Index of this FederatedConnectionBundle in the Environment's net_bundles array }; -void FederatedConnectionBundle_ctor(FederatedConnectionBundle *self, Reactor *parent, NetworkChannel *net_channel, - FederatedInputConnection **inputs, deserialize_hook *deserialize_hooks, - size_t inputs_size, FederatedOutputConnection **outputs, - serialize_hook *serialize_hooks, size_t outputs_size, size_t index); +void FederatedConnectionBundle_ctor(FederatedConnectionBundle* self, Reactor* parent, NetworkChannel* net_channel, + FederatedInputConnection** inputs, deserialize_hook* deserialize_hooks, + size_t inputs_size, FederatedOutputConnection** outputs, + serialize_hook* serialize_hooks, size_t outputs_size, size_t index); /** * @brief A single output connection from this federate to another federate. @@ -73,16 +73,16 @@ void FederatedConnectionBundle_ctor(FederatedConnectionBundle *self, Reactor *pa */ struct FederatedOutputConnection { Connection super; // Inherits from Connection, it wastes some memory but makes for a nicer architecture. - FederatedConnectionBundle *bundle; // A pointer to the super it is within + FederatedConnectionBundle* bundle; // A pointer to the super it is within EventPayloadPool payload_pool; // Output buffer - void *staged_payload_ptr; + void* staged_payload_ptr; int conn_id; }; -void FederatedConnectionBundle_validate(FederatedConnectionBundle *bundle); +void FederatedConnectionBundle_validate(FederatedConnectionBundle* bundle); -void FederatedOutputConnection_ctor(FederatedOutputConnection *self, Reactor *parent, FederatedConnectionBundle *bundle, - int conn_id, void *payload_buf, bool *payload_used_buf, size_t payload_size, +void FederatedOutputConnection_ctor(FederatedOutputConnection* self, Reactor* parent, FederatedConnectionBundle* bundle, + int conn_id, void* payload_buf, bool* payload_used_buf, size_t payload_size, size_t payload_buf_capacity); /** @@ -106,11 +106,11 @@ struct FederatedInputConnection { * * This is called by the network channel when a message is received. */ - void (*schedule)(FederatedInputConnection *self, TaggedMessage *msg); + void (*schedule)(FederatedInputConnection* self, TaggedMessage* msg); }; -void FederatedInputConnection_ctor(FederatedInputConnection *self, Reactor *parent, interval_t delay, bool is_physical, - interval_t max_wait, Port **downstreams, size_t downstreams_size, void *payload_buf, - bool *payload_used_buf, size_t payload_size, size_t payload_buf_capacity); +void FederatedInputConnection_ctor(FederatedInputConnection* self, Reactor* parent, interval_t delay, bool is_physical, + interval_t max_wait, Port** downstreams, size_t downstreams_size, void* payload_buf, + bool* payload_used_buf, size_t payload_size, size_t payload_buf_capacity); #endif diff --git a/include/reactor-uc/logging.h b/include/reactor-uc/logging.h index d8f020710..806c6bb33 100644 --- a/include/reactor-uc/logging.h +++ b/include/reactor-uc/logging.h @@ -172,7 +172,7 @@ */ #define LF_DEBUG(module, fmt, ...) LF_LOG(LF_LOG_LEVEL_DEBUG, module, fmt, ##__VA_ARGS__) -void log_message(int level, const char *module, const char *fmt, ...); +void log_message(int level, const char* module, const char* fmt, ...); #endif #endif diff --git a/include/reactor-uc/macros_api.h b/include/reactor-uc/macros_api.h index 0f0bac8b6..c7237ebac 100644 --- a/include/reactor-uc/macros_api.h +++ b/include/reactor-uc/macros_api.h @@ -19,7 +19,7 @@ #define lf_set(port, val) \ do { \ __typeof__((port)->value) __val = (val); \ - Port *_port = (Port *)(port); \ + Port* _port = (Port*)(port); \ _port->set(_port, &__val); \ } while (0) @@ -33,7 +33,7 @@ */ #define lf_set_array(port, array) \ do { \ - Port *_port = (Port *)(port); \ + Port* _port = (Port*)(port); \ _port->set(_port, array); \ } while (0) @@ -52,17 +52,17 @@ * @param trigger The trigger. * @returns True if the trigger is present, false otherwise. */ -#define lf_is_present(trigger) (((Trigger *)(trigger))->is_present) +#define lf_is_present(trigger) (((Trigger*)(trigger))->is_present) /// @private #define lf_schedule_with_val(action, offset, val) \ do { \ __typeof__(val) __val = (val); \ - Action *__a = (Action *)(action); \ - lf_ret_t ret = __a->schedule(__a, (offset), (const void *)&__val); \ + Action* __a = (Action*)(action); \ + lf_ret_t ret = __a->schedule(__a, (offset), (const void*)&__val); \ if (ret == LF_FATAL) { \ LF_ERR(TRIG, "Scheduling an value, that doesn't have value!"); \ - Scheduler *sched = __a->super.parent->env->scheduler; \ + Scheduler* sched = __a->super.parent->env->scheduler; \ sched->do_shutdown(sched, sched->current_tag(sched)); \ throw("Tried to schedule a value onto an action without a type!"); \ } \ @@ -71,7 +71,7 @@ /// @private #define lf_schedule_without_val(action, offset) \ do { \ - Action *__a = (Action *)(action); \ + Action* __a = (Action*)(action); \ __a->schedule(__a, (offset), NULL); \ } while (0) @@ -106,11 +106,11 @@ */ #define lf_schedule_array(action, offset, array) \ do { \ - Action *__a = (Action *)(action); \ - lf_ret_t __ret = __a->schedule(__a, (offset), (const void *)array); \ + Action* __a = (Action*)(action); \ + lf_ret_t __ret = __a->schedule(__a, (offset), (const void*)array); \ if (__ret == LF_FATAL) { \ LF_ERR(TRIG, "Scheduling an value, that doesn't have value!"); \ - Scheduler *__sched = __a->super.parent->env->scheduler; \ + Scheduler* __sched = __a->super.parent->env->scheduler; \ __sched->do_shutdown(__sched, __sched->current_tag(__sched)); \ } \ } while (0) diff --git a/include/reactor-uc/macros_internal.h b/include/reactor-uc/macros_internal.h index e8003a418..2a45a17db 100644 --- a/include/reactor-uc/macros_internal.h +++ b/include/reactor-uc/macros_internal.h @@ -36,48 +36,48 @@ // The following macros casts the inputs into the correct types before calling TRIGGER_REGISTER_EFFECTs #define LF_ACTION_REGISTER_EFFECT(TheAction, TheEffect) \ - LF_TRIGGER_REGISTER_EFFECT((Action *)&(TheAction), (Reaction *)&(TheEffect)) + LF_TRIGGER_REGISTER_EFFECT((Action*)&(TheAction), (Reaction*)&(TheEffect)) #define LF_ACTION_REGISTER_SOURCE(TheAction, TheSource) \ - LF_TRIGGER_REGISTER_SOURCE((Action *)&(TheAction), (Reaction *)&(TheSource)); \ + LF_TRIGGER_REGISTER_SOURCE((Action*)&(TheAction), (Reaction*)&(TheSource)); \ LF_REACTION_REGISTER_EFFECT(TheSource, TheAction); #define LF_ACTION_REGISTER_OBSERVER(TheAction, TheObserver) \ - LF_TRIGGER_REGISTER_OBSERVER((Action *)&(TheAction), (Reaction *)&(TheObserver)) + LF_TRIGGER_REGISTER_OBSERVER((Action*)&(TheAction), (Reaction*)&(TheObserver)) #define LF_TIMER_REGISTER_EFFECT(TheTimer, TheEffect) \ - LF_TRIGGER_REGISTER_EFFECT((Timer *)(&(TheTimer)), (Reaction *)(&(TheEffect))) + LF_TRIGGER_REGISTER_EFFECT((Timer*)(&(TheTimer)), (Reaction*)(&(TheEffect))) #define LF_TIMER_REGISTER_OBSERVER(TheTimer, TheObserver) \ - LF_TRIGGER_REGISTER_OBSERVER((Timer *)(&(TheTimer)), (Reaction *)(&(TheObserver))) + LF_TRIGGER_REGISTER_OBSERVER((Timer*)(&(TheTimer)), (Reaction*)(&(TheObserver))) #define LF_STARTUP_REGISTER_EFFECT(TheEffect) \ - LF_TRIGGER_REGISTER_EFFECT((BuiltinTrigger *)&(self->startup), (Reaction *)&(TheEffect)) + LF_TRIGGER_REGISTER_EFFECT((BuiltinTrigger*)&(self->startup), (Reaction*)&(TheEffect)) #define LF_STARTUP_REGISTER_OBSERVER(TheObserver) \ - LF_TRIGGER_REGISTER_OBSERVER((BuiltinTrigger *)&(self->startup), (Reaction *)&(TheObserver)) + LF_TRIGGER_REGISTER_OBSERVER((BuiltinTrigger*)&(self->startup), (Reaction*)&(TheObserver)) #define LF_PORT_REGISTER_EFFECT(ThePort, TheEffect, PortWidth) \ for (int i = 0; i < PortWidth; i++) { \ - LF_TRIGGER_REGISTER_EFFECT((Port *)&(ThePort)[i], (Reaction *)&(TheEffect)); \ + LF_TRIGGER_REGISTER_EFFECT((Port*)&(ThePort)[i], (Reaction*)&(TheEffect)); \ } #define LF_PORT_REGISTER_SOURCE(ThePort, TheSource, PortWidth) \ for (int i = 0; i < PortWidth; i++) { \ - LF_TRIGGER_REGISTER_SOURCE((Port *)&(ThePort)[i], (Reaction *)&(TheSource)); \ + LF_TRIGGER_REGISTER_SOURCE((Port*)&(ThePort)[i], (Reaction*)&(TheSource)); \ LF_REACTION_REGISTER_EFFECT(TheSource, ThePort[i]); \ } #define LF_PORT_REGISTER_OBSERVER(ThePort, TheObserver, PortWidth) \ for (int i = 0; i < PortWidth; i++) { \ - LF_TRIGGER_REGISTER_OBSERVER((Port *)&(ThePort)[i], (Reaction *)&(TheObserver)); \ + LF_TRIGGER_REGISTER_OBSERVER((Port*)&(ThePort)[i], (Reaction*)&(TheObserver)); \ } #define LF_SHUTDOWN_REGISTER_EFFECT(TheEffect) \ - LF_TRIGGER_REGISTER_EFFECT((BuiltinTrigger *)&(self->shutdown), (Reaction *)&(TheEffect)) + LF_TRIGGER_REGISTER_EFFECT((BuiltinTrigger*)&(self->shutdown), (Reaction*)&(TheEffect)) #define LF_SHUTDOWN_REGISTER_OBSERVER(TheObserver) \ - LF_TRIGGER_REGISTER_OBSERVER((BuiltinTrigger *)&(self->shutdown), (Reaction *)&(TheObserver)) + LF_TRIGGER_REGISTER_OBSERVER((BuiltinTrigger*)&(self->shutdown), (Reaction*)&(TheObserver)) /** * @brief Convenience macro for registering a trigger as an effect of a reaction. @@ -85,9 +85,9 @@ */ #define LF_REACTION_REGISTER_EFFECT(TheReaction, TheEffect) \ do { \ - Reaction *__reaction = (Reaction *)&(TheReaction); \ + Reaction* __reaction = (Reaction*)&(TheReaction); \ assert((__reaction)->effects_registered < (__reaction)->effects_size); \ - (__reaction)->effects[(__reaction)->effects_registered++] = (Trigger *)&(TheEffect); \ + (__reaction)->effects[(__reaction)->effects_registered++] = (Trigger*)&(TheEffect); \ } while (0) // Macros for creating the structs and ctors @@ -111,33 +111,33 @@ sizeof(self->_triggers) / sizeof(self->_triggers[0])); #define LF_REACTOR_BOOKKEEPING_INSTANCES(NumReactions, NumTriggers, NumChildren) \ - Reaction *_reactions[NumReactions]; \ - Trigger *_triggers[NumTriggers]; \ - Reactor *_children[NumChildren]; + Reaction* _reactions[NumReactions]; \ + Trigger* _triggers[NumTriggers]; \ + Reactor* _children[NumChildren]; #define LF_FEDERATE_CONNECTION_BUNDLE_INSTANCE(ReactorName, OtherName) \ ReactorName##_##OtherName##_Bundle ReactorName##_##OtherName_bundle #define LF_FEDERATE_BOOKKEEPING_INSTANCES(NumBundles) \ LF_REACTOR_BOOKKEEPING_INSTANCES(0, 0, 1); \ - FederatedConnectionBundle *_bundles[NumBundles]; + FederatedConnectionBundle* _bundles[NumBundles]; #define LF_DEFINE_OUTPUT_STRUCT(ReactorName, PortName, SourceSize, BufferType) \ typedef struct { \ Port super; \ - Reaction *sources[(SourceSize)]; \ + Reaction* sources[(SourceSize)]; \ BufferType value; \ } ReactorName##_##PortName; #define LF_DEFINE_OUTPUT_ARRAY_STRUCT(ReactorName, PortName, SourceSize, BufferType, ArrayLen) \ typedef struct { \ Port super; \ - Reaction *sources[(SourceSize)]; \ + Reaction* sources[(SourceSize)]; \ BufferType value[(ArrayLen)]; \ } ReactorName##_##PortName; #define LF_DEFINE_OUTPUT_CTOR(ReactorName, PortName, SourceSize) \ - void ReactorName##_##PortName##_ctor(ReactorName##_##PortName *self, Reactor *parent, \ + void ReactorName##_##PortName##_ctor(ReactorName##_##PortName* self, Reactor* parent, \ OutputExternalCtorArgs external) { \ Port_ctor(&self->super, TRIG_OUTPUT, parent, &self->value, sizeof(self->value), external.parent_effects, \ external.parent_effects_size, self->sources, SourceSize, external.parent_observers, \ @@ -145,59 +145,59 @@ } #define LF_PORT_INSTANCE(ReactorName, PortName, PortWidth) ReactorName##_##PortName PortName[PortWidth]; -#define LF_PORT_PTR_INSTANCE(ReactorName, PortName) ReactorName##_##PortName *PortName; +#define LF_PORT_PTR_INSTANCE(ReactorName, PortName) ReactorName##_##PortName* PortName; #define LF_MULTIPORT_PTR_INSTANCE(ReactorName, PortName, PortWidth) \ - ReactorName##_##PortName *PortName[PortWidth]; \ + ReactorName##_##PortName* PortName[PortWidth]; \ int PortName##_width; #define LF_INITIALIZE_OUTPUT(ReactorName, PortName, PortWidth, External) \ for (int i = 0; i < (PortWidth); i++) { \ - self->_triggers[_triggers_idx++] = (Trigger *)&self->PortName[i]; \ + self->_triggers[_triggers_idx++] = (Trigger*)&self->PortName[i]; \ ReactorName##_##PortName##_ctor(&self->PortName[i], &self->super, External[i]); \ } #define LF_INITIALIZE_INPUT(ReactorName, PortName, PortWidth, External) \ for (int i = 0; i < (PortWidth); i++) { \ - self->_triggers[_triggers_idx++] = (Trigger *)&self->PortName[i]; \ + self->_triggers[_triggers_idx++] = (Trigger*)&self->PortName[i]; \ ReactorName##_##PortName##_ctor(&self->PortName[i], &self->super, External[i]); \ } #define LF_DEFINE_INPUT_STRUCT(ReactorName, PortName, EffectSize, ObserversSize, BufferType, NumConnsOut) \ typedef struct { \ Port super; \ - Reaction *effects[(EffectSize)]; \ - Reaction *observers[(ObserversSize)]; \ + Reaction* effects[(EffectSize)]; \ + Reaction* observers[(ObserversSize)]; \ BufferType value; \ - Connection *conns_out[(NumConnsOut)]; \ + Connection* conns_out[(NumConnsOut)]; \ } ReactorName##_##PortName; #define LF_DEFINE_INPUT_ARRAY_STRUCT(ReactorName, PortName, EffectSize, ObserversSize, BufferType, ArrayLen, \ NumConnsOut) \ typedef struct { \ Port super; \ - Reaction *effects[(EffectSize)]; \ - Reaction *observers[(ObserversSize)]; \ + Reaction* effects[(EffectSize)]; \ + Reaction* observers[(ObserversSize)]; \ BufferType value[(ArrayLen)]; \ - Connection *conns_out[(NumConnsOut)]; \ + Connection* conns_out[(NumConnsOut)]; \ } ReactorName##_##PortName; #define LF_DEFINE_INPUT_CTOR(ReactorName, PortName, EffectSize, ObserverSize, BufferType, NumConnsOut) \ - void ReactorName##_##PortName##_ctor(ReactorName##_##PortName *self, Reactor *parent, \ + void ReactorName##_##PortName##_ctor(ReactorName##_##PortName* self, Reactor* parent, \ InputExternalCtorArgs external) { \ Port_ctor(&self->super, TRIG_INPUT, parent, &self->value, sizeof(self->value), self->effects, (EffectSize), \ external.parent_sources, external.parent_sources_size, self->observers, ObserverSize, \ - (Connection **)&self->conns_out, NumConnsOut); \ + (Connection**)&self->conns_out, NumConnsOut); \ } #define LF_DEFINE_TIMER_STRUCT(ReactorName, TimerName, EffectSize, ObserversSize) \ typedef struct { \ Timer super; \ - Reaction *effects[(EffectSize)]; \ - Reaction *observers[(ObserversSize)]; \ + Reaction* effects[(EffectSize)]; \ + Reaction* observers[(ObserversSize)]; \ } ReactorName##_##TimerName; #define LF_DEFINE_TIMER_CTOR(ReactorName, TimerName, EffectSize, ObserverSize) \ - void ReactorName##_##TimerName##_ctor(ReactorName##_##TimerName *self, Reactor *parent, interval_t offset, \ + void ReactorName##_##TimerName##_ctor(ReactorName##_##TimerName* self, Reactor* parent, interval_t offset, \ interval_t period) { \ Timer_ctor(&self->super, parent, offset, period, self->effects, EffectSize, self->observers, ObserverSize); \ } @@ -205,7 +205,7 @@ #define LF_TIMER_INSTANCE(ReactorName, TimerName) ReactorName##_##TimerName TimerName #define LF_INITIALIZE_TIMER(ReactorName, TimerName, Offset, Period) \ - self->_triggers[_triggers_idx++] = (Trigger *)&self->TimerName; \ + self->_triggers[_triggers_idx++] = (Trigger*)&self->TimerName; \ ReactorName##_##TimerName##_ctor(&self->TimerName, &self->super, Offset, Period) #define LF_REACTION_TYPE(ReactorName, ReactionName) ReactorName##_Reaction_##ReactionName @@ -213,13 +213,13 @@ #define LF_DEFINE_REACTION_STRUCT(ReactorName, ReactionName, EffectSize) \ typedef struct { \ Reaction super; \ - Trigger *effects[(EffectSize)]; \ + Trigger* effects[(EffectSize)]; \ } LF_REACTION_TYPE(ReactorName, ReactionName); #define LF_REACTION_INSTANCE(ReactorName, ReactionName) LF_REACTION_TYPE(ReactorName, ReactionName) ReactionName #define LF_INITIALIZE_REACTION(ReactorName, ReactionName, Deadline) \ - self->_reactions[_reactions_idx++] = (Reaction *)&self->ReactionName; \ + self->_reactions[_reactions_idx++] = (Reaction*)&self->ReactionName; \ LF_REACTION_TYPE(ReactorName, ReactionName##_ctor)(&self->ReactionName, &self->super, Deadline) #define LF_DEFINE_REACTION_BODY(ReactorName, ReactionName) \ @@ -243,12 +243,12 @@ #define LF_DEFINE_STARTUP_STRUCT(ReactorName, EffectSize, ObserversSize) \ typedef struct { \ BuiltinTrigger super; \ - Reaction *effects[(EffectSize)]; \ - Reaction *observers[(ObserversSize)]; \ + Reaction* effects[(EffectSize)]; \ + Reaction* observers[(ObserversSize)]; \ } ReactorName##_Startup; #define LF_DEFINE_STARTUP_CTOR(ReactorName) \ - void ReactorName##_Startup_ctor(ReactorName##_Startup *self, Reactor *parent) { \ + void ReactorName##_Startup_ctor(ReactorName##_Startup* self, Reactor* parent) { \ BuiltinTrigger_ctor(&self->super, TRIG_STARTUP, parent, self->effects, \ sizeof(self->effects) / sizeof(self->effects[0]), self->observers, \ sizeof(self->observers) / sizeof(self->observers[0])); \ @@ -256,18 +256,18 @@ #define LF_STARTUP_INSTANCE(ReactorName) ReactorName##_Startup startup #define LF_INITIALIZE_STARTUP(ReactorName) \ - self->_triggers[_triggers_idx++] = (Trigger *)&self->startup; \ + self->_triggers[_triggers_idx++] = (Trigger*)&self->startup; \ ReactorName##_Startup_ctor(&self->startup, &self->super) #define LF_DEFINE_SHUTDOWN_STRUCT(ReactorName, EffectSize, ObserversSize) \ typedef struct { \ BuiltinTrigger super; \ - Reaction *effects[(EffectSize)]; \ - Reaction *observers[(ObserversSize)]; \ + Reaction* effects[(EffectSize)]; \ + Reaction* observers[(ObserversSize)]; \ } ReactorName##_Shutdown; #define LF_DEFINE_SHUTDOWN_CTOR(ReactorName) \ - void ReactorName##_Shutdown_ctor(ReactorName##_Shutdown *self, Reactor *parent) { \ + void ReactorName##_Shutdown_ctor(ReactorName##_Shutdown* self, Reactor* parent) { \ BuiltinTrigger_ctor(&self->super, TRIG_SHUTDOWN, parent, self->effects, \ sizeof(self->effects) / sizeof(self->effects[0]), self->observers, \ sizeof(self->observers) / sizeof(self->observers[0])); \ @@ -276,7 +276,7 @@ #define LF_SHUTDOWN_INSTANCE(ReactorName) ReactorName##_Shutdown shutdown #define LF_INITIALIZE_SHUTDOWN(ReactorName) \ - self->_triggers[_triggers_idx++] = (Trigger *)&self->shutdown; \ + self->_triggers[_triggers_idx++] = (Trigger*)&self->shutdown; \ ReactorName##_Shutdown_ctor(&self->shutdown, &self->super) #define LF_DEFINE_ACTION_STRUCT(ReactorName, ActionName, ActionType, EffectSize, SourceSize, ObserverSize, \ @@ -286,9 +286,9 @@ BufferType value; \ BufferType payload_buf[(MaxPendingEvents)]; \ bool payload_used_buf[(MaxPendingEvents)]; \ - Reaction *sources[(SourceSize)]; \ - Reaction *effects[(EffectSize)]; \ - Reaction *observers[(ObserverSize)]; \ + Reaction* sources[(SourceSize)]; \ + Reaction* effects[(EffectSize)]; \ + Reaction* observers[(ObserverSize)]; \ } ReactorName##_##ActionName; #define LF_DEFINE_ACTION_STRUCT_ARRAY(ReactorName, ActionName, ActionType, EffectSize, SourceSize, ObserverSize, \ @@ -298,32 +298,32 @@ BufferType value[(ArrayLength)]; \ BufferType payload_buf[(ArrayLength)][(MaxPendingEvents)]; \ bool payload_used_buf[(MaxPendingEvents)]; \ - Reaction *sources[(SourceSize)]; \ - Reaction *effects[(EffectSize)]; \ - Reaction *observers[(ObserverSize)]; \ + Reaction* sources[(SourceSize)]; \ + Reaction* effects[(EffectSize)]; \ + Reaction* observers[(ObserverSize)]; \ } ReactorName##_##ActionName; #define LF_DEFINE_ACTION_STRUCT_VOID(ReactorName, ActionName, ActionType, EffectSize, SourceSize, ObserverSize, \ MaxPendingEvents) \ typedef struct { \ ActionType super; \ - Reaction *sources[(SourceSize)]; \ - Reaction *effects[(EffectSize)]; \ - Reaction *observers[(ObserverSize)]; \ + Reaction* sources[(SourceSize)]; \ + Reaction* effects[(EffectSize)]; \ + Reaction* observers[(ObserverSize)]; \ } ReactorName##_##ActionName; #define LF_DEFINE_ACTION_CTOR(ReactorName, ActionName, ActionType, EffectSize, SourceSize, ObserverSize, \ MaxPendingEvents, BufferType) \ - void ReactorName##_##ActionName##_ctor(ReactorName##_##ActionName *self, Reactor *parent, interval_t min_delay, \ + void ReactorName##_##ActionName##_ctor(ReactorName##_##ActionName* self, Reactor* parent, interval_t min_delay, \ interval_t min_spacing) { \ ActionType##_ctor(&self->super, min_delay, min_spacing, parent, self->sources, (SourceSize), self->effects, \ (EffectSize), self->observers, ObserverSize, &self->value, sizeof(self->value), \ - (void *)&self->payload_buf, self->payload_used_buf, (MaxPendingEvents)); \ + (void*)&self->payload_buf, self->payload_used_buf, (MaxPendingEvents)); \ } #define LF_DEFINE_ACTION_CTOR_VOID(ReactorName, ActionName, ActionType, EffectSize, SourceSize, ObserverSize, \ MaxPendingEvents) \ - void ReactorName##_##ActionName##_ctor(ReactorName##_##ActionName *self, Reactor *parent, interval_t min_delay, \ + void ReactorName##_##ActionName##_ctor(ReactorName##_##ActionName* self, Reactor* parent, interval_t min_delay, \ interval_t min_spacing) { \ ActionType##_ctor(&self->super, min_delay, min_spacing, parent, self->sources, (SourceSize), self->effects, \ (EffectSize), self->observers, ObserverSize, NULL, 0, NULL, NULL, (MaxPendingEvents)); \ @@ -332,53 +332,53 @@ #define LF_ACTION_INSTANCE(ReactorName, ActionName) ReactorName##_##ActionName ActionName #define LF_INITIALIZE_ACTION(ReactorName, ActionName, MinDelay, MinSpacing) \ - self->_triggers[_triggers_idx++] = (Trigger *)&self->ActionName; \ + self->_triggers[_triggers_idx++] = (Trigger*)&self->ActionName; \ ReactorName##_##ActionName##_ctor(&self->ActionName, &self->super, MinDelay, MinSpacing) #define LF_SCOPE_ACTION(ReactorName, ActionName) \ - ReactorName##_##ActionName *ActionName = &self->ActionName; \ + ReactorName##_##ActionName* ActionName = &self->ActionName; \ (void)ActionName; #define LF_SCOPE_TIMER(ReactorName, TimerName) \ - ReactorName##_##TimerName *TimerName = &self->TimerName; \ + ReactorName##_##TimerName* TimerName = &self->TimerName; \ (void)TimerName; #define LF_SCOPE_PORT(ReactorName, PortName) \ - ReactorName##_##PortName *PortName = &self->PortName[0]; \ + ReactorName##_##PortName* PortName = &self->PortName[0]; \ (void)PortName; #define LF_SCOPE_MULTIPORT(ReactorName, PortName) \ size_t PortName##_width = sizeof(self->PortName) / sizeof(self->PortName[0]); \ - ReactorName##_##PortName *PortName[PortName##_width]; \ + ReactorName##_##PortName* PortName[PortName##_width]; \ for (int i = 0; i < PortName##_width; i++) { \ PortName[i] = &self->PortName[i]; \ } \ (void)PortName; #define LF_SCOPE_SELF(ReactorName) \ - ReactorName *self = (ReactorName *)_self->parent; \ + ReactorName* self = (ReactorName*)_self->parent; \ (void)self; #define LF_SCOPE_ENV() \ - Environment *env = self->super.env; \ + Environment* env = self->super.env; \ (void)env; #define LF_SCOPE_STARTUP(ReactorName) \ - ReactorName##_Startup *startup = &self->startup; \ + ReactorName##_Startup* startup = &self->startup; \ (void)startup; #define LF_SCOPE_SHUTDOWN(ReactorName) \ - ReactorName##_Shutdown *shutdown = &self->shutdown; \ + ReactorName##_Shutdown* shutdown = &self->shutdown; \ (void)shutdown; #define LF_DEFINE_LOGICAL_CONNECTION_STRUCT(ParentName, ConnName, DownstreamSize) \ typedef struct { \ LogicalConnection super; \ - Port *downstreams[(DownstreamSize)]; \ + Port* downstreams[(DownstreamSize)]; \ } ParentName##_##ConnName; #define LF_DEFINE_LOGICAL_CONNECTION_CTOR(ParentName, ConnName, DownstreamSize) \ - void ParentName##_##ConnName##_ctor(ParentName##_##ConnName *self, Reactor *parent) { \ + void ParentName##_##ConnName##_ctor(ParentName##_##ConnName* self, Reactor* parent) { \ LogicalConnection_ctor(&self->super, parent, self->downstreams, \ sizeof(self->downstreams) / sizeof(self->downstreams[0])); \ } @@ -387,16 +387,16 @@ ParentName##_##ConnName ConnName[BankWidth][PortWidth]; #define LF_CHILD_OUTPUT_CONNECTIONS(ReactorName, OutputPort, BankWidth, PortWidth, NumConnsOut) \ - Connection *_conns_##ReactorName##_##OutputPort[BankWidth][PortWidth][NumConnsOut]; + Connection* _conns_##ReactorName##_##OutputPort[BankWidth][PortWidth][NumConnsOut]; #define LF_CHILD_INPUT_SOURCES(ReactorName, InputPort, BankWidth, PortWidth, NumSources) \ - Reaction *_sources_##ReactorName##_##InputPort[BankWidth][PortWidth][NumSources]; + Reaction* _sources_##ReactorName##_##InputPort[BankWidth][PortWidth][NumSources]; #define LF_CHILD_OUTPUT_EFFECTS(ReactorName, OutputPort, BankWidth, PortWidth, NumEffects) \ - Reaction *_effects_##ReactorName##_##OutputPort[BankWidth][PortWidth][NumEffects]; + Reaction* _effects_##ReactorName##_##OutputPort[BankWidth][PortWidth][NumEffects]; #define LF_CHILD_OUTPUT_OBSERVERS(ReactorName, OutputPort, BankWidth, PortWidth, NumObservers) \ - Reaction *_observers_##ReactorName##_##OutputPort[BankWidth][PortWidth][NumObservers]; + Reaction* _observers_##ReactorName##_##OutputPort[BankWidth][PortWidth][NumObservers]; #define LF_DEFINE_CHILD_OUTPUT_ARGS(ReactorName, OutputPort, BankWidth, PortWidth) \ OutputExternalCtorArgs _##ReactorName##_##OutputPort##_args[BankWidth][PortWidth]; \ @@ -404,14 +404,14 @@ for (int j = 0; j < (PortWidth); j++) { \ _##ReactorName##_##OutputPort##_args[i][j].parent_effects = self->_effects_##ReactorName##_##OutputPort[i][j]; \ _##ReactorName##_##OutputPort##_args[i][j].parent_effects_size = \ - sizeof(self->_effects_##ReactorName##_##OutputPort[i][j]) / sizeof(Reaction *); \ + sizeof(self->_effects_##ReactorName##_##OutputPort[i][j]) / sizeof(Reaction*); \ _##ReactorName##_##OutputPort##_args[i][j].parent_observers = \ self->_observers_##ReactorName##_##OutputPort[i][j]; \ _##ReactorName##_##OutputPort##_args[i][j].parent_observers_size = \ - sizeof(self->_observers_##ReactorName##_##OutputPort[i][j]) / sizeof(Reaction *); \ + sizeof(self->_observers_##ReactorName##_##OutputPort[i][j]) / sizeof(Reaction*); \ _##ReactorName##_##OutputPort##_args[i][j].conns_out = self->_conns_##ReactorName##_##OutputPort[i][j]; \ _##ReactorName##_##OutputPort##_args[i][j].conns_out_size = \ - sizeof(self->_conns_##ReactorName##_##OutputPort[i][j]) / sizeof(Connection *); \ + sizeof(self->_conns_##ReactorName##_##OutputPort[i][j]) / sizeof(Connection*); \ } \ } @@ -421,7 +421,7 @@ for (int j = 0; j < (PortWidth); j++) { \ _##ReactorName##_##InputPort##_args[i][j].parent_sources = self->_sources_##ReactorName##_##InputPort[i][j]; \ _##ReactorName##_##InputPort##_args[i][j].parent_sources_size = \ - sizeof(self->_sources_##ReactorName##_##InputPort[i][j]) / sizeof(Reaction *); \ + sizeof(self->_sources_##ReactorName##_##InputPort[i][j]) / sizeof(Reaction*); \ } \ } @@ -437,7 +437,7 @@ DelayedConnection super; \ BufferType payload_buf[(BufferSize)]; \ bool payload_used_buf[(BufferSize)]; \ - Port *downstreams[(BufferSize)]; \ + Port* downstreams[(BufferSize)]; \ } ParentName##_##ConnName; #define LF_DEFINE_DELAYED_CONNECTION_STRUCT_ARRAY(ParentName, ConnName, DownstreamSize, BufferType, BufferSize, \ @@ -446,13 +446,13 @@ DelayedConnection super; \ BufferType payload_buf[(BufferSize)][(ArrayLength)]; \ bool payload_used_buf[(BufferSize)]; \ - Port *downstreams[(BufferSize)]; \ + Port* downstreams[(BufferSize)]; \ } ParentName##_##ConnName; #define LF_DEFINE_DELAYED_CONNECTION_CTOR(ParentName, ConnName, DownstreamSize, BufferSize, IsPhysical) \ - void ParentName##_##ConnName##_ctor(ParentName##_##ConnName *self, Reactor *parent, interval_t delay) { \ + void ParentName##_##ConnName##_ctor(ParentName##_##ConnName* self, Reactor* parent, interval_t delay) { \ DelayedConnection_ctor(&self->super, parent, self->downstreams, DownstreamSize, delay, IsPhysical, \ - sizeof(self->payload_buf[0]), (void *)self->payload_buf, self->payload_used_buf, \ + sizeof(self->payload_buf[0]), (void*)self->payload_buf, self->payload_used_buf, \ BufferSize); \ } // FIXME: Duplicated @@ -483,10 +483,10 @@ typedef struct FederatedOutputConnection FederatedOutputConnection; } ReactorName##_##OutputName##_conn; #define LF_DEFINE_FEDERATED_OUTPUT_CONNECTION_CTOR(ReactorName, OutputName, BufferType, DestinationConnId) \ - void ReactorName##_##OutputName##_conn_ctor(ReactorName##_##OutputName##_conn *self, Reactor *parent, \ - FederatedConnectionBundle *bundle) { \ - FederatedOutputConnection_ctor(&self->super, parent, bundle, DestinationConnId, (void *)&self->payload_buf, \ - (bool *)&self->payload_used_buf, sizeof(self->payload_buf[0]), 1); \ + void ReactorName##_##OutputName##_conn_ctor(ReactorName##_##OutputName##_conn* self, Reactor* parent, \ + FederatedConnectionBundle* bundle) { \ + FederatedOutputConnection_ctor(&self->super, parent, bundle, DestinationConnId, (void*)&self->payload_buf, \ + (bool*)&self->payload_used_buf, sizeof(self->payload_buf[0]), 1); \ } #define LF_FEDERATED_OUTPUT_CONNECTION_INSTANCE(ReactorName, OutputName) ReactorName##_##OutputName##_conn OutputName @@ -500,16 +500,16 @@ typedef struct FederatedOutputConnection FederatedOutputConnection; LF_FEDERATED_CONNECTION_BUNDLE_NAME(ReactorName, OtherName) #define LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(ReactorName, OtherName) \ - void ReactorName##_##OtherName##_Bundle_ctor(ReactorName##_##OtherName##_Bundle *self, Reactor *parent, size_t index) + void ReactorName##_##OtherName##_Bundle_ctor(ReactorName##_##OtherName##_Bundle* self, Reactor* parent, size_t index) #define LF_REACTOR_CTOR_SIGNATURE(ReactorName) \ - void ReactorName##_ctor(ReactorName *self, Reactor *parent, Environment *env) + void ReactorName##_ctor(ReactorName* self, Reactor* parent, Environment* env) #define LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(ReactorName, ...) \ - void ReactorName##_ctor(ReactorName *self, Reactor *parent, Environment *env, __VA_ARGS__) + void ReactorName##_ctor(ReactorName* self, Reactor* parent, Environment* env, __VA_ARGS__) #define LF_FEDERATED_CONNECTION_BUNDLE_CALL_CTOR() \ - FederatedConnectionBundle_ctor(&self->super, parent, (NetworkChannel *)&self->channel.super, &self->inputs[0], \ + FederatedConnectionBundle_ctor(&self->super, parent, (NetworkChannel*)&self->channel.super, &self->inputs[0], \ self->deserialize_hooks, sizeof(self->inputs) / sizeof(self->inputs[0]), \ &self->outputs[0], self->serialize_hooks, \ sizeof(self->outputs) / sizeof(self->outputs[0]), index); @@ -530,7 +530,7 @@ typedef struct FederatedInputConnection FederatedInputConnection; FederatedInputConnection super; \ BufferType payload_buf[(BufferSize)]; \ bool payload_used_buf[(BufferSize)]; \ - Port *downstreams[1]; \ + Port* downstreams[1]; \ } ReactorName##_##InputName##_conn; #define LF_DEFINE_FEDERATED_INPUT_CONNECTION_STRUCT_ARRAY(ReactorName, InputName, BufferType, BufferSize, ArrayLength) \ @@ -538,14 +538,14 @@ typedef struct FederatedInputConnection FederatedInputConnection; FederatedInputConnection super; \ BufferType payload_buf[(BufferSize)][(ArrayLength)]; \ bool payload_used_buf[(BufferSize)]; \ - Port *downstreams[1]; \ + Port* downstreams[1]; \ } ReactorName##_##InputName##_conn; #define LF_DEFINE_FEDERATED_INPUT_CONNECTION_CTOR(ReactorName, InputName, BufferType, BufferSize, Delay, IsPhysical, \ MaxWait) \ - void ReactorName##_##InputName##_conn_ctor(ReactorName##_##InputName##_conn *self, Reactor *parent) { \ - FederatedInputConnection_ctor(&self->super, parent, Delay, IsPhysical, MaxWait, (Port **)&self->downstreams, 1, \ - (void *)&self->payload_buf, (bool *)&self->payload_used_buf, \ + void ReactorName##_##InputName##_conn_ctor(ReactorName##_##InputName##_conn* self, Reactor* parent) { \ + FederatedInputConnection_ctor(&self->super, parent, Delay, IsPhysical, MaxWait, (Port**)&self->downstreams, 1, \ + (void*)&self->payload_buf, (bool*)&self->payload_used_buf, \ sizeof(self->payload_buf[0]), BufferSize); \ } @@ -560,9 +560,9 @@ typedef struct FederatedInputConnection FederatedInputConnection; } ReactorName##StartupCoordinator; #define LF_DEFINE_STARTUP_COORDINATOR_CTOR(ReactorName, NumNeighbors, LongestPath, NumEvents, JoiningPolicy) \ - void ReactorName##StartupCoordinator_ctor(ReactorName##StartupCoordinator *self, Environment *env) { \ + void ReactorName##StartupCoordinator_ctor(ReactorName##StartupCoordinator* self, Environment* env) { \ StartupCoordinator_ctor(&self->super, env, self->neighbors, NumNeighbors, LongestPath, JoiningPolicy, \ - sizeof(StartupEvent), (void *)self->events, self->used, (NumEvents)); \ + sizeof(StartupEvent), (void*)self->events, self->used, (NumEvents)); \ } #define LF_DEFINE_STARTUP_COORDINATOR(ReactorName) ReactorName##StartupCoordinator startup_coordinator; @@ -579,16 +579,16 @@ typedef struct FederatedInputConnection FederatedInputConnection; } ReactorName##ClockSynchronization; #define LF_DEFINE_CLOCK_SYNC_CTOR(ReactorName, NumNeighbors, NumEvents, IsGrandmaster, Period, MaxAdj, Kp, Ki) \ - void ReactorName##ClockSynchronization_ctor(ReactorName##ClockSynchronization *self, Environment *env) { \ + void ReactorName##ClockSynchronization_ctor(ReactorName##ClockSynchronization* self, Environment* env) { \ ClockSynchronization_ctor(&self->super, env, self->neighbor_clocks, NumNeighbors, IsGrandmaster, \ - sizeof(ClockSyncEvent), (void *)self->events, self->used, (NumEvents), Period, MaxAdj, \ + sizeof(ClockSyncEvent), (void*)self->events, self->used, (NumEvents), Period, MaxAdj, \ Kp, Ki); \ } #define LF_DEFINE_CLOCK_SYNC_DEFAULTS_CTOR(ReactorName, NumNeighbors, NumEvents, IsGrandmaster) \ - void ReactorName##ClockSynchronization_ctor(ReactorName##ClockSynchronization *self, Environment *env) { \ + void ReactorName##ClockSynchronization_ctor(ReactorName##ClockSynchronization* self, Environment* env) { \ ClockSynchronization_ctor(&self->super, env, self->neighbor_clocks, NumNeighbors, IsGrandmaster, \ - sizeof(ClockSyncEvent), (void *)self->events, self->used, (NumEvents), \ + sizeof(ClockSyncEvent), (void*)self->events, self->used, (NumEvents), \ CLOCK_SYNC_DEFAULT_PERIOD, CLOCK_SYNC_DEFAULT_MAX_ADJ, CLOCK_SYNC_DEFAULT_KP, \ CLOCK_SYNC_DEFAULT_KI); \ } @@ -604,8 +604,8 @@ typedef struct FederatedInputConnection FederatedInputConnection; _inputs_idx++; #define LF_FEDERATED_CONNECTION_BUNDLE_BOOKKEEPING_INSTANCES(NumInputs, NumOutputs) \ - FederatedInputConnection *inputs[NumInputs]; \ - FederatedOutputConnection *outputs[NumOutputs]; \ + FederatedInputConnection* inputs[NumInputs]; \ + FederatedOutputConnection* outputs[NumOutputs]; \ deserialize_hook deserialize_hooks[NumInputs]; \ serialize_hook serialize_hooks[NumOutputs]; @@ -639,7 +639,7 @@ typedef struct FederatedInputConnection FederatedInputConnection; #define LF_DEFINE_REACTION_QUEUE(Name, NumReactions) \ typedef struct { \ ReactionQueue super; \ - Reaction *reactions[(NumReactions)][(NumReactions)]; \ + Reaction* reactions[(NumReactions)][(NumReactions)]; \ int level_size[(NumReactions)]; \ } Name##_t; \ static Name##_t Name; @@ -647,26 +647,24 @@ typedef struct FederatedInputConnection FederatedInputConnection; #define LF_INITIALIZE_EVENT_QUEUE(Name, NumEvents) EventQueue_ctor(&Name.super, Name.events, NumEvents); #define LF_INITIALIZE_REACTION_QUEUE(Name, NumReactions) \ - ReactionQueue_ctor(&Name.super, (Reaction **)Name.reactions, Name.level_size, NumReactions); + ReactionQueue_ctor(&Name.super, (Reaction**)Name.reactions, Name.level_size, NumReactions); #define LF_ENTRY_POINT(MainReactorName, NumEvents, NumReactions, Timeout, KeepAlive, Fast) \ static MainReactorName main_reactor; \ static Environment env; \ - Environment *_lf_environment = &env; \ + Environment* _lf_environment = &env; \ static ArbitraryEvent events[NumEvents]; \ static EventQueue event_queue; \ - static Reaction *reactions[NumReactions][NumReactions]; \ + static Reaction* reactions[NumReactions][NumReactions]; \ static int level_size[NumReactions]; \ static ReactionQueue reaction_queue; \ static DynamicScheduler scheduler; \ - void lf_exit(void) { \ - Environment_free(&env); \ - } \ + void lf_exit(void) { Environment_free(&env); } \ void lf_start() { \ EventQueue_ctor(&event_queue, events, NumEvents); \ - ReactionQueue_ctor(&reaction_queue, (Reaction **)reactions, level_size, NumReactions); \ + ReactionQueue_ctor(&reaction_queue, (Reaction**)reactions, level_size, NumReactions); \ DynamicScheduler_ctor(&scheduler, _lf_environment, &event_queue, NULL, &reaction_queue, (Timeout), (KeepAlive)); \ - Environment_ctor(&env, (Reactor *)&main_reactor, &scheduler.super, Fast); \ + Environment_ctor(&env, (Reactor*)&main_reactor, &scheduler.super, Fast); \ MainReactorName##_ctor(&main_reactor, NULL, &env); \ env.scheduler->duration = Timeout; \ env.scheduler->keep_alive = KeepAlive; \ @@ -680,30 +678,28 @@ typedef struct FederatedInputConnection FederatedInputConnection; NumBundles, DoClockSync) \ static FederateName main_reactor; \ static FederatedEnvironment env; \ - Environment *_lf_environment = &env.super; \ + Environment* _lf_environment = &env.super; \ static DynamicScheduler scheduler; \ static ArbitraryEvent events[(NumEvents)]; \ static EventQueue event_queue; \ static ArbitraryEvent system_events[(NumSystemEvents)]; \ static EventQueue system_event_queue; \ - static Reaction *reactions[(NumReactions)][(NumReactions)]; \ + static Reaction* reactions[(NumReactions)][(NumReactions)]; \ static int level_size[(NumReactions)]; \ static ReactionQueue reaction_queue; \ - void lf_exit(void) { \ - FederatedEnvironment_free(&env); \ - } \ + void lf_exit(void) { FederatedEnvironment_free(&env); } \ void lf_start() { \ EventQueue_ctor(&event_queue, events, (NumEvents)); \ EventQueue_ctor(&system_event_queue, system_events, (NumSystemEvents)); \ - ReactionQueue_ctor(&reaction_queue, (Reaction **)reactions, level_size, (NumReactions)); \ + ReactionQueue_ctor(&reaction_queue, (Reaction**)reactions, level_size, (NumReactions)); \ DynamicScheduler_ctor(&scheduler, _lf_environment, &event_queue, &system_event_queue, &reaction_queue, (Timeout), \ (KeepAlive)); \ FederatedEnvironment_ctor( \ - &env, (Reactor *)&main_reactor, &scheduler.super, false, (FederatedConnectionBundle **)&main_reactor._bundles, \ + &env, (Reactor*)&main_reactor, &scheduler.super, false, (FederatedConnectionBundle**)&main_reactor._bundles, \ (NumBundles), &main_reactor.startup_coordinator.super, (DoClockSync) ? &main_reactor.clock_sync.super : NULL); \ FederateName##_ctor(&main_reactor, NULL, _lf_environment); \ env.net_bundles_size = (NumBundles); \ - env.net_bundles = (FederatedConnectionBundle **)&main_reactor._bundles; \ + env.net_bundles = (FederatedConnectionBundle**)&main_reactor._bundles; \ _lf_environment->assemble(_lf_environment); \ _lf_environment->start(_lf_environment); \ lf_exit(); \ diff --git a/include/reactor-uc/network_channel.h b/include/reactor-uc/network_channel.h index 8796528bf..49a8e2528 100644 --- a/include/reactor-uc/network_channel.h +++ b/include/reactor-uc/network_channel.h @@ -39,7 +39,7 @@ typedef enum { NETWORK_CHANNEL_MODE_POLLED, } NetworkChannelMode; -char *NetworkChannel_state_to_string(NetworkChannelState state); +char* NetworkChannel_state_to_string(NetworkChannelState state); typedef struct FederatedConnectionBundle FederatedConnectionBundle; typedef struct NetworkChannel NetworkChannel; @@ -66,7 +66,7 @@ struct NetworkChannel { * @brief Get the current state of the connection. * @return true if the channel is connected, false if the channel is not connected */ - bool (*is_connected)(NetworkChannel *self); + bool (*is_connected)(NetworkChannel* self); /** * @brief Opens the connection to the corresponding NetworkChannel on another federate (non-blocking). @@ -75,14 +75,14 @@ struct NetworkChannel { * @return LF_OK if channel opened without error, LF_ERR if the channel is configured incorrectly or the connection * open operation fails. */ - lf_ret_t (*open_connection)(NetworkChannel *self); + lf_ret_t (*open_connection)(NetworkChannel* self); /** * @brief Closes the connection to the corresponding NetworkChannel on another federate. * * NOTE: Can not be called in a critical section. */ - void (*close_connection)(NetworkChannel *self); + void (*close_connection)(NetworkChannel* self); /** * @brief Sends a FederateMessage and blocks until the message is fully sent (or failed). @@ -90,7 +90,7 @@ struct NetworkChannel { * * @return LF_OK if message is sent successfully, LF_ERR if sending message failed. */ - lf_ret_t (*send_blocking)(NetworkChannel *self, const FederateMessage *message); + lf_ret_t (*send_blocking)(NetworkChannel* self, const FederateMessage* message); /** * @brief Register async callback for handling incoming messages from another federate. @@ -100,15 +100,15 @@ struct NetworkChannel { * the callback needs to perform a blocking operation, it should schedule a system event * such that it can be handled from the main event loop. */ - void (*register_receive_callback)(NetworkChannel *self, - void (*receive_callback)(FederatedConnectionBundle *conn, - const FederateMessage *message), - FederatedConnectionBundle *conn); + void (*register_receive_callback)(NetworkChannel* self, + void (*receive_callback)(FederatedConnectionBundle* conn, + const FederateMessage* message), + FederatedConnectionBundle* conn); /** * @brief Free up NetworkChannel, join threads etc. */ - void (*free)(NetworkChannel *self); + void (*free)(NetworkChannel* self); }; struct PolledNetworkChannel { @@ -117,7 +117,7 @@ struct PolledNetworkChannel { /** * @brief Polls for new data and calls the callback handler if a message is successfully decoded */ - void (*poll)(PolledNetworkChannel *self); + void (*poll)(PolledNetworkChannel* self); }; struct AsyncNetworkChannel { diff --git a/include/reactor-uc/physical_clock.h b/include/reactor-uc/physical_clock.h index b7b669cd1..4a9352b37 100644 --- a/include/reactor-uc/physical_clock.h +++ b/include/reactor-uc/physical_clock.h @@ -10,7 +10,7 @@ typedef struct PhysicalClock PhysicalClock; typedef struct Environment Environment; struct PhysicalClock { - Environment *env; + Environment* env; MUTEX_T mutex; interval_t offset; // Constant offset applied to each reading of the HW clock instant_t adjustment_epoch_hw; // The time at which the frequency adjustment should by applied from. @@ -21,30 +21,30 @@ struct PhysicalClock { * If this function is called from a context outside the runtime, it must be in a critical section! * When called from the runtime context, it does not need to be in a critical section. */ - instant_t (*get_time)(PhysicalClock *self); + instant_t (*get_time)(PhysicalClock* self); /** * @brief Step the clock backwards or forwards. * * Should only ever be called from the runtime context and within a critical section. */ - lf_ret_t (*set_time)(PhysicalClock *self, instant_t time); + lf_ret_t (*set_time)(PhysicalClock* self, instant_t time); /** * @brief Change the adjustment applied to the underlying wallclock. * * Should only ever be called from the runtime context and within a critical section. */ - lf_ret_t (*adjust_time)(PhysicalClock *self, interval_t adjustment_ppb); + lf_ret_t (*adjust_time)(PhysicalClock* self, interval_t adjustment_ppb); /** * @brief Translate a physical, synchronized, time instant to the corresponding wall-clock * time instant. This is needed in order to correctly tell the platform how long to * sleep. */ - instant_t (*to_hw_time)(PhysicalClock *self, instant_t time); + instant_t (*to_hw_time)(PhysicalClock* self, instant_t time); }; -void PhysicalClock_ctor(PhysicalClock *self, Environment *env, bool clock_sync_enabled); +void PhysicalClock_ctor(PhysicalClock* self, Environment* env, bool clock_sync_enabled); #endif // REACTOR_UC_PHYSICAL_CLOCK_H \ No newline at end of file diff --git a/include/reactor-uc/platform.h b/include/reactor-uc/platform.h index ad87c5892..dfc3ff12d 100644 --- a/include/reactor-uc/platform.h +++ b/include/reactor-uc/platform.h @@ -16,49 +16,49 @@ typedef struct Mutex Mutex; * */ struct Mutex { - void (*lock)(Mutex *super); - void (*unlock)(Mutex *super); + void (*lock)(Mutex* super); + void (*unlock)(Mutex* super); }; /** Construct a Mutex*/ -void Mutex_ctor(Mutex *super); +void Mutex_ctor(Mutex* super); struct Platform { /** * @brief Return the current physical time in nanoseconds. */ - instant_t (*get_physical_time)(Platform *super); + instant_t (*get_physical_time)(Platform* super); /** * @brief Put system to sleep until the wakeup time. Asynchronous events * does not need to be handled. */ - lf_ret_t (*wait_until)(Platform *super, instant_t wakeup_time); + lf_ret_t (*wait_until)(Platform* super, instant_t wakeup_time); /** * @brief Put system to sleep until the wakeup time. Asynchronous events * does not need to be handled. */ - lf_ret_t (*wait_for)(Platform *super, interval_t duration); + lf_ret_t (*wait_for)(Platform* super, interval_t duration); /** * @brief Put the system to sleep until the wakeup time or until an * asynchronous event occurs. Must be called from a critical section. */ - lf_ret_t (*wait_until_interruptible)(Platform *super, instant_t wakeup_time); + lf_ret_t (*wait_until_interruptible)(Platform* super, instant_t wakeup_time); /** * @brief Signal the occurrence of an asynchronous event. This should wake * up the platform if it is sleeping on `wait_until_interruptible_locked`. */ - void (*notify)(Platform *super); + void (*notify)(Platform* super); }; // Construct a Platform object. Must be implemented for each target platform. -void Platform_ctor(Platform *super); +void Platform_ctor(Platform* super); // Returns a pointer to the platform.P -Platform *Platform_new(); +Platform* Platform_new(); // Allow each platform to provide its own implementation for printing. -void Platform_vprintf(const char *fmt, va_list args); +void Platform_vprintf(const char* fmt, va_list args); #if defined(PLATFORM_POSIX) #include "reactor-uc/platform/posix/posix.h" diff --git a/include/reactor-uc/platform/flexpret/flexpret.h b/include/reactor-uc/platform/flexpret/flexpret.h index 3b4d775b1..f7bab2fd0 100644 --- a/include/reactor-uc/platform/flexpret/flexpret.h +++ b/include/reactor-uc/platform/flexpret/flexpret.h @@ -16,7 +16,7 @@ typedef struct { volatile int num_nested_critical_sections; } PlatformFlexpret; -void PlatformFlexpret_ctor(Platform *super); +void PlatformFlexpret_ctor(Platform* super); #define PLATFORM_T PlatformFlexpret #define MUTEX_T MutexFlexpret diff --git a/include/reactor-uc/platform/patmos/patmos.h b/include/reactor-uc/platform/patmos/patmos.h index 0bb925cd3..db6e94642 100644 --- a/include/reactor-uc/platform/patmos/patmos.h +++ b/include/reactor-uc/platform/patmos/patmos.h @@ -10,7 +10,7 @@ typedef struct { volatile int num_nested_critical_sections; } PlatformPatmos; -void PlatformPatmos_ctor(Platform *super); +void PlatformPatmos_ctor(Platform* super); typedef struct { Mutex super; diff --git a/include/reactor-uc/platform/pico/uart_channel.h b/include/reactor-uc/platform/pico/uart_channel.h index f1f6e50c7..cd7efac20 100644 --- a/include/reactor-uc/platform/pico/uart_channel.h +++ b/include/reactor-uc/platform/pico/uart_channel.h @@ -22,15 +22,15 @@ struct UartPolledChannel { unsigned char receive_buffer[UART_CHANNEL_BUFFERSIZE]; unsigned char send_buffer[UART_CHANNEL_BUFFERSIZE]; unsigned int receive_buffer_index; - uart_inst_t *uart_device; + uart_inst_t* uart_device; - FederatedConnectionBundle *bundle; - void (*receive_callback)(FederatedConnectionBundle *bundle, const FederateMessage *message); + FederatedConnectionBundle* bundle; + void (*receive_callback)(FederatedConnectionBundle* bundle, const FederateMessage* message); bool send_response; bool received_response; }; -void UartPolledChannel_ctor(UartPolledChannel *self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, +void UartPolledChannel_ctor(UartPolledChannel* self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, UartParityBits parity, UartStopBits stop_bits); #endif \ No newline at end of file diff --git a/include/reactor-uc/platform/posix/tcp_ip_channel.h b/include/reactor-uc/platform/posix/tcp_ip_channel.h index 50ca178ba..e23d16ca1 100644 --- a/include/reactor-uc/platform/posix/tcp_ip_channel.h +++ b/include/reactor-uc/platform/posix/tcp_ip_channel.h @@ -29,7 +29,7 @@ struct TcpIpChannel { NetworkChannelState state; pthread_mutex_t mutex; - const char *host; + const char* host; unsigned short port; int protocol_family; @@ -47,10 +47,10 @@ struct TcpIpChannel { pthread_attr_t worker_thread_attr; char worker_thread_stack[TCP_IP_CHANNEL_RECV_THREAD_STACK_SIZE]; - FederatedConnectionBundle *federated_connection; - void (*receive_callback)(FederatedConnectionBundle *conn, const FederateMessage *message); + FederatedConnectionBundle* federated_connection; + void (*receive_callback)(FederatedConnectionBundle* conn, const FederateMessage* message); }; -void TcpIpChannel_ctor(TcpIpChannel *self, const char *host, unsigned short port, int protocol_family, bool is_server); +void TcpIpChannel_ctor(TcpIpChannel* self, const char* host, unsigned short port, int protocol_family, bool is_server); #endif diff --git a/include/reactor-uc/platform/riot/coap_udp_ip_channel.h b/include/reactor-uc/platform/riot/coap_udp_ip_channel.h index 9a0e2ad23..94e5f0b4e 100644 --- a/include/reactor-uc/platform/riot/coap_udp_ip_channel.h +++ b/include/reactor-uc/platform/riot/coap_udp_ip_channel.h @@ -26,10 +26,10 @@ struct CoapUdpIpChannel { FederateMessage output; uint8_t write_buffer[COAP_UDP_IP_CHANNEL_BUFFERSIZE]; - FederatedConnectionBundle *federated_connection; - void (*receive_callback)(FederatedConnectionBundle *conn, const FederateMessage *message); + FederatedConnectionBundle* federated_connection; + void (*receive_callback)(FederatedConnectionBundle* conn, const FederateMessage* message); }; -void CoapUdpIpChannel_ctor(CoapUdpIpChannel *self, const char *remote_address, int remote_protocol_family); +void CoapUdpIpChannel_ctor(CoapUdpIpChannel* self, const char* remote_address, int remote_protocol_family); #endif diff --git a/include/reactor-uc/platform/riot/uart_channel.h b/include/reactor-uc/platform/riot/uart_channel.h index 935d27982..9fc8b8cd2 100644 --- a/include/reactor-uc/platform/riot/uart_channel.h +++ b/include/reactor-uc/platform/riot/uart_channel.h @@ -26,8 +26,8 @@ struct UartPolledChannel { unsigned int receive_buffer_index; uart_t uart_dev; - FederatedConnectionBundle *federated_connection; - void (*receive_callback)(FederatedConnectionBundle *conn, const FederateMessage *message); + FederatedConnectionBundle* federated_connection; + void (*receive_callback)(FederatedConnectionBundle* conn, const FederateMessage* message); }; struct UartAsyncChannel { @@ -39,10 +39,10 @@ struct UartAsyncChannel { cond_t receive_cv; }; -void UartPolledChannel_ctor(UartPolledChannel *self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, +void UartPolledChannel_ctor(UartPolledChannel* self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, UartParityBits parity, UartStopBits stop_bits); -void UartAsyncChannel_ctor(UartAsyncChannel *self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, +void UartAsyncChannel_ctor(UartAsyncChannel* self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, UartParityBits parity, UartStopBits stop_bits); #endif diff --git a/include/reactor-uc/port.h b/include/reactor-uc/port.h index 677fbab3d..ed48a879f 100644 --- a/include/reactor-uc/port.h +++ b/include/reactor-uc/port.h @@ -11,42 +11,42 @@ typedef struct Port Port; struct Port { Trigger super; - void *value_ptr; // Pointer to the `buffer` field in the user Input port struct. + void* value_ptr; // Pointer to the `buffer` field in the user Input port struct. size_t value_size; // Size of the data stored in this Port. tag_t intended_tag; // The tag that this port is intended to be triggered at. Might be different from the current tag. // if the port is written to from a federated connection. TriggerEffects effects; // The reactions triggered by this Port TriggerSources sources; // The reactions that can write to this Port. TriggerObservers observers; // The reactions that can observe this Port. - Connection *conn_in; // Connection coming into the port. - Connection **conns_out; // Connections going out of the port. + Connection* conn_in; // Connection coming into the port. + Connection** conns_out; // Connections going out of the port. size_t conns_out_size; // Number of connections going out of the port. size_t conns_out_registered; // Number of connections that have been registered for cleanup. - void (*set)(Port *self, const void *value); + void (*set)(Port* self, const void* value); }; // Output ports need pointers to arrays of effects, observers and connections which are not // located within the same reactor, but in the parent reactor. This struct has all the arguments // that are needed to initialize an Output port. This is only used in the code-generated code. typedef struct { - Reaction **parent_effects; + Reaction** parent_effects; size_t parent_effects_size; - Reaction **parent_observers; + Reaction** parent_observers; size_t parent_observers_size; - Connection **conns_out; + Connection** conns_out; size_t conns_out_size; } OutputExternalCtorArgs; // Likewise, Input ports need pointers to arrays of sources, which are not located within the same reactor // this struct captures all those arguments. typedef struct { - Reaction **parent_sources; + Reaction** parent_sources; size_t parent_sources_size; } InputExternalCtorArgs; -void Port_ctor(Port *self, TriggerType type, Reactor *parent, void *value_ptr, size_t value_size, Reaction **effects, - size_t effects_size, Reaction **sources, size_t sources_size, Reaction **observers, - size_t observers_size, Connection **conns_out, size_t conns_out_size); +void Port_ctor(Port* self, TriggerType type, Reactor* parent, void* value_ptr, size_t value_size, Reaction** effects, + size_t effects_size, Reaction** sources, size_t sources_size, Reaction** observers, + size_t observers_size, Connection** conns_out, size_t conns_out_size); #endif diff --git a/include/reactor-uc/queues.h b/include/reactor-uc/queues.h index 9ad62f998..6a6380f3e 100644 --- a/include/reactor-uc/queues.h +++ b/include/reactor-uc/queues.h @@ -12,34 +12,34 @@ typedef struct EventQueue EventQueue; typedef struct ReactionQueue ReactionQueue; struct EventQueue { - tag_t (*next_tag)(EventQueue *self); - lf_ret_t (*insert)(EventQueue *self, AbstractEvent *event); - lf_ret_t (*pop)(EventQueue *self, AbstractEvent *event); - bool (*empty)(EventQueue *self); - void (*heapify_locked)(EventQueue *self, size_t idx); + tag_t (*next_tag)(EventQueue* self); + lf_ret_t (*insert)(EventQueue* self, AbstractEvent* event); + lf_ret_t (*pop)(EventQueue* self, AbstractEvent* event); + bool (*empty)(EventQueue* self); + void (*heapify_locked)(EventQueue* self, size_t idx); size_t size; size_t capacity; - ArbitraryEvent *array; + ArbitraryEvent* array; MUTEX_T mutex; }; -void EventQueue_ctor(EventQueue *self, ArbitraryEvent *array, size_t capacity); +void EventQueue_ctor(EventQueue* self, ArbitraryEvent* array, size_t capacity); struct ReactionQueue { - lf_ret_t (*insert)(ReactionQueue *self, Reaction *reaction); - Reaction *(*pop)(ReactionQueue *self); - bool (*empty)(ReactionQueue *self); - void (*reset)(ReactionQueue *self); + lf_ret_t (*insert)(ReactionQueue* self, Reaction* reaction); + Reaction* (*pop)(ReactionQueue* self); + bool (*empty)(ReactionQueue* self); + void (*reset)(ReactionQueue* self); - int *level_size; + int* level_size; int curr_level; int max_active_level; int curr_index; - Reaction **array; + Reaction** array; size_t capacity; }; -void ReactionQueue_ctor(ReactionQueue *self, Reaction **array, int *level_size, size_t capacity); +void ReactionQueue_ctor(ReactionQueue* self, Reaction** array, int* level_size, size_t capacity); #endif diff --git a/include/reactor-uc/reaction.h b/include/reactor-uc/reaction.h index f9ea4e451..6557dfb91 100644 --- a/include/reactor-uc/reaction.h +++ b/include/reactor-uc/reaction.h @@ -9,22 +9,22 @@ typedef struct Reactor Reactor; typedef struct Trigger Trigger; struct Reaction { - Reactor *parent; - void (*body)(Reaction *self); - void (*deadline_violation_handler)(Reaction *self); - void (*stp_violation_handler)(Reaction *self); + Reactor* parent; + void (*body)(Reaction* self); + void (*deadline_violation_handler)(Reaction* self); + void (*stp_violation_handler)(Reaction* self); interval_t deadline; int level; // Negative level means it is invalid. size_t index; - Trigger **effects; + Trigger** effects; size_t effects_size; size_t effects_registered; - size_t (*calculate_level)(Reaction *self); - size_t (*get_level)(Reaction *self); + size_t (*calculate_level)(Reaction* self); + size_t (*get_level)(Reaction* self); }; -void Reaction_ctor(Reaction *self, Reactor *parent, void (*body)(Reaction *self), Trigger **effects, - size_t effects_size, size_t index, void (*deadline_violation_handler)(Reaction *), - interval_t deadline, void (*stp_violation_handler)(Reaction *)); +void Reaction_ctor(Reaction* self, Reactor* parent, void (*body)(Reaction* self), Trigger** effects, + size_t effects_size, size_t index, void (*deadline_violation_handler)(Reaction*), + interval_t deadline, void (*stp_violation_handler)(Reaction*)); #endif diff --git a/include/reactor-uc/reactor-c.h b/include/reactor-uc/reactor-c.h index 42c92bc58..4f5de5c21 100644 --- a/include/reactor-uc/reactor-c.h +++ b/include/reactor-uc/reactor-c.h @@ -21,7 +21,7 @@ #define lf_schedule_token(action, offset, val) \ do { \ __typeof__(val) __val = (val); \ - lf_ret_t ret = (action)->super.schedule(&(action)->super, (offset), (const void *)&__val); \ + lf_ret_t ret = (action)->super.schedule(&(action)->super, (offset), (const void*)&__val); \ if (ret == LF_FATAL) { \ LF_ERR(TRIG, "Scheduling an value, that doesn't have value!"); \ throw("Tried to schedule a value onto an action without a type!"); \ @@ -33,7 +33,7 @@ #define lf_set_token(action, val) \ do { \ __typeof__(val) __val = (val); \ - Port *_port = (Port *)(port); \ + Port* _port = (Port*)(port); \ _port->set(_port, &__val); \ } while (0) diff --git a/include/reactor-uc/reactor.h b/include/reactor-uc/reactor.h index 25b8c71f3..9e9527873 100644 --- a/include/reactor-uc/reactor.h +++ b/include/reactor-uc/reactor.h @@ -12,23 +12,23 @@ typedef struct Reaction Reaction; typedef struct Trigger Trigger; struct Reactor { - Environment *env; - void (*register_startup)(Reactor *self, BuiltinTrigger *startup); - void (*register_shutdown)(Reactor *self, BuiltinTrigger *shutdown); - lf_ret_t (*calculate_levels)(Reactor *self); - Reactor *parent; - Reactor **children; + Environment* env; + void (*register_startup)(Reactor* self, BuiltinTrigger* startup); + void (*register_shutdown)(Reactor* self, BuiltinTrigger* shutdown); + lf_ret_t (*calculate_levels)(Reactor* self); + Reactor* parent; + Reactor** children; size_t children_size; - Reaction **reactions; + Reaction** reactions; size_t reactions_size; - Trigger **triggers; + Trigger** triggers; size_t triggers_size; char name[REACTOR_NAME_MAX_LEN]; }; -void Reactor_ctor(Reactor *self, const char *name, Environment *env, Reactor *parent, Reactor **children, - size_t children_size, Reaction **reactions, size_t reactions_size, Trigger **triggers, +void Reactor_ctor(Reactor* self, const char* name, Environment* env, Reactor* parent, Reactor** children, + size_t children_size, Reaction** reactions, size_t reactions_size, Trigger** triggers, size_t triggers_size); -void Reactor_validate(Reactor *self); +void Reactor_validate(Reactor* self); #endif diff --git a/include/reactor-uc/scheduler.h b/include/reactor-uc/scheduler.h index a4dad2d09..8641568a6 100644 --- a/include/reactor-uc/scheduler.h +++ b/include/reactor-uc/scheduler.h @@ -19,47 +19,47 @@ struct Scheduler { * @brief Schedules an event on trigger at a specified tag. This function will * enter a critcal section if the environment has async events. */ - lf_ret_t (*schedule_at)(Scheduler *self, Event *event); + lf_ret_t (*schedule_at)(Scheduler* self, Event* event); - lf_ret_t (*schedule_system_event_at)(Scheduler *self, SystemEvent *event); + lf_ret_t (*schedule_system_event_at)(Scheduler* self, SystemEvent* event); /** * @brief Runs the program. Does not return until program has completed. */ - void (*run)(Scheduler *self); + void (*run)(Scheduler* self); - void (*step_clock)(Scheduler *self, interval_t step); + void (*step_clock)(Scheduler* self, interval_t step); /** * @brief Called to execute all reactions triggered by a shutdown trigger. */ - void (*do_shutdown)(Scheduler *self, tag_t stop_tag); + void (*do_shutdown)(Scheduler* self, tag_t stop_tag); - void (*request_shutdown)(Scheduler *self); + void (*request_shutdown)(Scheduler* self); /** * @brief Register Trigger for cleanup. The cleanup function of the trigger * will be called in `clean_up_timestep`. */ - void (*register_for_cleanup)(Scheduler *self, Trigger *trigger); + void (*register_for_cleanup)(Scheduler* self, Trigger* trigger); - void (*set_and_schedule_start_tag)(Scheduler *self, instant_t start_time); + void (*set_and_schedule_start_tag)(Scheduler* self, instant_t start_time); // void (*set_duration)(Scheduler *self, interval_t duration); - lf_ret_t (*add_to_reaction_queue)(Scheduler *self, Reaction *reaction); + lf_ret_t (*add_to_reaction_queue)(Scheduler* self, Reaction* reaction); - tag_t (*current_tag)(Scheduler *self); + tag_t (*current_tag)(Scheduler* self); /** * @brief After committing to a tag, but before executing reactions, the * scheduler must prepare the timestep by adding reactions to the reaction * queue. */ - void (*prepare_timestep)(Scheduler *self, tag_t tag); + void (*prepare_timestep)(Scheduler* self, tag_t tag); }; -Scheduler *Scheduler_new(Environment *env, EventQueue *event_queue, EventQueue *system_event_queue, - ReactionQueue *reaction_queue, interval_t duration, bool keep_alive); +Scheduler* Scheduler_new(Environment* env, EventQueue* event_queue, EventQueue* system_event_queue, + ReactionQueue* reaction_queue, interval_t duration, bool keep_alive); #endif diff --git a/include/reactor-uc/schedulers/dynamic/scheduler.h b/include/reactor-uc/schedulers/dynamic/scheduler.h index d57084547..e08ceaa86 100644 --- a/include/reactor-uc/schedulers/dynamic/scheduler.h +++ b/include/reactor-uc/schedulers/dynamic/scheduler.h @@ -14,15 +14,15 @@ typedef struct Environment Environment; struct DynamicScheduler { Scheduler super; MUTEX_T mutex; - Environment *env; - EventQueue *event_queue; - ReactionQueue *reaction_queue; - EventQueue *system_event_queue; + Environment* env; + EventQueue* event_queue; + ReactionQueue* reaction_queue; + EventQueue* system_event_queue; // The following two fields are used to implement a linked list of Triggers // that are registered for cleanup at the end of the current tag. - Trigger *cleanup_ll_head; - Trigger *cleanup_ll_tail; + Trigger* cleanup_ll_head; + Trigger* cleanup_ll_tail; tag_t stop_tag; // The tag at which the program should stop. This is set by the user or by the scheduler. tag_t current_tag; // The current logical tag. Set by the scheduler and read by user in the reaction bodies. @@ -30,17 +30,17 @@ struct DynamicScheduler { * @brief After completing all reactions at a tag, this function is called to * reset is_present fields and increment index pointers of the EventPayloadPool. */ - void (*clean_up_timestep)(Scheduler *self); + void (*clean_up_timestep)(Scheduler* self); /** * @brief Called after `prepare_timestep` to run all reactions on the current * tag. */ - void (*run_timestep)(Scheduler *self); + void (*run_timestep)(Scheduler* self); }; -void DynamicScheduler_ctor(DynamicScheduler *self, Environment *env, EventQueue *event_queue, - EventQueue *system_event_queue, ReactionQueue *reaction_queue, interval_t duration, +void DynamicScheduler_ctor(DynamicScheduler* self, Environment* env, EventQueue* event_queue, + EventQueue* system_event_queue, ReactionQueue* reaction_queue, interval_t duration, bool keep_alive); #endif // SCHEDULER_H diff --git a/include/reactor-uc/schedulers/static/instructions.h b/include/reactor-uc/schedulers/static/instructions.h index 4dbdb750f..543b3fb89 100644 --- a/include/reactor-uc/schedulers/static/instructions.h +++ b/include/reactor-uc/schedulers/static/instructions.h @@ -18,33 +18,33 @@ /** * @brief Wrapper function for peeking a priority queue. */ -void push_pop_peek_pqueue(void *self); +void push_pop_peek_pqueue(void* self); -void execute_inst_ADD(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_ADDI(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, - bool debug, size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_BEQ(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_BGE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_BLT(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_BNE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_DU(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_EXE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_WLT(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_WU(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_JAL(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_JALR(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, - bool debug, size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); -void execute_inst_STP(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop); +void execute_inst_ADD(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_ADDI(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, + bool debug, size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_BEQ(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_BGE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_BLT(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_BNE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_DU(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_EXE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_WLT(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_WU(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_JAL(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_JALR(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, + bool debug, size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); +void execute_inst_STP(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop); #endif diff --git a/include/reactor-uc/schedulers/static/scheduler.h b/include/reactor-uc/schedulers/static/scheduler.h index 4e5b91bad..3a95b020e 100644 --- a/include/reactor-uc/schedulers/static/scheduler.h +++ b/include/reactor-uc/schedulers/static/scheduler.h @@ -12,12 +12,12 @@ typedef struct StaticScheduler StaticScheduler; typedef struct Environment Environment; struct StaticScheduler { - Scheduler *super; - Environment *env; - const inst_t **static_schedule; - size_t *pc; + Scheduler* super; + Environment* env; + const inst_t** static_schedule; + size_t* pc; }; -void StaticScheduler_ctor(StaticScheduler *self, Environment *env, const inst_t **static_schedule); +void StaticScheduler_ctor(StaticScheduler* self, Environment* env, const inst_t** static_schedule); #endif // STATIC_SCHEDULER_H diff --git a/include/reactor-uc/schedulers/static/scheduler_instructions.h b/include/reactor-uc/schedulers/static/scheduler_instructions.h index e4dd34092..bb3c4c608 100644 --- a/include/reactor-uc/schedulers/static/scheduler_instructions.h +++ b/include/reactor-uc/schedulers/static/scheduler_instructions.h @@ -43,16 +43,16 @@ typedef uint64_t imm_t; * */ typedef union { - reg_t *reg; + reg_t* reg; imm_t imm; } operand_t; /** * @brief Virtual instruction function pointer */ -typedef void (*function_virtual_instruction_t)(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, - operand_t op3, bool debug, size_t *program_counter, - Reaction **returned_reaction, bool *exit_loop); +typedef void (*function_virtual_instruction_t)(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, + operand_t op3, bool debug, size_t* program_counter, + Reaction** returned_reaction, bool* exit_loop); /** * @brief This struct represents a PRET VM instruction for C platforms. diff --git a/include/reactor-uc/serialization.h b/include/reactor-uc/serialization.h index 0854a7205..7bf07e5aa 100644 --- a/include/reactor-uc/serialization.h +++ b/include/reactor-uc/serialization.h @@ -11,10 +11,10 @@ #define SERIALIZATION_MAX_PAYLOAD_SIZE 832 #endif -int serialize_to_protobuf(const FederateMessage *message, unsigned char *buffer, size_t buffer_size); -int deserialize_from_protobuf(FederateMessage *message, const unsigned char *buffer, size_t buffer_size); +int serialize_to_protobuf(const FederateMessage* message, unsigned char* buffer, size_t buffer_size); +int deserialize_from_protobuf(FederateMessage* message, const unsigned char* buffer, size_t buffer_size); -lf_ret_t deserialize_payload_default(void *user_struct, const unsigned char *msg_buf, size_t msg_size); +lf_ret_t deserialize_payload_default(void* user_struct, const unsigned char* msg_buf, size_t msg_size); -int serialize_payload_default(const void *user_struct, size_t user_struct_size, unsigned char *msg_buf); +int serialize_payload_default(const void* user_struct, size_t user_struct_size, unsigned char* msg_buf); #endif // REACTOR_UC_SERIALIZATION_H diff --git a/include/reactor-uc/startup_coordinator.h b/include/reactor-uc/startup_coordinator.h index e3579afb0..95b8f67c5 100644 --- a/include/reactor-uc/startup_coordinator.h +++ b/include/reactor-uc/startup_coordinator.h @@ -41,23 +41,23 @@ typedef struct { /** This structure is used to coordinate the startup of the federation. */ struct StartupCoordinator { SystemEventHandler super; - Environment *env; + Environment* env; size_t longest_path; StartupCoordinationState state; - NeighborState *neighbor_state; + NeighborState* neighbor_state; size_t num_neighbours; uint32_t start_time_proposal_step; FederateMessage msg; instant_t start_time_proposal; JoiningPolicy joining_policy; - void (*handle_message_callback)(StartupCoordinator *self, const StartupCoordination *msg, size_t bundle_idx); - lf_ret_t (*connect_to_neighbors_blocking)(StartupCoordinator *self); - void (*start)(StartupCoordinator *self); + void (*handle_message_callback)(StartupCoordinator* self, const StartupCoordination* msg, size_t bundle_idx); + lf_ret_t (*connect_to_neighbors_blocking)(StartupCoordinator* self); + void (*start)(StartupCoordinator* self); }; -void StartupCoordinator_ctor(StartupCoordinator *self, Environment *env, NeighborState *neighbor_state, +void StartupCoordinator_ctor(StartupCoordinator* self, Environment* env, NeighborState* neighbor_state, size_t num_neighbors, size_t longest_path, JoiningPolicy joining_policy, - size_t payload_size, void *payload_buf, bool *payload_used_buf, + size_t payload_size, void* payload_buf, bool* payload_used_buf, size_t payload_buf_capacity); #endif // REACTOR_UC_STARTUP_COORDINATOR_H diff --git a/include/reactor-uc/tag.h b/include/reactor-uc/tag.h index 3e52188b9..a1d0edb92 100644 --- a/include/reactor-uc/tag.h +++ b/include/reactor-uc/tag.h @@ -36,15 +36,11 @@ #define FOREVER ((interval_t)LLONG_MAX) #define FOREVER_MICROSTEP UINT_MAX #define NEVER_TAG \ - (tag_t) { \ - .time = NEVER, .microstep = NEVER_MICROSTEP \ - } + (tag_t) { .time = NEVER, .microstep = NEVER_MICROSTEP } // Need a separate initializer expression to comply with some C compilers #define NEVER_TAG_INITIALIZER {NEVER, NEVER_MICROSTEP} #define FOREVER_TAG \ - (tag_t) { \ - .time = FOREVER, .microstep = FOREVER_MICROSTEP \ - } + (tag_t) { .time = FOREVER, .microstep = FOREVER_MICROSTEP } // Need a separate initializer expression to comply with some C compilers #define FOREVER_TAG_INITIALIZER {FOREVER, FOREVER_MICROSTEP} #define ZERO_TAG (tag_t){.time = 0LL, .microstep = 0u} @@ -101,7 +97,7 @@ typedef struct { * Return the current tag, a logical time, microstep pair. * @param env A pointer to the environment from which we want the current tag. */ -tag_t lf_tag(void *env); +tag_t lf_tag(void* env); /** * Add two tags. If either tag has has NEVER or FOREVER in its time field, then diff --git a/include/reactor-uc/timer.h b/include/reactor-uc/timer.h index 8e91af95a..87513b90e 100644 --- a/include/reactor-uc/timer.h +++ b/include/reactor-uc/timer.h @@ -15,7 +15,7 @@ struct Timer { TriggerObservers observers; } __attribute__((aligned(MEM_ALIGNMENT))); -void Timer_ctor(Timer *self, Reactor *parent, instant_t offset, interval_t period, Reaction **effects, - size_t effects_size, Reaction **observers, size_t observers_size); +void Timer_ctor(Timer* self, Reactor* parent, instant_t offset, interval_t period, Reaction** effects, + size_t effects_size, Reaction** observers, size_t observers_size); #endif diff --git a/include/reactor-uc/trigger.h b/include/reactor-uc/trigger.h index 2795a2ed9..81b83b0b3 100644 --- a/include/reactor-uc/trigger.h +++ b/include/reactor-uc/trigger.h @@ -31,7 +31,7 @@ typedef enum { * as effects of a certain trigger. */ typedef struct { - Reaction **reactions; + Reaction** reactions; size_t size; size_t num_registered; } TriggerEffects; @@ -41,7 +41,7 @@ typedef struct { * as sources of a certain trigger. */ typedef struct { - Reaction **reactions; + Reaction** reactions; size_t size; size_t num_registered; } TriggerSources; @@ -51,7 +51,7 @@ typedef struct { * as observers for a certain trigger. */ typedef struct { - Reaction **reactions; + Reaction** reactions; size_t size; size_t num_registered; } TriggerObservers; @@ -62,18 +62,18 @@ typedef struct { */ struct Trigger { TriggerType type; - Reactor *parent; + Reactor* parent; bool is_present; bool is_registered_for_cleanup; // Field used by Scheduler to avoid adding the same trigger multiple times to the // linked list of triggers registered for cleanup - Trigger *next; // For chaining together triggers, used by Scheduler to store triggers that should be cleaned up in a + Trigger* next; // For chaining together triggers, used by Scheduler to store triggers that should be cleaned up in a // linked list - EventPayloadPool *payload_pool; // A pointer to a EventPayloadPool field in a child type, Can be NULL - void (*prepare)(Trigger *, Event *); - void (*cleanup)(Trigger *); + EventPayloadPool* payload_pool; // A pointer to a EventPayloadPool field in a child type, Can be NULL + void (*prepare)(Trigger*, Event*); + void (*cleanup)(Trigger*); } __attribute__((aligned(MEM_ALIGNMENT))); -void Trigger_ctor(Trigger *self, TriggerType type, Reactor *parent, EventPayloadPool *payload_pool, - void (*prepare)(Trigger *, Event *), void (*cleanup)(Trigger *)); +void Trigger_ctor(Trigger* self, TriggerType type, Reactor* parent, EventPayloadPool* payload_pool, + void (*prepare)(Trigger*, Event*), void (*cleanup)(Trigger*)); #endif diff --git a/include/reactor-uc/util.h b/include/reactor-uc/util.h index 6189fbc3a..219f4ae05 100644 --- a/include/reactor-uc/util.h +++ b/include/reactor-uc/util.h @@ -4,10 +4,10 @@ #include "reactor-uc/port.h" #include "reactor-uc/connection.h" -void lf_connect(Connection *connection, Port *upstream, Port *downstream); +void lf_connect(Connection* connection, Port* upstream, Port* downstream); -void lf_connect_federated_output(Connection *connection, Port *output); +void lf_connect_federated_output(Connection* connection, Port* output); -void lf_connect_federated_input(Connection *connection, Port *input); +void lf_connect_federated_input(Connection* connection, Port* input); #endif diff --git a/src/action.c b/src/action.c index 0e83d1eec..05ebe3827 100644 --- a/src/action.c +++ b/src/action.c @@ -5,16 +5,16 @@ #include -void Action_cleanup(Trigger *self) { +void Action_cleanup(Trigger* self) { LF_DEBUG(TRIG, "Cleaning up action %p", self); self->is_present = false; } -void Action_prepare(Trigger *self, Event *event) { +void Action_prepare(Trigger* self, Event* event) { LF_DEBUG(TRIG, "Preparing action %p", self); - Environment *env = self->parent->env; - Action *act = (Action *)self; - Scheduler *sched = env->scheduler; + Environment* env = self->parent->env; + Action* act = (Action*)self; + Scheduler* sched = env->scheduler; memcpy(act->value_ptr, event->super.payload, act->payload_pool.payload_size); if (self->is_present) { @@ -31,11 +31,11 @@ void Action_prepare(Trigger *self, Event *event) { self->payload_pool->free(self->payload_pool, event->super.payload); } -lf_ret_t Action_schedule(Action *self, interval_t offset, const void *value) { +lf_ret_t Action_schedule(Action* self, interval_t offset, const void* value) { lf_ret_t ret; - Environment *env = self->super.parent->env; - Scheduler *sched = env->scheduler; - void *payload = NULL; + Environment* env = self->super.parent->env; + Scheduler* sched = env->scheduler; + void* payload = NULL; if (self->events_scheduled >= self->max_pending_events) { LF_ERR(TRIG, "Action event buffer is full, dropping event. Capacity is %i", self->max_pending_events); @@ -69,7 +69,7 @@ lf_ret_t Action_schedule(Action *self, interval_t offset, const void *value) { } } - Event event = EVENT_INIT(tag, (Trigger *)self, payload); + Event event = EVENT_INIT(tag, (Trigger*)self, payload); ret = sched->schedule_at(sched, &event); @@ -81,15 +81,15 @@ lf_ret_t Action_schedule(Action *self, interval_t offset, const void *value) { return ret; } -void Action_ctor(Action *self, ActionType type, interval_t min_offset, interval_t min_spacing, Reactor *parent, - Reaction **sources, size_t sources_size, Reaction **effects, size_t effects_size, Reaction **observers, - size_t observers_size, void *value_ptr, size_t value_size, void *payload_buf, bool *payload_used_buf, +void Action_ctor(Action* self, ActionType type, interval_t min_offset, interval_t min_spacing, Reactor* parent, + Reaction** sources, size_t sources_size, Reaction** effects, size_t effects_size, Reaction** observers, + size_t observers_size, void* value_ptr, size_t value_size, void* payload_buf, bool* payload_used_buf, size_t event_bound) { int capacity = 0; if (payload_buf != NULL) { capacity = event_bound; } - EventPayloadPool_ctor(&self->payload_pool, (char *)payload_buf, payload_used_buf, value_size, capacity, 0); + EventPayloadPool_ctor(&self->payload_pool, (char*)payload_buf, payload_used_buf, value_size, capacity, 0); Trigger_ctor(&self->super, TRIG_ACTION, parent, &self->payload_pool, Action_prepare, Action_cleanup); self->type = type; @@ -115,17 +115,17 @@ void Action_ctor(Action *self, ActionType type, interval_t min_offset, interval_ } } -void LogicalAction_ctor(LogicalAction *self, interval_t min_offset, interval_t min_spacing, Reactor *parent, - Reaction **sources, size_t sources_size, Reaction **effects, size_t effects_size, - Reaction **observers, size_t observers_size, void *value_ptr, size_t value_size, - void *payload_buf, bool *payload_used_buf, size_t event_bound) { +void LogicalAction_ctor(LogicalAction* self, interval_t min_offset, interval_t min_spacing, Reactor* parent, + Reaction** sources, size_t sources_size, Reaction** effects, size_t effects_size, + Reaction** observers, size_t observers_size, void* value_ptr, size_t value_size, + void* payload_buf, bool* payload_used_buf, size_t event_bound) { Action_ctor(&self->super, LOGICAL_ACTION, min_offset, min_spacing, parent, sources, sources_size, effects, effects_size, observers, observers_size, value_ptr, value_size, payload_buf, payload_used_buf, event_bound); } -static lf_ret_t PhysicalAction_schedule(Action *super, interval_t offset, const void *value) { - PhysicalAction *self = (PhysicalAction *)super; +static lf_ret_t PhysicalAction_schedule(Action* super, interval_t offset, const void* value) { + PhysicalAction* self = (PhysicalAction*)super; // We need a mutex because this can be called asynchronously and reads the events_scheduled variable. MUTEX_LOCK(self->mutex); @@ -134,18 +134,18 @@ static lf_ret_t PhysicalAction_schedule(Action *super, interval_t offset, const return ret; } -static void PhysicalAction_prepare(Trigger *super, Event *event) { - PhysicalAction *self = (PhysicalAction *)super; +static void PhysicalAction_prepare(Trigger* super, Event* event) { + PhysicalAction* self = (PhysicalAction*)super; // We need a mutex because this writes the events_scheduled variable that is read from async context. MUTEX_LOCK(self->mutex); Action_prepare(super, event); MUTEX_UNLOCK(self->mutex); } -void PhysicalAction_ctor(PhysicalAction *self, interval_t min_offset, interval_t min_spacing, Reactor *parent, - Reaction **sources, size_t sources_size, Reaction **effects, size_t effects_size, - Reaction **observers, size_t observers_size, void *value_ptr, size_t value_size, - void *payload_buf, bool *payload_used_buf, size_t event_bound) { +void PhysicalAction_ctor(PhysicalAction* self, interval_t min_offset, interval_t min_spacing, Reactor* parent, + Reaction** sources, size_t sources_size, Reaction** effects, size_t effects_size, + Reaction** observers, size_t observers_size, void* value_ptr, size_t value_size, + void* payload_buf, bool* payload_used_buf, size_t event_bound) { Action_ctor(&self->super, PHYSICAL_ACTION, min_offset, min_spacing, parent, sources, sources_size, effects, effects_size, observers, observers_size, value_ptr, value_size, payload_buf, payload_used_buf, event_bound); diff --git a/src/builtin_triggers.c b/src/builtin_triggers.c index 52b7b1080..527d53fbb 100644 --- a/src/builtin_triggers.c +++ b/src/builtin_triggers.c @@ -3,12 +3,12 @@ #include "reactor-uc/logging.h" #include "reactor-uc/scheduler.h" -void Builtin_prepare(Trigger *_self, Event *event) { +void Builtin_prepare(Trigger* _self, Event* event) { (void)event; LF_DEBUG(TRIG, "Preparing builtin trigger %p", _self); lf_ret_t ret; - BuiltinTrigger *self = (BuiltinTrigger *)_self; - Scheduler *sched = _self->parent->env->scheduler; + BuiltinTrigger* self = (BuiltinTrigger*)_self; + Scheduler* sched = _self->parent->env->scheduler; _self->is_present = true; sched->register_for_cleanup(sched, _self); assert(self->effects.size > 0); @@ -18,14 +18,14 @@ void Builtin_prepare(Trigger *_self, Event *event) { validate(ret == LF_OK); } } -void Builtin_cleanup(Trigger *self) { +void Builtin_cleanup(Trigger* self) { LF_DEBUG(TRIG, "Cleaning up builtin trigger %p", self); self->is_present = false; self->is_registered_for_cleanup = false; } -void BuiltinTrigger_ctor(BuiltinTrigger *self, TriggerType type, Reactor *parent, Reaction **effects, - size_t effects_size, Reaction **observers, size_t observers_size) { +void BuiltinTrigger_ctor(BuiltinTrigger* self, TriggerType type, Reactor* parent, Reaction** effects, + size_t effects_size, Reaction** observers, size_t observers_size) { Trigger_ctor(&self->super, type, parent, NULL, Builtin_prepare, Builtin_cleanup); self->effects.reactions = effects; self->effects.num_registered = 0; diff --git a/src/clock_synchronization.c b/src/clock_synchronization.c index e666816c3..20e162999 100644 --- a/src/clock_synchronization.c +++ b/src/clock_synchronization.c @@ -10,13 +10,13 @@ #define NEIGHBOR_INDEX_UNKNOWN -2 #define NUM_RESERVED_EVENTS 2 // There is 1 periodic event, but it is rescheduled before it is freed so we need 2. -static void ClockSynchronization_correct_clock(ClockSynchronization *self, ClockSyncTimestamps *timestamps) { +static void ClockSynchronization_correct_clock(ClockSynchronization* self, ClockSyncTimestamps* timestamps) { LF_DEBUG(CLOCK_SYNC, "Correcting clock. T1=" PRINTF_TIME " T2=" PRINTF_TIME " T3=" PRINTF_TIME " T4=" PRINTF_TIME, timestamps->t1, timestamps->t2, timestamps->t3, timestamps->t4); interval_t rtt = (timestamps->t4 - timestamps->t1) - (timestamps->t3 - timestamps->t2); interval_t owd = rtt / 2; interval_t clock_offset = owd - (timestamps->t2 - timestamps->t1); - FederatedEnvironment *env_fed = (FederatedEnvironment *)self->env; + FederatedEnvironment* env_fed = (FederatedEnvironment*)self->env; LF_DEBUG(CLOCK_SYNC, "RTT: " PRINTF_TIME " OWD: " PRINTF_TIME " offset: " PRINTF_TIME, rtt, owd, clock_offset); // The very first iteration of clock sync we possibly step the clock (forwards or backwards) @@ -59,9 +59,9 @@ static void ClockSynchronization_correct_clock(ClockSynchronization *self, Clock } /** Send our current clock priority to all connected neighbors. */ -static void ClockSynchronization_broadcast_priority(ClockSynchronization *self) { +static void ClockSynchronization_broadcast_priority(ClockSynchronization* self) { lf_ret_t ret; - FederatedEnvironment *env_fed = (FederatedEnvironment *)self->env; + FederatedEnvironment* env_fed = (FederatedEnvironment*)self->env; LF_DEBUG(CLOCK_SYNC, "Broadcasting priority %d to all neighbors", self->my_priority); for (size_t i = 0; i < self->num_neighbours; i++) { // Do not send out the priority to the master neighbor, because this is the origin @@ -70,8 +70,8 @@ static void ClockSynchronization_broadcast_priority(ClockSynchronization *self) continue; } - FederatedConnectionBundle *bundle = env_fed->net_bundles[i]; - NetworkChannel *chan = bundle->net_channel; + FederatedConnectionBundle* bundle = env_fed->net_bundles[i]; + NetworkChannel* chan = bundle->net_channel; bundle->send_msg.which_message = FederateMessage_clock_sync_msg_tag; bundle->send_msg.message.clock_sync_msg.which_message = ClockSyncMessage_priority_tag; bundle->send_msg.message.clock_sync_msg.message.priority.priority = self->my_priority; @@ -86,11 +86,11 @@ static void ClockSynchronization_broadcast_priority(ClockSynchronization *self) * @brief * Schedule a system event for the given time with the given message type with source neighbor set to self. */ -static void ClockSynchronization_schedule_system_event(ClockSynchronization *self, instant_t time, int message_type) { - ClockSyncEvent *payload = NULL; +static void ClockSynchronization_schedule_system_event(ClockSynchronization* self, instant_t time, int message_type) { + ClockSyncEvent* payload = NULL; lf_ret_t ret; - ret = self->super.payload_pool.allocate_reserved(&self->super.payload_pool, (void **)&payload); + ret = self->super.payload_pool.allocate_reserved(&self->super.payload_pool, (void**)&payload); if (ret != LF_OK) { LF_ERR(CLOCK_SYNC, "Failed to allocate payload for clock-sync system event."); @@ -111,7 +111,7 @@ static void ClockSynchronization_schedule_system_event(ClockSynchronization *sel } /** Compute my clock sync priority and also set the correct index of the master neighbor. */ -static void ClockSynchronization_update_neighbor_priority(ClockSynchronization *self, int neighbor, int priority) { +static void ClockSynchronization_update_neighbor_priority(ClockSynchronization* self, int neighbor, int priority) { self->neighbor_clock[neighbor].priority = priority; if (self->is_grandmaster) { self->master_neighbor_index = -1; @@ -132,13 +132,13 @@ static void ClockSynchronization_update_neighbor_priority(ClockSynchronization * } /** Handle incoming network messages with ClockSyncMessages. Called from async context. */ -static void ClockSynchronization_handle_message_callback(ClockSynchronization *self, const ClockSyncMessage *msg, +static void ClockSynchronization_handle_message_callback(ClockSynchronization* self, const ClockSyncMessage* msg, size_t bundle_idx) { LF_DEBUG(CLOCK_SYNC, "Received clock sync message from neighbor %zu. Scheduling as a system event", bundle_idx); - ClockSyncEvent *payload = NULL; + ClockSyncEvent* payload = NULL; tag_t tag = {.time = self->env->get_physical_time(self->env), .microstep = 0}; - lf_ret_t ret = self->super.payload_pool.allocate(&self->super.payload_pool, (void **)&payload); + lf_ret_t ret = self->super.payload_pool.allocate(&self->super.payload_pool, (void**)&payload); if (ret == LF_OK) { payload->neighbor_index = bundle_idx; @@ -155,9 +155,9 @@ static void ClockSynchronization_handle_message_callback(ClockSynchronization *s } } -static void ClockSynchronization_handle_priority_request(ClockSynchronization *self, int src_neighbor) { +static void ClockSynchronization_handle_priority_request(ClockSynchronization* self, int src_neighbor) { lf_ret_t ret; - FederatedEnvironment *env_fed = (FederatedEnvironment *)self->env; + FederatedEnvironment* env_fed = (FederatedEnvironment*)self->env; if (src_neighbor == NEIGHBOR_INDEX_SELF) { LF_DEBUG(CLOCK_SYNC, "Send clock sync priority requests to all neighbors"); for (size_t i = 0; i < self->num_neighbours; i++) { @@ -167,8 +167,8 @@ static void ClockSynchronization_handle_priority_request(ClockSynchronization *s continue; } - FederatedConnectionBundle *bundle = env_fed->net_bundles[i]; - NetworkChannel *chan = bundle->net_channel; + FederatedConnectionBundle* bundle = env_fed->net_bundles[i]; + NetworkChannel* chan = bundle->net_channel; bundle->send_msg.which_message = FederateMessage_clock_sync_msg_tag; bundle->send_msg.message.clock_sync_msg.which_message = ClockSyncMessage_priority_request_tag; ret = chan->send_blocking(chan, &bundle->send_msg); @@ -179,8 +179,8 @@ static void ClockSynchronization_handle_priority_request(ClockSynchronization *s } else { LF_DEBUG(CLOCK_SYNC, "Handling priority request from neighbor %d replying with %d", src_neighbor, self->my_priority); - FederatedConnectionBundle *bundle = env_fed->net_bundles[src_neighbor]; - NetworkChannel *chan = bundle->net_channel; + FederatedConnectionBundle* bundle = env_fed->net_bundles[src_neighbor]; + NetworkChannel* chan = bundle->net_channel; bundle->send_msg.which_message = FederateMessage_clock_sync_msg_tag; bundle->send_msg.message.clock_sync_msg.which_message = ClockSyncMessage_priority_tag; bundle->send_msg.message.clock_sync_msg.message.priority.priority = self->my_priority; @@ -192,7 +192,7 @@ static void ClockSynchronization_handle_priority_request(ClockSynchronization *s } /** Update the priority of a neighbour and possibly update our own priority and broadcast it, if it has changed. */ -static void ClockSynchronization_handle_priority_update(ClockSynchronization *self, int src_neighbor, int priority) { +static void ClockSynchronization_handle_priority_update(ClockSynchronization* self, int src_neighbor, int priority) { LF_DEBUG(CLOCK_SYNC, "Received priority %d from neighbor %d", priority, src_neighbor); int my_old_priority = self->my_priority; ClockSynchronization_update_neighbor_priority(self, src_neighbor, priority); @@ -205,16 +205,16 @@ static void ClockSynchronization_handle_priority_update(ClockSynchronization *se } /** Handle a DelayRequest message from a slave. Respond with the time at which the request was received. */ -static void ClockSynchronization_handle_delay_request(ClockSynchronization *self, SystemEvent *event) { +static void ClockSynchronization_handle_delay_request(ClockSynchronization* self, SystemEvent* event) { lf_ret_t ret; - FederatedEnvironment *env_fed = (FederatedEnvironment *)self->env; - ClockSyncEvent *payload = (ClockSyncEvent *)event->super.payload; + FederatedEnvironment* env_fed = (FederatedEnvironment*)self->env; + ClockSyncEvent* payload = (ClockSyncEvent*)event->super.payload; int src_neighbor = payload->neighbor_index; LF_DEBUG(CLOCK_SYNC, "Handling delay request from neighbor %d", src_neighbor); assert(src_neighbor >= 0); assert(src_neighbor < (int)self->num_neighbours); - FederatedConnectionBundle *bundle = env_fed->net_bundles[src_neighbor]; - NetworkChannel *chan = bundle->net_channel; + FederatedConnectionBundle* bundle = env_fed->net_bundles[src_neighbor]; + NetworkChannel* chan = bundle->net_channel; bundle->send_msg.which_message = FederateMessage_clock_sync_msg_tag; bundle->send_msg.message.clock_sync_msg.which_message = ClockSyncMessage_delay_response_tag; bundle->send_msg.message.clock_sync_msg.message.sync_response.time = event->super.tag.time; @@ -227,11 +227,11 @@ static void ClockSynchronization_handle_delay_request(ClockSynchronization *self } /** Handle a SyncResponse from a master. Record the time of arrival and send a DelayRequest. */ -static void ClockSynchronization_handle_sync_response(ClockSynchronization *self, SystemEvent *event) { - ClockSyncEvent *payload = (ClockSyncEvent *)event->super.payload; - FederatedEnvironment *env_fed = (FederatedEnvironment *)self->env; +static void ClockSynchronization_handle_sync_response(ClockSynchronization* self, SystemEvent* event) { + ClockSyncEvent* payload = (ClockSyncEvent*)event->super.payload; + FederatedEnvironment* env_fed = (FederatedEnvironment*)self->env; lf_ret_t ret; - SyncResponse *msg = &payload->msg.message.sync_response; + SyncResponse* msg = &payload->msg.message.sync_response; int src_neighbor = payload->neighbor_index; LF_DEBUG(CLOCK_SYNC, "Handling sync response from neighbor %d", src_neighbor); @@ -244,8 +244,8 @@ static void ClockSynchronization_handle_sync_response(ClockSynchronization *self self->timestamps.t1 = msg->time; self->timestamps.t2 = event->super.tag.time; - FederatedConnectionBundle *bundle = env_fed->net_bundles[src_neighbor]; - NetworkChannel *chan = bundle->net_channel; + FederatedConnectionBundle* bundle = env_fed->net_bundles[src_neighbor]; + NetworkChannel* chan = bundle->net_channel; bundle->send_msg.which_message = FederateMessage_clock_sync_msg_tag; bundle->send_msg.message.clock_sync_msg.which_message = ClockSyncMessage_delay_request_tag; bundle->send_msg.message.clock_sync_msg.message.delay_request.sequence_number = self->sequence_number; @@ -258,8 +258,8 @@ static void ClockSynchronization_handle_sync_response(ClockSynchronization *self } /** Handle a DelayResponse from a master. This completes a sync round and we can run the PI controller. */ -static void ClockSynchronization_handle_delay_response(ClockSynchronization *self, SystemEvent *event) { - DelayResponse *msg = &((ClockSyncEvent *)event->super.payload)->msg.message.delay_response; +static void ClockSynchronization_handle_delay_response(ClockSynchronization* self, SystemEvent* event) { + DelayResponse* msg = &((ClockSyncEvent*)event->super.payload)->msg.message.delay_response; LF_DEBUG(CLOCK_SYNC, "Handling delay response"); if (msg->sequence_number != self->sequence_number) { LF_WARN(CLOCK_SYNC, "Received out-of-order sync response %d, dropping", msg->sequence_number); @@ -270,16 +270,16 @@ static void ClockSynchronization_handle_delay_response(ClockSynchronization *sel } /** Handle a SyncRequest message from a slave. Repond with SyncResponse which contains the time of its transmission. */ -static void ClockSynchronization_handle_request_sync(ClockSynchronization *self, SystemEvent *event) { - FederatedEnvironment *env_fed = (FederatedEnvironment *)self->env; - ClockSyncEvent *payload = (ClockSyncEvent *)event->super.payload; +static void ClockSynchronization_handle_request_sync(ClockSynchronization* self, SystemEvent* event) { + FederatedEnvironment* env_fed = (FederatedEnvironment*)self->env; + ClockSyncEvent* payload = (ClockSyncEvent*)event->super.payload; lf_ret_t ret; int src_neighbor = payload->neighbor_index; if (src_neighbor == NEIGHBOR_INDEX_SELF) { if (self->master_neighbor_index >= 0) { LF_DEBUG(CLOCK_SYNC, "Sending out ReguestSync to master neighbor %d", self->master_neighbor_index); - FederatedConnectionBundle *bundle = env_fed->net_bundles[self->master_neighbor_index]; - NetworkChannel *chan = bundle->net_channel; + FederatedConnectionBundle* bundle = env_fed->net_bundles[self->master_neighbor_index]; + NetworkChannel* chan = bundle->net_channel; bundle->send_msg.which_message = FederateMessage_clock_sync_msg_tag; bundle->send_msg.message.clock_sync_msg.which_message = ClockSyncMessage_request_sync_tag; bundle->send_msg.message.clock_sync_msg.message.request_sync.sequence_number = ++self->sequence_number; @@ -299,8 +299,8 @@ static void ClockSynchronization_handle_request_sync(ClockSynchronization *self, ClockSyncMessage_request_sync_tag); } else { LF_DEBUG(CLOCK_SYNC, "Handling RequestSync from neighbor %d", src_neighbor); - FederatedConnectionBundle *bundle = env_fed->net_bundles[src_neighbor]; - NetworkChannel *chan = bundle->net_channel; + FederatedConnectionBundle* bundle = env_fed->net_bundles[src_neighbor]; + NetworkChannel* chan = bundle->net_channel; bundle->send_msg.which_message = FederateMessage_clock_sync_msg_tag; bundle->send_msg.message.clock_sync_msg.which_message = ClockSyncMessage_sync_response_tag; bundle->send_msg.message.clock_sync_msg.message.sync_response.time = self->env->get_physical_time(self->env); @@ -314,9 +314,9 @@ static void ClockSynchronization_handle_request_sync(ClockSynchronization *self, } /** Handle system events. This is done synchronously from the runtime context. */ -static void ClockSynchronization_handle_system_event(SystemEventHandler *_self, SystemEvent *event) { - ClockSynchronization *self = (ClockSynchronization *)_self; - ClockSyncEvent *payload = (ClockSyncEvent *)event->super.payload; +static void ClockSynchronization_handle_system_event(SystemEventHandler* _self, SystemEvent* event) { + ClockSynchronization* self = (ClockSynchronization*)_self; + ClockSyncEvent* payload = (ClockSyncEvent*)event->super.payload; LF_DEBUG(CLOCK_SYNC, "Handle ClockSync system event %d from neighbor %d", payload->msg.which_message, payload->neighbor_index); @@ -347,9 +347,9 @@ static void ClockSynchronization_handle_system_event(SystemEventHandler *_self, self->super.payload_pool.free(&self->super.payload_pool, event->super.payload); } -void ClockSynchronization_ctor(ClockSynchronization *self, Environment *env, NeighborClock *neighbor_clock, - size_t num_neighbors, bool is_grandmaster, size_t payload_size, void *payload_buf, - bool *payload_used_buf, size_t payload_buf_capacity, interval_t period, +void ClockSynchronization_ctor(ClockSynchronization* self, Environment* env, NeighborClock* neighbor_clock, + size_t num_neighbors, bool is_grandmaster, size_t payload_size, void* payload_buf, + bool* payload_used_buf, size_t payload_buf_capacity, interval_t period, interval_t max_adj, float servo_kp, float servo_ki) { self->env = env; self->neighbor_clock = neighbor_clock; @@ -361,7 +361,7 @@ void ClockSynchronization_ctor(ClockSynchronization *self, Environment *env, Nei self->super.handle = ClockSynchronization_handle_system_event; self->period = period; - EventPayloadPool_ctor(&self->super.payload_pool, (char *)payload_buf, payload_used_buf, payload_size, + EventPayloadPool_ctor(&self->super.payload_pool, (char*)payload_buf, payload_used_buf, payload_size, payload_buf_capacity, NUM_RESERVED_EVENTS); for (size_t i = 0; i < num_neighbors; i++) { diff --git a/src/connection.c b/src/connection.c index 262b115b4..ba6d37ebc 100644 --- a/src/connection.c +++ b/src/connection.c @@ -5,7 +5,7 @@ #include #include -Port *Connection_get_final_upstream(Connection *self) { +Port* Connection_get_final_upstream(Connection* self) { if (!self->upstream || self->super.type != TRIG_CONN) { return NULL; @@ -29,7 +29,7 @@ Port *Connection_get_final_upstream(Connection *self) { } } -void Connection_register_downstream(Connection *self, Port *port) { +void Connection_register_downstream(Connection* self, Port* port) { LF_DEBUG(CONN, "Registering downstream %p with connection %p", port, self); validate(self->downstreams_registered < self->downstreams_size); @@ -40,10 +40,10 @@ void Connection_register_downstream(Connection *self, Port *port) { /** * @brief Recursively walks down connection graph and copies value into Input ports and triggers reactions. */ -void LogicalConnection_trigger_downstreams(Connection *self, const void *value, size_t value_size) { +void LogicalConnection_trigger_downstreams(Connection* self, const void* value, size_t value_size) { LF_DEBUG(CONN, "Triggering downstreams of %p with value %p", self, value); for (size_t i = 0; i < self->downstreams_registered; i++) { - Port *down = self->downstreams[i]; + Port* down = self->downstreams[i]; if (down->effects.size > 0 || down->observers.size > 0) { validate(value_size == down->value_size); @@ -64,9 +64,9 @@ void LogicalConnection_trigger_downstreams(Connection *self, const void *value, } } -void Connection_ctor(Connection *self, TriggerType type, Reactor *parent, Port **downstreams, size_t num_downstreams, - EventPayloadPool *payload_pool, void (*prepare)(Trigger *, Event *), void (*cleanup)(Trigger *), - void (*trigger_downstreams)(Connection *, const void *, size_t)) { +void Connection_ctor(Connection* self, TriggerType type, Reactor* parent, Port** downstreams, size_t num_downstreams, + EventPayloadPool* payload_pool, void (*prepare)(Trigger*, Event*), void (*cleanup)(Trigger*), + void (*trigger_downstreams)(Connection*, const void*, size_t)) { self->upstream = NULL; self->downstreams_size = num_downstreams; @@ -79,7 +79,7 @@ void Connection_ctor(Connection *self, TriggerType type, Reactor *parent, Port * Trigger_ctor(&self->super, type, parent, payload_pool, prepare, cleanup); } -void LogicalConnection_ctor(LogicalConnection *self, Reactor *parent, Port **downstreams, size_t num_downstreams) { +void LogicalConnection_ctor(LogicalConnection* self, Reactor* parent, Port** downstreams, size_t num_downstreams) { Connection_ctor(&self->super, TRIG_CONN, parent, downstreams, num_downstreams, NULL, NULL, NULL, LogicalConnection_trigger_downstreams); } @@ -91,12 +91,12 @@ void LogicalConnection_ctor(LogicalConnection *self, Reactor *parent, Port **dow * * @param trigger */ -void DelayedConnection_prepare(Trigger *trigger, Event *event) { +void DelayedConnection_prepare(Trigger* trigger, Event* event) { LF_DEBUG(CONN, "Preparing delayed connection %p for triggering", trigger); - DelayedConnection *self = (DelayedConnection *)trigger; + DelayedConnection* self = (DelayedConnection*)trigger; assert(self->staged_payload_ptr == NULL); // Should be reset to NULL at end of last tag. - Scheduler *sched = trigger->parent->env->scheduler; - EventPayloadPool *pool = trigger->payload_pool; + Scheduler* sched = trigger->parent->env->scheduler; + EventPayloadPool* pool = trigger->payload_pool; trigger->is_present = true; sched->register_for_cleanup(sched, trigger); @@ -104,9 +104,9 @@ void DelayedConnection_prepare(Trigger *trigger, Event *event) { validate(pool->free(pool, event->super.payload) == LF_OK); } -void DelayedConnection_cleanup(Trigger *trigger) { +void DelayedConnection_cleanup(Trigger* trigger) { LF_DEBUG(CONN, "Cleaning up delayed connection %p", trigger); - DelayedConnection *self = (DelayedConnection *)trigger; + DelayedConnection* self = (DelayedConnection*)trigger; validate(trigger->is_registered_for_cleanup); if (trigger->is_present) { @@ -116,8 +116,8 @@ void DelayedConnection_cleanup(Trigger *trigger) { if (self->staged_payload_ptr) { LF_DEBUG(CONN, "Delayed connection %p had a staged value. Schedule it", trigger); - Environment *env = self->super.super.parent->env; - Scheduler *sched = env->scheduler; + Environment* env = self->super.super.parent->env; + Scheduler* sched = env->scheduler; tag_t base_tag = ZERO_TAG; if (self->type == PHYSICAL_CONNECTION) { @@ -132,15 +132,15 @@ void DelayedConnection_cleanup(Trigger *trigger) { } } -void DelayedConnection_trigger_downstreams(Connection *_self, const void *value, size_t value_size) { - DelayedConnection *self = (DelayedConnection *)_self; +void DelayedConnection_trigger_downstreams(Connection* _self, const void* value, size_t value_size) { + DelayedConnection* self = (DelayedConnection*)_self; assert(value); assert(value_size > 0); lf_ret_t ret; LF_DEBUG(CONN, "Triggering downstreams on delayed connection %p. Stage the value for later scheduling", _self); - Trigger *trigger = &_self->super; - Scheduler *sched = _self->super.parent->env->scheduler; - EventPayloadPool *pool = trigger->payload_pool; + Trigger* trigger = &_self->super; + Scheduler* sched = _self->super.parent->env->scheduler; + EventPayloadPool* pool = trigger->payload_pool; if (self->staged_payload_ptr == NULL) { ret = pool->allocate(pool, &self->staged_payload_ptr); if (ret != LF_OK) { @@ -153,14 +153,14 @@ void DelayedConnection_trigger_downstreams(Connection *_self, const void *value, sched->register_for_cleanup(sched, &_self->super); } -void DelayedConnection_ctor(DelayedConnection *self, Reactor *parent, Port **downstreams, size_t num_downstreams, - interval_t delay, ConnectionType type, size_t payload_size, void *payload_buf, - bool *payload_used_buf, size_t payload_buf_capacity) { +void DelayedConnection_ctor(DelayedConnection* self, Reactor* parent, Port** downstreams, size_t num_downstreams, + interval_t delay, ConnectionType type, size_t payload_size, void* payload_buf, + bool* payload_used_buf, size_t payload_buf_capacity) { self->delay = delay; self->staged_payload_ptr = NULL; self->type = type; - EventPayloadPool_ctor(&self->payload_pool, (char *)payload_buf, payload_used_buf, payload_size, payload_buf_capacity, + EventPayloadPool_ctor(&self->payload_pool, (char*)payload_buf, payload_used_buf, payload_size, payload_buf_capacity, 0); Connection_ctor(&self->super, TRIG_CONN_DELAYED, parent, downstreams, num_downstreams, &self->payload_pool, DelayedConnection_prepare, DelayedConnection_cleanup, DelayedConnection_trigger_downstreams); diff --git a/src/environment.c b/src/environment.c index 32730c6b9..69a932f6b 100644 --- a/src/environment.c +++ b/src/environment.c @@ -7,7 +7,7 @@ #include "reactor-uc/timer.h" -void Environment_schedule_startups(const Environment *self, const tag_t start_tag) { +void Environment_schedule_startups(const Environment* self, const tag_t start_tag) { if (self->startup) { LF_DEBUG(FED, "Scheduling Startup Reactions at" PRINTF_TAG, start_tag); Event event = EVENT_INIT(start_tag, &self->startup->super, NULL); @@ -17,12 +17,12 @@ void Environment_schedule_startups(const Environment *self, const tag_t start_ta } } -void Environment_schedule_timers(Environment *self, const Reactor *reactor, const tag_t start_tag) { +void Environment_schedule_timers(Environment* self, const Reactor* reactor, const tag_t start_tag) { lf_ret_t ret; for (size_t i = 0; i < reactor->triggers_size; i++) { - Trigger *trigger = reactor->triggers[i]; + Trigger* trigger = reactor->triggers[i]; if (trigger->type == TRIG_TIMER) { - Timer *timer = (Timer *)trigger; + Timer* timer = (Timer*)trigger; tag_t tag = {.time = start_tag.time + timer->offset, .microstep = start_tag.microstep}; Event event = EVENT_INIT(tag, trigger, NULL); ret = self->scheduler->schedule_at(self->scheduler, &event); diff --git a/src/environments/federated_environment.c b/src/environments/federated_environment.c index 760f932a0..92073d38e 100644 --- a/src/environments/federated_environment.c +++ b/src/environments/federated_environment.c @@ -9,16 +9,16 @@ #include #include -static void FederatedEnvironment_validate(Environment *super) { - FederatedEnvironment *self = (FederatedEnvironment *)super; +static void FederatedEnvironment_validate(Environment* super) { + FederatedEnvironment* self = (FederatedEnvironment*)super; Reactor_validate(super->main); for (size_t i = 0; i < self->net_bundles_size; i++) { FederatedConnectionBundle_validate(self->net_bundles[i]); } } -static void FederatedEnvironment_assemble(Environment *super) { - FederatedEnvironment *self = (FederatedEnvironment *)super; +static void FederatedEnvironment_assemble(Environment* super) { + FederatedEnvironment* self = (FederatedEnvironment*)super; // Here we enter a critical section which do not leave. // The scheduler will leave the critical section before executing the reactions. // Everything else within the runtime happens in a critical section. @@ -32,14 +32,14 @@ static void FederatedEnvironment_assemble(Environment *super) { self->startup_coordinator->start(self->startup_coordinator); } -static void FederatedEnvironment_start(Environment *super) { +static void FederatedEnvironment_start(Environment* super) { // We do not set the start time here in federated mode, instead the StartupCoordinator will do it. // So we just start the main loop and the StartupCoordinator. super->scheduler->run(super->scheduler); } -static lf_ret_t FederatedEnvironment_wait_until(Environment *super, instant_t wakeup_time) { - FederatedEnvironment *self = (FederatedEnvironment *)super; +static lf_ret_t FederatedEnvironment_wait_until(Environment* super, instant_t wakeup_time) { + FederatedEnvironment* self = (FederatedEnvironment*)super; if (wakeup_time <= super->get_physical_time(super) || super->fast_mode) { return LF_OK; } @@ -56,8 +56,8 @@ static lf_ret_t FederatedEnvironment_wait_until(Environment *super, instant_t wa } } -static interval_t FederatedEnvironment_get_physical_time(Environment *super) { - FederatedEnvironment *self = (FederatedEnvironment *)super; +static interval_t FederatedEnvironment_get_physical_time(Environment* super) { + FederatedEnvironment* self = (FederatedEnvironment*)super; return self->clock.get_time(&self->clock); } @@ -70,19 +70,19 @@ static interval_t FederatedEnvironment_get_physical_time(Environment *super) { * @param next_tag * @return lf_ret_t */ -static lf_ret_t FederatedEnvironment_acquire_tag(Environment *super, tag_t next_tag) { +static lf_ret_t FederatedEnvironment_acquire_tag(Environment* super, tag_t next_tag) { LF_DEBUG(SCHED, "Acquiring tag " PRINTF_TAG, next_tag); - FederatedEnvironment *self = (FederatedEnvironment *)super; + FederatedEnvironment* self = (FederatedEnvironment*)super; instant_t additional_sleep = 0; for (size_t i = 0; i < self->net_bundles_size; i++) { - FederatedConnectionBundle *bundle = self->net_bundles[i]; + FederatedConnectionBundle* bundle = self->net_bundles[i]; if (!bundle->net_channel->is_connected(bundle->net_channel)) { continue; } for (size_t j = 0; j < bundle->inputs_size; j++) { - FederatedInputConnection *input = bundle->inputs[j]; + FederatedInputConnection* input = bundle->inputs[j]; // Before reading the last_known_tag of an FederatedInputConnection, we must acquire its mutex. MUTEX_LOCK(input->mutex); if (lf_tag_compare(input->last_known_tag, next_tag) < 0) { @@ -105,20 +105,20 @@ static lf_ret_t FederatedEnvironment_acquire_tag(Environment *super, tag_t next_ } } -static lf_ret_t FederatedEnvironment_poll_network_channels(Environment *super) { - FederatedEnvironment *self = (FederatedEnvironment *)super; +static lf_ret_t FederatedEnvironment_poll_network_channels(Environment* super) { + FederatedEnvironment* self = (FederatedEnvironment*)super; for (size_t i = 0; i < self->net_bundles_size; i++) { if (self->net_bundles[i]->net_channel->mode == NETWORK_CHANNEL_MODE_POLLED) { - PolledNetworkChannel *poll_channel = (PolledNetworkChannel *)self->net_bundles[i]->net_channel; + PolledNetworkChannel* poll_channel = (PolledNetworkChannel*)self->net_bundles[i]->net_channel; poll_channel->poll(poll_channel); } } return LF_OK; } -void FederatedEnvironment_ctor(FederatedEnvironment *self, Reactor *main, Scheduler *scheduler, bool fast_mode, - FederatedConnectionBundle **net_bundles, size_t net_bundles_size, - StartupCoordinator *startup_coordinator, ClockSynchronization *clock_sync) { +void FederatedEnvironment_ctor(FederatedEnvironment* self, Reactor* main, Scheduler* scheduler, bool fast_mode, + FederatedConnectionBundle** net_bundles, size_t net_bundles_size, + StartupCoordinator* startup_coordinator, ClockSynchronization* clock_sync) { Environment_ctor(&self->super, main, scheduler, fast_mode); self->super.assemble = FederatedEnvironment_assemble; self->super.start = FederatedEnvironment_start; @@ -140,11 +140,11 @@ void FederatedEnvironment_ctor(FederatedEnvironment *self, Reactor *main, Schedu validate(self->startup_coordinator); } -void FederatedEnvironment_free(FederatedEnvironment *self) { +void FederatedEnvironment_free(FederatedEnvironment* self) { LF_INFO(ENV, "Reactor shutting down, freeing federated environment."); Environment_free(&self->super); for (size_t i = 0; i < self->net_bundles_size; i++) { - NetworkChannel *chan = self->net_bundles[i]->net_channel; + NetworkChannel* chan = self->net_bundles[i]->net_channel; chan->free(chan); } LF_INFO(ENV, "All Network Channels freed. Exiting."); diff --git a/src/environments/unfederated_environment.c b/src/environments/unfederated_environment.c index 8cb5c789f..3327916fa 100644 --- a/src/environments/unfederated_environment.c +++ b/src/environments/unfederated_environment.c @@ -7,16 +7,14 @@ #include #include -static void Environment_validate(Environment *self) { - Reactor_validate(self->main); -} +static void Environment_validate(Environment* self) { Reactor_validate(self->main); } -static void Environment_assemble(Environment *self) { +static void Environment_assemble(Environment* self) { validaten(self->main->calculate_levels(self->main)); Environment_validate(self); } -static void Environment_start(Environment *self) { +static void Environment_start(Environment* self) { instant_t start_time = self->get_physical_time(self); LF_INFO(ENV, "Starting program at " PRINTF_TIME " nsec", start_time); tag_t start_tag = {.time = start_time, .microstep = 0}; @@ -28,7 +26,7 @@ static void Environment_start(Environment *self) { self->scheduler->run(self->scheduler); } -static lf_ret_t Environment_wait_until(Environment *self, instant_t wakeup_time) { +static lf_ret_t Environment_wait_until(Environment* self, instant_t wakeup_time) { if (wakeup_time <= self->get_physical_time(self) || self->fast_mode) { return LF_OK; } @@ -40,7 +38,7 @@ static lf_ret_t Environment_wait_until(Environment *self, instant_t wakeup_time) } } -static lf_ret_t Environment_wait_for(Environment *self, interval_t wait_time) { +static lf_ret_t Environment_wait_for(Environment* self, interval_t wait_time) { if (wait_time <= 0 || self->fast_mode) { return LF_OK; } @@ -48,16 +46,16 @@ static lf_ret_t Environment_wait_for(Environment *self, interval_t wait_time) { return self->platform->wait_for(self->platform, wait_time); } -static interval_t Environment_get_logical_time(Environment *self) { +static interval_t Environment_get_logical_time(Environment* self) { return self->scheduler->current_tag(self->scheduler).time; } -static interval_t Environment_get_elapsed_logical_time(Environment *self) { +static interval_t Environment_get_elapsed_logical_time(Environment* self) { return self->scheduler->current_tag(self->scheduler).time - self->scheduler->start_time; } -static interval_t Environment_get_physical_time(Environment *self) { +static interval_t Environment_get_physical_time(Environment* self) { return self->platform->get_physical_time(self->platform); } -static interval_t Environment_get_elapsed_physical_time(Environment *self) { +static interval_t Environment_get_elapsed_physical_time(Environment* self) { if (self->scheduler->start_time == NEVER) { return NEVER; } else { @@ -65,15 +63,13 @@ static interval_t Environment_get_elapsed_physical_time(Environment *self) { } } -static void Environment_request_shutdown(Environment *self) { - self->scheduler->request_shutdown(self->scheduler); -} +static void Environment_request_shutdown(Environment* self) { self->scheduler->request_shutdown(self->scheduler); } -static interval_t Environment_get_lag(Environment *self) { +static interval_t Environment_get_lag(Environment* self) { return self->get_physical_time(self) - self->get_logical_time(self); } -void Environment_ctor(Environment *self, Reactor *main, Scheduler *scheduler, bool fast_mode) { +void Environment_ctor(Environment* self, Reactor* main, Scheduler* scheduler, bool fast_mode) { self->main = main; self->scheduler = scheduler; self->platform = Platform_new(); @@ -97,7 +93,7 @@ void Environment_ctor(Environment *self, Reactor *main, Scheduler *scheduler, bo self->shutdown = NULL; } -void Environment_free(Environment *self) { +void Environment_free(Environment* self) { (void)self; LF_DEBUG(ENV, "Freeing top-level environment."); } diff --git a/src/event.c b/src/event.c index b7f485019..6e935ad38 100644 --- a/src/event.c +++ b/src/event.c @@ -1,6 +1,6 @@ #include "reactor-uc/event.h" -static lf_ret_t EventPayloadPool_free(EventPayloadPool *self, void *payload) { +static lf_ret_t EventPayloadPool_free(EventPayloadPool* self, void* payload) { MUTEX_LOCK(self->mutex); for (size_t i = 0; i < self->capacity; i++) { if (&self->buffer[i * self->payload_size] == payload) { @@ -13,7 +13,7 @@ static lf_ret_t EventPayloadPool_free(EventPayloadPool *self, void *payload) { return LF_INVALID_VALUE; } -static lf_ret_t EventPayloadPool_allocate(EventPayloadPool *self, void **payload) { +static lf_ret_t EventPayloadPool_allocate(EventPayloadPool* self, void** payload) { MUTEX_LOCK(self->mutex); for (size_t i = self->reserved; i < self->capacity; i++) { if (!self->used[i]) { @@ -27,7 +27,7 @@ static lf_ret_t EventPayloadPool_allocate(EventPayloadPool *self, void **payload return LF_NO_MEM; } -static lf_ret_t EventPayloadPool_allocate_reserved(EventPayloadPool *self, void **payload) { +static lf_ret_t EventPayloadPool_allocate_reserved(EventPayloadPool* self, void** payload) { MUTEX_LOCK(self->mutex); for (size_t i = 0; i < self->reserved; i++) { if (!self->used[i]) { @@ -41,7 +41,7 @@ static lf_ret_t EventPayloadPool_allocate_reserved(EventPayloadPool *self, void return LF_NO_MEM; } -void EventPayloadPool_ctor(EventPayloadPool *self, char *buffer, bool *used, size_t element_size, size_t capacity, +void EventPayloadPool_ctor(EventPayloadPool* self, char* buffer, bool* used, size_t element_size, size_t capacity, size_t reserved) { self->buffer = buffer; self->used = used; diff --git a/src/federated.c b/src/federated.c index 6fc9d91ec..ed07c8378 100644 --- a/src/federated.c +++ b/src/federated.c @@ -7,13 +7,13 @@ // Called when a reaction does lf_set(outputPort). Should buffer the output data // for later transmission. -void FederatedOutputConnection_trigger_downstream(Connection *_self, const void *value, size_t value_size) { +void FederatedOutputConnection_trigger_downstream(Connection* _self, const void* value, size_t value_size) { LF_DEBUG(FED, "Triggering downstreams on federated output connection %p. Stage for later TX", _self); lf_ret_t ret; - FederatedOutputConnection *self = (FederatedOutputConnection *)_self; - Scheduler *sched = _self->super.parent->env->scheduler; - Trigger *trigger = &_self->super; - EventPayloadPool *pool = trigger->payload_pool; + FederatedOutputConnection* self = (FederatedOutputConnection*)_self; + Scheduler* sched = _self->super.parent->env->scheduler; + Trigger* trigger = &_self->super; + EventPayloadPool* pool = trigger->payload_pool; assert(value); assert(value_size == self->payload_pool.payload_size); @@ -31,14 +31,14 @@ void FederatedOutputConnection_trigger_downstream(Connection *_self, const void } // Called at the end of a logical tag if lf_set was called on the output -void FederatedOutputConnection_cleanup(Trigger *trigger) { +void FederatedOutputConnection_cleanup(Trigger* trigger) { LF_DEBUG(FED, "Cleaning up federated output connection %p", trigger); - FederatedOutputConnection *self = (FederatedOutputConnection *)trigger; - Environment *env = trigger->parent->env; - Scheduler *sched = env->scheduler; - NetworkChannel *channel = self->bundle->net_channel; + FederatedOutputConnection* self = (FederatedOutputConnection*)trigger; + Environment* env = trigger->parent->env; + Scheduler* sched = env->scheduler; + NetworkChannel* channel = self->bundle->net_channel; - EventPayloadPool *pool = trigger->payload_pool; + EventPayloadPool* pool = trigger->payload_pool; if (channel->is_connected(channel)) { assert(self->staged_payload_ptr); @@ -47,7 +47,7 @@ void FederatedOutputConnection_cleanup(Trigger *trigger) { self->bundle->send_msg.which_message = FederateMessage_tagged_message_tag; - TaggedMessage *tagged_msg = &self->bundle->send_msg.message.tagged_message; + TaggedMessage* tagged_msg = &self->bundle->send_msg.message.tagged_message; tagged_msg->conn_id = self->conn_id; tagged_msg->tag.time = sched->current_tag(sched).time; tagged_msg->tag.microstep = sched->current_tag(sched).microstep; @@ -77,11 +77,11 @@ void FederatedOutputConnection_cleanup(Trigger *trigger) { LF_DEBUG(FED, "Federated output connection %p cleaned up", trigger); } -void FederatedOutputConnection_ctor(FederatedOutputConnection *self, Reactor *parent, FederatedConnectionBundle *bundle, - int conn_id, void *payload_buf, bool *payload_used_buf, size_t payload_size, +void FederatedOutputConnection_ctor(FederatedOutputConnection* self, Reactor* parent, FederatedConnectionBundle* bundle, + int conn_id, void* payload_buf, bool* payload_used_buf, size_t payload_size, size_t payload_buf_capacity) { - EventPayloadPool_ctor(&self->payload_pool, (char *)payload_buf, payload_used_buf, payload_size, payload_buf_capacity, + EventPayloadPool_ctor(&self->payload_pool, (char*)payload_buf, payload_used_buf, payload_size, payload_buf_capacity, 0); Connection_ctor(&self->super, TRIG_CONN_FEDERATED_OUTPUT, parent, NULL, payload_size, &self->payload_pool, NULL, FederatedOutputConnection_cleanup, FederatedOutputConnection_trigger_downstream); @@ -90,18 +90,18 @@ void FederatedOutputConnection_ctor(FederatedOutputConnection *self, Reactor *pa } // Called by Scheduler if an event for this Trigger is popped of event queue -void FederatedInputConnection_prepare(Trigger *trigger, Event *event) { +void FederatedInputConnection_prepare(Trigger* trigger, Event* event) { (void)event; LF_DEBUG(FED, "Preparing federated input connection %p for triggering", trigger); - FederatedInputConnection *self = (FederatedInputConnection *)trigger; - Environment *env = trigger->parent->env; - Scheduler *sched = env->scheduler; - EventPayloadPool *pool = trigger->payload_pool; + FederatedInputConnection* self = (FederatedInputConnection*)trigger; + Environment* env = trigger->parent->env; + Scheduler* sched = env->scheduler; + EventPayloadPool* pool = trigger->payload_pool; trigger->is_present = true; sched->register_for_cleanup(sched, trigger); assert(self->super.downstreams_size == 1); - Port *down = self->super.downstreams[0]; + Port* down = self->super.downstreams[0]; if (down->effects.size > 0 || down->observers.size > 0) { validate(pool->payload_size == down->value_size); @@ -118,17 +118,17 @@ void FederatedInputConnection_prepare(Trigger *trigger, Event *event) { } // Called at the end of a logical tag if it was registered for cleanup. -void FederatedInputConnection_cleanup(Trigger *trigger) { +void FederatedInputConnection_cleanup(Trigger* trigger) { LF_DEBUG(FED, "Cleaning up federated input connection %p", trigger); assert(trigger->is_registered_for_cleanup); assert(trigger->is_present); trigger->is_present = false; } -void FederatedInputConnection_ctor(FederatedInputConnection *self, Reactor *parent, interval_t delay, bool is_physical, - interval_t max_wait, Port **downstreams, size_t downstreams_size, void *payload_buf, - bool *payload_used_buf, size_t payload_size, size_t payload_buf_capacity) { - EventPayloadPool_ctor(&self->payload_pool, (char *)payload_buf, payload_used_buf, payload_size, payload_buf_capacity, +void FederatedInputConnection_ctor(FederatedInputConnection* self, Reactor* parent, interval_t delay, bool is_physical, + interval_t max_wait, Port** downstreams, size_t downstreams_size, void* payload_buf, + bool* payload_used_buf, size_t payload_size, size_t payload_buf_capacity) { + EventPayloadPool_ctor(&self->payload_pool, (char*)payload_buf, payload_used_buf, payload_size, payload_buf_capacity, 0); Connection_ctor(&self->super, TRIG_CONN_FEDERATED_INPUT, parent, downstreams, downstreams_size, &self->payload_pool, FederatedInputConnection_prepare, FederatedInputConnection_cleanup, NULL); @@ -140,16 +140,16 @@ void FederatedInputConnection_ctor(FederatedInputConnection *self, Reactor *pare } // Callback registered with the NetworkChannel. Is called asynchronously when there is a TaggedMessage available. -void FederatedConnectionBundle_handle_tagged_msg(FederatedConnectionBundle *self, const FederateMessage *_msg) { - const TaggedMessage *msg = &_msg->message.tagged_message; +void FederatedConnectionBundle_handle_tagged_msg(FederatedConnectionBundle* self, const FederateMessage* _msg) { + const TaggedMessage* msg = &_msg->message.tagged_message; LF_DEBUG(FED, "Callback on FedConnBundle %p for message of size=%u with tag:" PRINTF_TAG, self, msg->payload.size, msg->tag); assert(((size_t)msg->conn_id) < self->inputs_size); lf_ret_t ret; - FederatedInputConnection *input = self->inputs[msg->conn_id]; - Environment *env = self->parent->env; - Scheduler *sched = env->scheduler; - EventPayloadPool *pool = &input->payload_pool; + FederatedInputConnection* input = self->inputs[msg->conn_id]; + Environment* env = self->parent->env; + Scheduler* sched = env->scheduler; + EventPayloadPool* pool = &input->payload_pool; tag_t base_tag = ZERO_TAG; @@ -165,7 +165,7 @@ void FederatedConnectionBundle_handle_tagged_msg(FederatedConnectionBundle *self // Take the value received over the network copy it into the payload_pool of // the input port and schedule an event for it. - void *payload; + void* payload; // Note that we now lock the FederatedInputConnection mutex so we can read the last_know_tag from it. MUTEX_LOCK(input->mutex); @@ -217,8 +217,8 @@ void FederatedConnectionBundle_handle_tagged_msg(FederatedConnectionBundle *self } } -void FederatedConnectionBundle_msg_received_cb(FederatedConnectionBundle *self, const FederateMessage *msg) { - FederatedEnvironment *env_fed = (FederatedEnvironment *)self->parent->env; +void FederatedConnectionBundle_msg_received_cb(FederatedConnectionBundle* self, const FederateMessage* msg) { + FederatedEnvironment* env_fed = (FederatedEnvironment*)self->parent->env; switch (msg->which_message) { case FederateMessage_tagged_message_tag: LF_DEBUG(FED, "Handling tagged message"); @@ -244,10 +244,10 @@ void FederatedConnectionBundle_msg_received_cb(FederatedConnectionBundle *self, } } -void FederatedConnectionBundle_ctor(FederatedConnectionBundle *self, Reactor *parent, NetworkChannel *net_channel, - FederatedInputConnection **inputs, deserialize_hook *deserialize_hooks, - size_t inputs_size, FederatedOutputConnection **outputs, - serialize_hook *serialize_hooks, size_t outputs_size, size_t index) { +void FederatedConnectionBundle_ctor(FederatedConnectionBundle* self, Reactor* parent, NetworkChannel* net_channel, + FederatedInputConnection** inputs, deserialize_hook* deserialize_hooks, + size_t inputs_size, FederatedOutputConnection** outputs, + serialize_hook* serialize_hooks, size_t outputs_size, size_t index) { validate(self); validate(parent); validate(net_channel); @@ -263,7 +263,7 @@ void FederatedConnectionBundle_ctor(FederatedConnectionBundle *self, Reactor *pa self->net_channel->register_receive_callback(self->net_channel, FederatedConnectionBundle_msg_received_cb, self); } -void FederatedConnectionBundle_validate(FederatedConnectionBundle *bundle) { +void FederatedConnectionBundle_validate(FederatedConnectionBundle* bundle) { validate(bundle); validate(bundle->net_channel); for (size_t i = 0; i < bundle->inputs_size; i++) { diff --git a/src/logging.c b/src/logging.c index 0b13dbc3a..b87a68906 100644 --- a/src/logging.c +++ b/src/logging.c @@ -13,15 +13,15 @@ #define ANSI_COLOR_CYAN "\x1b[36m" #define ANSI_COLOR_RESET "\x1b[0m" -void log_printf(const char *fmt, ...) { +void log_printf(const char* fmt, ...) { va_list args; va_start(args, fmt); Platform_vprintf(fmt, args); va_end(args); } -void log_message(int level, const char *module, const char *fmt, ...) { - const char *level_str; +void log_message(int level, const char* module, const char* fmt, ...) { + const char* level_str; switch (level) { case LF_LOG_LEVEL_ERROR: level_str = "ERROR"; diff --git a/src/network_channel.c b/src/network_channel.c index 43c91f93f..ff0fdb029 100644 --- a/src/network_channel.c +++ b/src/network_channel.c @@ -36,7 +36,7 @@ #endif #endif -char *NetworkChannel_state_to_string(NetworkChannelState state) { +char* NetworkChannel_state_to_string(NetworkChannelState state) { switch (state) { case NETWORK_CHANNEL_STATE_UNINITIALIZED: return "UNINITIALIZED"; diff --git a/src/physical_clock.c b/src/physical_clock.c index 7e3b77407..b9a8c4614 100644 --- a/src/physical_clock.c +++ b/src/physical_clock.c @@ -2,7 +2,7 @@ #include "reactor-uc/logging.h" #include "reactor-uc/environment.h" -lf_ret_t PhysicalClock_set_time(PhysicalClock *self, instant_t time) { +lf_ret_t PhysicalClock_set_time(PhysicalClock* self, instant_t time) { if (time < 0) { return LF_INVALID_VALUE; } @@ -19,7 +19,7 @@ lf_ret_t PhysicalClock_set_time(PhysicalClock *self, instant_t time) { return LF_OK; } -instant_t PhysicalClock_get_time(PhysicalClock *self) { +instant_t PhysicalClock_get_time(PhysicalClock* self) { MUTEX_LOCK(self->mutex); instant_t current_hw_time = self->env->platform->get_physical_time(self->env->platform); @@ -34,7 +34,7 @@ instant_t PhysicalClock_get_time(PhysicalClock *self) { return ret; } -lf_ret_t PhysicalClock_adjust_time(PhysicalClock *self, interval_t adjustment_ppb) { +lf_ret_t PhysicalClock_adjust_time(PhysicalClock* self, interval_t adjustment_ppb) { MUTEX_LOCK(self->mutex); instant_t current_hw_time = self->env->platform->get_physical_time(self->env->platform); @@ -54,11 +54,11 @@ lf_ret_t PhysicalClock_adjust_time(PhysicalClock *self, interval_t adjustment_pp return LF_OK; } -instant_t PhysicalClock_get_time_no_adjustment(PhysicalClock *self) { +instant_t PhysicalClock_get_time_no_adjustment(PhysicalClock* self) { return self->env->platform->get_physical_time(self->env->platform); } -instant_t PhysicalClock_to_hw_time(PhysicalClock *self, instant_t time) { +instant_t PhysicalClock_to_hw_time(PhysicalClock* self, instant_t time) { if (time == FOREVER || time == NEVER) { return time; } @@ -78,12 +78,12 @@ instant_t PhysicalClock_to_hw_time(PhysicalClock *self, instant_t time) { return (instant_t)hw_time; } -instant_t PhysicalClock_to_hw_time_no_adjustment(PhysicalClock *self, instant_t time) { +instant_t PhysicalClock_to_hw_time_no_adjustment(PhysicalClock* self, instant_t time) { (void)self; return time; } -void PhysicalClock_ctor(PhysicalClock *self, Environment *env, bool clock_sync_enabled) { +void PhysicalClock_ctor(PhysicalClock* self, Environment* env, bool clock_sync_enabled) { self->env = env; self->offset = 0; self->adjustment_epoch_hw = 0; diff --git a/src/platform/aducm355/aducm355.c b/src/platform/aducm355/aducm355.c index 94fc0e747..13f3f2491 100644 --- a/src/platform/aducm355/aducm355.c +++ b/src/platform/aducm355/aducm355.c @@ -38,9 +38,7 @@ void busy_wait(long int length) { length--; } -void Platform_vprintf(const char *fmt, va_list args) { - vprintf(fmt, args); -} +void Platform_vprintf(const char* fmt, va_list args) { vprintf(fmt, args); } /** Initialize the clock system. This function was copied from vendor examples. */ void ClockInit(void) { @@ -107,8 +105,8 @@ void RtcInit(void) { RtcCfgCR0(BITM_RTC_CR0_CNTEN, 1); } -instant_t PlatformAducm355_get_physical_time(Platform *super) { - PlatformAducm355 *self = (PlatformAducm355 *)super; +instant_t PlatformAducm355_get_physical_time(Platform* super) { + PlatformAducm355* self = (PlatformAducm355*)super; // To translate the current RTC counter value into nanoseconds with the minimal loss of // precision we translate the 32bit counter value alone, and later adds it to the epoch value @@ -132,14 +130,14 @@ instant_t PlatformAducm355_get_physical_time(Platform *super) { return res; } -lf_ret_t PlatformAducm355_wait_for(Platform *super, instant_t duration) { +lf_ret_t PlatformAducm355_wait_for(Platform* super, instant_t duration) { if (duration <= 0) return LF_OK; instant_t wakeup_time = duration + super->get_physical_time(super); return super->wait_until(super, wakeup_time); } -lf_ret_t PlatformAducm355_wait_until(Platform *super, instant_t wakeup_time) { +lf_ret_t PlatformAducm355_wait_until(Platform* super, instant_t wakeup_time) { LF_DEBUG(PLATFORM, "Waiting until " PRINTF_TIME, wakeup_time); // If the requested sleep duration is shorter than the minimum hibernation @@ -174,8 +172,8 @@ lf_ret_t PlatformAducm355_wait_until(Platform *super, instant_t wakeup_time) { return LF_OK; } -lf_ret_t PlatformAducm355_wait_until_interruptible(Platform *super, instant_t wakeup_time) { - PlatformAducm355 *self = (PlatformAducm355 *)super; +lf_ret_t PlatformAducm355_wait_until_interruptible(Platform* super, instant_t wakeup_time) { + PlatformAducm355* self = (PlatformAducm355*)super; LF_DEBUG(PLATFORM, "Wait until interruptible " PRINTF_TIME, wakeup_time); while (super->get_physical_time(super) < wakeup_time && !self->new_async_event) { @@ -186,14 +184,14 @@ lf_ret_t PlatformAducm355_wait_until_interruptible(Platform *super, instant_t wa return return_value; } -void PlatformAducm355_notify(Platform *super) { - PlatformAducm355 *self = (PlatformAducm355 *)super; +void PlatformAducm355_notify(Platform* super) { + PlatformAducm355* self = (PlatformAducm355*)super; LF_DEBUG(PLATFORM, "New async event"); self->new_async_event = true; } -void Platform_ctor(Platform *super) { - PlatformAducm355 *self = (PlatformAducm355 *)super; +void Platform_ctor(Platform* super) { + PlatformAducm355* self = (PlatformAducm355*)super; super->get_physical_time = PlatformAducm355_get_physical_time; super->wait_until = PlatformAducm355_wait_until; super->wait_for = PlatformAducm355_wait_for; @@ -212,13 +210,11 @@ void Platform_ctor(Platform *super) { RtcInit(); } -Platform *Platform_new() { - return &platform.super; -} +Platform* Platform_new() { return &platform.super; } -void MutexAducm355_unlock(Mutex *super) { +void MutexAducm355_unlock(Mutex* super) { (void)super; - PlatformAducm355 *platform = (PlatformAducm355 *)_lf_environment->platform; + PlatformAducm355* platform = (PlatformAducm355*)_lf_environment->platform; platform->num_nested_critical_sections--; if (platform->num_nested_critical_sections == 0) { @@ -226,16 +222,16 @@ void MutexAducm355_unlock(Mutex *super) { } } -void MutexAducm355_lock(Mutex *super) { +void MutexAducm355_lock(Mutex* super) { (void)super; - PlatformAducm355 *platform = (PlatformAducm355 *)_lf_environment->platform; + PlatformAducm355* platform = (PlatformAducm355*)_lf_environment->platform; if (platform->num_nested_critical_sections == 0) { __disable_irq(); } platform->num_nested_critical_sections++; } -void Mutex_ctor(Mutex *super) { +void Mutex_ctor(Mutex* super) { super->lock = MutexAducm355_lock; super->unlock = MutexAducm355_unlock; } diff --git a/src/platform/flexpret/flexpret.c b/src/platform/flexpret/flexpret.c index c0452c4b6..afa575cb1 100644 --- a/src/platform/flexpret/flexpret.c +++ b/src/platform/flexpret/flexpret.c @@ -4,17 +4,15 @@ static PlatformFlexpret platform; -void Platform_vprintf(const char *fmt, va_list args) { - vprintf(fmt, args); -} +void Platform_vprintf(const char* fmt, va_list args) { vprintf(fmt, args); } -instant_t PlatformFlexpret_get_physical_time(Platform *super) { +instant_t PlatformFlexpret_get_physical_time(Platform* super) { (void)super; return (instant_t)rdtime64(); } -lf_ret_t PlatformFlexpret_wait_until_interruptible(Platform *super, instant_t wakeup_time) { - PlatformFlexpret *self = (PlatformFlexpret *)super; +lf_ret_t PlatformFlexpret_wait_until_interruptible(Platform* super, instant_t wakeup_time) { + PlatformFlexpret* self = (PlatformFlexpret*)super; if (self->async_event_occurred) { self->async_event_occurred = false; @@ -31,14 +29,14 @@ lf_ret_t PlatformFlexpret_wait_until_interruptible(Platform *super, instant_t wa } } -lf_ret_t PlatformFlexpret_wait_until(Platform *super, instant_t wakeup_time) { +lf_ret_t PlatformFlexpret_wait_until(Platform* super, instant_t wakeup_time) { (void)super; fp_delay_until(wakeup_time); return LF_OK; } -lf_ret_t PlatformFlexpret_wait_for(Platform *super, interval_t wait_time) { +lf_ret_t PlatformFlexpret_wait_for(Platform* super, interval_t wait_time) { (void)super; // Interrupts should be disabled here so it does not matter whether we @@ -47,13 +45,13 @@ lf_ret_t PlatformFlexpret_wait_for(Platform *super, interval_t wait_time) { return LF_OK; } -void PlatformFlexpret_notify(Platform *super) { - PlatformFlexpret *self = (PlatformFlexpret *)super; +void PlatformFlexpret_notify(Platform* super) { + PlatformFlexpret* self = (PlatformFlexpret*)super; self->async_event_occurred = true; } -void Platform_ctor(Platform *super) { - PlatformFlexpret *self = (PlatformFlexpret *)super; +void Platform_ctor(Platform* super) { + PlatformFlexpret* self = (PlatformFlexpret*)super; super->get_physical_time = PlatformFlexpret_get_physical_time; super->wait_until = PlatformFlexpret_wait_until; super->wait_for = PlatformFlexpret_wait_for; @@ -64,13 +62,11 @@ void Platform_ctor(Platform *super) { self->mutex = (fp_lock_t)FP_LOCK_INITIALIZER; } -Platform *Platform_new() { - return &platform.super; -} +Platform* Platform_new() { return &platform.super; } -void MutexFlexpret_unlock(Mutex *super) { - MutexFlexpret *self = (MutexFlexpret *)super; - PlatformFlexpret *platform = (PlatformFlexpret *)_lf_environment->platform; +void MutexFlexpret_unlock(Mutex* super) { + MutexFlexpret* self = (MutexFlexpret*)super; + PlatformFlexpret* platform = (PlatformFlexpret*)_lf_environment->platform; // In the special case where this function is called during an interrupt // subroutine (isr) it should have no effect if ((read_csr(CSR_STATUS) & 0x04) == 0x04) @@ -85,9 +81,9 @@ void MutexFlexpret_unlock(Mutex *super) { } } -void MutexFlexpret_lock(Mutex *super) { - MutexFlexpret *self = (MutexFlexpret *)super; - PlatformFlexpret *platform = (PlatformFlexpret *)_lf_environment->platform; +void MutexFlexpret_lock(Mutex* super) { + MutexFlexpret* self = (MutexFlexpret*)super; + PlatformFlexpret* platform = (PlatformFlexpret*)_lf_environment->platform; // In the special case where this function is called during an interrupt // subroutine (isr) it should have no effect if ((read_csr(CSR_STATUS) & 0x04) == 0x04) @@ -100,8 +96,8 @@ void MutexFlexpret_lock(Mutex *super) { platform->num_nested_critical_sections++; } -void Mutex_ctor(Mutex *super) { - MutexFlexpret *self = (MutexFlexpret *)super; +void Mutex_ctor(Mutex* super) { + MutexFlexpret* self = (MutexFlexpret*)super; super->lock = MutexFlexpret_lock; super->unlock = MutexFlexpret_unlock; self->mutex = (fp_lock_t)FP_LOCK_INITIALIZER; diff --git a/src/platform/patmos/patmos.c b/src/platform/patmos/patmos.c index 0ae35c732..6135018f8 100644 --- a/src/platform/patmos/patmos.c +++ b/src/platform/patmos/patmos.c @@ -8,17 +8,15 @@ static PlatformPatmos platform; -void Platform_vprintf(const char *fmt, va_list args) { - vprintf(fmt, args); -} +void Platform_vprintf(const char* fmt, va_list args) { vprintf(fmt, args); } -instant_t PlatformPatmos_get_physical_time(Platform *super) { +instant_t PlatformPatmos_get_physical_time(Platform* super) { (void)super; return USEC(get_cpu_usecs()); } -lf_ret_t PlatformPatmos_wait_until_interruptible(Platform *super, instant_t wakeup_time) { - PlatformPatmos *self = (PlatformPatmos *)super; +lf_ret_t PlatformPatmos_wait_until_interruptible(Platform* super, instant_t wakeup_time) { + PlatformPatmos* self = (PlatformPatmos*)super; self->async_event = false; super->leave_critical_section(super); // turing on interrupts @@ -48,7 +46,7 @@ lf_ret_t PlatformPatmos_wait_until_interruptible(Platform *super, instant_t wake return LF_OK; } -lf_ret_t PlatformPatmos_wait_until(Platform *super, instant_t wakeup_time) { +lf_ret_t PlatformPatmos_wait_until(Platform* super, instant_t wakeup_time) { interval_t sleep_duration = wakeup_time - super->get_physical_time(super); if (sleep_duration < 0) { return LF_OK; @@ -63,7 +61,7 @@ lf_ret_t PlatformPatmos_wait_until(Platform *super, instant_t wakeup_time) { return LF_OK; } -lf_ret_t PlatformPatmos_wait_for(Platform *super, interval_t duration) { +lf_ret_t PlatformPatmos_wait_for(Platform* super, interval_t duration) { if (duration <= 0) { return LF_OK; } @@ -79,21 +77,17 @@ lf_ret_t PlatformPatmos_wait_for(Platform *super, interval_t duration) { return LF_OK; } -void PlatformPatmos_leave_critical_section(Platform *super) { - PlatformPatmos *self = (PlatformPatmos *)super; -} +void PlatformPatmos_leave_critical_section(Platform* super) { PlatformPatmos* self = (PlatformPatmos*)super; } -void PlatformPatmos_enter_critical_section(Platform *super) { - PlatformPatmos *self = (PlatformPatmos *)super; -} +void PlatformPatmos_enter_critical_section(Platform* super) { PlatformPatmos* self = (PlatformPatmos*)super; } -void PlatformPatmos_notify(Platform *super) { - PlatformPatmos *self = (PlatformPatmos *)super; +void PlatformPatmos_notify(Platform* super) { + PlatformPatmos* self = (PlatformPatmos*)super; self->async_event = true; } -void Platform_ctor(Platform *super) { - PlatformPatmos *self = (PlatformPatmos *)super; +void Platform_ctor(Platform* super) { + PlatformPatmos* self = (PlatformPatmos*)super; super->get_physical_time = PlatformPatmos_get_physical_time; super->wait_until = PlatformPatmos_wait_until; super->wait_for = PlatformPatmos_wait_for; @@ -102,13 +96,11 @@ void Platform_ctor(Platform *super) { self->num_nested_critical_sections = 0; } -Platform *Platform_new(void) { - return (Platform *)&platform; -} +Platform* Platform_new(void) { return (Platform*)&platform; } -void MutexPatmos_unlock(Mutex *super) { - MutexPatmos *self = (MutexPatmos *)super; - PlatformPatmos *platform = (PlatformPatmos *)_lf_environment->platform; +void MutexPatmos_unlock(Mutex* super) { + MutexPatmos* self = (MutexPatmos*)super; + PlatformPatmos* platform = (PlatformPatmos*)_lf_environment->platform; platform->num_nested_critical_sections--; if (platform->num_nested_critical_sections == 0) { intr_enable(); @@ -117,17 +109,17 @@ void MutexPatmos_unlock(Mutex *super) { } } -void MutexPatmos_lock(Mutex *super) { - MutexPatmos *self = (MutexPatmos *)super; - PlatformPatmos *platform = (PlatformPatmos *)_lf_environment->platform; +void MutexPatmos_lock(Mutex* super) { + MutexPatmos* self = (MutexPatmos*)super; + PlatformPatmos* platform = (PlatformPatmos*)_lf_environment->platform; if (platform->num_nested_critical_sections == 0) { intr_disable(); } platform->num_nested_critical_sections++; } -void Mutex_ctor(Mutex *super) { - MutexPatmos *self = (MutexPatmos *)super; +void Mutex_ctor(Mutex* super) { + MutexPatmos* self = (MutexPatmos*)super; super->lock = MutexPatmos_lock; super->unlock = MutexPatmos_unlock; critical_section_init(&self->crit_sec); diff --git a/src/platform/pico/pico.c b/src/platform/pico/pico.c index 49013f3b1..f0ce9e2b5 100644 --- a/src/platform/pico/pico.c +++ b/src/platform/pico/pico.c @@ -9,18 +9,16 @@ static PlatformPico platform; -void Platform_vprintf(const char *fmt, va_list args) { - vprintf(fmt, args); -} +void Platform_vprintf(const char* fmt, va_list args) { vprintf(fmt, args); } -instant_t PlatformPico_get_physical_time(Platform *super) { +instant_t PlatformPico_get_physical_time(Platform* super) { (void)super; absolute_time_t now; now = get_absolute_time(); return to_us_since_boot(now) * 1000; } -lf_ret_t PlatformPico_wait_for(Platform *super, instant_t duration) { +lf_ret_t PlatformPico_wait_for(Platform* super, instant_t duration) { (void)super; if (duration <= 0) return LF_OK; @@ -30,14 +28,14 @@ lf_ret_t PlatformPico_wait_for(Platform *super, instant_t duration) { return LF_OK; } -lf_ret_t PlatformPico_wait_until(Platform *super, instant_t wakeup_time) { +lf_ret_t PlatformPico_wait_until(Platform* super, instant_t wakeup_time) { LF_DEBUG(PLATFORM, "Waiting until " PRINTF_TIME, wakeup_time); interval_t sleep_duration = wakeup_time - super->get_physical_time(super); return PlatformPico_wait_for(super, sleep_duration); } -lf_ret_t PlatformPico_wait_until_interruptible(Platform *super, instant_t wakeup_time) { - PlatformPico *self = (PlatformPico *)super; +lf_ret_t PlatformPico_wait_until_interruptible(Platform* super, instant_t wakeup_time) { + PlatformPico* self = (PlatformPico*)super; LF_DEBUG(PLATFORM, "Wait until interruptible " PRINTF_TIME, wakeup_time); // time struct absolute_time_t target; @@ -60,14 +58,14 @@ lf_ret_t PlatformPico_wait_until_interruptible(Platform *super, instant_t wakeup } } -void PlatformPico_notify(Platform *super) { - PlatformPico *self = (PlatformPico *)super; +void PlatformPico_notify(Platform* super) { + PlatformPico* self = (PlatformPico*)super; LF_DEBUG(PLATFORM, "New async event"); sem_release(&self->sem); } -void Platform_ctor(Platform *super) { - PlatformPico *self = (PlatformPico *)super; +void Platform_ctor(Platform* super) { + PlatformPico* self = (PlatformPico*)super; super->get_physical_time = PlatformPico_get_physical_time; super->wait_until = PlatformPico_wait_until; super->wait_for = PlatformPico_wait_for; @@ -79,30 +77,28 @@ void Platform_ctor(Platform *super) { sem_init(&self->sem, 0, 1); } -Platform *Platform_new() { - return &platform.super; -} +Platform* Platform_new() { return &platform.super; } -void MutexPico_unlock(Mutex *super) { - MutexPico *self = (MutexPico *)super; - PlatformPico *platform = (PlatformPico *)_lf_environment->platform; +void MutexPico_unlock(Mutex* super) { + MutexPico* self = (MutexPico*)super; + PlatformPico* platform = (PlatformPico*)_lf_environment->platform; platform->num_nested_critical_sections--; if (platform->num_nested_critical_sections == 0) { critical_section_exit(&self->crit_sec); } } -void MutexPico_lock(Mutex *super) { - MutexPico *self = (MutexPico *)super; - PlatformPico *platform = (PlatformPico *)_lf_environment->platform; +void MutexPico_lock(Mutex* super) { + MutexPico* self = (MutexPico*)super; + PlatformPico* platform = (PlatformPico*)_lf_environment->platform; if (platform->num_nested_critical_sections == 0) { critical_section_enter_blocking(&self->crit_sec); } platform->num_nested_critical_sections++; } -void Mutex_ctor(Mutex *super) { - MutexPico *self = (MutexPico *)super; +void Mutex_ctor(Mutex* super) { + MutexPico* self = (MutexPico*)super; super->lock = MutexPico_lock; super->unlock = MutexPico_unlock; critical_section_init(&self->crit_sec); diff --git a/src/platform/pico/uart_channel.c b/src/platform/pico/uart_channel.c index f0a77b88c..9a96608fa 100644 --- a/src/platform/pico/uart_channel.c +++ b/src/platform/pico/uart_channel.c @@ -17,41 +17,41 @@ #define MINIMUM_MESSAGE_SIZE 10 #define UART_CHANNEL_EXPECTED_CONNECT_DURATION MSEC(2500) -static UartPolledChannel *uart_channel_0 = NULL; -static UartPolledChannel *uart_channel_1 = NULL; +static UartPolledChannel* uart_channel_0 = NULL; +static UartPolledChannel* uart_channel_1 = NULL; -static void UartPolledChannel_close_connection(NetworkChannel *untyped_self) { +static void UartPolledChannel_close_connection(NetworkChannel* untyped_self) { UART_CHANNEL_DEBUG("Close connection"); (void)untyped_self; } -static void UartPolledChannel_free(NetworkChannel *untyped_self) { +static void UartPolledChannel_free(NetworkChannel* untyped_self) { UART_CHANNEL_DEBUG("Free"); (void)untyped_self; } -static bool UartPolledChannel_is_connected(NetworkChannel *untyped_self) { - UartPolledChannel *self = (UartPolledChannel *)untyped_self; +static bool UartPolledChannel_is_connected(NetworkChannel* untyped_self) { + UartPolledChannel* self = (UartPolledChannel*)untyped_self; if (!self->received_response) { UART_CHANNEL_DEBUG("Open connection - Sending Ping"); char connect_message[] = UART_OPEN_MESSAGE_REQUEST; - uart_write_blocking(self->uart_device, (const uint8_t *)connect_message, sizeof(connect_message)); + uart_write_blocking(self->uart_device, (const uint8_t*)connect_message, sizeof(connect_message)); // uart_tx_wait_blocking(self->uart_device); } return self->state == NETWORK_CHANNEL_STATE_CONNECTED && self->received_response && self->send_response; } -static lf_ret_t UartPolledChannel_open_connection(NetworkChannel *untyped_self) { +static lf_ret_t UartPolledChannel_open_connection(NetworkChannel* untyped_self) { UART_CHANNEL_DEBUG("Open connection"); UartPolledChannel_is_connected(untyped_self); return LF_OK; } -static lf_ret_t UartPolledChannel_send_blocking(NetworkChannel *untyped_self, const FederateMessage *message) { +static lf_ret_t UartPolledChannel_send_blocking(NetworkChannel* untyped_self, const FederateMessage* message) { // adding message preamble - UartPolledChannel *self = (UartPolledChannel *)untyped_self; + UartPolledChannel* self = (UartPolledChannel*)untyped_self; char uart_message_prefix[] = UART_MESSAGE_PREFIX; memcpy(self->send_buffer, uart_message_prefix, sizeof(uart_message_prefix)); @@ -67,24 +67,24 @@ static lf_ret_t UartPolledChannel_send_blocking(NetworkChannel *untyped_self, co UART_CHANNEL_DEBUG("sending message of size: %d", message_size + sizeof(uart_message_prefix) + sizeof(uart_message_postfix)); // writing message out - uart_write_blocking(self->uart_device, (const uint8_t *)self->send_buffer, + uart_write_blocking(self->uart_device, (const uint8_t*)self->send_buffer, message_size + sizeof(uart_message_prefix) + sizeof(uart_message_postfix)); return LF_OK; } -static void UartPolledChannel_register_receive_callback(NetworkChannel *untyped_self, - void (*receive_callback)(FederatedConnectionBundle *conn, - const FederateMessage *message), - FederatedConnectionBundle *bundle) { +static void UartPolledChannel_register_receive_callback(NetworkChannel* untyped_self, + void (*receive_callback)(FederatedConnectionBundle* conn, + const FederateMessage* message), + FederatedConnectionBundle* bundle) { UART_CHANNEL_DEBUG("Register receive callback"); - UartPolledChannel *self = (UartPolledChannel *)untyped_self; + UartPolledChannel* self = (UartPolledChannel*)untyped_self; self->receive_callback = receive_callback; self->bundle = bundle; } -void _UartPolledChannel_interrupt_handler(UartPolledChannel *self) { +void _UartPolledChannel_interrupt_handler(UartPolledChannel* self) { bool wake_up = false; while (uart_is_readable(self->uart_device)) { @@ -99,7 +99,7 @@ void _UartPolledChannel_interrupt_handler(UartPolledChannel *self) { sizeof(request_message)) == 0) { self->receive_buffer_index -= sizeof(request_message); self->send_response = true; - uart_write_blocking(self->uart_device, (const uint8_t *)response_message, sizeof(response_message)); + uart_write_blocking(self->uart_device, (const uint8_t*)response_message, sizeof(response_message)); } else if (memcmp(response_message, &self->receive_buffer[self->receive_buffer_index - sizeof(response_message)], sizeof(response_message)) == 0) { self->receive_buffer_index -= sizeof(response_message); @@ -133,8 +133,8 @@ static void _UartPolledChannel_pico_interrupt_handler_1(void) { } } -void UartPolledChannel_poll(PolledNetworkChannel *untyped_self) { - UartPolledChannel *self = (UartPolledChannel *)untyped_self; +void UartPolledChannel_poll(PolledNetworkChannel* untyped_self) { + UartPolledChannel* self = (UartPolledChannel*)untyped_self; while (self->receive_buffer_index > MINIMUM_MESSAGE_SIZE) { char uart_message_prefix[] = UART_MESSAGE_PREFIX; int message_start_index = -1; @@ -237,7 +237,7 @@ static unsigned int from_uc_stop_bits(UartStopBits stop_bits) { return 2; } -void UartPolledChannel_ctor(UartPolledChannel *self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, +void UartPolledChannel_ctor(UartPolledChannel* self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, UartParityBits parity_bits, UartStopBits stop_bits) { assert(self != NULL); diff --git a/src/platform/posix/posix.c b/src/platform/posix/posix.c index daf76e260..7e8e4a456 100644 --- a/src/platform/posix/posix.c +++ b/src/platform/posix/posix.c @@ -9,17 +9,12 @@ static PlatformPosix platform; -static instant_t convert_timespec_to_ns(struct timespec tp) { - return ((instant_t)tp.tv_sec) * BILLION + tp.tv_nsec; -} +static instant_t convert_timespec_to_ns(struct timespec tp) { return ((instant_t)tp.tv_sec) * BILLION + tp.tv_nsec; } -void Platform_vprintf(const char *fmt, va_list args) { - vprintf(fmt, args); -} +void Platform_vprintf(const char* fmt, va_list args) { vprintf(fmt, args); } // lf_exit should be defined in main.c and should call Environment_free, if not we provide an empty implementation here. -__attribute__((weak)) void lf_exit(void) { -} +__attribute__((weak)) void lf_exit(void) {} static void handle_signal(int sig) { (void)sig; @@ -35,19 +30,19 @@ static struct timespec convert_ns_to_timespec(instant_t time) { return tspec; } -instant_t PlatformPosix_get_physical_time(Platform *super) { +instant_t PlatformPosix_get_physical_time(Platform* super) { (void)super; struct timespec tspec; - if (clock_gettime(CLOCK_REALTIME, (struct timespec *)&tspec) != 0) { + if (clock_gettime(CLOCK_REALTIME, (struct timespec*)&tspec) != 0) { throw("POSIX could not get physical time"); } return convert_timespec_to_ns(tspec); } -lf_ret_t PlatformPosix_wait_until_interruptible(Platform *super, instant_t wakeup_time) { +lf_ret_t PlatformPosix_wait_until_interruptible(Platform* super, instant_t wakeup_time) { LF_DEBUG(PLATFORM, "Interruptable wait until " PRINTF_TIME, wakeup_time); lf_ret_t ret; - PlatformPosix *self = (PlatformPosix *)super; + PlatformPosix* self = (PlatformPosix*)super; MUTEX_LOCK(self->mutex); if (self->new_async_event) { @@ -74,13 +69,13 @@ lf_ret_t PlatformPosix_wait_until_interruptible(Platform *super, instant_t wakeu return ret; } -lf_ret_t PlatformPosix_wait_for(Platform *super, instant_t duration) { +lf_ret_t PlatformPosix_wait_for(Platform* super, instant_t duration) { (void)super; if (duration <= 0) return LF_OK; const struct timespec tspec = convert_ns_to_timespec(duration); struct timespec remaining; - int res = nanosleep((const struct timespec *)&tspec, (struct timespec *)&remaining); + int res = nanosleep((const struct timespec*)&tspec, (struct timespec*)&remaining); if (res == 0) { return LF_OK; } else { @@ -88,15 +83,15 @@ lf_ret_t PlatformPosix_wait_for(Platform *super, instant_t duration) { } } -lf_ret_t PlatformPosix_wait_until(Platform *super, instant_t wakeup_time) { +lf_ret_t PlatformPosix_wait_until(Platform* super, instant_t wakeup_time) { LF_DEBUG(PLATFORM, "wait until " PRINTF_TIME, wakeup_time); interval_t sleep_duration = wakeup_time - super->get_physical_time(super); LF_DEBUG(PLATFORM, "wait duration " PRINTF_TIME, sleep_duration); return PlatformPosix_wait_for(super, sleep_duration); } -void PlatformPosix_notify(Platform *super) { - PlatformPosix *self = (PlatformPosix *)super; +void PlatformPosix_notify(Platform* super) { + PlatformPosix* self = (PlatformPosix*)super; MUTEX_LOCK(self->mutex); self->new_async_event = true; validaten(pthread_cond_signal(&self->cond)); @@ -105,8 +100,8 @@ void PlatformPosix_notify(Platform *super) { LF_DEBUG(PLATFORM, "New async event"); } -void Platform_ctor(Platform *super) { - PlatformPosix *self = (PlatformPosix *)super; +void Platform_ctor(Platform* super) { + PlatformPosix* self = (PlatformPosix*)super; super->get_physical_time = PlatformPosix_get_physical_time; super->wait_until = PlatformPosix_wait_until; super->wait_for = PlatformPosix_wait_for; @@ -121,22 +116,20 @@ void Platform_ctor(Platform *super) { validaten(pthread_cond_init(&self->cond, NULL)); } -Platform *Platform_new() { - return &platform.super; -} +Platform* Platform_new() { return &platform.super; } -void MutexPosix_lock(Mutex *super) { - MutexPosix *self = (MutexPosix *)super; +void MutexPosix_lock(Mutex* super) { + MutexPosix* self = (MutexPosix*)super; validaten(pthread_mutex_lock(&self->lock)); } -void MutexPosix_unlock(Mutex *super) { - MutexPosix *self = (MutexPosix *)super; +void MutexPosix_unlock(Mutex* super) { + MutexPosix* self = (MutexPosix*)super; validaten(pthread_mutex_unlock(&self->lock)); } -void Mutex_ctor(Mutex *super) { - MutexPosix *self = (MutexPosix *)super; +void Mutex_ctor(Mutex* super) { + MutexPosix* self = (MutexPosix*)super; super->lock = MutexPosix_lock; super->unlock = MutexPosix_unlock; validaten(pthread_mutex_init(&self->lock, NULL)); diff --git a/src/platform/posix/tcp_ip_channel.c b/src/platform/posix/tcp_ip_channel.c index 87b638d03..fb4f927d6 100644 --- a/src/platform/posix/tcp_ip_channel.c +++ b/src/platform/posix/tcp_ip_channel.c @@ -37,9 +37,9 @@ LF_DEBUG(NET, "TcpIpChannel: [%s] " fmt, self->is_server ? "server" : "client", ##__VA_ARGS__) // Forward declarations -static void *_TcpIpChannel_worker_thread(void *untyped_self); +static void* _TcpIpChannel_worker_thread(void* untyped_self); -static void _TcpIpChannel_update_state_locked(TcpIpChannel *self, NetworkChannelState new_state) { +static void _TcpIpChannel_update_state_locked(TcpIpChannel* self, NetworkChannelState new_state) { // Store old state NetworkChannelState old_state = self->state; @@ -52,7 +52,7 @@ static void _TcpIpChannel_update_state_locked(TcpIpChannel *self, NetworkChannel _lf_environment->platform->notify(_lf_environment->platform); } } -static void _TcpIpChannel_update_state(TcpIpChannel *self, NetworkChannelState new_state) { +static void _TcpIpChannel_update_state(TcpIpChannel* self, NetworkChannelState new_state) { TCP_IP_CHANNEL_DEBUG("Update state: %s => %s", NetworkChannel_state_to_string(self->state), NetworkChannel_state_to_string(new_state)); @@ -66,11 +66,9 @@ static void _TcpIpChannel_update_state(TcpIpChannel *self, NetworkChannelState n NetworkChannel_state_to_string(new_state)); } -static NetworkChannelState _TcpIpChannel_get_state_locked(TcpIpChannel *self) { - return self->state; -} +static NetworkChannelState _TcpIpChannel_get_state_locked(TcpIpChannel* self) { return self->state; } -static NetworkChannelState _TcpIpChannel_get_state(TcpIpChannel *self) { +static NetworkChannelState _TcpIpChannel_get_state(TcpIpChannel* self) { NetworkChannelState state; pthread_mutex_lock(&self->mutex); @@ -80,7 +78,7 @@ static NetworkChannelState _TcpIpChannel_get_state(TcpIpChannel *self) { return state; } -static lf_ret_t _TcpIpChannel_reset_socket(TcpIpChannel *self) { +static lf_ret_t _TcpIpChannel_reset_socket(TcpIpChannel* self) { FD_ZERO(&self->set); if (self->fd > 0) { if (close(self->fd) < 0) { @@ -119,7 +117,7 @@ static lf_ret_t _TcpIpChannel_reset_socket(TcpIpChannel *self) { return LF_OK; } -static void _TcpIpChannel_spawn_worker_thread(TcpIpChannel *self) { +static void _TcpIpChannel_spawn_worker_thread(TcpIpChannel* self) { int res; TCP_IP_CHANNEL_DEBUG("Spawning worker thread"); @@ -138,7 +136,7 @@ static void _TcpIpChannel_spawn_worker_thread(TcpIpChannel *self) { } } -static lf_ret_t _TcpIpChannel_server_bind(TcpIpChannel *self) { +static lf_ret_t _TcpIpChannel_server_bind(TcpIpChannel* self) { struct sockaddr_in serv_addr; serv_addr.sin_family = self->protocol_family; serv_addr.sin_port = htons(self->port); @@ -151,7 +149,7 @@ static lf_ret_t _TcpIpChannel_server_bind(TcpIpChannel *self) { } // bind the socket to that address - int ret = bind(self->fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); + int ret = bind(self->fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); if (ret < 0) { TCP_IP_CHANNEL_ERR("Could not bind to %s:%d errno=%d", self->host, self->port, errno); throw("bind() failed"); @@ -170,14 +168,14 @@ static lf_ret_t _TcpIpChannel_server_bind(TcpIpChannel *self) { return LF_OK; } -static lf_ret_t _TcpIpChannel_try_connect_server(NetworkChannel *untyped_self) { - TcpIpChannel *self = (TcpIpChannel *)untyped_self; +static lf_ret_t _TcpIpChannel_try_connect_server(NetworkChannel* untyped_self) { + TcpIpChannel* self = (TcpIpChannel*)untyped_self; int new_socket; struct sockaddr_in address; socklen_t addrlen = sizeof(address); - new_socket = accept(self->fd, (struct sockaddr *)&address, &addrlen); + new_socket = accept(self->fd, (struct sockaddr*)&address, &addrlen); if (new_socket >= 0) { self->client = new_socket; FD_SET(new_socket, &self->set); @@ -199,8 +197,8 @@ static lf_ret_t _TcpIpChannel_try_connect_server(NetworkChannel *untyped_self) { } } -static lf_ret_t _TcpIpChannel_try_connect_client(NetworkChannel *untyped_self) { - TcpIpChannel *self = (TcpIpChannel *)untyped_self; +static lf_ret_t _TcpIpChannel_try_connect_client(NetworkChannel* untyped_self) { + TcpIpChannel* self = (TcpIpChannel*)untyped_self; if (_TcpIpChannel_get_state(self) == NETWORK_CHANNEL_STATE_OPEN) { // First time trying to connect @@ -213,7 +211,7 @@ static lf_ret_t _TcpIpChannel_try_connect_client(NetworkChannel *untyped_self) { return LF_INVALID_VALUE; } - int ret = connect(self->fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); + int ret = connect(self->fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); if (ret == 0) { TCP_IP_CHANNEL_INFO("Connected to server on %s:%d", self->host, self->port); _TcpIpChannel_update_state(self, NETWORK_CHANNEL_STATE_CONNECTED); @@ -241,8 +239,8 @@ static lf_ret_t _TcpIpChannel_try_connect_client(NetworkChannel *untyped_self) { return LF_ERR; // Should never reach here } -static lf_ret_t TcpIpChannel_open_connection(NetworkChannel *untyped_self) { - TcpIpChannel *self = (TcpIpChannel *)untyped_self; +static lf_ret_t TcpIpChannel_open_connection(NetworkChannel* untyped_self) { + TcpIpChannel* self = (TcpIpChannel*)untyped_self; TCP_IP_CHANNEL_DEBUG("Open connection"); _TcpIpChannel_update_state(self, NETWORK_CHANNEL_STATE_OPEN); @@ -250,8 +248,8 @@ static lf_ret_t TcpIpChannel_open_connection(NetworkChannel *untyped_self) { return LF_OK; } -static lf_ret_t TcpIpChannel_send_blocking(NetworkChannel *untyped_self, const FederateMessage *message) { - TcpIpChannel *self = (TcpIpChannel *)untyped_self; +static lf_ret_t TcpIpChannel_send_blocking(NetworkChannel* untyped_self, const FederateMessage* message) { + TcpIpChannel* self = (TcpIpChannel*)untyped_self; TCP_IP_CHANNEL_DEBUG("Send blocking msg %d", message->which_message); lf_ret_t lf_ret = LF_ERR; @@ -314,8 +312,8 @@ static lf_ret_t TcpIpChannel_send_blocking(NetworkChannel *untyped_self, const F return lf_ret; } -static lf_ret_t _TcpIpChannel_receive(NetworkChannel *untyped_self, FederateMessage *return_message) { - TcpIpChannel *self = (TcpIpChannel *)untyped_self; +static lf_ret_t _TcpIpChannel_receive(NetworkChannel* untyped_self, FederateMessage* return_message) { + TcpIpChannel* self = (TcpIpChannel*)untyped_self; int socket; // based if this super is in the server or client role we need to select different sockets @@ -386,8 +384,8 @@ static lf_ret_t _TcpIpChannel_receive(NetworkChannel *untyped_self, FederateMess } } -static void TcpIpChannel_close_connection(NetworkChannel *untyped_self) { - TcpIpChannel *self = (TcpIpChannel *)untyped_self; +static void TcpIpChannel_close_connection(NetworkChannel* untyped_self) { + TcpIpChannel* self = (TcpIpChannel*)untyped_self; TCP_IP_CHANNEL_DEBUG("Closing connection"); if (self->state == NETWORK_CHANNEL_STATE_CLOSED) { @@ -409,8 +407,8 @@ static void TcpIpChannel_close_connection(NetworkChannel *untyped_self) { /** * @brief Main loop of the TcpIpChannel. */ -static void *_TcpIpChannel_worker_thread(void *untyped_self) { - TcpIpChannel *self = untyped_self; +static void* _TcpIpChannel_worker_thread(void* untyped_self) { + TcpIpChannel* self = untyped_self; lf_ret_t ret; int res; @@ -514,18 +512,18 @@ static void *_TcpIpChannel_worker_thread(void *untyped_self) { return NULL; } -static void TcpIpChannel_register_receive_callback(NetworkChannel *untyped_self, - void (*receive_callback)(FederatedConnectionBundle *conn, - const FederateMessage *msg), - FederatedConnectionBundle *conn) { - TcpIpChannel *self = (TcpIpChannel *)untyped_self; +static void TcpIpChannel_register_receive_callback(NetworkChannel* untyped_self, + void (*receive_callback)(FederatedConnectionBundle* conn, + const FederateMessage* msg), + FederatedConnectionBundle* conn) { + TcpIpChannel* self = (TcpIpChannel*)untyped_self; TCP_IP_CHANNEL_DEBUG("Register receive callback"); self->receive_callback = receive_callback; self->federated_connection = conn; } -static void TcpIpChannel_free(NetworkChannel *untyped_self) { - TcpIpChannel *self = (TcpIpChannel *)untyped_self; +static void TcpIpChannel_free(NetworkChannel* untyped_self) { + TcpIpChannel* self = (TcpIpChannel*)untyped_self; int err = 0; TCP_IP_CHANNEL_DEBUG("Free"); validate(self->worker_thread != 0); @@ -551,7 +549,7 @@ static void TcpIpChannel_free(NetworkChannel *untyped_self) { } // 3. We clean up and close all sockets and file descriptors. - self->super.close_connection((NetworkChannel *)self); + self->super.close_connection((NetworkChannel*)self); // 4. Free up any memory etc. of the thread. err = pthread_attr_destroy(&self->worker_thread_attr); @@ -562,13 +560,13 @@ static void TcpIpChannel_free(NetworkChannel *untyped_self) { pthread_mutex_destroy(&self->mutex); } -static bool TcpIpChannel_is_connected(NetworkChannel *untyped_self) { - TcpIpChannel *self = (TcpIpChannel *)untyped_self; +static bool TcpIpChannel_is_connected(NetworkChannel* untyped_self) { + TcpIpChannel* self = (TcpIpChannel*)untyped_self; return _TcpIpChannel_get_state(self) == NETWORK_CHANNEL_STATE_CONNECTED; } -void TcpIpChannel_ctor(TcpIpChannel *self, const char *host, unsigned short port, int protocol_family, bool is_server) { +void TcpIpChannel_ctor(TcpIpChannel* self, const char* host, unsigned short port, int protocol_family, bool is_server) { assert(self != NULL); assert(host != NULL); diff --git a/src/platform/riot/coap_udp_ip_channel.c b/src/platform/riot/coap_udp_ip_channel.c index db38ec224..7949d39bb 100644 --- a/src/platform/riot/coap_udp_ip_channel.c +++ b/src/platform/riot/coap_udp_ip_channel.c @@ -17,7 +17,7 @@ char _connection_thread_stack[THREAD_STACKSIZE_MAIN]; int _connection_thread_pid = 0; static bool _coap_is_globals_initialized = false; -static void _CoapUdpIpChannel_update_state(CoapUdpIpChannel *self, NetworkChannelState new_state) { +static void _CoapUdpIpChannel_update_state(CoapUdpIpChannel* self, NetworkChannelState new_state) { COAP_UDP_IP_CHANNEL_DEBUG("Update state: %s => %s", NetworkChannel_state_to_string(self->state), NetworkChannel_state_to_string(new_state)); @@ -43,7 +43,7 @@ static void _CoapUdpIpChannel_update_state(CoapUdpIpChannel *self, NetworkChanne msg_try_send(&msg, _connection_thread_pid); } -static void _CoapUdpIpChannel_update_state_if_not(CoapUdpIpChannel *self, NetworkChannelState new_state, +static void _CoapUdpIpChannel_update_state_if_not(CoapUdpIpChannel* self, NetworkChannelState new_state, NetworkChannelState if_not) { // Update the state of the channel itself mutex_lock(&self->state_mutex); @@ -58,7 +58,7 @@ static void _CoapUdpIpChannel_update_state_if_not(CoapUdpIpChannel *self, Networ _lf_environment->platform->notify(_lf_environment->platform); } -static NetworkChannelState _CoapUdpIpChannel_get_state(CoapUdpIpChannel *self) { +static NetworkChannelState _CoapUdpIpChannel_get_state(CoapUdpIpChannel* self) { NetworkChannelState state; mutex_lock(&self->state_mutex); @@ -68,12 +68,12 @@ static NetworkChannelState _CoapUdpIpChannel_get_state(CoapUdpIpChannel *self) { return state; } -static CoapUdpIpChannel *_CoapUdpIpChannel_get_coap_channel_by_remote(const sock_udp_ep_t *remote) { - CoapUdpIpChannel *channel; - FederatedEnvironment *env = (FederatedEnvironment *)_lf_environment; +static CoapUdpIpChannel* _CoapUdpIpChannel_get_coap_channel_by_remote(const sock_udp_ep_t* remote) { + CoapUdpIpChannel* channel; + FederatedEnvironment* env = (FederatedEnvironment*)_lf_environment; for (size_t i = 0; i < env->net_bundles_size; i++) { if (env->net_bundles[i]->net_channel->type == NETWORK_CHANNEL_TYPE_COAP_UDP_IP) { - channel = (CoapUdpIpChannel *)env->net_bundles[i]->net_channel; + channel = (CoapUdpIpChannel*)env->net_bundles[i]->net_channel; if (sock_udp_ep_equal(&channel->remote, remote)) { return channel; @@ -88,7 +88,7 @@ static CoapUdpIpChannel *_CoapUdpIpChannel_get_coap_channel_by_remote(const sock return NULL; } -static bool _CoapUdpIpChannel_send_coap_message(sock_udp_ep_t *remote, char *path, gcoap_resp_handler_t resp_handler) { +static bool _CoapUdpIpChannel_send_coap_message(sock_udp_ep_t* remote, char* path, gcoap_resp_handler_t resp_handler) { coap_pkt_t pdu; uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE]; @@ -106,9 +106,9 @@ static bool _CoapUdpIpChannel_send_coap_message(sock_udp_ep_t *remote, char *pat return false; } -static bool _CoapUdpIpChannel_send_coap_message_with_payload(CoapUdpIpChannel *self, sock_udp_ep_t *remote, char *path, +static bool _CoapUdpIpChannel_send_coap_message_with_payload(CoapUdpIpChannel* self, sock_udp_ep_t* remote, char* path, gcoap_resp_handler_t resp_handler, - const FederateMessage *message) { + const FederateMessage* message) { coap_pkt_t pdu; gcoap_req_init(&pdu, &self->write_buffer[0], CONFIG_GCOAP_PDU_BUF_SIZE, COAP_POST, path); @@ -144,10 +144,10 @@ static bool _CoapUdpIpChannel_send_coap_message_with_payload(CoapUdpIpChannel *s return false; } -static ssize_t _CoapUdpIpChannel_server_connect_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, - coap_request_ctx_t *ctx) { +static ssize_t _CoapUdpIpChannel_server_connect_handler(coap_pkt_t* pdu, uint8_t* buf, size_t len, + coap_request_ctx_t* ctx) { COAP_UDP_IP_CHANNEL_DEBUG("Server connect handler"); - CoapUdpIpChannel *self = _CoapUdpIpChannel_get_coap_channel_by_remote(ctx->remote); + CoapUdpIpChannel* self = _CoapUdpIpChannel_get_coap_channel_by_remote(ctx->remote); // Error => return 401 (unauthorized) if (self == NULL) { @@ -171,10 +171,10 @@ static ssize_t _CoapUdpIpChannel_server_connect_handler(coap_pkt_t *pdu, uint8_t return gcoap_response(pdu, buf, len, COAP_CODE_204); } -static ssize_t _CoapUdpIpChannel_server_disconnect_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, - coap_request_ctx_t *ctx) { +static ssize_t _CoapUdpIpChannel_server_disconnect_handler(coap_pkt_t* pdu, uint8_t* buf, size_t len, + coap_request_ctx_t* ctx) { COAP_UDP_IP_CHANNEL_DEBUG("Server disconnect handler"); - CoapUdpIpChannel *self = _CoapUdpIpChannel_get_coap_channel_by_remote(ctx->remote); + CoapUdpIpChannel* self = _CoapUdpIpChannel_get_coap_channel_by_remote(ctx->remote); // Error => return 401 (unauthorized) if (self == NULL) { @@ -192,10 +192,10 @@ static ssize_t _CoapUdpIpChannel_server_disconnect_handler(coap_pkt_t *pdu, uint return gcoap_response(pdu, buf, len, COAP_CODE_204); } -static ssize_t _CoapUdpIpChannel_server_message_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, - coap_request_ctx_t *ctx) { +static ssize_t _CoapUdpIpChannel_server_message_handler(coap_pkt_t* pdu, uint8_t* buf, size_t len, + coap_request_ctx_t* ctx) { COAP_UDP_IP_CHANNEL_DEBUG("Server message handler"); - CoapUdpIpChannel *self = _CoapUdpIpChannel_get_coap_channel_by_remote(ctx->remote); + CoapUdpIpChannel* self = _CoapUdpIpChannel_get_coap_channel_by_remote(ctx->remote); // Error => return 401 (unauthorized) if (self == NULL) { @@ -223,11 +223,11 @@ static const coap_resource_t _resources[] = { static gcoap_listener_t _listener = {&_resources[0], ARRAY_SIZE(_resources), GCOAP_SOCKET_TYPE_UDP, NULL, NULL, NULL}; -static void _CoapUdpIpChannel_client_open_connection_callback(const gcoap_request_memo_t *memo, coap_pkt_t *pdu, - const sock_udp_ep_t *remote) { +static void _CoapUdpIpChannel_client_open_connection_callback(const gcoap_request_memo_t* memo, coap_pkt_t* pdu, + const sock_udp_ep_t* remote) { (void)remote; // This pointer is useless and always NULL COAP_UDP_IP_CHANNEL_DEBUG("Client open connection callback"); - CoapUdpIpChannel *self = _CoapUdpIpChannel_get_coap_channel_by_remote(&memo->remote_ep); + CoapUdpIpChannel* self = _CoapUdpIpChannel_get_coap_channel_by_remote(&memo->remote_ep); if (memo->state == GCOAP_MEMO_TIMEOUT) { // Failure COAP_UDP_IP_CHANNEL_ERR("TIMEOUT => Try to connect again"); @@ -242,7 +242,7 @@ static void _CoapUdpIpChannel_client_open_connection_callback(const gcoap_reques } } -static lf_ret_t _CoapUdpIpChannel_client_send_connect_message(CoapUdpIpChannel *self) { +static lf_ret_t _CoapUdpIpChannel_client_send_connect_message(CoapUdpIpChannel* self) { if (!_CoapUdpIpChannel_send_coap_message(&self->remote, "/connect", _CoapUdpIpChannel_client_open_connection_callback)) { _CoapUdpIpChannel_update_state(self, NETWORK_CHANNEL_STATE_CONNECTION_FAILED); @@ -256,9 +256,9 @@ static lf_ret_t _CoapUdpIpChannel_client_send_connect_message(CoapUdpIpChannel * return LF_OK; } -static lf_ret_t CoapUdpIpChannel_open_connection(NetworkChannel *untyped_self) { +static lf_ret_t CoapUdpIpChannel_open_connection(NetworkChannel* untyped_self) { COAP_UDP_IP_CHANNEL_DEBUG("Open connection"); - CoapUdpIpChannel *self = (CoapUdpIpChannel *)untyped_self; + CoapUdpIpChannel* self = (CoapUdpIpChannel*)untyped_self; /* Server */ // Do nothing. Every CoAP client is also a server in our case. @@ -272,8 +272,8 @@ static lf_ret_t CoapUdpIpChannel_open_connection(NetworkChannel *untyped_self) { return LF_OK; } -static void _CoapUdpIpChannel_client_close_connection_callback(const gcoap_request_memo_t *memo, coap_pkt_t *pdu, - const sock_udp_ep_t *remote) { +static void _CoapUdpIpChannel_client_close_connection_callback(const gcoap_request_memo_t* memo, coap_pkt_t* pdu, + const sock_udp_ep_t* remote) { (void)remote; // This pointer is useless and always NULL COAP_UDP_IP_CHANNEL_DEBUG("Client close connection callback"); (void)memo; @@ -282,9 +282,9 @@ static void _CoapUdpIpChannel_client_close_connection_callback(const gcoap_reque // Do nothing } -static void CoapUdpIpChannel_close_connection(NetworkChannel *untyped_self) { +static void CoapUdpIpChannel_close_connection(NetworkChannel* untyped_self) { COAP_UDP_IP_CHANNEL_DEBUG("Close connection"); - CoapUdpIpChannel *self = (CoapUdpIpChannel *)untyped_self; + CoapUdpIpChannel* self = (CoapUdpIpChannel*)untyped_self; // Immediately close the channel _CoapUdpIpChannel_update_state(self, NETWORK_CHANNEL_STATE_CLOSED); @@ -293,11 +293,11 @@ static void CoapUdpIpChannel_close_connection(NetworkChannel *untyped_self) { _CoapUdpIpChannel_send_coap_message(&self->remote, "/disconnect", _CoapUdpIpChannel_client_close_connection_callback); } -static void _client_send_blocking_callback(const gcoap_request_memo_t *memo, coap_pkt_t *pdu, - const sock_udp_ep_t *remote) { +static void _client_send_blocking_callback(const gcoap_request_memo_t* memo, coap_pkt_t* pdu, + const sock_udp_ep_t* remote) { (void)remote; // This pointer is useless and always NULL COAP_UDP_IP_CHANNEL_DEBUG("Client send blocking callback"); - CoapUdpIpChannel *self = _CoapUdpIpChannel_get_coap_channel_by_remote(&memo->remote_ep); + CoapUdpIpChannel* self = _CoapUdpIpChannel_get_coap_channel_by_remote(&memo->remote_ep); if (memo->state == GCOAP_MEMO_TIMEOUT) { // Failure @@ -313,9 +313,9 @@ static void _client_send_blocking_callback(const gcoap_request_memo_t *memo, coa _lf_environment->platform->notify(_lf_environment->platform); } -static lf_ret_t CoapUdpIpChannel_send_blocking(NetworkChannel *untyped_self, const FederateMessage *message) { +static lf_ret_t CoapUdpIpChannel_send_blocking(NetworkChannel* untyped_self, const FederateMessage* message) { COAP_UDP_IP_CHANNEL_DEBUG("Send blocking"); - CoapUdpIpChannel *self = (CoapUdpIpChannel *)untyped_self; + CoapUdpIpChannel* self = (CoapUdpIpChannel*)untyped_self; // Send message self->send_ack_received = false; @@ -335,31 +335,31 @@ static lf_ret_t CoapUdpIpChannel_send_blocking(NetworkChannel *untyped_self, con return LF_ERR; } -static void CoapUdpIpChannel_register_receive_callback(NetworkChannel *untyped_self, - void (*receive_callback)(FederatedConnectionBundle *conn, - const FederateMessage *msg), - FederatedConnectionBundle *conn) { +static void CoapUdpIpChannel_register_receive_callback(NetworkChannel* untyped_self, + void (*receive_callback)(FederatedConnectionBundle* conn, + const FederateMessage* msg), + FederatedConnectionBundle* conn) { COAP_UDP_IP_CHANNEL_INFO("Register receive callback"); - CoapUdpIpChannel *self = (CoapUdpIpChannel *)untyped_self; + CoapUdpIpChannel* self = (CoapUdpIpChannel*)untyped_self; self->receive_callback = receive_callback; self->federated_connection = conn; } -static void CoapUdpIpChannel_free(NetworkChannel *untyped_self) { +static void CoapUdpIpChannel_free(NetworkChannel* untyped_self) { COAP_UDP_IP_CHANNEL_DEBUG("Free"); - CoapUdpIpChannel *self = (CoapUdpIpChannel *)untyped_self; + CoapUdpIpChannel* self = (CoapUdpIpChannel*)untyped_self; (void)self; // Do nothing } -static bool CoapUdpIpChannel_is_connected(NetworkChannel *untyped_self) { - CoapUdpIpChannel *self = (CoapUdpIpChannel *)untyped_self; +static bool CoapUdpIpChannel_is_connected(NetworkChannel* untyped_self) { + CoapUdpIpChannel* self = (CoapUdpIpChannel*)untyped_self; return _CoapUdpIpChannel_get_state(self) == NETWORK_CHANNEL_STATE_CONNECTED; } -void *_CoapUdpIpChannel_connection_thread(void *arg) { +void* _CoapUdpIpChannel_connection_thread(void* arg) { COAP_UDP_IP_CHANNEL_DEBUG("Start connection thread"); (void)arg; msg_t m; @@ -367,7 +367,7 @@ void *_CoapUdpIpChannel_connection_thread(void *arg) { while (true) { msg_receive(&m); - CoapUdpIpChannel *self = m.content.ptr; + CoapUdpIpChannel* self = m.content.ptr; switch (self->state) { case NETWORK_CHANNEL_STATE_OPEN: { @@ -397,7 +397,7 @@ void *_CoapUdpIpChannel_connection_thread(void *arg) { return NULL; } -void CoapUdpIpChannel_ctor(CoapUdpIpChannel *self, const char *remote_address, int remote_protocol_family) { +void CoapUdpIpChannel_ctor(CoapUdpIpChannel* self, const char* remote_address, int remote_protocol_family) { assert(self != NULL); assert(remote_address != NULL); diff --git a/src/platform/riot/riot.c b/src/platform/riot/riot.c index 2d1fccf35..26306ee5d 100644 --- a/src/platform/riot/riot.c +++ b/src/platform/riot/riot.c @@ -13,17 +13,15 @@ static PlatformRiot platform; -void Platform_vprintf(const char *fmt, va_list args) { - vprintf(fmt, args); -} +void Platform_vprintf(const char* fmt, va_list args) { vprintf(fmt, args); } -instant_t PlatformRiot_get_physical_time(Platform *super) { +instant_t PlatformRiot_get_physical_time(Platform* super) { (void)super; return USEC_TO_NSEC((ztimer64_now(ZTIMER64_USEC))); } -lf_ret_t PlatformRiot_wait_until_interruptible(Platform *super, instant_t wakeup_time) { - PlatformRiot *self = (PlatformRiot *)super; +lf_ret_t PlatformRiot_wait_until_interruptible(Platform* super, instant_t wakeup_time) { + PlatformRiot* self = (PlatformRiot*)super; interval_t sleep_duration = wakeup_time - super->get_physical_time(super); LF_DEBUG(PLATFORM, "Wait until interruptible for " PRINTF_TIME " ns", sleep_duration); if (sleep_duration < 0) { @@ -42,7 +40,7 @@ lf_ret_t PlatformRiot_wait_until_interruptible(Platform *super, instant_t wakeup } } -lf_ret_t PlatformRiot_wait_until(Platform *super, instant_t wakeup_time) { +lf_ret_t PlatformRiot_wait_until(Platform* super, instant_t wakeup_time) { interval_t sleep_duration = wakeup_time - super->get_physical_time(super); if (sleep_duration < 0) { return LF_OK; @@ -52,7 +50,7 @@ lf_ret_t PlatformRiot_wait_until(Platform *super, instant_t wakeup_time) { return LF_OK; } -lf_ret_t PlatformRiot_wait_for(Platform *super, interval_t duration) { +lf_ret_t PlatformRiot_wait_for(Platform* super, interval_t duration) { (void)super; if (duration <= 0) return LF_OK; @@ -60,13 +58,13 @@ lf_ret_t PlatformRiot_wait_for(Platform *super, interval_t duration) { return LF_OK; } -void PlatformRiot_notify(Platform *super) { - PlatformRiot *self = (PlatformRiot *)super; +void PlatformRiot_notify(Platform* super) { + PlatformRiot* self = (PlatformRiot*)super; mutex_unlock(&self->lock); } -void Platform_ctor(Platform *super) { - PlatformRiot *self = (PlatformRiot *)super; +void Platform_ctor(Platform* super) { + PlatformRiot* self = (PlatformRiot*)super; super->get_physical_time = PlatformRiot_get_physical_time; super->wait_until = PlatformRiot_wait_until; super->wait_for = PlatformRiot_wait_for; @@ -77,22 +75,20 @@ void Platform_ctor(Platform *super) { mutex_lock(&self->lock); } -Platform *Platform_new() { - return &platform.super; -} +Platform* Platform_new() { return &platform.super; } -void MutexRiot_lock(Mutex *super) { - MutexRiot *self = (MutexRiot *)super; +void MutexRiot_lock(Mutex* super) { + MutexRiot* self = (MutexRiot*)super; mutex_lock(&self->mutex); } -void MutexRiot_unlock(Mutex *super) { - MutexRiot *self = (MutexRiot *)super; +void MutexRiot_unlock(Mutex* super) { + MutexRiot* self = (MutexRiot*)super; mutex_unlock(&self->mutex); } -void Mutex_ctor(Mutex *super) { - MutexRiot *self = (MutexRiot *)super; +void Mutex_ctor(Mutex* super) { + MutexRiot* self = (MutexRiot*)super; super->lock = MutexRiot_lock; super->unlock = MutexRiot_unlock; mutex_init(&self->mutex); diff --git a/src/platform/riot/uart_channel.c b/src/platform/riot/uart_channel.c index 3edcb72e6..31f317b7b 100644 --- a/src/platform/riot/uart_channel.c +++ b/src/platform/riot/uart_channel.c @@ -7,29 +7,29 @@ #define UART_CHANNEL_INFO(fmt, ...) LF_INFO(NET, "UartPolledChannel: " fmt, ##__VA_ARGS__) #define UART_CHANNEL_DEBUG(fmt, ...) LF_DEBUG(NET, "UartPolledChannel: " fmt, ##__VA_ARGS__) -static lf_ret_t UartPolledChannel_open_connection(NetworkChannel *untyped_self) { +static lf_ret_t UartPolledChannel_open_connection(NetworkChannel* untyped_self) { UART_CHANNEL_DEBUG("Open connection"); (void)untyped_self; return LF_OK; } -static void UartPolledChannel_close_connection(NetworkChannel *untyped_self) { +static void UartPolledChannel_close_connection(NetworkChannel* untyped_self) { UART_CHANNEL_DEBUG("Close connection"); (void)untyped_self; } -static void UartPolledChannel_free(NetworkChannel *untyped_self) { +static void UartPolledChannel_free(NetworkChannel* untyped_self) { UART_CHANNEL_DEBUG("Free"); (void)untyped_self; } -static bool UartPolledChannel_is_connected(NetworkChannel *untyped_self) { - UartPolledChannel *self = (UartPolledChannel *)untyped_self; +static bool UartPolledChannel_is_connected(NetworkChannel* untyped_self) { + UartPolledChannel* self = (UartPolledChannel*)untyped_self; return self->state == NETWORK_CHANNEL_STATE_CONNECTED; } -static lf_ret_t UartPolledChannel_send_blocking(NetworkChannel *untyped_self, const FederateMessage *message) { - UartPolledChannel *self = (UartPolledChannel *)untyped_self; +static lf_ret_t UartPolledChannel_send_blocking(NetworkChannel* untyped_self, const FederateMessage* message) { + UartPolledChannel* self = (UartPolledChannel*)untyped_self; if (self->state == NETWORK_CHANNEL_STATE_CONNECTED) { int message_size = serialize_to_protobuf(message, self->write_buffer, UART_CHANNEL_BUFFERSIZE); @@ -43,19 +43,19 @@ static lf_ret_t UartPolledChannel_send_blocking(NetworkChannel *untyped_self, co } } -static void UartPolledChannel_register_receive_callback(NetworkChannel *untyped_self, - void (*receive_callback)(FederatedConnectionBundle *conn, - const FederateMessage *msg), - FederatedConnectionBundle *conn) { +static void UartPolledChannel_register_receive_callback(NetworkChannel* untyped_self, + void (*receive_callback)(FederatedConnectionBundle* conn, + const FederateMessage* msg), + FederatedConnectionBundle* conn) { UART_CHANNEL_INFO("Register receive callback"); - UartPolledChannel *self = (UartPolledChannel *)untyped_self; + UartPolledChannel* self = (UartPolledChannel*)untyped_self; self->receive_callback = receive_callback; self->federated_connection = conn; } -void _UartPolledChannel_interrupt_callback(void *arg, uint8_t received_byte) { - UartPolledChannel *self = (UartPolledChannel *)arg; +void _UartPolledChannel_interrupt_callback(void* arg, uint8_t received_byte) { + UartPolledChannel* self = (UartPolledChannel*)arg; const uint32_t minimum_message_size = 12; int receive_buffer_index = self->receive_buffer_index; @@ -65,13 +65,13 @@ void _UartPolledChannel_interrupt_callback(void *arg, uint8_t received_byte) { if (self->receive_buffer_index >= minimum_message_size) { if (self->super.super.mode == NETWORK_CHANNEL_MODE_ASYNC) { - cond_signal(&((UartAsyncChannel *)self)->receive_cv); + cond_signal(&((UartAsyncChannel*)self)->receive_cv); } } } -void UartPolledChannel_poll(NetworkChannel *untyped_self) { - UartPolledChannel *self = (UartPolledChannel *)untyped_self; +void UartPolledChannel_poll(NetworkChannel* untyped_self) { + UartPolledChannel* self = (UartPolledChannel*)untyped_self; const uint32_t minimum_message_size = 12; while (self->receive_buffer_index > minimum_message_size) { @@ -95,15 +95,15 @@ void UartPolledChannel_poll(NetworkChannel *untyped_self) { } } -void *_UartAsyncChannel_decode_loop(void *arg) { - UartAsyncChannel *self = (UartAsyncChannel *)arg; +void* _UartAsyncChannel_decode_loop(void* arg) { + UartAsyncChannel* self = (UartAsyncChannel*)arg; mutex_lock(&self->receive_lock); UART_CHANNEL_DEBUG("Entering decoding loop"); while (true) { cond_wait(&self->receive_cv, &self->receive_lock); - UartPolledChannel_poll((NetworkChannel *)&self->super); + UartPolledChannel_poll((NetworkChannel*)&self->super); } return NULL; @@ -152,7 +152,7 @@ uart_stop_bits_t from_uc_stop_bits(UartStopBits stop_bits) { return UART_STOP_BITS_2; } -void UartPolledChannel_ctor(UartPolledChannel *self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, +void UartPolledChannel_ctor(UartPolledChannel* self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, UartParityBits parity_bits, UartStopBits stop_bits) { assert(self != NULL); @@ -198,7 +198,7 @@ void UartPolledChannel_ctor(UartPolledChannel *self, uint32_t uart_device, uint3 } } -void UartAsyncChannel_ctor(UartAsyncChannel *self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, +void UartAsyncChannel_ctor(UartAsyncChannel* self, uint32_t uart_device, uint32_t baud, UartDataBits data_bits, UartParityBits parity, UartStopBits stop_bits) { UartPolledChannel_ctor(&self->super, uart_device, baud, data_bits, parity, stop_bits); diff --git a/src/platform/zephyr/zephyr.c b/src/platform/zephyr/zephyr.c index ee6f86488..d17ecc0df 100644 --- a/src/platform/zephyr/zephyr.c +++ b/src/platform/zephyr/zephyr.c @@ -9,23 +9,21 @@ static PlatformZephyr platform; -void Platform_vprintf(const char *fmt, va_list args) { - vprintk(fmt, args); -} +void Platform_vprintf(const char* fmt, va_list args) { vprintk(fmt, args); } // Catch kernel panics from Zephyr -void k_sys_fatal_error_handler(unsigned int reason, const struct arch_esf *esf) { +void k_sys_fatal_error_handler(unsigned int reason, const struct arch_esf* esf) { (void)esf; LF_ERR(PLATFORM, "Zephyr kernel panic reason=%d", reason); throw("Zephyr kernel panic"); } -instant_t PlatformZephyr_get_physical_time(Platform *super) { +instant_t PlatformZephyr_get_physical_time(Platform* super) { (void)super; return k_uptime_get() * MSEC(1); } -lf_ret_t PlatformZephyr_wait_for(Platform *super, interval_t duration) { +lf_ret_t PlatformZephyr_wait_for(Platform* super, interval_t duration) { (void)super; if (duration <= 0) return LF_OK; @@ -44,14 +42,14 @@ lf_ret_t PlatformZephyr_wait_for(Platform *super, interval_t duration) { return LF_OK; } -lf_ret_t PlatformZephyr_wait_until(Platform *super, instant_t wakeup_time) { +lf_ret_t PlatformZephyr_wait_until(Platform* super, instant_t wakeup_time) { LF_DEBUG(PLATFORM, "Waiting until " PRINTF_TIME, wakeup_time); interval_t sleep_duration = wakeup_time - super->get_physical_time(super); return PlatformZephyr_wait_for(super, sleep_duration); } -lf_ret_t PlatformZephyr_wait_until_interruptible(Platform *super, instant_t wakeup_time) { - PlatformZephyr *self = (PlatformZephyr *)super; +lf_ret_t PlatformZephyr_wait_until_interruptible(Platform* super, instant_t wakeup_time) { + PlatformZephyr* self = (PlatformZephyr*)super; LF_DEBUG(PLATFORM, "Wait until interruptible " PRINTF_TIME, wakeup_time); interval_t sleep_duration = wakeup_time - super->get_physical_time(super); LF_DEBUG(PLATFORM, "Wait until interruptible for " PRINTF_TIME, wakeup_time); @@ -74,14 +72,14 @@ lf_ret_t PlatformZephyr_wait_until_interruptible(Platform *super, instant_t wake } } -void PlatformZephyr_notify(Platform *super) { - PlatformZephyr *self = (PlatformZephyr *)super; +void PlatformZephyr_notify(Platform* super) { + PlatformZephyr* self = (PlatformZephyr*)super; LF_DEBUG(PLATFORM, "New async event"); k_sem_give(&self->sem); } -void Platform_ctor(Platform *super) { - PlatformZephyr *self = (PlatformZephyr *)super; +void Platform_ctor(Platform* super) { + PlatformZephyr* self = (PlatformZephyr*)super; super->get_physical_time = PlatformZephyr_get_physical_time; super->wait_until = PlatformZephyr_wait_until; super->wait_for = PlatformZephyr_wait_for; @@ -96,22 +94,20 @@ void Platform_ctor(Platform *super) { } } -Platform *Platform_new() { - return &platform.super; -} +Platform* Platform_new() { return &platform.super; } -void MutexZephyr_lock(Mutex *super) { - MutexZephyr *self = (MutexZephyr *)super; +void MutexZephyr_lock(Mutex* super) { + MutexZephyr* self = (MutexZephyr*)super; validaten(k_mutex_lock(&self->mutex, K_FOREVER)); } -void MutexZephyr_unlock(Mutex *super) { - MutexZephyr *self = (MutexZephyr *)super; +void MutexZephyr_unlock(Mutex* super) { + MutexZephyr* self = (MutexZephyr*)super; validaten(k_mutex_unlock(&self->mutex)); } -void Mutex_ctor(Mutex *super) { - MutexZephyr *self = (MutexZephyr *)super; +void Mutex_ctor(Mutex* super) { + MutexZephyr* self = (MutexZephyr*)super; super->lock = MutexZephyr_lock; super->unlock = MutexZephyr_unlock; validaten(k_mutex_init(&self->mutex)); diff --git a/src/port.c b/src/port.c index c04616c56..96713f518 100644 --- a/src/port.c +++ b/src/port.c @@ -5,10 +5,10 @@ #include #include -void Port_prepare(Trigger *_self, Event *event) { +void Port_prepare(Trigger* _self, Event* event) { (void)event; assert(_self->type == TRIG_INPUT || _self->type == TRIG_OUTPUT); - Port *self = (Port *)_self; + Port* self = (Port*)_self; // If this is a federated input port, we will get passed an event, if it is a // normal port there will be no event. @@ -17,7 +17,7 @@ void Port_prepare(Trigger *_self, Event *event) { } LF_DEBUG(TRIG, "Preparing port %p with %d effects", self, self->effects.size); - Scheduler *sched = self->super.parent->env->scheduler; + Scheduler* sched = self->super.parent->env->scheduler; _self->is_present = true; assert(!_self->is_registered_for_cleanup); sched->register_for_cleanup(sched, _self); @@ -27,7 +27,7 @@ void Port_prepare(Trigger *_self, Event *event) { } } -void Port_set(Port *self, const void *value) { +void Port_set(Port* self, const void* value) { if (self->effects.size > 0 || self->observers.size > 0) { memcpy(self->value_ptr, value, self->value_size); if (!self->super.is_present) { @@ -36,21 +36,21 @@ void Port_set(Port *self, const void *value) { } for (size_t i = 0; i < self->conns_out_registered; i++) { - Connection *conn = self->conns_out[i]; + Connection* conn = self->conns_out[i]; conn->trigger_downstreams(conn, value, self->value_size); } } -void Port_cleanup(Trigger *_self) { +void Port_cleanup(Trigger* _self) { assert(_self->type == TRIG_INPUT || _self->type == TRIG_OUTPUT); assert(_self->is_registered_for_cleanup); LF_DEBUG(TRIG, "Cleaning up port %p", _self); _self->is_present = false; } -void Port_ctor(Port *self, TriggerType type, Reactor *parent, void *value_ptr, size_t value_size, Reaction **effects, - size_t effects_size, Reaction **sources, size_t sources_size, Reaction **observers, - size_t observers_size, Connection **conns_out, size_t conns_out_size) { +void Port_ctor(Port* self, TriggerType type, Reactor* parent, void* value_ptr, size_t value_size, Reaction** effects, + size_t effects_size, Reaction** sources, size_t sources_size, Reaction** observers, + size_t observers_size, Connection** conns_out, size_t conns_out_size) { Trigger_ctor(&self->super, type, parent, NULL, Port_prepare, Port_cleanup); self->set = Port_set; self->conn_in = NULL; diff --git a/src/queues.c b/src/queues.c index 6a00e734a..57df65cf7 100644 --- a/src/queues.c +++ b/src/queues.c @@ -6,12 +6,12 @@ #define GET_TAG(arbitrary_event) (arbitrary_event).event.super.tag #define ACCESS(arr, size, row, col) (arr)[(row) * (size) + (col)] -static void swap(ArbitraryEvent *ev1, ArbitraryEvent *ev2) { +static void swap(ArbitraryEvent* ev1, ArbitraryEvent* ev2) { ArbitraryEvent temp = *ev2; *ev2 = *ev1; *ev1 = temp; } -static tag_t EventQueue_next_tag(EventQueue *self) { +static tag_t EventQueue_next_tag(EventQueue* self) { MUTEX_LOCK(self->mutex); tag_t ret = FOREVER_TAG; if (self->size > 0) { @@ -21,7 +21,7 @@ static tag_t EventQueue_next_tag(EventQueue *self) { return ret; } -static lf_ret_t EventQueue_insert(EventQueue *self, AbstractEvent *event) { +static lf_ret_t EventQueue_insert(EventQueue* self, AbstractEvent* event) { LF_DEBUG(QUEUE, "Inserting event with tag " PRINTF_TAG " into EventQueue", event->tag); MUTEX_LOCK(self->mutex); if (self->size >= self->capacity) { @@ -56,7 +56,7 @@ static lf_ret_t EventQueue_insert(EventQueue *self, AbstractEvent *event) { return LF_OK; } -static void EventQueue_heapify_locked(EventQueue *self, size_t idx) { +static void EventQueue_heapify_locked(EventQueue* self, size_t idx) { LF_DEBUG(QUEUE, "Heapifying EventQueue at index %d", idx); // Find the smallest among root, left child and right child size_t smallest = idx; @@ -77,7 +77,7 @@ static void EventQueue_heapify_locked(EventQueue *self, size_t idx) { } } -static lf_ret_t EventQueue_pop(EventQueue *self, AbstractEvent *event) { +static lf_ret_t EventQueue_pop(EventQueue* self, AbstractEvent* event) { LF_DEBUG(QUEUE, "Popping event from EventQueue"); MUTEX_LOCK(self->mutex); if (self->size == 0) { @@ -111,11 +111,9 @@ static lf_ret_t EventQueue_pop(EventQueue *self, AbstractEvent *event) { return LF_OK; } -static bool EventQueue_empty(EventQueue *self) { - return self->size == 0; -} +static bool EventQueue_empty(EventQueue* self) { return self->size == 0; } -void EventQueue_ctor(EventQueue *self, ArbitraryEvent *array, size_t capacity) { +void EventQueue_ctor(EventQueue* self, ArbitraryEvent* array, size_t capacity) { self->insert = EventQueue_insert; self->pop = EventQueue_pop; self->empty = EventQueue_empty; @@ -127,7 +125,7 @@ void EventQueue_ctor(EventQueue *self, ArbitraryEvent *array, size_t capacity) { Mutex_ctor(&self->mutex.super); } -static lf_ret_t ReactionQueue_insert(ReactionQueue *self, Reaction *reaction) { +static lf_ret_t ReactionQueue_insert(ReactionQueue* self, Reaction* reaction) { validate(reaction); validate(reaction->level < (int)self->capacity); validate(reaction->level >= 0); @@ -147,8 +145,8 @@ static lf_ret_t ReactionQueue_insert(ReactionQueue *self, Reaction *reaction) { return LF_OK; } -static Reaction *ReactionQueue_pop(ReactionQueue *self) { - Reaction *ret = NULL; +static Reaction* ReactionQueue_pop(ReactionQueue* self) { + Reaction* ret = NULL; // Check if we can fetch a new reaction from same level if (self->level_size[self->curr_level] > self->curr_index) { ret = ACCESS(self->array, self->capacity, self->curr_level, self->curr_index); @@ -163,7 +161,7 @@ static Reaction *ReactionQueue_pop(ReactionQueue *self) { return ret; } -static bool ReactionQueue_empty(ReactionQueue *self) { +static bool ReactionQueue_empty(ReactionQueue* self) { if (self->max_active_level < 0 || self->curr_level > self->max_active_level) { return true; } @@ -173,7 +171,7 @@ static bool ReactionQueue_empty(ReactionQueue *self) { return false; } -static void ReactionQueue_reset(ReactionQueue *self) { +static void ReactionQueue_reset(ReactionQueue* self) { self->curr_index = 0; self->curr_level = 0; for (int i = 0; i <= self->max_active_level; i++) { @@ -182,7 +180,7 @@ static void ReactionQueue_reset(ReactionQueue *self) { self->max_active_level = -1; } -void ReactionQueue_ctor(ReactionQueue *self, Reaction **array, int *level_size, size_t capacity) { +void ReactionQueue_ctor(ReactionQueue* self, Reaction** array, int* level_size, size_t capacity) { self->insert = ReactionQueue_insert; self->pop = ReactionQueue_pop; self->empty = ReactionQueue_empty; diff --git a/src/reaction.c b/src/reaction.c index 088be5131..2d1dff5fc 100644 --- a/src/reaction.c +++ b/src/reaction.c @@ -3,20 +3,20 @@ #include "reactor-uc/port.h" #include "reactor-uc/trigger.h" -size_t Reaction_get_level(Reaction *self) { +size_t Reaction_get_level(Reaction* self) { if (self->level < 0) { self->level = (int)self->calculate_level(self); } return self->level; } -int calculate_port_level(Port *port) { +int calculate_port_level(Port* port) { int current = -1; if (port->conn_in) { - Port *final_upstream_port = port->conn_in->get_final_upstream(port->conn_in); + Port* final_upstream_port = port->conn_in->get_final_upstream(port->conn_in); if (final_upstream_port) { for (size_t k = 0; k < final_upstream_port->sources.size; k++) { - Reaction *upstream = final_upstream_port->sources.reactions[k]; + Reaction* upstream = final_upstream_port->sources.reactions[k]; int upstream_level = upstream->get_level(upstream); if (upstream_level > current) { current = upstream_level; @@ -26,7 +26,7 @@ int calculate_port_level(Port *port) { } for (size_t i = 0; i < port->sources.size; i++) { - Reaction *source = port->sources.reactions[i]; + Reaction* source = port->sources.reactions[i]; validate(source); int source_level = source->get_level(source); if (source_level > current) { @@ -38,10 +38,10 @@ int calculate_port_level(Port *port) { return current; } -size_t Reaction_calculate_trigger_level(Reaction *self, Trigger *trigger) { +size_t Reaction_calculate_trigger_level(Reaction* self, Trigger* trigger) { int max_level = 0; if (trigger->type == TRIG_INPUT || trigger->type == TRIG_OUTPUT) { - Port *port = (Port *)trigger; + Port* port = (Port*)trigger; for (size_t j = 0; j < port->effects.size; j++) { if (port->effects.reactions[j] == self) { int level_from_port = calculate_port_level(port) + 1; @@ -62,12 +62,12 @@ size_t Reaction_calculate_trigger_level(Reaction *self, Trigger *trigger) { return max_level; } -size_t Reaction_calculate_level(Reaction *self) { +size_t Reaction_calculate_level(Reaction* self) { size_t max_level = 0; // Possibly inherit level from reactions within same reactor with precedence. if (self->index >= 1) { - Reaction *reaction_prev_index = self->parent->reactions[self->index - 1]; + Reaction* reaction_prev_index = self->parent->reactions[self->index - 1]; size_t prev_level = reaction_prev_index->get_level(reaction_prev_index) + 1; if (prev_level > max_level) { max_level = prev_level; @@ -76,7 +76,7 @@ size_t Reaction_calculate_level(Reaction *self) { // Find all Input ports with the current reaction as an effect for (size_t i = 0; i < self->parent->triggers_size; i++) { - Trigger *trigger = self->parent->triggers[i]; + Trigger* trigger = self->parent->triggers[i]; size_t trigger_from_level = Reaction_calculate_trigger_level(self, trigger); if (trigger_from_level > max_level) { max_level = trigger_from_level; @@ -86,9 +86,9 @@ size_t Reaction_calculate_level(Reaction *self) { // Find all output ports within contained reactors which has marked our reaction // as an effect or observer. for (size_t i = 0; i < self->parent->children_size; i++) { - Reactor *child = self->parent->children[i]; + Reactor* child = self->parent->children[i]; for (size_t j = 0; j < child->triggers_size; j++) { - Trigger *trigger = child->triggers[j]; + Trigger* trigger = child->triggers[j]; size_t trigger_from_level = Reaction_calculate_trigger_level(self, trigger); if (trigger_from_level > max_level) { max_level = trigger_from_level; @@ -99,9 +99,9 @@ size_t Reaction_calculate_level(Reaction *self) { return max_level; } -void Reaction_ctor(Reaction *self, Reactor *parent, void (*body)(Reaction *self), Trigger **effects, - size_t effects_size, size_t index, void (*deadline_violation_handler)(Reaction *), - interval_t deadline, void (*stp_violation_handler)(Reaction *)) { +void Reaction_ctor(Reaction* self, Reactor* parent, void (*body)(Reaction* self), Trigger** effects, + size_t effects_size, size_t index, void (*deadline_violation_handler)(Reaction*), + interval_t deadline, void (*stp_violation_handler)(Reaction*)) { self->body = body; self->parent = parent; self->effects = effects; diff --git a/src/reactor.c b/src/reactor.c index fe25faf48..8f50b6248 100644 --- a/src/reactor.c +++ b/src/reactor.c @@ -6,11 +6,11 @@ #include -void Reactor_validate(Reactor *self) { +void Reactor_validate(Reactor* self) { validate(self->env); int prev_level = -1; for (size_t i = 0; i < self->reactions_size; i++) { - Reaction *reaction = self->reactions[i]; + Reaction* reaction = self->reactions[i]; validate(reaction); validate(reaction->index == i); validate(reaction->parent == self); @@ -18,22 +18,22 @@ void Reactor_validate(Reactor *self) { validate(reaction->level > prev_level); validate(reaction->effects_size == reaction->effects_registered); for (size_t i = 0; i < reaction->effects_size; i++) { - Trigger *effect = reaction->effects[i]; + Trigger* effect = reaction->effects[i]; validate(effect); } prev_level = reaction->level; } for (size_t i = 0; i < self->triggers_size; i++) { - Trigger *trigger = self->triggers[i]; + Trigger* trigger = self->triggers[i]; validate(trigger); if (trigger->type == TRIG_INPUT || trigger->type == TRIG_OUTPUT) { - Port *port = (Port *)trigger; + Port* port = (Port*)trigger; validate(port->effects.num_registered == port->effects.size); validate(port->sources.num_registered == port->sources.size); validate(port->conns_out_size >= port->conns_out_registered); for (size_t i = 0; i < port->conns_out_registered; i++) { - Connection *conn = port->conns_out[i]; + Connection* conn = port->conns_out[i]; validate(conn); validate(conn->upstream == port); } @@ -48,14 +48,14 @@ void Reactor_validate(Reactor *self) { * @brief We only add a single startup event to the event queue, instead * chain all startup triggers together. */ -void Reactor_register_startup(Reactor *self, BuiltinTrigger *startup) { +void Reactor_register_startup(Reactor* self, BuiltinTrigger* startup) { (void)self; LF_DEBUG(ENV, "Registering startup trigger %p with Reactor %s", startup, self->name); - Environment *env = self->env; + Environment* env = self->env; if (!env->startup) { env->startup = startup; } else { - BuiltinTrigger *last_in_chain = env->startup; + BuiltinTrigger* last_in_chain = env->startup; while (last_in_chain->next) { assert(last_in_chain->super.type == TRIG_STARTUP); last_in_chain = last_in_chain->next; @@ -69,16 +69,16 @@ void Reactor_register_startup(Reactor *self, BuiltinTrigger *startup) { * we chain the shutdown triggers together and handle them when we arrive * at the timeout, or due to starvation. */ -void Reactor_register_shutdown(Reactor *self, BuiltinTrigger *shutdown) { +void Reactor_register_shutdown(Reactor* self, BuiltinTrigger* shutdown) { (void)self; LF_DEBUG(ENV, "Registering shutdown trigger %p with Reactor %s", shutdown, self->name); - Environment *env = self->env; + Environment* env = self->env; assert(shutdown->super.type == TRIG_SHUTDOWN); if (!env->shutdown) { env->shutdown = shutdown; } else { - BuiltinTrigger *last_in_chain = env->shutdown; + BuiltinTrigger* last_in_chain = env->shutdown; while (last_in_chain->next) { assert(last_in_chain->super.type == TRIG_SHUTDOWN); last_in_chain = last_in_chain->next; @@ -87,7 +87,7 @@ void Reactor_register_shutdown(Reactor *self, BuiltinTrigger *shutdown) { } } -lf_ret_t Reactor_calculate_levels(Reactor *self) { +lf_ret_t Reactor_calculate_levels(Reactor* self) { validate(self); LF_DEBUG(ENV, "Calculating levels for Reactor %s", self->name); for (size_t i = 0; i < self->reactions_size; i++) { @@ -105,8 +105,8 @@ lf_ret_t Reactor_calculate_levels(Reactor *self) { return LF_OK; } -void Reactor_ctor(Reactor *self, const char *name, Environment *env, Reactor *parent, Reactor **children, - size_t children_size, Reaction **reactions, size_t reactions_size, Trigger **triggers, +void Reactor_ctor(Reactor* self, const char* name, Environment* env, Reactor* parent, Reactor** children, + size_t children_size, Reaction** reactions, size_t reactions_size, Trigger** triggers, size_t triggers_size) { strncpy(self->name, name, REACTOR_NAME_MAX_LEN - 1); // NOLINT self->parent = parent; diff --git a/src/schedulers/dynamic/scheduler.c b/src/schedulers/dynamic/scheduler.c index fe7831802..eebd1aeb1 100644 --- a/src/schedulers/dynamic/scheduler.c +++ b/src/schedulers/dynamic/scheduler.c @@ -12,16 +12,16 @@ * @brief Builtin triggers (startup/shutdown) are chained together as a linked * list and to prepare such a trigger we must iterate through the list. */ -static void Scheduler_prepare_builtin(Event *event) { - Trigger *trigger = event->trigger; +static void Scheduler_prepare_builtin(Event* event) { + Trigger* trigger = event->trigger; do { trigger->prepare(trigger, event); - trigger = (Trigger *)((BuiltinTrigger *)trigger)->next; + trigger = (Trigger*)((BuiltinTrigger*)trigger)->next; } while (trigger); } -static void Scheduler_pop_system_events_and_handle(Scheduler *untyped_self, tag_t next_tag) { - DynamicScheduler *self = (DynamicScheduler *)untyped_self; +static void Scheduler_pop_system_events_and_handle(Scheduler* untyped_self, tag_t next_tag) { + DynamicScheduler* self = (DynamicScheduler*)untyped_self; lf_ret_t ret; validate(self->system_event_queue); @@ -29,7 +29,7 @@ static void Scheduler_pop_system_events_and_handle(Scheduler *untyped_self, tag_ do { ArbitraryEvent _event; - SystemEvent *system_event = &_event.system_event; + SystemEvent* system_event = &_event.system_event; ret = self->system_event_queue->pop(self->system_event_queue, &system_event->super); validate(ret == LF_OK); @@ -46,8 +46,8 @@ static void Scheduler_pop_system_events_and_handle(Scheduler *untyped_self, tag_ * @brief Pop off all the events from the event queue which have a tag matching * `next_tag` and prepare the associated triggers. */ -static void Scheduler_pop_events_and_prepare(Scheduler *untyped_self, tag_t next_tag) { - DynamicScheduler *self = (DynamicScheduler *)untyped_self; +static void Scheduler_pop_events_and_prepare(Scheduler* untyped_self, tag_t next_tag) { + DynamicScheduler* self = (DynamicScheduler*)untyped_self; lf_ret_t ret; if (lf_tag_compare(next_tag, self->event_queue->next_tag(self->event_queue)) != 0) { @@ -56,7 +56,7 @@ static void Scheduler_pop_events_and_prepare(Scheduler *untyped_self, tag_t next do { ArbitraryEvent _event; - Event *event = &_event.event; + Event* event = &_event.event; ret = self->event_queue->pop(self->event_queue, &event->super); @@ -68,7 +68,7 @@ static void Scheduler_pop_events_and_prepare(Scheduler *untyped_self, tag_t next assert(lf_tag_compare(event->super.tag, next_tag) == 0); LF_DEBUG(SCHED, "Handling event %p for tag " PRINTF_TAG, event, event->super.tag); - Trigger *trigger = event->trigger; + Trigger* trigger = event->trigger; if (trigger->type == TRIG_STARTUP || trigger->type == TRIG_SHUTDOWN) { Scheduler_prepare_builtin(event); } else { @@ -78,8 +78,8 @@ static void Scheduler_pop_events_and_prepare(Scheduler *untyped_self, tag_t next } while (lf_tag_compare(next_tag, self->event_queue->next_tag(self->event_queue)) == 0); } -void Scheduler_register_for_cleanup(Scheduler *untyped_self, Trigger *trigger) { - DynamicScheduler *self = (DynamicScheduler *)untyped_self; +void Scheduler_register_for_cleanup(Scheduler* untyped_self, Trigger* trigger) { + DynamicScheduler* self = (DynamicScheduler*)untyped_self; LF_DEBUG(SCHED, "Registering trigger %p for cleanup", trigger); if (trigger->is_registered_for_cleanup) { @@ -97,8 +97,8 @@ void Scheduler_register_for_cleanup(Scheduler *untyped_self, Trigger *trigger) { trigger->is_registered_for_cleanup = true; } -void Scheduler_prepare_timestep(Scheduler *untyped_self, tag_t tag) { - DynamicScheduler *self = (DynamicScheduler *)untyped_self; +void Scheduler_prepare_timestep(Scheduler* untyped_self, tag_t tag) { + DynamicScheduler* self = (DynamicScheduler*)untyped_self; // Before setting `current_tag` we must lock because it is read from async and channel context. MUTEX_LOCK(self->mutex); @@ -108,17 +108,17 @@ void Scheduler_prepare_timestep(Scheduler *untyped_self, tag_t tag) { self->reaction_queue->reset(self->reaction_queue); } -void Scheduler_clean_up_timestep(Scheduler *untyped_self) { - DynamicScheduler *self = (DynamicScheduler *)untyped_self; +void Scheduler_clean_up_timestep(Scheduler* untyped_self) { + DynamicScheduler* self = (DynamicScheduler*)untyped_self; assert(self->reaction_queue->empty(self->reaction_queue)); assert(self->cleanup_ll_head && self->cleanup_ll_tail); LF_DEBUG(SCHED, "Cleaning up timestep for tag " PRINTF_TAG, self->current_tag); - Trigger *cleanup_trigger = self->cleanup_ll_head; + Trigger* cleanup_trigger = self->cleanup_ll_head; while (cleanup_trigger) { - Trigger *this = cleanup_trigger; + Trigger* this = cleanup_trigger; assert(!(this->next == NULL && this != self->cleanup_ll_tail)); this->cleanup(this); this->is_registered_for_cleanup = false; @@ -138,12 +138,12 @@ void Scheduler_clean_up_timestep(Scheduler *untyped_self) { * @param reaction * @return true if a violation was detected and handled, false otherwise. */ -static bool _Scheduler_check_and_handle_stp_violations(DynamicScheduler *self, Reaction *reaction) { - Reactor *parent = reaction->parent; +static bool _Scheduler_check_and_handle_stp_violations(DynamicScheduler* self, Reaction* reaction) { + Reactor* parent = reaction->parent; for (size_t i = 0; i < parent->triggers_size; i++) { - Trigger *trigger = parent->triggers[i]; + Trigger* trigger = parent->triggers[i]; if (trigger->type == TRIG_INPUT && trigger->is_present) { - Port *port = (Port *)trigger; + Port* port = (Port*)trigger; if (lf_tag_compare(port->intended_tag, self->current_tag) == 0) { continue; } @@ -175,7 +175,7 @@ static bool _Scheduler_check_and_handle_stp_violations(DynamicScheduler *self, R * @param reaction * @return true if a violation was detected and handled, false otherwise. */ -static bool _Scheduler_check_and_handle_deadline_violations(DynamicScheduler *self, Reaction *reaction) { +static bool _Scheduler_check_and_handle_deadline_violations(DynamicScheduler* self, Reaction* reaction) { if (self->env->get_lag(self->env) >= reaction->deadline) { LF_WARN(SCHED, "Deadline violation detected for %s->reaction_%d", reaction->parent->name, reaction->index); reaction->deadline_violation_handler(reaction); @@ -184,11 +184,11 @@ static bool _Scheduler_check_and_handle_deadline_violations(DynamicScheduler *se return false; } -void Scheduler_run_timestep(Scheduler *untyped_self) { - DynamicScheduler *self = (DynamicScheduler *)untyped_self; +void Scheduler_run_timestep(Scheduler* untyped_self) { + DynamicScheduler* self = (DynamicScheduler*)untyped_self; while (!self->reaction_queue->empty(self->reaction_queue)) { - Reaction *reaction = self->reaction_queue->pop(self->reaction_queue); + Reaction* reaction = self->reaction_queue->pop(self->reaction_queue); if (reaction->stp_violation_handler != NULL) { if (_Scheduler_check_and_handle_stp_violations(self, reaction)) { @@ -207,15 +207,15 @@ void Scheduler_run_timestep(Scheduler *untyped_self) { } } -void Scheduler_do_shutdown(Scheduler *untyped_self, tag_t shutdown_tag) { - DynamicScheduler *self = (DynamicScheduler *)untyped_self; +void Scheduler_do_shutdown(Scheduler* untyped_self, tag_t shutdown_tag) { + DynamicScheduler* self = (DynamicScheduler*)untyped_self; LF_INFO(SCHED, "Scheduler terminating at tag " PRINTF_TAG, shutdown_tag); self->super.prepare_timestep(untyped_self, shutdown_tag); Scheduler_pop_events_and_prepare(untyped_self, shutdown_tag); - Trigger *shutdown = &self->env->shutdown->super; + Trigger* shutdown = &self->env->shutdown->super; Event event = EVENT_INIT(shutdown_tag, shutdown, NULL); if (shutdown) { @@ -226,8 +226,8 @@ void Scheduler_do_shutdown(Scheduler *untyped_self, tag_t shutdown_tag) { } } -void Scheduler_set_and_schedule_start_tag(Scheduler *untyped_self, instant_t start_time) { - DynamicScheduler *self = (DynamicScheduler *)untyped_self; +void Scheduler_set_and_schedule_start_tag(Scheduler* untyped_self, instant_t start_time) { + DynamicScheduler* self = (DynamicScheduler*)untyped_self; // Set start and stop tags. This is always called from the runtime context. But asynchronous and channel context // read start_time and stop_tag when calling `Scheduler_schedule_at` and thus we must lock before updating them. @@ -241,10 +241,10 @@ void Scheduler_set_and_schedule_start_tag(Scheduler *untyped_self, instant_t sta // Initial events will be scheduled by the Startup Coordinator, based on which policy was selected } -void Scheduler_run(Scheduler *untyped_self) { - DynamicScheduler *self = (DynamicScheduler *)untyped_self; +void Scheduler_run(Scheduler* untyped_self) { + DynamicScheduler* self = (DynamicScheduler*)untyped_self; - Environment *env = self->env; + Environment* env = self->env; lf_ret_t res; tag_t start_tag = {.time = untyped_self->start_time, .microstep = 0}; tag_t next_tag = NEVER_TAG; @@ -262,7 +262,7 @@ void Scheduler_run(Scheduler *untyped_self) { LF_WARN(SCHED, "Dropping event with tag " PRINTF_TAG " because it is before start tag " PRINTF_TAG, next_tag, start_tag); ArbitraryEvent e; - self->event_queue->pop(self->event_queue, (AbstractEvent *)&e); + self->event_queue->pop(self->event_queue, (AbstractEvent*)&e); e.event.trigger->payload_pool->free(e.event.trigger->payload_pool, e.event.super.payload); continue; } @@ -353,8 +353,8 @@ void Scheduler_run(Scheduler *untyped_self) { self->super.do_shutdown(untyped_self, shutdown_tag); } -lf_ret_t Scheduler_schedule_at(Scheduler *super, Event *event) { - DynamicScheduler *self = (DynamicScheduler *)super; +lf_ret_t Scheduler_schedule_at(Scheduler* super, Event* event) { + DynamicScheduler* self = (DynamicScheduler*)super; lf_ret_t ret; // This can be called from the async context and the channel context. It reads stop_tag, current_tag, start_time @@ -387,7 +387,7 @@ lf_ret_t Scheduler_schedule_at(Scheduler *super, Event *event) { } } - ret = self->event_queue->insert(self->event_queue, (AbstractEvent *)event); + ret = self->event_queue->insert(self->event_queue, (AbstractEvent*)event); validate(ret == LF_OK); self->env->platform->notify(self->env->platform); @@ -397,12 +397,12 @@ lf_ret_t Scheduler_schedule_at(Scheduler *super, Event *event) { return ret; } -lf_ret_t Scheduler_schedule_system_event_at(Scheduler *super, SystemEvent *event) { - DynamicScheduler *self = (DynamicScheduler *)super; +lf_ret_t Scheduler_schedule_system_event_at(Scheduler* super, SystemEvent* event) { + DynamicScheduler* self = (DynamicScheduler*)super; lf_ret_t ret; MUTEX_LOCK(self->mutex); - ret = self->system_event_queue->insert(self->system_event_queue, (AbstractEvent *)event); + ret = self->system_event_queue->insert(self->system_event_queue, (AbstractEvent*)event); validate(ret == LF_OK); MUTEX_UNLOCK(self->mutex); @@ -410,14 +410,12 @@ lf_ret_t Scheduler_schedule_system_event_at(Scheduler *super, SystemEvent *event return LF_OK; } -void Scheduler_set_duration(Scheduler *self, interval_t duration) { - self->duration = duration; -} +void Scheduler_set_duration(Scheduler* self, interval_t duration) { self->duration = duration; } -void Scheduler_request_shutdown(Scheduler *untyped_self) { - DynamicScheduler *self = (DynamicScheduler *)untyped_self; +void Scheduler_request_shutdown(Scheduler* untyped_self) { + DynamicScheduler* self = (DynamicScheduler*)untyped_self; - Environment *env = self->env; + Environment* env = self->env; // request shutdown is called from reactions which are not executed in critical sections. // Thus we enter a critical section before setting the stop tag. MUTEX_LOCK(self->mutex); @@ -428,9 +426,9 @@ void Scheduler_request_shutdown(Scheduler *untyped_self) { } /** If the clock is stepped, forward or backward, we need to adjust the tags of all events in the system event queue. */ -static void Scheduler_step_clock(Scheduler *_self, interval_t step) { - DynamicScheduler *self = (DynamicScheduler *)_self; - EventQueue *q = self->system_event_queue; +static void Scheduler_step_clock(Scheduler* _self, interval_t step) { + DynamicScheduler* self = (DynamicScheduler*)_self; + EventQueue* q = self->system_event_queue; // Note that we must lock the mutex of the queue, not the scheduler to do this! MUTEX_LOCK(q->mutex); @@ -446,18 +444,16 @@ static void Scheduler_step_clock(Scheduler *_self, interval_t step) { MUTEX_UNLOCK(q->mutex); } -lf_ret_t Scheduler_add_to_reaction_queue(Scheduler *untyped_self, Reaction *reaction) { - DynamicScheduler *self = (DynamicScheduler *)untyped_self; +lf_ret_t Scheduler_add_to_reaction_queue(Scheduler* untyped_self, Reaction* reaction) { + DynamicScheduler* self = (DynamicScheduler*)untyped_self; return self->reaction_queue->insert(self->reaction_queue, reaction); } -tag_t Scheduler_current_tag(Scheduler *untyped_self) { - return ((DynamicScheduler *)untyped_self)->current_tag; -} +tag_t Scheduler_current_tag(Scheduler* untyped_self) { return ((DynamicScheduler*)untyped_self)->current_tag; } -void DynamicScheduler_ctor(DynamicScheduler *self, Environment *env, EventQueue *event_queue, - EventQueue *system_event_queue, ReactionQueue *reaction_queue, interval_t duration, +void DynamicScheduler_ctor(DynamicScheduler* self, Environment* env, EventQueue* event_queue, + EventQueue* system_event_queue, ReactionQueue* reaction_queue, interval_t duration, bool keep_alive) { self->env = env; diff --git a/src/schedulers/static/instructions.c b/src/schedulers/static/instructions.c index 78f8d4c2d..17a42919c 100644 --- a/src/schedulers/static/instructions.c +++ b/src/schedulers/static/instructions.c @@ -21,23 +21,23 @@ #endif #define SPIN_WAIT_THRESHOLD SEC(1) -const void *zero; +const void* zero; /** * @brief The implementation of the ADD instruction */ -void execute_inst_ADD(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, // NOLINT - operand_t op3, bool debug, size_t *program_counter, Reaction **returned_reaction, - bool *exit_loop) { +void execute_inst_ADD(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, // NOLINT + operand_t op3, bool debug, size_t* program_counter, Reaction** returned_reaction, + bool* exit_loop) { (void)worker_number; (void)debug; (void)returned_reaction; (void)exit_loop; (void)platform; - reg_t *dst = op1.reg; - reg_t *src = op2.reg; - reg_t *src2 = op3.reg; + reg_t* dst = op1.reg; + reg_t* src = op2.reg; + reg_t* src2 = op3.reg; *dst = *src + *src2; *program_counter += 1; // Increment pc. } @@ -45,16 +45,16 @@ void execute_inst_ADD(Platform *platform, size_t worker_number, operand_t op1, o /** * @brief The implementation of the ADDI instruction */ -void execute_inst_ADDI(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, - bool debug, size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_ADDI(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, + bool debug, size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)debug; (void)returned_reaction; (void)exit_loop; (void)platform; - reg_t *dst = op1.reg; - reg_t *src = op2.reg; + reg_t* dst = op1.reg; + reg_t* src = op2.reg; // FIXME: Will there be problems if instant_t adds reg_t? *dst = *src + op3.imm; *program_counter += 1; // Increment pc. @@ -63,16 +63,16 @@ void execute_inst_ADDI(Platform *platform, size_t worker_number, operand_t op1, /** * @brief The implementation of the BEQ instruction */ -void execute_inst_BEQ(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_BEQ(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)debug; (void)returned_reaction; (void)exit_loop; (void)platform; - reg_t *_op1 = op1.reg; - reg_t *_op2 = op2.reg; + reg_t* _op1 = op1.reg; + reg_t* _op2 = op2.reg; // These NULL checks allow _op1 and _op2 to be uninitialized in the static // schedule, which can save a few lines in the schedule. But it is debatable // whether this is good practice. @@ -85,16 +85,16 @@ void execute_inst_BEQ(Platform *platform, size_t worker_number, operand_t op1, o /** * @brief The implementation of the BGE instruction */ -void execute_inst_BGE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_BGE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)debug; (void)returned_reaction; (void)exit_loop; (void)platform; - reg_t *_op1 = op1.reg; - reg_t *_op2 = op2.reg; + reg_t* _op1 = op1.reg; + reg_t* _op2 = op2.reg; if (_op1 != NULL && _op2 != NULL && *_op1 >= *_op2) *program_counter = op3.imm; else @@ -104,16 +104,16 @@ void execute_inst_BGE(Platform *platform, size_t worker_number, operand_t op1, o /** * @brief The implementation of the BLT instruction */ -void execute_inst_BLT(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_BLT(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)debug; (void)returned_reaction; (void)exit_loop; (void)platform; - reg_t *_op1 = op1.reg; - reg_t *_op2 = op2.reg; + reg_t* _op1 = op1.reg; + reg_t* _op2 = op2.reg; if (_op1 != NULL && _op2 != NULL && *_op1 < *_op2) *program_counter = op3.imm; else @@ -123,16 +123,16 @@ void execute_inst_BLT(Platform *platform, size_t worker_number, operand_t op1, o /** * @brief The implementation of the BNE instruction */ -void execute_inst_BNE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_BNE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)debug; (void)returned_reaction; (void)exit_loop; (void)platform; - reg_t *_op1 = op1.reg; - reg_t *_op2 = op2.reg; + reg_t* _op1 = op1.reg; + reg_t* _op2 = op2.reg; if (_op1 != NULL && _op2 != NULL && *_op1 != *_op2) *program_counter = op3.imm; else @@ -142,8 +142,8 @@ void execute_inst_BNE(Platform *platform, size_t worker_number, operand_t op1, o /** * @brief The implementation of the DU instruction */ -void execute_inst_DU(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_DU(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)op3; (void)debug; @@ -154,7 +154,7 @@ void execute_inst_DU(Platform *platform, size_t worker_number, operand_t op1, op // FIXME: There seems to be an overflow problem. // When wakeup_time overflows but lf_time_physical() doesn't, // _lf_interruptable_sleep_until_locked() terminates immediately. - reg_t *src = op1.reg; + reg_t* src = op1.reg; instant_t current_time = platform->get_physical_time(platform); instant_t wakeup_time = *src + op2.imm; instant_t wait_interval = wakeup_time - current_time; @@ -183,19 +183,19 @@ void execute_inst_DU(Platform *platform, size_t worker_number, operand_t op1, op /** * @brief The implementation of the EXE instruction */ -void execute_inst_EXE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_EXE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)op3; (void)debug; (void)returned_reaction; (void)exit_loop; (void)platform; - void (*function)(Reaction *); + void (*function)(Reaction*); - function = (void (*)(Reaction *))(uintptr_t)op1.reg; + function = (void (*)(Reaction*))(uintptr_t)op1.reg; - Reaction *args = (Reaction *)op2.reg; + Reaction* args = (Reaction*)op2.reg; // Execute the function directly. function(args); *program_counter += 1; // Increment pc. @@ -204,8 +204,8 @@ void execute_inst_EXE(Platform *platform, size_t worker_number, operand_t op1, o /** * @brief The implementation of the WLT instruction */ -void execute_inst_WLT(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_WLT(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)op3; (void)debug; @@ -213,7 +213,7 @@ void execute_inst_WLT(Platform *platform, size_t worker_number, operand_t op1, o (void)exit_loop; (void)platform; - reg_t *var = op1.reg; + reg_t* var = op1.reg; while (*var >= op2.imm) ; *program_counter += 1; // Increment pc. @@ -222,8 +222,8 @@ void execute_inst_WLT(Platform *platform, size_t worker_number, operand_t op1, o /** * @brief The implementation of the WU instruction */ -void execute_inst_WU(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_WU(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)op3; (void)debug; @@ -231,7 +231,7 @@ void execute_inst_WU(Platform *platform, size_t worker_number, operand_t op1, op (void)exit_loop; (void)platform; - reg_t *var = op1.reg; + reg_t* var = op1.reg; while (*var < op2.imm) ; *program_counter += 1; // Increment pc. @@ -240,8 +240,8 @@ void execute_inst_WU(Platform *platform, size_t worker_number, operand_t op1, op /** * @brief The implementation of the JAL instruction */ -void execute_inst_JAL(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_JAL(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)debug; (void)returned_reaction; @@ -250,7 +250,7 @@ void execute_inst_JAL(Platform *platform, size_t worker_number, operand_t op1, o // Use the destination register as the return address and, if the // destination register is not the zero register, store program_counter+1 in it. - reg_t *destReg = op1.reg; + reg_t* destReg = op1.reg; if (destReg != zero) { *destReg = *program_counter + 1; } @@ -260,8 +260,8 @@ void execute_inst_JAL(Platform *platform, size_t worker_number, operand_t op1, o /** * @brief The implementation of the JALR instruction */ -void execute_inst_JALR(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, - bool debug, size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_JALR(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, + bool debug, size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)debug; (void)returned_reaction; @@ -270,19 +270,19 @@ void execute_inst_JALR(Platform *platform, size_t worker_number, operand_t op1, // Use the destination register as the return address and, if the // destination register is not the zero register, store program_counter+1 in it. - reg_t *destReg = op1.reg; + reg_t* destReg = op1.reg; if (destReg != zero) *destReg = *program_counter + 1; // Set program_counter to base addr + immediate. - reg_t *baseAddr = op2.reg; + reg_t* baseAddr = op2.reg; *program_counter = *baseAddr + op3.imm; } /** * @brief The implementation of the STP instruction */ -void execute_inst_STP(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, - size_t *program_counter, Reaction **returned_reaction, bool *exit_loop) { +void execute_inst_STP(Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug, + size_t* program_counter, Reaction** returned_reaction, bool* exit_loop) { (void)worker_number; (void)debug; (void)returned_reaction; diff --git a/src/schedulers/static/scheduler.c b/src/schedulers/static/scheduler.c index 36f7a85de..ba0c5eec3 100644 --- a/src/schedulers/static/scheduler.c +++ b/src/schedulers/static/scheduler.c @@ -6,13 +6,13 @@ #include "reactor-uc/schedulers/static/instructions.h" #include "reactor-uc/schedulers/static/scheduler.h" -Reaction *lf_sched_get_ready_reaction(StaticScheduler *scheduler, int worker_number) { +Reaction* lf_sched_get_ready_reaction(StaticScheduler* scheduler, int worker_number) { LF_PRINT_DEBUG("Worker %d inside lf_sched_get_ready_reaction", worker_number); - const inst_t *current_schedule = scheduler->static_schedule[worker_number]; - Reaction *returned_reaction = NULL; + const inst_t* current_schedule = scheduler->static_schedule[worker_number]; + Reaction* returned_reaction = NULL; bool exit_loop = false; - size_t *pc = &scheduler->pc[worker_number]; + size_t* pc = &scheduler->pc[worker_number]; function_virtual_instruction_t func; operand_t op1; @@ -35,7 +35,7 @@ Reaction *lf_sched_get_ready_reaction(StaticScheduler *scheduler, int worker_num return returned_reaction; } -void StaticScheduler_ctor(StaticScheduler *self, Environment *env, const inst_t **static_schedule) { +void StaticScheduler_ctor(StaticScheduler* self, Environment* env, const inst_t** static_schedule) { self->env = env; self->static_schedule = static_schedule; diff --git a/src/serialization.c b/src/serialization.c index 216adf3b8..b2e334f5c 100644 --- a/src/serialization.c +++ b/src/serialization.c @@ -8,7 +8,7 @@ #endif #define MIN(x, y) (((x) < (y)) ? (x) : (y)) -int serialize_to_protobuf(const FederateMessage *message, unsigned char *buffer, size_t buffer_size) { +int serialize_to_protobuf(const FederateMessage* message, unsigned char* buffer, size_t buffer_size) { // turing write buffer into pb_ostream buffer pb_ostream_t stream_out = pb_ostream_from_buffer(buffer, buffer_size); @@ -20,7 +20,7 @@ int serialize_to_protobuf(const FederateMessage *message, unsigned char *buffer, return (int)stream_out.bytes_written; } -int deserialize_from_protobuf(FederateMessage *message, const unsigned char *buffer, size_t buffer_size) { +int deserialize_from_protobuf(FederateMessage* message, const unsigned char* buffer, size_t buffer_size) { pb_istream_t stream_in = pb_istream_from_buffer(buffer, buffer_size); if (!pb_decode_delimited(&stream_in, FederateMessage_fields, message)) { @@ -30,7 +30,7 @@ int deserialize_from_protobuf(FederateMessage *message, const unsigned char *buf return (int)stream_in.bytes_left; } -lf_ret_t deserialize_payload_default(void *user_struct, const unsigned char *msg_buf, size_t msg_size) { +lf_ret_t deserialize_payload_default(void* user_struct, const unsigned char* msg_buf, size_t msg_size) { if (msg_size > SERIALIZATION_MAX_PAYLOAD_SIZE) { return LF_ERR; } @@ -38,7 +38,7 @@ lf_ret_t deserialize_payload_default(void *user_struct, const unsigned char *msg return LF_OK; } -int serialize_payload_default(const void *user_struct, size_t user_struct_size, unsigned char *msg_buf) { +int serialize_payload_default(const void* user_struct, size_t user_struct_size, unsigned char* msg_buf) { if (user_struct_size > SERIALIZATION_MAX_PAYLOAD_SIZE) { return -1; } diff --git a/src/startup_coordinator.c b/src/startup_coordinator.c index 54e6eaad7..79b4b4b1e 100644 --- a/src/startup_coordinator.c +++ b/src/startup_coordinator.c @@ -16,8 +16,8 @@ /** * @brief Open connections to all neighbors. This function will block until all connections are established. */ -static lf_ret_t StartupCoordinator_connect_to_neighbors_blocking(StartupCoordinator *self) { - FederatedEnvironment *env_fed = (FederatedEnvironment *)self->env; +static lf_ret_t StartupCoordinator_connect_to_neighbors_blocking(StartupCoordinator* self) { + FederatedEnvironment* env_fed = (FederatedEnvironment*)self->env; validate(self->state == StartupCoordinationState_UNINITIALIZED); self->state = StartupCoordinationState_CONNECTING; LF_DEBUG(FED, "%s connecting to %zu federated peers", self->env->main->name, env_fed->net_bundles_size); @@ -25,8 +25,8 @@ static lf_ret_t StartupCoordinator_connect_to_neighbors_blocking(StartupCoordina // Open all connections. for (size_t i = 0; i < env_fed->net_bundles_size; i++) { - FederatedConnectionBundle *bundle = env_fed->net_bundles[i]; - NetworkChannel *chan = bundle->net_channel; + FederatedConnectionBundle* bundle = env_fed->net_bundles[i]; + NetworkChannel* chan = bundle->net_channel; ret = chan->open_connection(chan); // If we cannot open our network channels, then we cannot proceed and must abort. validate(ret == LF_OK); @@ -38,7 +38,7 @@ static lf_ret_t StartupCoordinator_connect_to_neighbors_blocking(StartupCoordina // Wait time initialized to minimum value so we can find the maximum. all_connected = true; for (size_t i = 0; i < self->num_neighbours; i++) { - NetworkChannel *chan = env_fed->net_bundles[i]->net_channel; + NetworkChannel* chan = env_fed->net_bundles[i]->net_channel; // Check whether the neighbor has reached the desired state. if (!chan->is_connected(chan)) { // If a retry function is provided, call it. @@ -61,13 +61,13 @@ static lf_ret_t StartupCoordinator_connect_to_neighbors_blocking(StartupCoordina return LF_OK; } -void StartupCoordinator_schedule_timers_joining(StartupCoordinator *self, Reactor *reactor, +void StartupCoordinator_schedule_timers_joining(StartupCoordinator* self, Reactor* reactor, interval_t federation_start_time, interval_t join_time) { lf_ret_t ret; for (size_t i = 0; i < reactor->triggers_size; i++) { - Trigger *trigger = reactor->triggers[i]; + Trigger* trigger = reactor->triggers[i]; if (trigger->type == TRIG_TIMER) { - Timer *timer = (Timer *)trigger; + Timer* timer = (Timer*)trigger; const interval_t duration = join_time - federation_start_time - timer->offset; const interval_t individual_join_time = ((duration / timer->period) + 1) * timer->period + federation_start_time; tag_t tag = {.time = individual_join_time + timer->offset, .microstep = 0}; @@ -82,11 +82,11 @@ void StartupCoordinator_schedule_timers_joining(StartupCoordinator *self, Reacto } /** Schedule a system-event with `self` as the origin for some future time. */ -static void StartupCoordinator_schedule_system_self_event(StartupCoordinator *self, instant_t time, int message_type) { - StartupEvent *payload = NULL; +static void StartupCoordinator_schedule_system_self_event(StartupCoordinator* self, instant_t time, int message_type) { + StartupEvent* payload = NULL; lf_ret_t ret; // Allocate one of the reserved events for our own use. - ret = self->super.payload_pool.allocate_reserved(&self->super.payload_pool, (void **)&payload); + ret = self->super.payload_pool.allocate_reserved(&self->super.payload_pool, (void**)&payload); if (ret != LF_OK) { LF_ERR(FED, "Failed to allocate payload for startup system event."); @@ -108,11 +108,11 @@ static void StartupCoordinator_schedule_system_self_event(StartupCoordinator *se } /** Handle an incoming message from the network. Invoked from an async context in a critical section. */ -static void StartupCoordinator_handle_message_callback(StartupCoordinator *self, const StartupCoordination *msg, +static void StartupCoordinator_handle_message_callback(StartupCoordinator* self, const StartupCoordination* msg, size_t bundle_idx) { LF_DEBUG(FED, "Received startup message from neighbor %zu. Scheduling as a system event", bundle_idx); - ClockSyncEvent *payload = NULL; - lf_ret_t ret = self->super.payload_pool.allocate(&self->super.payload_pool, (void **)&payload); + ClockSyncEvent* payload = NULL; + lf_ret_t ret = self->super.payload_pool.allocate(&self->super.payload_pool, (void**)&payload); if (ret == LF_OK) { payload->neighbor_index = bundle_idx; memcpy(&payload->msg, msg, sizeof(StartupCoordination)); @@ -130,16 +130,16 @@ static void StartupCoordinator_handle_message_callback(StartupCoordinator *self, } /** Handle a request, either local or external, to do a startup handshake. This is called from the runtime context. */ -static void StartupCoordinator_handle_startup_handshake_request(StartupCoordinator *self, StartupEvent *payload) { +static void StartupCoordinator_handle_startup_handshake_request(StartupCoordinator* self, StartupEvent* payload) { lf_ret_t ret; - FederatedEnvironment *env_fed = (FederatedEnvironment *)self->env; + FederatedEnvironment* env_fed = (FederatedEnvironment*)self->env; if (payload->neighbor_index == NEIGHBOR_INDEX_SELF) { LF_DEBUG(FED, "Received handshake request from self"); switch (self->state) { case StartupCoordinationState_HANDSHAKING: for (size_t i = 0; i < self->num_neighbours; i++) { - FederateMessage *msg = &env_fed->net_bundles[i]->send_msg; - NetworkChannel *chan = env_fed->net_bundles[i]->net_channel; + FederateMessage* msg = &env_fed->net_bundles[i]->send_msg; + NetworkChannel* chan = env_fed->net_bundles[i]->net_channel; if (!self->neighbor_state[i].handshake_response_received) { msg->which_message = FederateMessage_startup_coordination_tag; @@ -159,8 +159,8 @@ static void StartupCoordinator_handle_startup_handshake_request(StartupCoordinat LF_DEBUG(FED, "Received handshake request from federate %d", payload->neighbor_index); // Received a handshake request from a neighbor. Respond with our current state. self->neighbor_state[payload->neighbor_index].handshake_request_received = true; - FederateMessage *msg = &env_fed->net_bundles[payload->neighbor_index]->send_msg; - NetworkChannel *chan = env_fed->net_bundles[payload->neighbor_index]->net_channel; + FederateMessage* msg = &env_fed->net_bundles[payload->neighbor_index]->send_msg; + NetworkChannel* chan = env_fed->net_bundles[payload->neighbor_index]->net_channel; msg->which_message = FederateMessage_startup_coordination_tag; msg->message.startup_coordination.which_message = StartupCoordination_startup_handshake_response_tag; msg->message.startup_coordination.message.startup_handshake_response.state = self->state; @@ -183,7 +183,7 @@ static void StartupCoordinator_handle_startup_handshake_request(StartupCoordinat } /** Handle external handshake responses. */ -static void StartupCoordinator_handle_startup_handshake_response(StartupCoordinator *self, StartupEvent *payload) { +static void StartupCoordinator_handle_startup_handshake_response(StartupCoordinator* self, StartupEvent* payload) { LF_DEBUG(FED, "Received handshake response from federate %d", payload->neighbor_index); switch (self->state) { case StartupCoordinationState_CONNECTING: @@ -245,12 +245,12 @@ static void StartupCoordinator_handle_startup_handshake_response(StartupCoordina } /** Convenience function to send out a start time proposal to all neighbors for a step. */ -static void send_start_time_proposal(StartupCoordinator *self, instant_t start_time, int step) { +static void send_start_time_proposal(StartupCoordinator* self, instant_t start_time, int step) { lf_ret_t ret; - FederatedEnvironment *env_fed = (FederatedEnvironment *)self->env; + FederatedEnvironment* env_fed = (FederatedEnvironment*)self->env; LF_DEBUG(FED, "Sending start time proposal " PRINTF_TIME " step %d to all neighbors", start_time, step); for (size_t i = 0; i < self->num_neighbours; i++) { - NetworkChannel *chan = env_fed->net_bundles[i]->net_channel; + NetworkChannel* chan = env_fed->net_bundles[i]->net_channel; self->msg.which_message = FederateMessage_startup_coordination_tag; self->msg.message.startup_coordination.which_message = StartupCoordination_start_time_proposal_tag; self->msg.message.startup_coordination.message.start_time_proposal.time = start_time; @@ -262,8 +262,8 @@ static void send_start_time_proposal(StartupCoordinator *self, instant_t start_t } /** Handle a start time proposal, either from self or from neighbor. */ -static void StartupCoordinator_handle_start_time_proposal(StartupCoordinator *self, StartupEvent *payload) { - FederatedEnvironment *env_fed = (FederatedEnvironment *)self->env; +static void StartupCoordinator_handle_start_time_proposal(StartupCoordinator* self, StartupEvent* payload) { + FederatedEnvironment* env_fed = (FederatedEnvironment*)self->env; if (payload->neighbor_index == NEIGHBOR_INDEX_SELF) { LF_DEBUG(FED, "Received start time proposal from self"); switch (self->state) { @@ -355,11 +355,11 @@ static void StartupCoordinator_handle_start_time_proposal(StartupCoordinator *se } } -static void StartupCoordinator_handle_start_time_request(StartupCoordinator *self, StartupEvent *payload) { - FederatedEnvironment *env = (FederatedEnvironment *)self->env; +static void StartupCoordinator_handle_start_time_request(StartupCoordinator* self, StartupEvent* payload) { + FederatedEnvironment* env = (FederatedEnvironment*)self->env; if (payload->neighbor_index == NEIGHBOR_INDEX_SELF) { for (size_t i = 0; i < self->num_neighbours; i++) { - NetworkChannel *chan = env->net_bundles[i]->net_channel; + NetworkChannel* chan = env->net_bundles[i]->net_channel; self->msg.which_message = FederateMessage_startup_coordination_tag; self->msg.message.startup_coordination.which_message = StartupCoordination_start_time_request_tag; lf_ret_t ret; @@ -375,8 +375,8 @@ static void StartupCoordinator_handle_start_time_request(StartupCoordinator *sel } else { switch (self->state) { case StartupCoordinationState_RUNNING: { - FederateMessage *msg = &env->net_bundles[payload->neighbor_index]->send_msg; - NetworkChannel *chan = env->net_bundles[payload->neighbor_index]->net_channel; + FederateMessage* msg = &env->net_bundles[payload->neighbor_index]->send_msg; + NetworkChannel* chan = env->net_bundles[payload->neighbor_index]->net_channel; msg->which_message = FederateMessage_startup_coordination_tag; msg->message.startup_coordination.which_message = StartupCoordination_start_time_response_tag; msg->message.startup_coordination.message.start_time_response.elapsed_logical_time = @@ -393,7 +393,7 @@ static void StartupCoordinator_handle_start_time_request(StartupCoordinator *sel } } -static void StartupCoordinator_handle_start_time_response(StartupCoordinator *self, StartupEvent *payload) { +static void StartupCoordinator_handle_start_time_response(StartupCoordinator* self, StartupEvent* payload) { if (self->start_time_proposal > 0) { return; } @@ -461,16 +461,16 @@ static void StartupCoordinator_handle_start_time_response(StartupCoordinator *se } } -static void StartupCoordinator_handle_join_time_announcement(const StartupCoordinator *self, - const StartupEvent *payload) { +static void StartupCoordinator_handle_join_time_announcement(const StartupCoordinator* self, + const StartupEvent* payload) { if (payload->neighbor_index != NEIGHBOR_INDEX_SELF) { - const FederatedEnvironment *env = (FederatedEnvironment *)self->env; + const FederatedEnvironment* env = (FederatedEnvironment*)self->env; for (size_t i = 0; i < env->net_bundles_size; i++) { if (env->net_bundles[i]->index == (size_t)payload->neighbor_index) { // we found the correct connection bundle to this federate now we set last known tag to the joining time. - const FederatedConnectionBundle *bundle = env->net_bundles[i]; + const FederatedConnectionBundle* bundle = env->net_bundles[i]; for (size_t j = 0; j < bundle->inputs_size; j++) { tag_t joining_time = {.time = payload->msg.message.joining_time_announcement.joining_time, .microstep = 0}; bundle->inputs[i]->last_known_tag = joining_time; @@ -481,9 +481,9 @@ static void StartupCoordinator_handle_join_time_announcement(const StartupCoordi } /** Invoked by scheduler when handling any system event destined for StartupCoordinator. */ -static void StartupCoordinator_handle_system_event(SystemEventHandler *_self, SystemEvent *event) { - StartupCoordinator *self = (StartupCoordinator *)_self; - StartupEvent *payload = (StartupEvent *)event->super.payload; +static void StartupCoordinator_handle_system_event(SystemEventHandler* _self, SystemEvent* event) { + StartupCoordinator* self = (StartupCoordinator*)_self; + StartupEvent* payload = (StartupEvent*)event->super.payload; switch (payload->msg.which_message) { case StartupCoordination_startup_handshake_request_tag: LF_INFO(FED, "Handle: Handshake Reqeust Tag System Event"); @@ -519,14 +519,14 @@ static void StartupCoordinator_handle_system_event(SystemEventHandler *_self, Sy _self->payload_pool.free(&_self->payload_pool, event->super.payload); } -void StartupCoordinator_start(StartupCoordinator *self) { +void StartupCoordinator_start(StartupCoordinator* self) { StartupCoordinator_schedule_system_self_event(self, self->env->get_physical_time(self->env) + MSEC(250), StartupCoordination_startup_handshake_request_tag); } -void StartupCoordinator_ctor(StartupCoordinator *self, Environment *env, NeighborState *neighbor_state, +void StartupCoordinator_ctor(StartupCoordinator* self, Environment* env, NeighborState* neighbor_state, size_t num_neighbors, size_t longest_path, JoiningPolicy joining_policy, - size_t payload_size, void *payload_buf, bool *payload_used_buf, + size_t payload_size, void* payload_buf, bool* payload_used_buf, size_t payload_buf_capacity) { validate(!(longest_path == 0 && num_neighbors > 0)); self->env = env; @@ -551,6 +551,6 @@ void StartupCoordinator_ctor(StartupCoordinator *self, Environment *env, Neighbo self->start = StartupCoordinator_start; self->connect_to_neighbors_blocking = StartupCoordinator_connect_to_neighbors_blocking; self->super.handle = StartupCoordinator_handle_system_event; - EventPayloadPool_ctor(&self->super.payload_pool, (char *)payload_buf, payload_used_buf, payload_size, + EventPayloadPool_ctor(&self->super.payload_pool, (char*)payload_buf, payload_used_buf, payload_size, payload_buf_capacity, NUM_RESERVED_EVENTS); } diff --git a/src/timer.c b/src/timer.c index 9874971bd..e9f82cde3 100644 --- a/src/timer.c +++ b/src/timer.c @@ -2,11 +2,11 @@ #include "reactor-uc/environment.h" #include "reactor-uc/logging.h" -void Timer_prepare(Trigger *_self, Event *event) { +void Timer_prepare(Trigger* _self, Event* event) { (void)event; LF_DEBUG(TRIG, "Preparing timer %p", _self); - Timer *self = (Timer *)_self; - Scheduler *sched = _self->parent->env->scheduler; + Timer* self = (Timer*)_self; + Scheduler* sched = _self->parent->env->scheduler; _self->is_present = true; sched->register_for_cleanup(sched, _self); LF_DEBUG(TRIG, "Triggering %d reactions", self->effects.size); @@ -15,10 +15,10 @@ void Timer_prepare(Trigger *_self, Event *event) { } } -void Timer_cleanup(Trigger *_self) { - Timer *self = (Timer *)_self; - Environment *env = _self->parent->env; - Scheduler *sched = env->scheduler; +void Timer_cleanup(Trigger* _self) { + Timer* self = (Timer*)_self; + Environment* env = _self->parent->env; + Scheduler* sched = env->scheduler; _self->is_present = false; // Schedule next event unless it is a single-shot timer. @@ -29,8 +29,8 @@ void Timer_cleanup(Trigger *_self) { } } -void Timer_ctor(Timer *self, Reactor *parent, instant_t offset, interval_t period, Reaction **effects, - size_t effects_size, Reaction **observers, size_t observers_size) { +void Timer_ctor(Timer* self, Reactor* parent, instant_t offset, interval_t period, Reaction** effects, + size_t effects_size, Reaction** observers, size_t observers_size) { self->offset = offset; self->period = period; diff --git a/src/trigger.c b/src/trigger.c index 395d135d7..c1aa73666 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -1,8 +1,8 @@ #include "reactor-uc/trigger.h" #include "reactor-uc/environment.h" -void Trigger_ctor(Trigger *self, TriggerType type, Reactor *parent, EventPayloadPool *payload_pool, - void (*prepare)(Trigger *, Event *), void (*cleanup)(Trigger *)) { +void Trigger_ctor(Trigger* self, TriggerType type, Reactor* parent, EventPayloadPool* payload_pool, + void (*prepare)(Trigger*, Event*), void (*cleanup)(Trigger*)) { self->type = type; self->parent = parent; self->next = NULL; diff --git a/src/util.c b/src/util.c index 34064959d..e958d0fcc 100644 --- a/src/util.c +++ b/src/util.c @@ -1,6 +1,6 @@ #include "reactor-uc/util.h" -void lf_connect(Connection *connection, Port *upstream, Port *downstream) { +void lf_connect(Connection* connection, Port* upstream, Port* downstream) { if (connection->upstream == NULL) { validate(upstream->conns_out_registered < upstream->conns_out_size); upstream->conns_out[upstream->conns_out_registered++] = connection; @@ -9,12 +9,12 @@ void lf_connect(Connection *connection, Port *upstream, Port *downstream) { connection->register_downstream(connection, downstream); } -void lf_connect_federated_output(Connection *connection, Port *output) { +void lf_connect_federated_output(Connection* connection, Port* output) { validate(output->conns_out_registered < output->conns_out_size); output->conns_out[output->conns_out_registered++] = connection; connection->upstream = output; } -void lf_connect_federated_input(Connection *connection, Port *input) { +void lf_connect_federated_input(Connection* connection, Port* input) { connection->register_downstream(connection, input); } diff --git a/test/unit/action_empty_test.c b/test/unit/action_empty_test.c index 157ead5c7..1e1f2b181 100644 --- a/test/unit/action_empty_test.c +++ b/test/unit/action_empty_test.c @@ -12,12 +12,9 @@ LF_DEFINE_REACTION_BODY(ActionLib, reaction) { self->cnt++; } -LF_DEFINE_REACTION_BODY(ActionLib, r_shutdown) { -} +LF_DEFINE_REACTION_BODY(ActionLib, r_shutdown) {} -void test_run() { - lf_start(); -} +void test_run() { lf_start(); } int main() { UNITY_BEGIN(); diff --git a/test/unit/action_microstep_test.c b/test/unit/action_microstep_test.c index 9366fda5f..c7b4f4443 100644 --- a/test/unit/action_microstep_test.c +++ b/test/unit/action_microstep_test.c @@ -31,11 +31,8 @@ LF_DEFINE_REACTION_BODY(ActionLib, reaction) { } } -LF_DEFINE_REACTION_BODY(ActionLib, r_shutdown) { -} -void test_run() { - lf_start(); -} +LF_DEFINE_REACTION_BODY(ActionLib, r_shutdown) {} +void test_run() { lf_start(); } int main() { UNITY_BEGIN(); RUN_TEST(test_run); diff --git a/test/unit/action_overwrite_test.c b/test/unit/action_overwrite_test.c index 72cbc0d7f..aa2e4202f 100644 --- a/test/unit/action_overwrite_test.c +++ b/test/unit/action_overwrite_test.c @@ -21,11 +21,8 @@ LF_DEFINE_REACTION_BODY(ActionLib, reaction) { self->cnt++; } -LF_DEFINE_REACTION_BODY(ActionLib, r_shutdown) { -} -void test_run() { - lf_start(); -} +LF_DEFINE_REACTION_BODY(ActionLib, r_shutdown) {} +void test_run() { lf_start(); } int main() { UNITY_BEGIN(); RUN_TEST(test_run); diff --git a/test/unit/action_test.c b/test/unit/action_test.c index c135f5419..e19dd4734 100644 --- a/test/unit/action_test.c +++ b/test/unit/action_test.c @@ -26,12 +26,9 @@ LF_DEFINE_REACTION_BODY(ActionLib, reaction) { lf_schedule(act, MSEC(1), ++self->cnt); } -LF_DEFINE_REACTION_BODY(ActionLib, r_shutdown) { -} +LF_DEFINE_REACTION_BODY(ActionLib, r_shutdown) {} -void test_run() { - lf_start(); -} +void test_run() { lf_start(); } int main() { UNITY_BEGIN(); RUN_TEST(test_run); diff --git a/test/unit/delayed_conn_test.c b/test/unit/delayed_conn_test.c index 1941df7c9..4e6c042ca 100644 --- a/test/unit/delayed_conn_test.c +++ b/test/unit/delayed_conn_test.c @@ -27,7 +27,7 @@ LF_DEFINE_REACTION_BODY(Sender, r_sender) { lf_set(out, env->get_elapsed_logical_time(env)); } -LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, OutputExternalCtorArgs *out_external) { +LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, OutputExternalCtorArgs* out_external) { LF_REACTOR_CTOR_PREAMBLE(); LF_REACTOR_CTOR(Sender); LF_INITIALIZE_REACTION(Sender, r_sender, NEVER); @@ -61,7 +61,7 @@ LF_DEFINE_REACTION_BODY(Receiver, r_recv) { TEST_ASSERT_EQUAL(in->value + MSEC(15), env->get_elapsed_logical_time(env)); } -LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs *sources_in) { +LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs* sources_in) { LF_REACTOR_CTOR_PREAMBLE(); LF_REACTOR_CTOR(Receiver); LF_INITIALIZE_REACTION(Receiver, r_recv, NEVER); diff --git a/test/unit/event_payload_pool_test.c b/test/unit/event_payload_pool_test.c index d119ccd6a..0d0825ab5 100644 --- a/test/unit/event_payload_pool_test.c +++ b/test/unit/event_payload_pool_test.c @@ -11,14 +11,14 @@ void test_allocate_free(void) { EventPayloadPool t; int buffer[10]; bool used[10]; - int *payloads[10]; - EventPayloadPool_ctor(&t, (void *)buffer, used, sizeof(int), 10, 0); + int* payloads[10]; + EventPayloadPool_ctor(&t, (void*)buffer, used, sizeof(int), 10, 0); for (int j = 0; j < 3; j++) { int val = 1; for (int i = 0; i < 10; i++) { int val = j * 10 + i; - ret = t.allocate(&t, (void *)&payloads[i]); + ret = t.allocate(&t, (void*)&payloads[i]); TEST_ASSERT_EQUAL(LF_OK, ret); memcpy(payloads[i], &val, sizeof(int)); } @@ -35,8 +35,8 @@ void test_allocate_reserved(void) { EventPayloadPool t; int buffer[2]; bool used[2]; - void *payload; - EventPayloadPool_ctor(&t, (void *)&buffer, used, sizeof(int), 4, 2); + void* payload; + EventPayloadPool_ctor(&t, (void*)&buffer, used, sizeof(int), 4, 2); TEST_ASSERT_EQUAL(LF_OK, t.allocate_reserved(&t, &payload)); TEST_ASSERT_EQUAL(LF_OK, t.allocate_reserved(&t, &payload)); TEST_ASSERT_EQUAL(LF_NO_MEM, t.allocate_reserved(&t, &payload)); @@ -49,8 +49,8 @@ void test_allocate_full(void) { EventPayloadPool t; int buffer[2]; bool used[2]; - void *payload; - EventPayloadPool_ctor(&t, (void *)&buffer, used, sizeof(int), 2, 0); + void* payload; + EventPayloadPool_ctor(&t, (void*)&buffer, used, sizeof(int), 2, 0); TEST_ASSERT_EQUAL(LF_OK, t.allocate(&t, &payload)); TEST_ASSERT_EQUAL(LF_OK, t.allocate(&t, &payload)); TEST_ASSERT_EQUAL(LF_NO_MEM, t.allocate(&t, &payload)); @@ -60,15 +60,15 @@ void test_free_wrong(void) { EventPayloadPool t; int buffer[2]; bool used[2]; - void *payload; + void* payload; - EventPayloadPool_ctor(&t, (void *)&buffer, used, sizeof(int), 2, 0); + EventPayloadPool_ctor(&t, (void*)&buffer, used, sizeof(int), 2, 0); TEST_ASSERT_EQUAL(LF_OK, t.allocate(&t, &payload)); TEST_ASSERT_EQUAL(LF_OK, t.allocate(&t, &payload)); - TEST_ASSERT_EQUAL(LF_INVALID_VALUE, t.free(&t, (void *)&used)); + TEST_ASSERT_EQUAL(LF_INVALID_VALUE, t.free(&t, (void*)&used)); } -Environment *_lf_environment = NULL; +Environment* _lf_environment = NULL; int main(void) { UNITY_BEGIN(); RUN_TEST(test_allocate_free); diff --git a/test/unit/event_queue_test.c b/test/unit/event_queue_test.c index 6b01f949c..8d51ac075 100644 --- a/test/unit/event_queue_test.c +++ b/test/unit/event_queue_test.c @@ -50,7 +50,7 @@ void test_zero_capacity_event_queue(void) { TEST_ASSERT_EQUAL(LF_EMPTY, q.pop(&q, &e.super)); } -Environment *_lf_environment = NULL; +Environment* _lf_environment = NULL; int main(void) { UNITY_BEGIN(); RUN_TEST(test_insert); diff --git a/test/unit/mock.c b/test/unit/mock.c index 978ed121b..d792b7692 100644 --- a/test/unit/mock.c +++ b/test/unit/mock.c @@ -1,7 +1,5 @@ #include "unity.h" // These can be overridden in the test files if needed -__attribute__((weak)) void setUp(void) { -} -__attribute__((weak)) void tearDown(void) { -} \ No newline at end of file +__attribute__((weak)) void setUp(void) {} +__attribute__((weak)) void tearDown(void) {} \ No newline at end of file diff --git a/test/unit/nanopb_test.c b/test/unit/nanopb_test.c index 5476f92a5..675e80798 100644 --- a/test/unit/nanopb_test.c +++ b/test/unit/nanopb_test.c @@ -15,14 +15,14 @@ void test_nanopb() { _original_msg.which_message = FederateMessage_tagged_message_tag; - TaggedMessage *original_message = &_original_msg.message.tagged_message; - TaggedMessage *deserialized_msg = &_deserialized_msg.message.tagged_message; + TaggedMessage* original_message = &_original_msg.message.tagged_message; + TaggedMessage* deserialized_msg = &_deserialized_msg.message.tagged_message; unsigned char buffer[BUFFER_SIZE]; - unsigned char *message = NULL; + unsigned char* message = NULL; int message_size = 0; original_message->conn_id = MSG_ID; - const char *text = "Hello World1234"; + const char* text = "Hello World1234"; memcpy(original_message->payload.bytes, text, sizeof("Hello World1234")); // NOLINT original_message->payload.size = sizeof("Hello World1234"); @@ -35,7 +35,7 @@ void test_nanopb() { TEST_ASSERT_TRUE(remaining_bytes >= 0); TEST_ASSERT_EQUAL(original_message->conn_id, deserialized_msg->conn_id); - TEST_ASSERT_EQUAL_STRING((char *)original_message->payload.bytes, (char *)deserialized_msg->payload.bytes); + TEST_ASSERT_EQUAL_STRING((char*)original_message->payload.bytes, (char*)deserialized_msg->payload.bytes); } int main(void) { diff --git a/test/unit/physical_clock_test.c b/test/unit/physical_clock_test.c index ba3ed1604..5bc558d41 100644 --- a/test/unit/physical_clock_test.c +++ b/test/unit/physical_clock_test.c @@ -4,10 +4,10 @@ #include "reactor-uc/physical_clock.h" Environment env; -Environment *_lf_environment = &env; +Environment* _lf_environment = &env; static instant_t hw_time = 0; -instant_t mock_get_physical_time(Platform *self) { +instant_t mock_get_physical_time(Platform* self) { (void)self; return hw_time; } diff --git a/test/unit/port_test.c b/test/unit/port_test.c index 0286b6c68..68d923159 100644 --- a/test/unit/port_test.c +++ b/test/unit/port_test.c @@ -26,7 +26,7 @@ LF_DEFINE_REACTION_BODY(Sender, r_sender) { // printf("Timer triggered @ %ld\n", env->get_elapsed_logical_time(env)); lf_set(out, env->get_elapsed_logical_time(env)); } -LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, OutputExternalCtorArgs *out_external) { +LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Sender, OutputExternalCtorArgs* out_external) { LF_REACTOR_CTOR_PREAMBLE(); LF_REACTOR_CTOR(Sender); LF_INITIALIZE_REACTION(Sender, r_sender, NEVER); @@ -60,7 +60,7 @@ LF_DEFINE_REACTION_BODY(Receiver, r_recv) { TEST_ASSERT_EQUAL(in->value, env->get_elapsed_logical_time(env)); } -LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs *in_external) { +LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs* in_external) { LF_REACTOR_CTOR(Receiver); LF_REACTOR_CTOR_PREAMBLE(); LF_INITIALIZE_REACTION(Receiver, r_recv, NEVER); diff --git a/test/unit/reaction_queue_test.c b/test/unit/reaction_queue_test.c index 00123d471..5ae0c3951 100644 --- a/test/unit/reaction_queue_test.c +++ b/test/unit/reaction_queue_test.c @@ -5,9 +5,9 @@ void test_insert(void) { ReactionQueue q; int level_size[REACTION_QUEUE_SIZE]; - Reaction *array[REACTION_QUEUE_SIZE][REACTION_QUEUE_SIZE]; + Reaction* array[REACTION_QUEUE_SIZE][REACTION_QUEUE_SIZE]; Reaction rs[REACTION_QUEUE_SIZE]; - ReactionQueue_ctor(&q, (Reaction **)array, level_size, REACTION_QUEUE_SIZE); + ReactionQueue_ctor(&q, (Reaction**)array, level_size, REACTION_QUEUE_SIZE); for (size_t i = 0; i < REACTION_QUEUE_SIZE; i++) { for (size_t j = 0; j < REACTION_QUEUE_SIZE; j++) { @@ -24,7 +24,7 @@ void test_insert(void) { for (int i = REACTION_QUEUE_SIZE - 1; i >= 0; i--) { TEST_ASSERT_FALSE(q.empty(&q)); - Reaction *r = q.pop(&q); + Reaction* r = q.pop(&q); TEST_ASSERT_EQUAL_PTR(r, &rs[i]); } TEST_ASSERT_TRUE(q.empty(&q)); @@ -33,9 +33,9 @@ void test_insert(void) { void test_levels_with_gaps(void) { ReactionQueue q; int level_size[REACTION_QUEUE_SIZE]; - Reaction *array[REACTION_QUEUE_SIZE][REACTION_QUEUE_SIZE]; + Reaction* array[REACTION_QUEUE_SIZE][REACTION_QUEUE_SIZE]; Reaction rs[REACTION_QUEUE_SIZE]; - ReactionQueue_ctor(&q, (Reaction **)array, level_size, REACTION_QUEUE_SIZE); + ReactionQueue_ctor(&q, (Reaction**)array, level_size, REACTION_QUEUE_SIZE); for (int i = 0; i < REACTION_QUEUE_SIZE; i++) { if (i < REACTION_QUEUE_SIZE / 2) { rs[i].level = 1; @@ -46,11 +46,11 @@ void test_levels_with_gaps(void) { } for (int i = 0; i < REACTION_QUEUE_SIZE; i++) { - Reaction *r = q.pop(&q); + Reaction* r = q.pop(&q); TEST_ASSERT_EQUAL_PTR(r, &rs[i]); } } -Environment *_lf_environment = NULL; +Environment* _lf_environment = NULL; int main(void) { UNITY_BEGIN(); diff --git a/test/unit/request_shutdown_test.c b/test/unit/request_shutdown_test.c index 6fb46c028..2df68fda0 100644 --- a/test/unit/request_shutdown_test.c +++ b/test/unit/request_shutdown_test.c @@ -25,9 +25,7 @@ LF_DEFINE_REACTION_BODY(ActionLib, r_shutdown) { TEST_ASSERT_EQUAL(1, env->scheduler->current_tag(env->scheduler).microstep); } -void test_run() { - lf_start(); -} +void test_run() { lf_start(); } int main() { UNITY_BEGIN(); RUN_TEST(test_run); diff --git a/test/unit/startup_test.c b/test/unit/startup_test.c index cfbb751a8..a253eb0ca 100644 --- a/test/unit/startup_test.c +++ b/test/unit/startup_test.c @@ -15,9 +15,7 @@ typedef struct { int cnt; } StartupTest; -LF_DEFINE_REACTION_BODY(StartupTest, r_startup) { - printf("Hello World\n"); -} +LF_DEFINE_REACTION_BODY(StartupTest, r_startup) { printf("Hello World\n"); } LF_REACTOR_CTOR_SIGNATURE(StartupTest) { LF_REACTOR_CTOR_PREAMBLE(); diff --git a/test/unit/tcp_channel_test.c b/test/unit/tcp_channel_test.c index 17e0c7bef..7cecc508c 100644 --- a/test/unit/tcp_channel_test.c +++ b/test/unit/tcp_channel_test.c @@ -17,16 +17,16 @@ Reactor parent; FederatedEnvironment env; -Environment *_lf_environment = &env.super; +Environment* _lf_environment = &env.super; FederatedConnectionBundle server_bundle; FederatedConnectionBundle client_bundle; -FederatedConnectionBundle *net_bundles[] = {&server_bundle, &client_bundle}; +FederatedConnectionBundle* net_bundles[] = {&server_bundle, &client_bundle}; StartupCoordinator startup_coordinator; TcpIpChannel _server_tcp_channel; TcpIpChannel _client_tcp_channel; -NetworkChannel *server_channel = &_server_tcp_channel.super; -NetworkChannel *client_channel = &_client_tcp_channel.super; +NetworkChannel* server_channel = &_server_tcp_channel.super; +NetworkChannel* client_channel = &_client_tcp_channel.super; bool server_callback_called = false; bool client_callback_called = false; @@ -62,12 +62,12 @@ void test_open_connection_non_blocking(void) { TEST_ASSERT_TRUE(client_channel->is_connected(client_channel)); } -void server_callback_handler(FederatedConnectionBundle *self, const FederateMessage *_msg) { +void server_callback_handler(FederatedConnectionBundle* self, const FederateMessage* _msg) { (void)self; - const TaggedMessage *msg = &_msg->message.tagged_message; + const TaggedMessage* msg = &_msg->message.tagged_message; printf("\nServer: Received message with connection number %i and content %s\n", msg->conn_id, - (char *)msg->payload.bytes); - TEST_ASSERT_EQUAL_STRING(MESSAGE_CONTENT, (char *)msg->payload.bytes); + (char*)msg->payload.bytes); + TEST_ASSERT_EQUAL_STRING(MESSAGE_CONTENT, (char*)msg->payload.bytes); TEST_ASSERT_EQUAL(MESSAGE_CONNECTION_ID, msg->conn_id); server_callback_called = true; @@ -90,9 +90,9 @@ void test_client_send_and_server_recv(void) { FederateMessage msg; msg.which_message = FederateMessage_tagged_message_tag; - TaggedMessage *port_message = &msg.message.tagged_message; + TaggedMessage* port_message = &msg.message.tagged_message; port_message->conn_id = MESSAGE_CONNECTION_ID; - const char *message = MESSAGE_CONTENT; + const char* message = MESSAGE_CONTENT; memcpy(port_message->payload.bytes, message, sizeof(MESSAGE_CONTENT)); // NOLINT port_message->payload.size = sizeof(MESSAGE_CONTENT); @@ -106,12 +106,12 @@ void test_client_send_and_server_recv(void) { TEST_ASSERT_TRUE(server_callback_called); } -void client_callback_handler(FederatedConnectionBundle *self, const FederateMessage *_msg) { +void client_callback_handler(FederatedConnectionBundle* self, const FederateMessage* _msg) { (void)self; - const TaggedMessage *msg = &_msg->message.tagged_message; + const TaggedMessage* msg = &_msg->message.tagged_message; printf("\nClient: Received message with connection number %i and content %s\n", msg->conn_id, - (char *)msg->payload.bytes); - TEST_ASSERT_EQUAL_STRING(MESSAGE_CONTENT, (char *)msg->payload.bytes); + (char*)msg->payload.bytes); + TEST_ASSERT_EQUAL_STRING(MESSAGE_CONTENT, (char*)msg->payload.bytes); TEST_ASSERT_EQUAL(MESSAGE_CONNECTION_ID, msg->conn_id); client_callback_called = true; @@ -134,9 +134,9 @@ void test_server_send_and_client_recv(void) { FederateMessage msg; msg.which_message = FederateMessage_tagged_message_tag; - TaggedMessage *port_message = &msg.message.tagged_message; + TaggedMessage* port_message = &msg.message.tagged_message; port_message->conn_id = MESSAGE_CONNECTION_ID; - const char *message = MESSAGE_CONTENT; + const char* message = MESSAGE_CONTENT; memcpy(port_message->payload.bytes, message, sizeof(MESSAGE_CONTENT)); // NOLINT port_message->payload.size = sizeof(MESSAGE_CONTENT);