@@ -96,7 +96,8 @@ struct internal_task {
9696 union {
9797 struct {
9898 const struct nrf_rpc_group * group ;
99- bool send_reply ;
99+ bool first_init ;
100+ bool needs_reply ;
100101 bool signal_groups_init_event ;
101102 } group_init ;
102103
@@ -126,6 +127,9 @@ static bool is_initialized;
126127/* Error handler provided to the init function. */
127128static nrf_rpc_err_handler_t global_err_handler ;
128129
130+ /* Bound group handler provided to the init function. */
131+ static nrf_rpc_group_bound_handler_t global_bound_handler ;
132+
129133static struct internal_task internal_task ;
130134static struct nrf_rpc_os_event internal_task_consumed ;
131135
@@ -379,13 +383,19 @@ static void internal_tx_handler(void)
379383 case NRF_RPC_TASK_GROUP_INIT : {
380384 const struct nrf_rpc_group * group = task .group_init .group ;
381385
382- if (task .group_init .send_reply && group_init_send (group )) {
386+ if (task .group_init .needs_reply && group_init_send (group )) {
383387 NRF_RPC_ERR ("Failed to send group init packet for group id: %d strid: %s" ,
384388 group -> data -> src_group_id , group -> strid );
385389 }
386390
387- if (group -> bound_handler != NULL ) {
388- group -> bound_handler (group );
391+ if (task .group_init .first_init || task .group_init .needs_reply ) {
392+ if (group -> bound_handler != NULL ) {
393+ group -> bound_handler (group );
394+ }
395+
396+ if (global_bound_handler != NULL ) {
397+ global_bound_handler (group );
398+ }
389399 }
390400
391401 if (task .group_init .signal_groups_init_event ) {
@@ -648,7 +658,7 @@ static int init_packet_handle(struct header *hdr, const struct nrf_rpc_group **g
648658 struct nrf_rpc_group_data * group_data ;
649659 bool first_init ;
650660 bool signal_groups_init_event = false;
651- bool send_reply ;
661+ bool needs_reply ;
652662
653663 * group = NULL ;
654664
@@ -697,18 +707,19 @@ static int init_packet_handle(struct header *hdr, const struct nrf_rpc_group **g
697707 * either we are not an initiator, which is indicated by NRF_RPC_FLAGS_INITIATOR
698708 * flag, or the remote has missed our init packet.
699709 */
700- send_reply = (hdr -> dst_group_id == NRF_RPC_ID_UNKNOWN );
710+ needs_reply = (hdr -> dst_group_id == NRF_RPC_ID_UNKNOWN );
701711
702712 /*
703713 * Spawn the async task only if necessary. The async task is used to avoid sending the init
704714 * reply in the transport receive thread. The application is also notified about the group
705715 * initialization from within the task to ensure that when this happens the init reply has
706716 * already been sent and the remote is ready to receive nRF RPC commands.
707717 */
708- if ((( * group ) -> bound_handler != NULL ) || send_reply || signal_groups_init_event ) {
718+ if (first_init || needs_reply || signal_groups_init_event ) {
709719 internal_task .type = NRF_RPC_TASK_GROUP_INIT ;
710720 internal_task .group_init .group = * group ;
711- internal_task .group_init .send_reply = send_reply ;
721+ internal_task .group_init .first_init = first_init ;
722+ internal_task .group_init .needs_reply = needs_reply ;
712723 internal_task .group_init .signal_groups_init_event = signal_groups_init_event ;
713724 nrf_rpc_os_thread_pool_send ((const uint8_t * )& internal_task , sizeof (internal_task ));
714725 nrf_rpc_os_event_wait (& internal_task_consumed , NRF_RPC_OS_WAIT_FOREVER );
@@ -1075,6 +1086,11 @@ void nrf_rpc_rsp_no_err(const struct nrf_rpc_group *group, uint8_t *packet, size
10751086
10761087/* ======================== Common API functions ======================== */
10771088
1089+ void nrf_rpc_set_bound_handler (nrf_rpc_group_bound_handler_t bound_handler )
1090+ {
1091+ global_bound_handler = bound_handler ;
1092+ }
1093+
10781094int nrf_rpc_init (nrf_rpc_err_handler_t err_handler )
10791095{
10801096 int err ;
0 commit comments