2012-05-15 19:37:41 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012, Sangoma Technologies
|
|
|
|
* Mathieu Rene <mrene@avgs.ca>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* <Insert license here>
|
|
|
|
*/
|
|
|
|
|
2012-06-06 16:36:22 -04:00
|
|
|
#include "mod_media_gateway.h"
|
2012-05-15 19:37:41 -04:00
|
|
|
|
2012-06-06 14:44:20 +05:30
|
|
|
megaco_profile_t *megaco_profile_locate(const char *name)
|
2012-05-15 19:37:41 -04:00
|
|
|
{
|
|
|
|
megaco_profile_t *profile = switch_core_hash_find_rdlock(megaco_globals.profile_hash, name, megaco_globals.profile_rwlock);
|
|
|
|
|
|
|
|
if (profile) {
|
|
|
|
if (switch_thread_rwlock_tryrdlock(profile->rwlock) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is locked\n", name);
|
|
|
|
profile = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2012-06-06 14:44:20 +05:30
|
|
|
mg_peer_profile_t *megaco_peer_profile_locate(const char *name)
|
2012-05-15 19:37:41 -04:00
|
|
|
{
|
2012-06-06 14:44:20 +05:30
|
|
|
mg_peer_profile_t *profile = switch_core_hash_find_rdlock(megaco_globals.peer_profile_hash, name, megaco_globals.peer_profile_rwlock);
|
2012-05-16 18:36:26 +05:30
|
|
|
|
2012-06-06 14:44:20 +05:30
|
|
|
if (profile) {
|
|
|
|
if (switch_thread_rwlock_tryrdlock(profile->rwlock) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is locked\n", name);
|
|
|
|
profile = NULL;
|
2012-05-16 18:36:26 +05:30
|
|
|
}
|
2012-05-15 19:37:41 -04:00
|
|
|
}
|
|
|
|
|
2012-06-06 14:44:20 +05:30
|
|
|
return profile;
|
|
|
|
}
|
2012-05-15 19:37:41 -04:00
|
|
|
|
2012-06-06 14:44:20 +05:30
|
|
|
void megaco_profile_release(megaco_profile_t *profile)
|
|
|
|
{
|
|
|
|
switch_thread_rwlock_unlock(profile->rwlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void megaco_peer_profile_release(mg_peer_profile_t *profile)
|
|
|
|
{
|
|
|
|
switch_thread_rwlock_unlock(profile->rwlock);
|
2012-05-15 19:37:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch_status_t megaco_profile_start(const char *profilename)
|
|
|
|
{
|
|
|
|
switch_memory_pool_t *pool;
|
|
|
|
megaco_profile_t *profile;
|
|
|
|
|
|
|
|
switch_assert(profilename);
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Starting profile: %s\n", profilename);
|
|
|
|
|
|
|
|
switch_core_new_memory_pool(&pool);
|
|
|
|
profile = switch_core_alloc(pool, sizeof(*profile));
|
|
|
|
profile->pool = pool;
|
|
|
|
profile->name = switch_core_strdup(pool, profilename);
|
|
|
|
|
|
|
|
switch_thread_rwlock_create(&profile->rwlock, pool);
|
2012-06-06 14:44:20 +05:30
|
|
|
|
|
|
|
if (SWITCH_STATUS_SUCCESS != config_profile(profile, SWITCH_FALSE)) {
|
2012-05-15 19:45:36 -04:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error configuring profile %s\n", profile->name);
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-05-15 19:37:41 -04:00
|
|
|
|
2012-06-06 14:44:20 +05:30
|
|
|
if(SWITCH_STATUS_FALSE == sng_mgco_start(profile)) {
|
2012-05-17 16:14:05 +05:30
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error starting MEGACO Stack for profile %s\n", profile->name);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2012-05-15 19:37:41 -04:00
|
|
|
switch_core_hash_insert_wrlock(megaco_globals.profile_hash, profile->name, profile, megaco_globals.profile_rwlock);
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Started profile: %s\n", profile->name);
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
2012-05-15 19:45:36 -04:00
|
|
|
|
2012-05-15 19:37:41 -04:00
|
|
|
fail:
|
|
|
|
switch_core_destroy_memory_pool(&pool);
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch_status_t megaco_profile_destroy(megaco_profile_t **profile)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Stopping profile: %s\n", (*profile)->name);
|
|
|
|
switch_thread_rwlock_wrlock((*profile)->rwlock);
|
|
|
|
|
|
|
|
|
2012-06-06 14:44:20 +05:30
|
|
|
if(SWITCH_STATUS_FALSE == sng_mgco_stop((*profile))) {
|
2012-05-31 17:31:06 +05:30
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error stopping MEGACO Stack for profile %s\n", (*profile)->name);
|
|
|
|
}
|
2012-05-15 19:37:41 -04:00
|
|
|
|
|
|
|
switch_thread_rwlock_unlock((*profile)->rwlock);
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Stopped profile: %s\n", (*profile)->name);
|
|
|
|
switch_core_hash_delete_wrlock(megaco_globals.profile_hash, (*profile)->name, megaco_globals.profile_rwlock);
|
|
|
|
|
2012-06-06 14:44:20 +05:30
|
|
|
mg_config_cleanup(*profile);
|
|
|
|
|
2012-05-15 19:37:41 -04:00
|
|
|
switch_core_destroy_memory_pool(&(*profile)->pool);
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
|
|
|
* indent-tabs-mode:t
|
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
|
|
|
*/
|