git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10244 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-11-05 00:20:30 +00:00
parent 71f94e0ee5
commit c217d45cf0
11 changed files with 114 additions and 33 deletions

View File

@ -52,9 +52,6 @@
#include <apr_general.h>
#include <apr_portable.h>
typedef apr_os_thread_t switch_thread_id_t;
#define switch_thread_self apr_os_thread_current
#ifdef HAVE_MLOCKALL
#include <sys/mman.h>

View File

@ -40,6 +40,16 @@
#define SWITCH_APR_H
SWITCH_BEGIN_EXTERN_C
#ifdef WIN32
typedef HANDLE switch_thread_id_t;
#else
typedef pthread_t switch_thread_id_t;
#endif
SWITCH_DECLARE(switch_thread_id_t) switch_thread_self(void);
/*
The pieces of apr we allow ppl to pass around between modules we typedef into our namespace and wrap all the functions
any other apr code should be as hidden as possible.

View File

@ -89,6 +89,9 @@ struct switch_core_session_message {
switch_size_t pointer_reply_size;
/*! message flags */
switch_core_session_message_flag_t flags;
const char *_file;
const char *_func;
int _line;
};
/*! \brief A generic object to pass as a thread's session object to allow mutiple arguements and a pool */
@ -777,7 +780,11 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(_In_z_
\param message the message to recieve
\return the status returned by the message handler
*/
SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(_In_ switch_core_session_t *session, _In_ switch_core_session_message_t *message);
SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(_In_ switch_core_session_t *session,
_In_ switch_core_session_message_t *message,
const char *file, const char *func, int line);
#define switch_core_session_receive_message(_session, _message) switch_core_session_perform_receive_message(_session, _message, \
__FILE__, __SWITCH_FUNC__, __LINE__)
/*!
\brief Queue an event on a given session
@ -927,7 +934,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(_In_ switch_core_s
\param pool the pool to use for the new hash
\return SWITCH_STATUS_SUCCESS if the hash is created
*/
SWITCH_DECLARE(switch_status_t) switch_core_hash_init(_Out_ switch_hash_t **hash, _In_ switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) switch_core_hash_init_case(_Out_ switch_hash_t **hash, _In_ switch_memory_pool_t *pool, switch_bool_t case_sensitive);
#define switch_core_hash_init(_hash, _pool) switch_core_hash_init_case(_hash, _pool, SWITCH_TRUE);
#define switch_core_hash_init_nocase(_hash, _pool) switch_core_hash_init_case(_hash, _pool, SWITCH_FALSE);
/*!
\brief Destroy an existing hash table

View File

@ -565,7 +565,8 @@ typedef enum {
SWITCH_MESSAGE_INDICATE_DEFLECT,
SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ,
SWITCH_MESSAGE_INDICATE_DISPLAY,
SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY
SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY,
SWITCH_MESSAGE_INVALID
} switch_core_session_message_types_t;

View File

@ -868,9 +868,15 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
default:
break;
}
/* ones that do need to lock sofia mutex */
switch_mutex_lock(tech_pvt->sofia_mutex);
if (switch_channel_get_state(channel) >= CS_HANGUP || !tech_pvt) {
status = SWITCH_STATUS_FALSE;
goto end_lock;
}
switch (msg->message_id) {
case SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ:
{
@ -958,7 +964,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
status = SWITCH_STATUS_FALSE;
goto end;
goto end_lock;
}
send_invite = 0;
}
@ -968,7 +974,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
sofia_glue_tech_prepare_codecs(tech_pvt);
if ((status = sofia_glue_tech_choose_port(tech_pvt, 0)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
goto end;
goto end_lock;
}
}
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 1);
@ -1098,7 +1104,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
msg->message_id = SWITCH_MESSAGE_INDICATE_REDIRECT;
msg->string_arg = p;
switch_core_session_receive_message(session, msg);
goto end;
goto end_lock;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Responding with %d [%s]\n", code, reason);
@ -1152,7 +1158,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
sofia_glue_tech_patch_sdp(tech_pvt);
if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_FALSE;
goto end;
goto end_lock;
}
}
} else {
@ -1165,18 +1171,16 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
sofia_glue_tech_prepare_codecs(tech_pvt);
if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
//switch_mutex_lock(tech_pvt->sofia_mutex);
//nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
//switch_mutex_unlock(tech_pvt->sofia_mutex);
status = SWITCH_STATUS_FALSE;
goto end;
goto end_lock;
}
}
}
if ((status = sofia_glue_tech_choose_port(tech_pvt, 0)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
goto end;
goto end_lock;
}
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
@ -1212,6 +1216,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
default:
break;
}
end_lock:
switch_mutex_unlock(tech_pvt->sofia_mutex);
end:

View File

@ -504,6 +504,7 @@ struct private_object {
int remote_port;
int got_bye;
int hold_laps;
switch_thread_id_t locker;
};
struct callback_t {

View File

@ -170,6 +170,7 @@ void sofia_event_callback(nua_event_t event,
switch_core_session_t *session = NULL;
switch_channel_t *channel = NULL;
sofia_gateway_t *gateway = NULL;
int locked = 0;
if (sofia_private && sofia_private != &mod_sofia_globals.destroy_private && sofia_private != &mod_sofia_globals.keep_private) {
if ((gateway = sofia_private->gateway)) {
@ -203,12 +204,15 @@ void sofia_event_callback(nua_event_t event,
}
if (session) {
switch_mutex_lock(tech_pvt->sofia_mutex);
if (channel && switch_channel_get_state(channel) >= CS_HANGUP) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is already hungup.\n");
goto done;
}
if (tech_pvt) {
switch_mutex_lock(tech_pvt->sofia_mutex);
locked = 1;
}
} else if (sofia_private && sofia_private->is_call) {
sofia_private->destroy_me = 22;
}
@ -360,9 +364,12 @@ void sofia_event_callback(nua_event_t event,
}
if (session) {
switch_mutex_unlock(tech_pvt->sofia_mutex);
switch_core_session_rwunlock(session);
}
if (tech_pvt && locked) {
switch_mutex_unlock(tech_pvt->sofia_mutex);
}
}
void event_handler(switch_event_t *event)

View File

@ -69,6 +69,11 @@
/* Memory Pools */
SWITCH_DECLARE(switch_thread_id_t) switch_thread_self(void)
{
return apr_os_thread_current();
}
SWITCH_DECLARE(void) switch_pool_clear(switch_memory_pool_t *p)
{
apr_pool_clear(p);

View File

@ -41,14 +41,14 @@ struct switch_hash {
Hash table;
};
SWITCH_DECLARE(switch_status_t) switch_core_hash_init(switch_hash_t **hash, switch_memory_pool_t *pool)
SWITCH_DECLARE(switch_status_t) switch_core_hash_init_case(switch_hash_t **hash, switch_memory_pool_t *pool, switch_bool_t case_sensitive)
{
switch_hash_t *newhash;
newhash = switch_core_alloc(pool, sizeof(*newhash));
switch_assert(newhash);
sqlite3HashInit(&newhash->table, SQLITE_HASH_BINARY, 1);
sqlite3HashInit(&newhash->table, case_sensitive ? SQLITE_HASH_BINARY : SQLITE_HASH_STRING, 1);
*hash = newhash;
return SWITCH_STATUS_SUCCESS;

View File

@ -413,7 +413,33 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_
return cause;
}
SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_session_t *session, switch_core_session_message_t *message)
static const char *message_names[] = {
"SWITCH_MESSAGE_REDIRECT_AUDIO",
"SWITCH_MESSAGE_TRANSMIT_TEXT",
"SWITCH_MESSAGE_INDICATE_ANSWER",
"SWITCH_MESSAGE_INDICATE_PROGRESS",
"SWITCH_MESSAGE_INDICATE_BRIDGE",
"SWITCH_MESSAGE_INDICATE_UNBRIDGE",
"SWITCH_MESSAGE_INDICATE_TRANSFER",
"SWITCH_MESSAGE_INDICATE_RINGING",
"SWITCH_MESSAGE_INDICATE_MEDIA",
"SWITCH_MESSAGE_INDICATE_NOMEDIA",
"SWITCH_MESSAGE_INDICATE_HOLD",
"SWITCH_MESSAGE_INDICATE_UNHOLD",
"SWITCH_MESSAGE_INDICATE_REDIRECT",
"SWITCH_MESSAGE_INDICATE_RESPOND",
"SWITCH_MESSAGE_INDICATE_BROADCAST",
"SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT",
"SWITCH_MESSAGE_INDICATE_DEFLECT",
"SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ",
"SWITCH_MESSAGE_INDICATE_DISPLAY",
"SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY",
"SWITCH_MESSAGE_INVALID"
};
SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(switch_core_session_t *session,
switch_core_session_message_t *message,
const char *file, const char *func, int line)
{
switch_io_event_hook_receive_message_t *ptr;
switch_status_t status = SWITCH_STATUS_SUCCESS;
@ -428,6 +454,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_
return status;
}
message->_file = file;
message->_func = func;
message->_line = line;
if (message->message_id > SWITCH_MESSAGE_INVALID) {
message->message_id = SWITCH_MESSAGE_INVALID;
}
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, "%s receive message [%s]\n",
switch_channel_get_name(session->channel), message_names[message->message_id]);
if (session->endpoint_interface->io_routines->receive_message) {
status = session->endpoint_interface->io_routines->receive_message(session, message);
}
@ -440,6 +477,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_
}
}
message->_file = NULL;
message->_func = NULL;
message->_line = 0;
switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
switch_core_session_rwunlock(session);

View File

@ -1020,19 +1020,19 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init()
#endif
switch_core_hash_init(&loadable_modules.module_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.endpoint_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.codec_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.timer_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.application_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.api_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.endpoint_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.codec_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.timer_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.application_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.api_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.file_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.speech_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.asr_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.directory_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.chat_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.say_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.management_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.dialplan_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.speech_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.asr_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.directory_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.chat_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.say_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.management_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.dialplan_hash, loadable_modules.pool);
switch_mutex_init(&loadable_modules.mutex, SWITCH_MUTEX_NESTED, loadable_modules.pool);
switch_loadable_module_load_module("", "CORE_SOFTTIMER_MODULE", SWITCH_FALSE, &err);