Add option to run callback that when the PMC agent receives signaling messages.
v2: changed pmc_agent implementation to not use a separate callback v3: updated poll thread to use less CPU v4: changed sleep routine to usleep, simplified poll thread v5: make sure management_tlv_id is not called on non-management messages v6: optimized code to not check signaling_cb_ena on management messages v7: rebase Signed-off-by: Maciek Machnikowski <mac...@machnikowski.net> --- pmc_agent.c | 22 ++++++++++++++++++++-- pmc_agent.h | 7 +++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pmc_agent.c b/pmc_agent.c index 62d1a86..bea6b59 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,9 +180,19 @@ 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 (res == 0 && 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) { + (res == 1 && management_tlv_id(*msg) != ds_id)) { msg_put(*msg); *msg = NULL; continue; @@ -430,3 +442,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); + #endif -- 2.30.2 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel