OpenCyphal / libcanard

A compact implementation of the Cyphal/CAN protocol in C for high-integrity real-time embedded systems
http://opencyphal.org
MIT License
327 stars 192 forks source link

Extend api with `canardRxGetSubscription ` #222

Closed serges147 closed 4 months ago

serges147 commented 4 months ago

c++ libcyphal needs api to detect already existing subscription (without "touching" one if any). Here is proposal:

/// This function allows to check the effect of canardRxSubscribe() and canardRxUnsubscribe().
/// The return value is 1 if the specified subscription exists, 0 otherwise.
/// The return value is a negated invalid argument error if any of the input arguments are invalid.
int8_t canardRxGetSubscription(CanardInstance* const       ins,
                               const CanardTransferKind    transfer_kind,
                               const CanardPortID          port_id,
                               CanardRxSubscription* const out_subscription);
serges147 commented 4 months ago

Looks like canardRxHasSubscription() → bool is enough - we only need to check for possible double subscription for the same kind & port pair.

pavel-kirienko commented 4 months ago

I actually wanted to mention this earlier but forgot: since we'll have to find that specific subscription in the tree anyway, should we not keep canardRxGetSubscription as it is more versatile? There are sensible use cases where one might want to find an existing subscription to modify it.

serges147 commented 4 months ago

ok, I revert back to → canardRxGetSubscription