Skip to content

Commit 058b818

Browse files
remove canard_user_context_t, use plain void*
1 parent f201ba7 commit 058b818

File tree

9 files changed

+522
-567
lines changed

9 files changed

+522
-567
lines changed

libcanard/canard.c

Lines changed: 91 additions & 91 deletions
Large diffs are not rendered by default.

libcanard/canard.h

Lines changed: 58 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -191,22 +191,6 @@ typedef struct canard_payload_t
191191
canard_bytes_mut_t origin; ///< Use this to free the memory, unless NULL/empty.
192192
} canard_payload_t;
193193

194-
/// The library carries the user-provided context from inputs to outputs without interpreting it,
195-
/// allowing the application to associate its own data with various entities inside the library.
196-
/// The size can be changed arbitrarily. This value is compromise between copy size and footprint and utility.
197-
#define CANARD_USER_CONTEXT_PTR_COUNT 2
198-
typedef union canard_user_context_t
199-
{
200-
void* ptr[CANARD_USER_CONTEXT_PTR_COUNT];
201-
unsigned char bytes[sizeof(void*) * CANARD_USER_CONTEXT_PTR_COUNT];
202-
} canard_user_context_t;
203-
#ifdef __cplusplus
204-
#define CANARD_USER_CONTEXT_NULL \
205-
canard_user_context_t {}
206-
#else
207-
#define CANARD_USER_CONTEXT_NULL ((canard_user_context_t){ .ptr = { NULL } })
208-
#endif
209-
210194
/// The filter only matches extended CAN IDs on data frames (no std/rtr). Bits above 29 are always zero.
211195
typedef struct canard_filter_t
212196
{
@@ -259,7 +243,7 @@ struct canard_subscription_t
259243
canard_tree_t* sessions;
260244
const canard_subscription_vtable_t* vtable;
261245

262-
canard_user_context_t user_context;
246+
void* user_context;
263247
};
264248

265249
typedef struct canard_vtable_t
@@ -273,7 +257,7 @@ typedef struct canard_vtable_t
273257
/// The callback must not mutate the TX pipeline (no publish/cancel/free/etc).
274258
/// If the can_data needs to be retained for later retransmission, use canard_refcount_inc()/canard_refcount_dec().
275259
bool (*tx)(canard_t*,
276-
canard_user_context_t,
260+
void* user_context,
277261
canard_us_t deadline,
278262
uint_least8_t iface_index,
279263
bool fd,
@@ -426,33 +410,33 @@ void canard_refcount_dec(canard_t* const self, const canard_bytes_t obj);
426410
/// The context is passed into the tx() vtable function.
427411
///
428412
/// Returns zero on success, false on OOM (error counters updated) or if any of the arguments are invalid.
429-
bool canard_publish(canard_t* const self,
430-
const canard_us_t deadline,
431-
const uint_least8_t iface_bitmap,
432-
const canard_prio_t priority,
433-
const uint16_t subject_id,
434-
const bool rev_1v0, ///< If set, subject-ID must be in [0,8192).
435-
const uint_least8_t transfer_id,
436-
const canard_bytes_chain_t payload,
437-
const canard_user_context_t context);
438-
439-
bool canard_request(canard_t* const self,
440-
const canard_us_t deadline,
441-
const canard_prio_t priority,
442-
const uint16_t service_id,
443-
const uint_least8_t server_node_id,
444-
const uint_least8_t transfer_id,
445-
const canard_bytes_chain_t payload,
446-
const canard_user_context_t context);
447-
448-
bool canard_respond(canard_t* const self,
449-
const canard_us_t deadline,
450-
const canard_prio_t priority,
451-
const uint16_t service_id,
452-
const uint_least8_t client_node_id,
453-
const uint_least8_t transfer_id,
454-
const canard_bytes_chain_t payload,
455-
const canard_user_context_t context);
413+
bool canard_publish(canard_t* const self,
414+
const canard_us_t deadline,
415+
const uint_least8_t iface_bitmap,
416+
const canard_prio_t priority,
417+
const uint16_t subject_id,
418+
const bool rev_1v0, ///< If set, subject-ID must be in [0,8192).
419+
const uint_least8_t transfer_id,
420+
const canard_bytes_chain_t payload,
421+
void* const user_context);
422+
423+
bool canard_request(canard_t* const self,
424+
const canard_us_t deadline,
425+
const canard_prio_t priority,
426+
const uint16_t service_id,
427+
const uint_least8_t server_node_id,
428+
const uint_least8_t transfer_id,
429+
const canard_bytes_chain_t payload,
430+
void* const user_context);
431+
432+
bool canard_respond(canard_t* const self,
433+
const canard_us_t deadline,
434+
const canard_prio_t priority,
435+
const uint16_t service_id,
436+
const uint_least8_t client_node_id,
437+
const uint_least8_t transfer_id,
438+
const canard_bytes_chain_t payload,
439+
void* const user_context);
456440

457441
/// Register a new subscription on a v1.1 or v1.0 subject. The subscription instance must not be moved while in use.
458442
/// The extent specifies the maximum message size that can be received from the subject; longer messages will be
@@ -521,35 +505,35 @@ void canard_unsubscribe(canard_t* const self, canard_subscription_t* const subsc
521505
///
522506
/// To obtain the CRC seed, use canard_0v1_crc_seed_from_data_type_signature(); if the payload does not exceed 7 bytes,
523507
/// the CRC seed can be arbitrary since it is not needed for single-frame transfers.
524-
bool canard_0v1_publish(canard_t* const self,
525-
const canard_us_t deadline,
526-
const uint_least8_t iface_bitmap,
527-
const canard_prio_t priority,
528-
const uint16_t data_type_id,
529-
const uint16_t crc_seed,
530-
const uint_least8_t transfer_id,
531-
const canard_bytes_chain_t payload,
532-
const canard_user_context_t context);
533-
534-
bool canard_0v1_request(canard_t* const self,
535-
const canard_us_t deadline,
536-
const canard_prio_t priority,
537-
const uint_least8_t data_type_id,
538-
const uint16_t crc_seed,
539-
const uint_least8_t server_node_id,
540-
const uint_least8_t transfer_id,
541-
const canard_bytes_chain_t payload,
542-
const canard_user_context_t context);
543-
544-
bool canard_0v1_respond(canard_t* const self,
545-
const canard_us_t deadline,
546-
const canard_prio_t priority,
547-
const uint_least8_t data_type_id,
548-
const uint16_t crc_seed,
549-
const uint_least8_t client_node_id,
550-
const uint_least8_t transfer_id,
551-
const canard_bytes_chain_t payload,
552-
const canard_user_context_t context);
508+
bool canard_0v1_publish(canard_t* const self,
509+
const canard_us_t deadline,
510+
const uint_least8_t iface_bitmap,
511+
const canard_prio_t priority,
512+
const uint16_t data_type_id,
513+
const uint16_t crc_seed,
514+
const uint_least8_t transfer_id,
515+
const canard_bytes_chain_t payload,
516+
void* const user_context);
517+
518+
bool canard_0v1_request(canard_t* const self,
519+
const canard_us_t deadline,
520+
const canard_prio_t priority,
521+
const uint_least8_t data_type_id,
522+
const uint16_t crc_seed,
523+
const uint_least8_t server_node_id,
524+
const uint_least8_t transfer_id,
525+
const canard_bytes_chain_t payload,
526+
void* const user_context);
527+
528+
bool canard_0v1_respond(canard_t* const self,
529+
const canard_us_t deadline,
530+
const canard_prio_t priority,
531+
const uint_least8_t data_type_id,
532+
const uint16_t crc_seed,
533+
const uint_least8_t client_node_id,
534+
const uint_least8_t transfer_id,
535+
const canard_bytes_chain_t payload,
536+
void* const user_context);
553537

554538
bool canard_0v1_subscribe(canard_t* const self,
555539
canard_subscription_t* const subscription,

tests/src/helpers.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ static inline void dummy_free(void* const user, const size_t size, const void* c
5959
TEST_PANIC_UNLESS(pointer == NULL);
6060
}
6161

62-
// Wraps an application pointer for user context plumbing.
63-
static inline canard_user_context_t make_user_context(void* const obj)
64-
{
65-
canard_user_context_t out = CANARD_USER_CONTEXT_NULL;
66-
out.ptr[0] = obj;
67-
return out;
68-
}
69-
7062
/// The instrumented allocator tracks memory consumption, checks for heap corruption, and can be configured to fail
7163
/// allocations above a certain threshold.
7264
#define INSTRUMENTED_ALLOCATOR_CANARY_SIZE 1024U

0 commit comments

Comments
 (0)