diff --git a/channels/chan_brcm.c b/channels/chan_brcm.c index 131936aca57a99da077e94d8dea1db2801faf2f0..e5415267380acc5221a830dc03cb9f092f2b97e4 100644 --- a/channels/chan_brcm.c +++ b/channels/chan_brcm.c @@ -424,14 +424,11 @@ static void ubus_call_complete(struct ubus_request *req, int ret) static void endpt_signal(int line, char *signal, char *state, char *data) { struct blob_buf bb; struct ubus_request *req; - uint32_t local_endpt_id; int res; //ast_debug(5, "line = %d, signal = %s, state = %s, data = %s\n", line, signal, state, data); - local_endpt_id = get_ubus_endpt_id(1); - - if (local_endpt_id) { + if (endpt_id) { memset(&bb, 0, sizeof(bb)); blob_buf_init(&bb, 0); @@ -444,7 +441,7 @@ static void endpt_signal(int line, char *signal, char *state, char *data) { req = calloc(1, sizeof(struct ubus_request)); if (!req) return; - res = ubus_invoke_async(ctx, local_endpt_id, "signal", bb.head, req); + res = ubus_invoke_async(ctx, endpt_id, "signal", bb.head, req); if(res != UBUS_STATUS_OK) { ast_log(LOG_ERROR, "Error invoking method: %s %d\n", "signal", res); @@ -462,12 +459,9 @@ static void endpt_signal(int line, char *signal, char *state, char *data) { static void endpt_connection(int line, int id, char *action) { struct blob_buf bb; struct ubus_request *req; - uint32_t local_endpt_id; int res; - local_endpt_id = get_ubus_endpt_id(1); - - if (local_endpt_id) { + if (endpt_id) { memset(&bb, 0, sizeof(bb)); blob_buf_init(&bb, 0); @@ -477,7 +471,7 @@ static void endpt_connection(int line, int id, char *action) { req = calloc(1, sizeof(struct ubus_request)); if (!req) return; - res = ubus_invoke_async(ctx, local_endpt_id, "connection", bb.head, req); + res = ubus_invoke_async(ctx, endpt_id, "connection", bb.head, req); if(res != UBUS_STATUS_OK) { ast_log(LOG_ERROR, "Error invoking method: %s %d\n", "connection", res); @@ -3247,18 +3241,17 @@ static void endpt_get_count_cb(struct ubus_request *req, } static int endpt_get_count(void) { - uint32_t local_endpt_id; struct blob_buf bb; - local_endpt_id = get_ubus_endpt_id(0); - if(!local_endpt_id) + endpt_id = get_ubus_endpt_id(0); + if(!endpt_id) return -1; memset(&bb, 0, sizeof(bb)); blob_buf_init(&bb, 0); blobmsg_add_u8(&bb, "effective", 0); - return (ubus_invoke(ctx, local_endpt_id, "count", bb.head, + return (ubus_invoke(ctx, endpt_id, "count", bb.head, endpt_get_count_cb, NULL, 2000) == UBUS_STATUS_OK ? 0 : -1); } @@ -3320,7 +3313,6 @@ static void ubus_stream_handler(pe_stream_t *stream __attribute__((unused)), pe_ static int ubus_init(void) { pe_stream_t *ubus_stream; - int try = 0; base = pe_base_new(); if (base < 0) @@ -3348,16 +3340,10 @@ static int ubus_init(void) { } /* Lookup path to Endptmngr AFTER registration of ubus object - * event handler above. When lookup fails endptmngr hangs causing - * chan_brcm.so module is not loaded and asterisk is not fully working - * so keep trying for 20s */ - for (try = 0; try < 20 && endpt_id == 0; try++) { - if(ubus_lookup_id(ctx, endpt_ubus_path, - (uint32_t*) &endpt_id) != UBUS_STATUS_OK) { - endpt_id = 0; - ast_log(LOG_DEBUG, "Waiting for endptmngr...\n"); - sleep(1); - } + * event handler above. It's no error if lookup fails. */ + if(ubus_lookup_id(ctx, endpt_ubus_path, + (uint32_t*) &endpt_id) != UBUS_STATUS_OK) { + endpt_id = 0; } if (ubus_add_object(ctx, &asterisk_obj) != UBUS_STATUS_OK) { @@ -3424,12 +3410,6 @@ static int load_module(void) if (!audio_rx_bus) exit_failure("Failed to create audio_rx bus"); pe_bus_add_handler(audio_rx_bus, audio_packet_handler); - /* Run pe_base_dispatch in separate thread. */ - if (ast_pthread_create_background(&ubus_thread, NULL, pe_base_run, NULL) < 0) { - ast_log(LOG_ERROR, "Unable to start ubus thread.\n"); - goto err; - } - for (try = 0; try < 20 && num_endpoints == -1; try++) { if(endpt_get_count()) { ast_log(LOG_DEBUG, "Waiting for endptmngr...\n"); @@ -3441,6 +3421,12 @@ static int load_module(void) goto err; } + /* Run pe_base_dispatch in separate thread. */ + if (ast_pthread_create_background(&ubus_thread, NULL, pe_base_run, NULL) < 0) { + ast_log(LOG_ERROR, "Unable to start ubus thread.\n"); + goto err; + } + registration_change_sub = calloc(num_endpoints, sizeof(struct stasis_subscription *)); /* Setup scheduler thread */