MIP SDK  0.0.1
MicroStrain Communications Library for embedded systems
mip_dispatch.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mip_types.h"
4 #include "mip_field.h"
5 #include "mip_packet.h"
7 
8 #include <stdbool.h>
9 
10 
11 #ifdef __cplusplus
12 namespace mip {
13 namespace C {
14 #endif
15 
16 
20 
21 
28 
29 
30 
38 typedef void (*mip_dispatch_packet_callback)(void* context, const mip_packet* packet, timestamp_type timestamp);
39 
47 typedef void (*mip_dispatch_field_callback )(void* context, const mip_field* field, timestamp_type timestamp);
48 
55 typedef bool (*mip_dispatch_extractor)(const mip_field* field, void* ptr);
56 
57 
58 enum {
64 
68 };
69 
84 
87 typedef struct mip_dispatch_handler
88 {
89  struct mip_dispatch_handler* _next;
90  union
91  {
92  mip_dispatch_packet_callback _packet_callback;
93  mip_dispatch_field_callback _field_callback;
94  mip_dispatch_extractor _extract_callback;
95  };
96  void* _user_data;
97  uint8_t _type;
98  uint8_t _descriptor_set;
99  uint8_t _field_descriptor;
100  uint8_t _enabled;
102 
103 
104 void mip_dispatch_handler_init_packet_handler(mip_dispatch_handler* handler, uint8_t descriptor_set, bool after_fields, mip_dispatch_packet_callback callback, void* context);
105 void mip_dispatch_handler_init_field_handler(mip_dispatch_handler* handler, uint8_t descriptor_set, uint8_t field_descriptor, mip_dispatch_field_callback callback, void* context);
106 void mip_dispatch_handler_init_extractor(mip_dispatch_handler* handler, uint8_t descriptor_set, uint8_t field_descriptor, mip_dispatch_extractor extractor, void* field_ptr);
107 
108 void mip_dispatch_handler_set_enabled(mip_dispatch_handler* handler, bool enable);
110 
111 
117 
118 
121 typedef struct mip_dispatcher
122 {
123  mip_dispatch_handler* _first_handler;
125 
126 
131 
132 void mip_dispatcher_dispatch_packet(mip_dispatcher* self, const mip_packet* packet, timestamp_type timestamp);
133 
138 
139 
140 #ifdef __cplusplus
141 } // namespace C
142 } // namespace mip
143 #endif
void(* mip_dispatch_packet_callback)(void *context, const mip_packet *packet, timestamp_type timestamp)
Signature for packet-level callbacks.
Definition: mip_dispatch.h:38
bool(* mip_dispatch_extractor)(const mip_field *field, void *ptr)
Signature for extraction callbacks.
Definition: mip_dispatch.h:55
void(* mip_dispatch_field_callback)(void *context, const mip_field *field, timestamp_type timestamp)
Signature for field-level callbacks.
Definition: mip_dispatch.h:47
@ MIP_DISPATCH_ANY_DATA_SET
Definition: mip_dispatch.h:63
@ MIP_DISPATCH_ANY_DESCRIPTOR
Definition: mip_dispatch.h:67
void mip_dispatcher_add_handler(mip_dispatcher *self, mip_dispatch_handler *handler)
Registers a handler in the dispatch system.
Definition: mip_dispatch.c:187
void mip_dispatcher_remove_all_handlers(mip_dispatcher *self)
Removes all handlers from the dispatcher.
Definition: mip_dispatch.c:237
struct mip::C::mip_dispatcher mip_dispatcher
Holds the state of the MIP dispatch system.
void mip_dispatcher_remove_handler(mip_dispatcher *self, mip_dispatch_handler *handler)
Removes a handler from the dispatch system.
Definition: mip_dispatch.c:208
void mip_dispatcher_init(mip_dispatcher *self)
Initializes the mip_dispatcher object.
Definition: mip_dispatch.c:176
void mip_dispatcher_dispatch_packet(mip_dispatcher *self, const mip_packet *packet, timestamp_type timestamp)
Called to dispatch the callbacks for a given packet.
Definition: mip_dispatch.c:351
bool mip_dispatch_handler_is_enabled(mip_dispatch_handler *handler)
Determines if the handler is currently enabled.
Definition: mip_dispatch.c:164
void mip_dispatch_handler_init_field_handler(mip_dispatch_handler *handler, uint8_t descriptor_set, uint8_t field_descriptor, mip_dispatch_field_callback callback, void *user_data)
Initialize the dispatch handler with a field callback.
Definition: mip_dispatch.c:84
struct mip::C::mip_dispatch_handler mip_dispatch_handler
Handler information for MIP Packet or Field callbacks.
void mip_dispatch_handler_init_packet_handler(mip_dispatch_handler *handler, uint8_t descriptor_set, bool post_callback, mip_dispatch_packet_callback callback, void *user_data)
Initialize the dispatch handler with a packet callback.
Definition: mip_dispatch.c:49
void mip_dispatch_handler_init_extractor(mip_dispatch_handler *handler, uint8_t descriptor_set, uint8_t field_descriptor, mip_dispatch_extractor extractor, void *field_ptr)
Initialize the dispatch handler with an extraction callback.
Definition: mip_dispatch.c:129
void mip_dispatch_handler_set_enabled(mip_dispatch_handler *handler, bool enable)
Enables or disables the handler.
Definition: mip_dispatch.c:154
struct mip::C::mip_packet mip_packet
Structure representing a MIP Packet.
uint64_t timestamp_type
Type used for packet timestamps and timeouts.
Definition: mip_types.h:32
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
Handler information for MIP Packet or Field callbacks.
Definition: mip_dispatch.h:88
Holds the state of the MIP dispatch system.
Definition: mip_dispatch.h:122
A structure representing a MIP field.
Definition: mip_field.h:53
Structure representing a MIP Packet.
Definition: mip_packet.h:44