@@ -96,7 +96,8 @@ struct internal_task {
96
96
union {
97
97
struct {
98
98
const struct nrf_rpc_group * group ;
99
- bool send_reply ;
99
+ bool first_init ;
100
+ bool needs_reply ;
100
101
bool signal_groups_init_event ;
101
102
} group_init ;
102
103
@@ -126,6 +127,9 @@ static bool is_initialized;
126
127
/* Error handler provided to the init function. */
127
128
static nrf_rpc_err_handler_t global_err_handler ;
128
129
130
+ /* Bound group handler provided to the init function. */
131
+ static nrf_rpc_group_bound_handler_t global_bound_handler ;
132
+
129
133
static struct internal_task internal_task ;
130
134
static struct nrf_rpc_os_event internal_task_consumed ;
131
135
@@ -379,13 +383,19 @@ static void internal_tx_handler(void)
379
383
case NRF_RPC_TASK_GROUP_INIT : {
380
384
const struct nrf_rpc_group * group = task .group_init .group ;
381
385
382
- if (task .group_init .send_reply && group_init_send (group )) {
386
+ if (task .group_init .needs_reply && group_init_send (group )) {
383
387
NRF_RPC_ERR ("Failed to send group init packet for group id: %d strid: %s" ,
384
388
group -> data -> src_group_id , group -> strid );
385
389
}
386
390
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
+ }
389
399
}
390
400
391
401
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
648
658
struct nrf_rpc_group_data * group_data ;
649
659
bool first_init ;
650
660
bool signal_groups_init_event = false;
651
- bool send_reply ;
661
+ bool needs_reply ;
652
662
653
663
* group = NULL ;
654
664
@@ -697,18 +707,19 @@ static int init_packet_handle(struct header *hdr, const struct nrf_rpc_group **g
697
707
* either we are not an initiator, which is indicated by NRF_RPC_FLAGS_INITIATOR
698
708
* flag, or the remote has missed our init packet.
699
709
*/
700
- send_reply = (hdr -> dst_group_id == NRF_RPC_ID_UNKNOWN );
710
+ needs_reply = (hdr -> dst_group_id == NRF_RPC_ID_UNKNOWN );
701
711
702
712
/*
703
713
* Spawn the async task only if necessary. The async task is used to avoid sending the init
704
714
* reply in the transport receive thread. The application is also notified about the group
705
715
* initialization from within the task to ensure that when this happens the init reply has
706
716
* already been sent and the remote is ready to receive nRF RPC commands.
707
717
*/
708
- if ((( * group ) -> bound_handler != NULL ) || send_reply || signal_groups_init_event ) {
718
+ if (first_init || needs_reply || signal_groups_init_event ) {
709
719
internal_task .type = NRF_RPC_TASK_GROUP_INIT ;
710
720
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 ;
712
723
internal_task .group_init .signal_groups_init_event = signal_groups_init_event ;
713
724
nrf_rpc_os_thread_pool_send ((const uint8_t * )& internal_task , sizeof (internal_task ));
714
725
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
1075
1086
1076
1087
/* ======================== Common API functions ======================== */
1077
1088
1089
+ void nrf_rpc_set_bound_handler (nrf_rpc_group_bound_handler_t bound_handler )
1090
+ {
1091
+ global_bound_handler = bound_handler ;
1092
+ }
1093
+
1078
1094
int nrf_rpc_init (nrf_rpc_err_handler_t err_handler )
1079
1095
{
1080
1096
int err ;
0 commit comments