On Sat, 8 Apr 2023 at 17:29, Erez <[email protected]> wrote:
>
>
> On Fri, 7 Apr 2023 at 17:15, Maciek Machnikowski <[email protected]>
> wrote:
>
>> Add option to run callback that when the PMC agent receives signaling
>> messages.
>>
>
> I support you!
>
>
>>
>> Signed-off-by: Maciek Machnikowski <[email protected]>
>> ---
>> pmc_agent.c | 19 ++++++++++++++++++-
>> pmc_agent.h | 7 +++++++
>> 2 files changed, 25 insertions(+), 1 deletion(-)
>>
>> diff --git a/pmc_agent.c b/pmc_agent.c
>> index 62d1a86..7ffcec8 100644
>> --- a/pmc_agent.c
>> +++ b/pmc_agent.c
>> @@ -42,6 +42,7 @@ struct pmc_agent {
>> bool dds_valid;
>> int leap;
>> int pmc_ds_requested;
>> + bool signaling_cb_ena;
>> bool stay_subscribed;
>> int sync_offset;
>> int utc_offset_traceable;
>> @@ -127,6 +128,7 @@ static int run_pmc(struct pmc_agent *node, int
>> timeout, int ds_id,
>> #define N_FD 1
>> struct pollfd pollfd[N_FD];
>> int cnt, res;
>> + bool skip_cb;
>>
>> while (1) {
>> pollfd[0].fd = pmc_get_transport_fd(node->pmc);
>> @@ -178,7 +180,16 @@ static int run_pmc(struct pmc_agent *node, int
>> timeout, int ds_id,
>> node->pmc_ds_requested = 0;
>> return RUN_PMC_NODEV;
>> }
>> - if (res <= 0 ||
>> +
>> + /* Skip callback if message is not management */
>> + skip_cb = (res <= 0) ? true : false;
>> +
>> + /* Run the callback on signaling messages if configured */
>> + if (node->signaling_cb_ena && (msg_type(*msg) ==
>> SIGNALING)) {
>> + skip_cb = false;
>> + }
>> +
>>
>
> You can do:
> if (res == 0 && node->signaling_cb_ena && (msg_type(*msg)
> == SIGNALING)) {
>
if(node->recv_subscribed(node->recv_context, *msg,
> ds_id) {
> msg_put(*msg);
> *msg = NULL;
> continue;
> }
> }
> else if (node->recv_subscribed(node->recv_context, *msg,
> ds_id) ||
> management_tlv_id(*msg) != ds_id) {
> msg_put(*msg);
> *msg = NULL;
> continue;
> }
>
>
My code is wrong, but you should call "management_tlv_id(*msg)" only if the
message is a management.
> + if (skip_cb ||
>> node->recv_subscribed(node->recv_context, *msg,
>> ds_id) ||
>> management_tlv_id(*msg) != ds_id) {
>>
>
> This condition: "management_tlv_id(*msg) != ds_id" seems irrelevant to
> signaling messages.
>
>
>> msg_put(*msg);
>> @@ -430,3 +441,9 @@ bool pmc_agent_utc_offset_traceable(struct pmc_agent
>> *agent)
>> {
>> return agent->utc_offset_traceable;
>> }
>> +
>> +void pmc_agent_enable_signaling_cb(struct pmc_agent *agent, bool enable)
>> +{
>> + agent->signaling_cb_ena = enable;
>> +}
>> +
>> diff --git a/pmc_agent.h b/pmc_agent.h
>> index 2fb1cc8..9ae37f7 100644
>> --- a/pmc_agent.h
>> +++ b/pmc_agent.h
>> @@ -170,4 +170,11 @@ int pmc_agent_update(struct pmc_agent *agent);
>> */
>> bool pmc_agent_utc_offset_traceable(struct pmc_agent *agent);
>>
>> +/**
>> + * Enables or disables callback on signaling messages
>> + * @param agent Pointer to a PMC instance obtained via @ref
>> pmc_agent_create().
>> + * @param enable - if set to true, callback will be called on signaling
>> msgs
>> + */
>> +void pmc_agent_enable_signaling_cb(struct pmc_agent *agent, bool enable);
>>
>
> I like the name!
>
>
>> +
>> #endif
>> --
>> 2.30.2
>>
>>
> Great work
> Erez
>
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel