From e60fbc2267e64dfe43e313f163a5e7dd16da09fc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 22 Dec 2005 01:57:32 +0000 Subject: [PATCH] get uuid from apr-utils for channel events git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@190 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch.h | 2 ++ src/include/switch_core.h | 1 + src/include/switch_types.h | 7 ++++++- src/switch_channel.c | 5 ++++- src/switch_core.c | 10 ++++++++++ src/switch_event.c | 16 ---------------- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/include/switch.h b/src/include/switch.h index 449ec62f85..bcdb11e757 100644 --- a/src/include/switch.h +++ b/src/include/switch.h @@ -59,6 +59,8 @@ extern "C" { #include #include #include +#include +#include #include #include diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 786300df15..0dcf1b08a2 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -122,6 +122,7 @@ SWITCH_DECLARE(switch_memory_pool *) switch_core_session_get_pool(switch_core_se SWITCH_DECLARE(void) pbx_core_session_signal_state_change(switch_core_session *session); SWITCH_DECLARE(char *) switch_core_strdup(switch_memory_pool *pool, char *todup); SWITCH_DECLARE(switch_core_db *) switch_core_db_open_file(char *filename); +SWITCH_DECLARE(char *) switch_core_session_get_uuid(switch_core_session *session); #define SWITCH_CORE_DB "core" #define switch_core_db_handle() switch_core_db_open_file(SWITCH_CORE_DB) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 77b49e0d50..61ca2077fd 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -65,7 +65,7 @@ typedef enum { #endif #endif - +#define SWITCH_UUID_FORMATTED_LENGTH APR_UUID_FORMATTED_LENGTH #define SWITCH_CHANNEL_CONSOLE SWITCH_CHANNEL_ID_CONSOLE, __FILE__, __FUNCTION__, __LINE__ #define SWITCH_CHANNEL_CONSOLE_CLEAN SWITCH_CHANNEL_ID_CONSOLE_CLEAN, __FILE__, __FUNCTION__, __LINE__ #define SWITCH_CHANNEL_EVENT SWITCH_CHANNEL_ID_EVENT, __FILE__, __FUNCTION__, __LINE__ @@ -193,6 +193,8 @@ typedef switch_status (*switch_api_function)(char *in, char *out, size_t outlen) 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. */ +typedef apr_uuid_t switch_uuid_t; +typedef apr_queue_t switch_queue_t; typedef apr_hash_t switch_hash; typedef apr_pool_t switch_memory_pool; typedef apr_thread_t switch_thread; @@ -226,6 +228,9 @@ typedef apr_hash_index_t switch_hash_index_t; #define switch_thread_cond_broadcast apr_thread_cond_broadcast #define switch_thread_cond_destroy apr_thread_cond_destroy +#define switch_uuid_format apr_uuid_format +#define switch_uuid_get apr_uuid_get +#define switch_uuid_parse apr_uuid_parse #define switch_queue_create apr_queue_create #define switch_queue_interrupt_all apr_queue_interrupt_all #define switch_queue_pop apr_queue_pop diff --git a/src/switch_channel.c b/src/switch_channel.c index df572d0645..d5603d929d 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -65,7 +65,8 @@ SWITCH_DECLARE(switch_status) switch_channel_alloc(switch_channel **channel, swi switch_core_hash_init(&(*channel)->variables, pool); switch_buffer_create(pool, &(*channel)->dtmf_buffer, 128); switch_mutex_init(&(*channel)->dtmf_mutex, SWITCH_MUTEX_NESTED, pool); - + + return SWITCH_STATUS_SUCCESS; } @@ -406,6 +407,8 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit switch_event_add_header(event, "channel_state", (char *) switch_channel_state_name(channel->state)); switch_event_add_header(event, "channel_name", switch_channel_get_name(channel)); + switch_event_add_header(event, "unique_id", switch_core_session_get_uuid(channel->session)); + /* Index Caller's Profile */ if (caller_profile) { diff --git a/src/switch_core.c b/src/switch_core.c index 21cada090f..1c312ec9b4 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -74,6 +74,7 @@ struct switch_core_session { switch_mutex_t *mutex; switch_thread_cond_t *cond; + char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1]; void *private; }; @@ -179,6 +180,11 @@ SWITCH_DECLARE(switch_status) switch_core_do_perl(char *txt) #endif +SWITCH_DECLARE(char *) switch_core_session_get_uuid(switch_core_session *session) +{ + return session->uuid_str; +} + SWITCH_DECLARE(switch_status) switch_core_session_set_read_codec(switch_core_session *session, switch_codec *codec) { assert(session != NULL); @@ -1490,6 +1496,7 @@ SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_e { switch_memory_pool *usepool; switch_core_session *session; + switch_uuid_t uuid; assert(endpoint_interface != NULL); @@ -1517,6 +1524,9 @@ SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_e /* The session *IS* the pool you may not alter it because you have no idea how its all private it will be passed to the thread run function */ + switch_uuid_get(&uuid); + switch_uuid_format(session->uuid_str, &uuid); + session->pool = usepool; session->endpoint_interface = endpoint_interface; diff --git a/src/switch_event.c b/src/switch_event.c index 05e314d229..1fb5c068a5 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -60,22 +60,6 @@ static char *EVENT_NAMES[] = { }; -#if 0 -static void debug_hash(void) { - switch_hash_index_t* hi; - void *val; - const void *var; - for (hi = switch_hash_first(EPOOL, CUSTOM_HASH); hi; hi = switch_hash_next(hi)) { - switch_event_subclass *subclass; - switch_hash_this(hi, &var, NULL, &val); - subclass = val; - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "***WTF %s=%s\n", (char *) var, subclass->name); - } -} -#endif - - - static int switch_events_match(switch_event *event, switch_event_node *node) { int match = 0;