mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-14 13:58:38 +00:00
sorcery: Create sorcery instance registry.
In order to retrieve an arbitrary sorcery instance from a dialplan function (or any place else) there needs to be a registry of sorcery instances. ast_sorcery_init now creates a hashtab as a registry. ast_sorcery_open now checks the hashtab for an existing sorcery instance matching the caller's module name. If it finds one, it bumps the refcount and returns it. If not, it creates a new sorcery instance, adds it to the hashtab, then returns it. ast_sorcery_retrieve_by_module_name is a new function that does a hashtab lookup by module name. It can be called by the future dialplan function. res_pjsip/config_system needed a small change to share the main res_pjsip sorcery instance. tests/test_sorcery was updated to include a test for the registry. (closes issue ASTERISK-22537) Review: http://reviewboard.asterisk.org/r/3184/ ........ Merged revisions 408518 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@408519 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -2296,6 +2296,7 @@ static int load_module(void)
|
||||
sip_threadpool = ast_threadpool_create("SIP", NULL, &options);
|
||||
if (!sip_threadpool) {
|
||||
ast_log(LOG_ERROR, "Failed to create SIP threadpool. Aborting load\n");
|
||||
ast_sip_destroy_system();
|
||||
pj_pool_release(memory_pool);
|
||||
memory_pool = NULL;
|
||||
pjsip_endpt_destroy(ast_pjsip_endpoint);
|
||||
@@ -2312,6 +2313,7 @@ static int load_module(void)
|
||||
NULL, PJ_THREAD_DEFAULT_STACK_SIZE * 2, 0, &monitor_thread);
|
||||
if (status != PJ_SUCCESS) {
|
||||
ast_log(LOG_ERROR, "Failed to start SIP monitor thread. Aborting load\n");
|
||||
ast_sip_destroy_system();
|
||||
pj_pool_release(memory_pool);
|
||||
memory_pool = NULL;
|
||||
pjsip_endpt_destroy(ast_pjsip_endpoint);
|
||||
@@ -2326,6 +2328,7 @@ static int load_module(void)
|
||||
ast_log(LOG_ERROR, "Failed to initialize SIP configuration. Aborting load\n");
|
||||
ast_sip_destroy_global_headers();
|
||||
stop_monitor_thread();
|
||||
ast_sip_destroy_system();
|
||||
pj_pool_release(memory_pool);
|
||||
memory_pool = NULL;
|
||||
pjsip_endpt_destroy(ast_pjsip_endpoint);
|
||||
@@ -2339,6 +2342,7 @@ static int load_module(void)
|
||||
ast_res_pjsip_destroy_configuration();
|
||||
ast_sip_destroy_global_headers();
|
||||
stop_monitor_thread();
|
||||
ast_sip_destroy_system();
|
||||
pj_pool_release(memory_pool);
|
||||
memory_pool = NULL;
|
||||
pjsip_endpt_destroy(ast_pjsip_endpoint);
|
||||
@@ -2353,6 +2357,7 @@ static int load_module(void)
|
||||
ast_res_pjsip_destroy_configuration();
|
||||
ast_sip_destroy_global_headers();
|
||||
stop_monitor_thread();
|
||||
ast_sip_destroy_system();
|
||||
pj_pool_release(memory_pool);
|
||||
memory_pool = NULL;
|
||||
pjsip_endpt_destroy(ast_pjsip_endpoint);
|
||||
@@ -2368,6 +2373,7 @@ static int load_module(void)
|
||||
ast_res_pjsip_destroy_configuration();
|
||||
ast_sip_destroy_global_headers();
|
||||
stop_monitor_thread();
|
||||
ast_sip_destroy_system();
|
||||
pj_pool_release(memory_pool);
|
||||
memory_pool = NULL;
|
||||
pjsip_endpt_destroy(ast_pjsip_endpoint);
|
||||
|
||||
@@ -120,7 +120,7 @@ int ast_sip_initialize_system(void)
|
||||
|
||||
ast_sorcery_apply_default(system_sorcery, "system", "config", "pjsip.conf,criteria=type=system");
|
||||
|
||||
if (ast_sorcery_object_register(system_sorcery, "system", system_alloc, NULL, system_apply)) {
|
||||
if (ast_sorcery_object_register_no_reload(system_sorcery, "system", system_alloc, NULL, system_apply)) {
|
||||
ast_log(LOG_ERROR, "Failed to register with sorcery (is res_sorcery_config loaded?)\n");
|
||||
ast_sorcery_unref(system_sorcery);
|
||||
system_sorcery = NULL;
|
||||
@@ -156,13 +156,21 @@ int ast_sip_initialize_system(void)
|
||||
system = ast_sorcery_alloc(system_sorcery, "system", NULL);
|
||||
if (!system) {
|
||||
ast_log(LOG_ERROR, "Unable to allocate default system config.\n");
|
||||
ast_sorcery_unref(system_sorcery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (system_apply(system_sorcery, system)) {
|
||||
ast_log(LOG_ERROR, "Failed to apply default system config.\n");
|
||||
ast_sorcery_unref(system_sorcery);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ast_sip_destroy_system(void)
|
||||
{
|
||||
ast_sorcery_unref(system_sorcery);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,11 @@ int ast_sip_initialize_outbound_authentication(void);
|
||||
*/
|
||||
int ast_sip_initialize_system(void);
|
||||
|
||||
/*!
|
||||
* \brief Destroy system configuration
|
||||
*/
|
||||
void ast_sip_destroy_system(void);
|
||||
|
||||
/*!
|
||||
* \brief Initialize global configuration
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user