On Fri, 7 Apr 2023 at 17:15, Maciek Machnikowski <mac...@machnikowski.net> wrote:
> Add option to run callback that when the PMC agent receives signaling > messages. > > Signed-off-by: Maciek Machnikowski <mac...@machnikowski.net> > --- > 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; > + } > + > + if (skip_cb || > node->recv_subscribed(node->recv_context, *msg, ds_id) > || > management_tlv_id(*msg) != ds_id) { > msg_put(*msg); > @@ -430,3 +441,9 @@ bool pmc_agent_utc_offset_traceable(struct pmc_agent > *agent) > { > return agent->utc_offset_traceable; > } > I think I have it: + /* Run the callback on signaling messages if configured */ + if (res == 0 && node->signaling_cb_ena && (msg_type(*msg) == SIGNALING)) { + res=2; + } - management_tlv_id(*msg) != ds_id) { + res == 1 && management_tlv_id(*msg) != ds_id) { Erez :-) > + > +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); > + > #endif > -- > 2.30.2 > >
_______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel