2005-12-13 20:52:33 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
2006-09-18 05:08:55 +00:00
|
|
|
* Michael Jerris <mike@jerris.com>
|
|
|
|
* Paul D. Tinsley <pdt at jackhammer.org>
|
2005-12-13 20:52:33 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* switch_event.c -- Event System
|
|
|
|
*
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
#include <switch.h>
|
2006-04-29 06:05:03 +00:00
|
|
|
#include <switch_event.h>
|
2005-12-13 20:52:33 +00:00
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
static switch_event_node_t *EVENT_NODES[SWITCH_EVENT_ALL + 1] = { NULL };
|
2005-12-14 21:29:46 +00:00
|
|
|
static switch_mutex_t *BLOCK = NULL;
|
2005-12-22 18:53:33 +00:00
|
|
|
static switch_mutex_t *POOL_LOCK = NULL;
|
2006-09-17 18:03:32 +00:00
|
|
|
static switch_mutex_t *EVENT_QUEUE_MUTEX = NULL;
|
|
|
|
static switch_mutex_t *EVENT_QUEUE_HAVEMORE_MUTEX = NULL;
|
|
|
|
static switch_thread_cond_t *EVENT_QUEUE_CONDITIONAL = NULL;
|
2006-04-29 01:00:52 +00:00
|
|
|
static switch_memory_pool_t *RUNTIME_POOL = NULL;
|
2007-03-04 01:50:52 +00:00
|
|
|
/* static switch_memory_pool_t *APOOL = NULL; */
|
|
|
|
/* static switch_memory_pool_t *BPOOL = NULL; */
|
2006-04-29 01:00:52 +00:00
|
|
|
static switch_memory_pool_t *THRUNTIME_POOL = NULL;
|
2007-03-29 22:31:56 +00:00
|
|
|
static switch_queue_t *EVENT_QUEUE[3] = { 0, 0, 0 };
|
2006-06-05 17:37:24 +00:00
|
|
|
static int POOL_COUNT_MAX = SWITCH_CORE_QUEUE_LEN;
|
2005-12-22 18:53:33 +00:00
|
|
|
|
2006-04-29 01:00:52 +00:00
|
|
|
static switch_hash_t *CUSTOM_HASH = NULL;
|
2005-12-14 20:22:19 +00:00
|
|
|
static int THREAD_RUNNING = 0;
|
2006-09-17 18:03:32 +00:00
|
|
|
static int EVENT_QUEUE_HAVEMORE = 0;
|
2005-12-13 20:52:33 +00:00
|
|
|
|
2006-03-29 19:11:20 +00:00
|
|
|
#if 0
|
2006-03-30 23:02:50 +00:00
|
|
|
static void *locked_alloc(switch_size_t len)
|
2005-12-22 18:53:33 +00:00
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
|
|
|
|
switch_mutex_lock(POOL_LOCK);
|
2006-01-20 15:05:05 +00:00
|
|
|
/* <LOCKED> ----------------------------------------------- */
|
2005-12-22 18:53:33 +00:00
|
|
|
mem = switch_core_alloc(THRUNTIME_POOL, len);
|
|
|
|
switch_mutex_unlock(POOL_LOCK);
|
2006-01-20 15:05:05 +00:00
|
|
|
/* </LOCKED> ---------------------------------------------- */
|
2005-12-22 18:53:33 +00:00
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *locked_dup(char *str)
|
|
|
|
{
|
|
|
|
char *dup;
|
|
|
|
|
|
|
|
switch_mutex_lock(POOL_LOCK);
|
2006-01-20 15:05:05 +00:00
|
|
|
/* <LOCKED> ----------------------------------------------- */
|
2005-12-22 18:53:33 +00:00
|
|
|
dup = switch_core_strdup(THRUNTIME_POOL, str);
|
|
|
|
switch_mutex_unlock(POOL_LOCK);
|
2006-01-20 15:05:05 +00:00
|
|
|
/* </LOCKED> ---------------------------------------------- */
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2005-12-22 18:53:33 +00:00
|
|
|
return dup;
|
|
|
|
}
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2005-12-22 18:53:33 +00:00
|
|
|
#define ALLOC(size) locked_alloc(size)
|
|
|
|
#define DUP(str) locked_dup(str)
|
2006-03-29 19:11:20 +00:00
|
|
|
#endif
|
2006-02-26 00:12:17 +00:00
|
|
|
|
2006-04-29 01:00:52 +00:00
|
|
|
#ifndef ALLOC
|
2006-03-29 19:11:20 +00:00
|
|
|
#define ALLOC(size) malloc(size)
|
2006-04-29 01:00:52 +00:00
|
|
|
#endif
|
|
|
|
#ifndef DUP
|
2006-03-29 19:11:20 +00:00
|
|
|
#define DUP(str) strdup(str)
|
2006-04-29 01:00:52 +00:00
|
|
|
#endif
|
|
|
|
#ifndef FREE
|
2006-03-29 19:11:20 +00:00
|
|
|
#define FREE(ptr) if (ptr) free(ptr)
|
2006-04-29 01:00:52 +00:00
|
|
|
#endif
|
2005-12-22 18:53:33 +00:00
|
|
|
|
2006-04-29 01:00:52 +00:00
|
|
|
/* make sure this is synced with the switch_event_types_t enum in switch_types.h
|
2006-01-03 01:17:59 +00:00
|
|
|
also never put any new ones before EVENT_ALL
|
2005-12-13 20:52:33 +00:00
|
|
|
*/
|
|
|
|
static char *EVENT_NAMES[] = {
|
|
|
|
"CUSTOM",
|
2006-04-04 21:26:21 +00:00
|
|
|
"CHANNEL_CREATE",
|
2006-04-25 23:11:56 +00:00
|
|
|
"CHANNEL_DESTROY",
|
2005-12-21 22:25:22 +00:00
|
|
|
"CHANNEL_STATE",
|
|
|
|
"CHANNEL_ANSWER",
|
2006-01-05 21:03:22 +00:00
|
|
|
"CHANNEL_HANGUP",
|
2006-04-04 21:26:21 +00:00
|
|
|
"CHANNEL_EXECUTE",
|
2007-06-23 05:41:07 +00:00
|
|
|
"CHANNEL_EXECUTE_COMPLETE",
|
2006-04-11 14:55:14 +00:00
|
|
|
"CHANNEL_BRIDGE",
|
|
|
|
"CHANNEL_UNBRIDGE",
|
2006-08-29 15:17:06 +00:00
|
|
|
"CHANNEL_PROGRESS",
|
|
|
|
"CHANNEL_OUTGOING",
|
2006-09-07 03:58:01 +00:00
|
|
|
"CHANNEL_PARK",
|
|
|
|
"CHANNEL_UNPARK",
|
2007-06-23 05:41:07 +00:00
|
|
|
"CHANNEL_APPLICATION",
|
2005-12-23 02:24:56 +00:00
|
|
|
"API",
|
2005-12-21 22:25:22 +00:00
|
|
|
"LOG",
|
2005-12-13 20:52:33 +00:00
|
|
|
"INBOUND_CHAN",
|
|
|
|
"OUTBOUND_CHAN",
|
|
|
|
"STARTUP",
|
2005-12-14 21:29:46 +00:00
|
|
|
"SHUTDOWN",
|
2006-02-13 23:59:14 +00:00
|
|
|
"PUBLISH",
|
|
|
|
"UNPUBLISH",
|
2006-04-21 22:31:08 +00:00
|
|
|
"TALK",
|
|
|
|
"NOTALK",
|
2006-04-27 21:09:58 +00:00
|
|
|
"SESSION_CRASH",
|
2006-05-01 19:44:21 +00:00
|
|
|
"MODULE_LOAD",
|
2007-05-03 16:28:23 +00:00
|
|
|
"MODULE_UNLOAD",
|
2006-05-04 17:51:53 +00:00
|
|
|
"DTMF",
|
2006-07-25 14:14:07 +00:00
|
|
|
"MESSAGE",
|
2006-10-12 00:59:09 +00:00
|
|
|
"PRESENCE_IN",
|
|
|
|
"PRESENCE_OUT",
|
2006-12-16 03:00:56 +00:00
|
|
|
"PRESENCE_PROBE",
|
2007-04-02 20:20:46 +00:00
|
|
|
"MESSAGE_WAITING",
|
|
|
|
"MESSAGE_QUERY",
|
2006-10-18 22:57:35 +00:00
|
|
|
"ROSTER",
|
2006-08-25 01:33:28 +00:00
|
|
|
"CODEC",
|
2006-09-07 03:58:01 +00:00
|
|
|
"BACKGROUND_JOB",
|
2006-11-09 05:39:04 +00:00
|
|
|
"DETECTED_SPEECH",
|
2007-06-16 02:25:40 +00:00
|
|
|
"DETECTED_TONE",
|
2007-02-19 21:06:27 +00:00
|
|
|
"PRIVATE_COMMAND",
|
2007-02-22 17:38:34 +00:00
|
|
|
"HEARTBEAT",
|
2007-03-05 20:55:41 +00:00
|
|
|
"TRAP",
|
2007-03-30 00:10:33 +00:00
|
|
|
"ADD_SCHEDULE",
|
|
|
|
"DEL_SCHEDULE",
|
|
|
|
"EXE_SCHEDULE",
|
|
|
|
"RE_SCHEDULE",
|
2005-12-13 20:52:33 +00:00
|
|
|
"ALL"
|
|
|
|
};
|
|
|
|
|
2005-12-19 18:55:31 +00:00
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
static int switch_events_match(switch_event_t *event, switch_event_node_t *node)
|
2005-12-15 19:10:43 +00:00
|
|
|
{
|
|
|
|
int match = 0;
|
|
|
|
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2005-12-19 18:55:31 +00:00
|
|
|
if (node->event_id == SWITCH_EVENT_ALL) {
|
2005-12-15 20:20:57 +00:00
|
|
|
match++;
|
|
|
|
|
|
|
|
if (!node->subclass) {
|
|
|
|
return match;
|
|
|
|
}
|
2005-12-15 19:10:43 +00:00
|
|
|
}
|
|
|
|
|
2005-12-19 18:55:31 +00:00
|
|
|
if (match || event->event_id == node->event_id) {
|
2006-02-13 23:59:14 +00:00
|
|
|
|
2005-12-15 20:20:57 +00:00
|
|
|
if (event->subclass && node->subclass) {
|
more event stuff
you should now be able to bind an event handler to a
paticiular file or function not just a paticular event
when using the custom event
like "file:somefile.c"
or "func:somefunc"
also events now have headers which can be added
with varargs and should be created and delivered with api calls
switch_event *event;
regular event:
if (switch_event_create(&event, SWITCH_EVENT_STARTUP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "System Ready");
switch_event_fire(&event);
}
custom event:
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "some_subclass_string") == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "hello world %d", 42);
switch_event_fire(&event);
}
switch_event_add_header(event, "test %d", 42);
also you can serialize and event into a buffer in
a printable/transferrable format with optional body
char buf[1024];
with body:
switch_event_serialize(event, buf, sizeof(buf), "This is a body my favorite number is %d", 42);
no body:
switch_event_serialize(event, buf, sizeof(buf), NULL);
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@173 d0543943-73ff-0310-b7d9-9358b9ac24b2
2005-12-19 19:57:32 +00:00
|
|
|
if (!strncasecmp(node->subclass->name, "file:", 5)) {
|
|
|
|
char *file_header;
|
2006-02-20 00:23:25 +00:00
|
|
|
if ((file_header = switch_event_get_header(event, "file")) != 0) {
|
more event stuff
you should now be able to bind an event handler to a
paticiular file or function not just a paticular event
when using the custom event
like "file:somefile.c"
or "func:somefunc"
also events now have headers which can be added
with varargs and should be created and delivered with api calls
switch_event *event;
regular event:
if (switch_event_create(&event, SWITCH_EVENT_STARTUP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "System Ready");
switch_event_fire(&event);
}
custom event:
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "some_subclass_string") == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "hello world %d", 42);
switch_event_fire(&event);
}
switch_event_add_header(event, "test %d", 42);
also you can serialize and event into a buffer in
a printable/transferrable format with optional body
char buf[1024];
with body:
switch_event_serialize(event, buf, sizeof(buf), "This is a body my favorite number is %d", 42);
no body:
switch_event_serialize(event, buf, sizeof(buf), NULL);
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@173 d0543943-73ff-0310-b7d9-9358b9ac24b2
2005-12-19 19:57:32 +00:00
|
|
|
match = strstr(node->subclass->name + 5, file_header) ? 1 : 0;
|
|
|
|
}
|
|
|
|
} else if (!strncasecmp(node->subclass->name, "func:", 5)) {
|
|
|
|
char *func_header;
|
2006-02-20 00:23:25 +00:00
|
|
|
if ((func_header = switch_event_get_header(event, "function")) != 0) {
|
more event stuff
you should now be able to bind an event handler to a
paticiular file or function not just a paticular event
when using the custom event
like "file:somefile.c"
or "func:somefunc"
also events now have headers which can be added
with varargs and should be created and delivered with api calls
switch_event *event;
regular event:
if (switch_event_create(&event, SWITCH_EVENT_STARTUP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "System Ready");
switch_event_fire(&event);
}
custom event:
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "some_subclass_string") == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "hello world %d", 42);
switch_event_fire(&event);
}
switch_event_add_header(event, "test %d", 42);
also you can serialize and event into a buffer in
a printable/transferrable format with optional body
char buf[1024];
with body:
switch_event_serialize(event, buf, sizeof(buf), "This is a body my favorite number is %d", 42);
no body:
switch_event_serialize(event, buf, sizeof(buf), NULL);
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@173 d0543943-73ff-0310-b7d9-9358b9ac24b2
2005-12-19 19:57:32 +00:00
|
|
|
match = strstr(node->subclass->name + 5, func_header) ? 1 : 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
match = strstr(event->subclass->name, node->subclass->name) ? 1 : 0;
|
|
|
|
}
|
2006-02-13 23:59:14 +00:00
|
|
|
} else if ((event->subclass && !node->subclass) || (!event->subclass && !node->subclass)) {
|
2005-12-15 20:20:57 +00:00
|
|
|
match = 1;
|
|
|
|
} else {
|
2005-12-15 19:10:43 +00:00
|
|
|
match = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread_t * thread, void *obj)
|
2005-12-14 20:22:19 +00:00
|
|
|
{
|
2006-04-29 01:00:52 +00:00
|
|
|
switch_event_t *out_event = NULL;
|
2006-02-26 00:12:17 +00:00
|
|
|
switch_queue_t *queue = NULL;
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_queue_t *queues[3] = { 0, 0, 0 };
|
2005-12-22 18:53:33 +00:00
|
|
|
void *pop;
|
2007-03-29 22:31:56 +00:00
|
|
|
int i, len[3] = { 0, 0, 0 };
|
2005-12-14 20:22:19 +00:00
|
|
|
|
2006-03-30 23:02:50 +00:00
|
|
|
assert(thread != NULL);
|
|
|
|
assert(obj == NULL);
|
2005-12-22 18:53:33 +00:00
|
|
|
assert(POOL_LOCK != NULL);
|
|
|
|
assert(RUNTIME_POOL != NULL);
|
2006-09-17 18:03:32 +00:00
|
|
|
assert(EVENT_QUEUE_MUTEX != NULL);
|
|
|
|
assert(EVENT_QUEUE_HAVEMORE_MUTEX != NULL);
|
|
|
|
assert(EVENT_QUEUE_CONDITIONAL != NULL);
|
2005-12-14 20:22:19 +00:00
|
|
|
THREAD_RUNNING = 1;
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-02-26 00:12:17 +00:00
|
|
|
queues[0] = EVENT_QUEUE[SWITCH_PRIORITY_HIGH];
|
|
|
|
queues[1] = EVENT_QUEUE[SWITCH_PRIORITY_NORMAL];
|
|
|
|
queues[2] = EVENT_QUEUE[SWITCH_PRIORITY_LOW];
|
2006-09-17 18:03:32 +00:00
|
|
|
|
|
|
|
switch_mutex_lock(EVENT_QUEUE_MUTEX);
|
2007-03-29 22:31:56 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2006-04-26 17:18:33 +00:00
|
|
|
int any;
|
|
|
|
|
2006-09-17 18:03:32 +00:00
|
|
|
|
2006-04-04 18:47:34 +00:00
|
|
|
len[1] = switch_queue_size(EVENT_QUEUE[SWITCH_PRIORITY_NORMAL]);
|
|
|
|
len[2] = switch_queue_size(EVENT_QUEUE[SWITCH_PRIORITY_LOW]);
|
|
|
|
len[0] = switch_queue_size(EVENT_QUEUE[SWITCH_PRIORITY_HIGH]);
|
2006-04-26 17:18:33 +00:00
|
|
|
any = len[1] + len[2] + len[0];
|
2006-02-26 00:12:17 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-04-26 17:18:33 +00:00
|
|
|
if (!any) {
|
2007-03-04 01:50:52 +00:00
|
|
|
/* lock on havemore so we are the only ones poking at it while we check it
|
|
|
|
* see if we saw anything in the queues or have a check again flag
|
|
|
|
*/
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_lock(EVENT_QUEUE_HAVEMORE_MUTEX);
|
2007-03-29 22:31:56 +00:00
|
|
|
if (!EVENT_QUEUE_HAVEMORE) {
|
2007-03-04 01:50:52 +00:00
|
|
|
/* See if we need to quit */
|
2006-09-17 18:03:32 +00:00
|
|
|
if (THREAD_RUNNING != 1) {
|
2007-03-04 01:50:52 +00:00
|
|
|
/* give up our lock */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_unlock(EVENT_QUEUE_HAVEMORE_MUTEX);
|
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* game over */
|
2006-09-17 18:03:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* give up our lock */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_unlock(EVENT_QUEUE_HAVEMORE_MUTEX);
|
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* wait until someone tells us we have something to do */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_thread_cond_wait(EVENT_QUEUE_CONDITIONAL, EVENT_QUEUE_MUTEX);
|
|
|
|
} else {
|
2007-03-04 01:50:52 +00:00
|
|
|
/* Caught a race, one of the queues was updated after we looked at it
|
|
|
|
* reset our flag
|
|
|
|
*/
|
2006-09-17 18:03:32 +00:00
|
|
|
EVENT_QUEUE_HAVEMORE = 0;
|
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* give up our lock */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_unlock(EVENT_QUEUE_HAVEMORE_MUTEX);
|
2006-04-26 17:18:33 +00:00
|
|
|
}
|
2006-09-17 18:03:32 +00:00
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* go grab some events */
|
2006-04-26 17:18:33 +00:00
|
|
|
continue;
|
2006-04-04 18:47:34 +00:00
|
|
|
}
|
2006-02-26 00:12:17 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2006-03-30 23:02:50 +00:00
|
|
|
if (len[i]) {
|
|
|
|
queue = queues[i];
|
2007-03-29 22:31:56 +00:00
|
|
|
while (queue) {
|
2006-04-26 17:18:33 +00:00
|
|
|
if (switch_queue_trypop(queue, &pop) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
out_event = pop;
|
|
|
|
switch_event_deliver(&out_event);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2006-03-30 23:02:50 +00:00
|
|
|
}
|
2005-12-22 18:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-01 17:06:10 +00:00
|
|
|
|
|
|
|
if (THREAD_RUNNING < 0) {
|
|
|
|
THREAD_RUNNING--;
|
|
|
|
}
|
2006-02-26 00:12:17 +00:00
|
|
|
}
|
2006-04-26 19:29:56 +00:00
|
|
|
|
|
|
|
|
2006-02-26 00:12:17 +00:00
|
|
|
THREAD_RUNNING = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-12-14 20:22:19 +00:00
|
|
|
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void) switch_event_deliver(switch_event_t **event)
|
2006-02-26 00:12:17 +00:00
|
|
|
{
|
2006-04-29 01:00:52 +00:00
|
|
|
switch_event_types_t e;
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_event_node_t *node;
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2006-02-26 00:12:17 +00:00
|
|
|
for (e = (*event)->event_id;; e = SWITCH_EVENT_ALL) {
|
|
|
|
for (node = EVENT_NODES[e]; node; node = node->next) {
|
|
|
|
if (switch_events_match(*event, node)) {
|
|
|
|
(*event)->bind_user_data = node->user_data;
|
|
|
|
node->callback(*event);
|
2005-12-14 20:22:19 +00:00
|
|
|
}
|
|
|
|
}
|
2005-12-14 21:29:46 +00:00
|
|
|
|
2006-02-26 00:12:17 +00:00
|
|
|
if (e == SWITCH_EVENT_ALL) {
|
|
|
|
break;
|
|
|
|
}
|
2005-12-14 20:22:19 +00:00
|
|
|
}
|
2006-02-26 00:12:17 +00:00
|
|
|
|
|
|
|
switch_event_destroy(event);
|
2005-12-14 20:22:19 +00:00
|
|
|
}
|
|
|
|
|
2006-02-26 00:12:17 +00:00
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_running(void)
|
2005-12-21 22:25:22 +00:00
|
|
|
{
|
|
|
|
return THREAD_RUNNING ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
|
|
|
}
|
2005-12-15 19:10:43 +00:00
|
|
|
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_event_name(switch_event_types_t event)
|
2005-12-13 20:52:33 +00:00
|
|
|
{
|
2005-12-14 21:29:46 +00:00
|
|
|
assert(BLOCK != NULL);
|
2005-12-22 18:53:33 +00:00
|
|
|
assert(RUNTIME_POOL != NULL);
|
2005-12-14 20:22:19 +00:00
|
|
|
|
2005-12-13 20:52:33 +00:00
|
|
|
return EVENT_NAMES[event];
|
|
|
|
}
|
|
|
|
|
2006-07-22 21:49:52 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_name_event(char *name, switch_event_types_t *type)
|
|
|
|
{
|
|
|
|
switch_event_types_t x;
|
|
|
|
assert(BLOCK != NULL);
|
|
|
|
assert(RUNTIME_POOL != NULL);
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-07-22 21:49:52 +00:00
|
|
|
for (x = 0; x <= SWITCH_EVENT_ALL; x++) {
|
2007-04-02 20:20:46 +00:00
|
|
|
if ((strlen(name) > 13 && !strcasecmp(name + 13, EVENT_NAMES[x])) || !strcasecmp(name, EVENT_NAMES[x])) {
|
2006-07-22 21:49:52 +00:00
|
|
|
*type = x;
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-07-22 21:49:52 +00:00
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_reserve_subclass_detailed(char *owner, char *subclass_name)
|
2005-12-14 22:46:09 +00:00
|
|
|
{
|
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_event_subclass_t *subclass;
|
2005-12-14 22:46:09 +00:00
|
|
|
|
2005-12-22 18:53:33 +00:00
|
|
|
assert(RUNTIME_POOL != NULL);
|
2005-12-14 22:46:09 +00:00
|
|
|
assert(CUSTOM_HASH != NULL);
|
|
|
|
|
2005-12-15 19:10:43 +00:00
|
|
|
if (switch_core_hash_find(CUSTOM_HASH, subclass_name)) {
|
2005-12-14 22:46:09 +00:00
|
|
|
return SWITCH_STATUS_INUSE;
|
|
|
|
}
|
2005-12-15 19:10:43 +00:00
|
|
|
|
2006-02-20 00:23:25 +00:00
|
|
|
if ((subclass = switch_core_alloc(RUNTIME_POOL, sizeof(*subclass))) == 0) {
|
2005-12-15 19:10:43 +00:00
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
|
|
|
|
2005-12-22 18:53:33 +00:00
|
|
|
subclass->owner = switch_core_strdup(RUNTIME_POOL, owner);
|
|
|
|
subclass->name = switch_core_strdup(RUNTIME_POOL, subclass_name);
|
2006-01-03 01:17:59 +00:00
|
|
|
|
more event stuff
you should now be able to bind an event handler to a
paticiular file or function not just a paticular event
when using the custom event
like "file:somefile.c"
or "func:somefunc"
also events now have headers which can be added
with varargs and should be created and delivered with api calls
switch_event *event;
regular event:
if (switch_event_create(&event, SWITCH_EVENT_STARTUP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "System Ready");
switch_event_fire(&event);
}
custom event:
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "some_subclass_string") == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "hello world %d", 42);
switch_event_fire(&event);
}
switch_event_add_header(event, "test %d", 42);
also you can serialize and event into a buffer in
a printable/transferrable format with optional body
char buf[1024];
with body:
switch_event_serialize(event, buf, sizeof(buf), "This is a body my favorite number is %d", 42);
no body:
switch_event_serialize(event, buf, sizeof(buf), NULL);
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@173 d0543943-73ff-0310-b7d9-9358b9ac24b2
2005-12-19 19:57:32 +00:00
|
|
|
switch_core_hash_insert(CUSTOM_HASH, subclass->name, subclass);
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2005-12-14 22:46:09 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void)
|
2005-12-14 20:22:19 +00:00
|
|
|
{
|
2006-03-01 17:06:10 +00:00
|
|
|
int x = 0, last = 0;
|
2005-12-22 18:53:33 +00:00
|
|
|
|
2006-03-01 17:06:10 +00:00
|
|
|
if (THREAD_RUNNING > 0) {
|
|
|
|
THREAD_RUNNING = -1;
|
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* lock on havemore to make sure he event thread, if currently running
|
|
|
|
* doesn't check the HAVEMORE flag before we set it
|
|
|
|
*/
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_lock(EVENT_QUEUE_HAVEMORE_MUTEX);
|
2007-03-04 01:50:52 +00:00
|
|
|
/* see if the event thread is sitting */
|
2007-03-29 22:31:56 +00:00
|
|
|
if (switch_mutex_trylock(EVENT_QUEUE_MUTEX) == SWITCH_STATUS_SUCCESS) {
|
2007-03-04 01:50:52 +00:00
|
|
|
/* we don't need havemore anymore, the thread was sitting already */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_unlock(EVENT_QUEUE_HAVEMORE_MUTEX);
|
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* wake up the event thread */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_thread_cond_signal(EVENT_QUEUE_CONDITIONAL);
|
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* give up our lock */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_unlock(EVENT_QUEUE_MUTEX);
|
2007-03-29 22:31:56 +00:00
|
|
|
} else {
|
2007-03-04 01:50:52 +00:00
|
|
|
/* it wasn't waiting which means we might have updated a queue it already looked at
|
|
|
|
* set a flag so it knows to read the queues again
|
|
|
|
*/
|
2006-09-17 18:03:32 +00:00
|
|
|
EVENT_QUEUE_HAVEMORE = 1;
|
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* variable updated, give up the mutex */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_unlock(EVENT_QUEUE_HAVEMORE_MUTEX);
|
|
|
|
}
|
|
|
|
|
2006-03-01 17:06:10 +00:00
|
|
|
while (x < 100 && THREAD_RUNNING) {
|
|
|
|
switch_yield(1000);
|
|
|
|
if (THREAD_RUNNING == last) {
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
last = THREAD_RUNNING;
|
|
|
|
}
|
2005-12-14 20:22:19 +00:00
|
|
|
}
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:15:25 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
|
2005-12-13 20:52:33 +00:00
|
|
|
{
|
2006-04-29 01:00:52 +00:00
|
|
|
switch_thread_t *thread;
|
2006-01-03 01:17:59 +00:00
|
|
|
switch_threadattr_t *thd_attr;;
|
|
|
|
switch_threadattr_create(&thd_attr, pool);
|
|
|
|
switch_threadattr_detach_set(thd_attr, 1);
|
2005-12-14 20:22:19 +00:00
|
|
|
|
2005-12-13 20:52:33 +00:00
|
|
|
assert(pool != NULL);
|
2007-03-30 17:25:48 +00:00
|
|
|
THRUNTIME_POOL = RUNTIME_POOL = pool;
|
2005-12-22 18:53:33 +00:00
|
|
|
|
2007-03-30 17:25:48 +00:00
|
|
|
/*
|
2006-03-29 19:11:20 +00:00
|
|
|
if (switch_core_new_memory_pool(&THRUNTIME_POOL) != SWITCH_STATUS_SUCCESS) {
|
2006-04-16 06:05:53 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not allocate memory pool\n");
|
2006-01-03 01:17:59 +00:00
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
2007-03-30 17:25:48 +00:00
|
|
|
*/
|
2006-03-29 19:11:20 +00:00
|
|
|
/*
|
2007-03-29 22:31:56 +00:00
|
|
|
if (switch_core_new_memory_pool(&BPOOL) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Could not allocate memory pool\n");
|
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
|
|
|
*/
|
2007-03-04 01:50:52 +00:00
|
|
|
/* THRUNTIME_POOL = APOOL; */
|
2006-02-26 00:12:17 +00:00
|
|
|
switch_queue_create(&EVENT_QUEUE[0], POOL_COUNT_MAX + 10, THRUNTIME_POOL);
|
|
|
|
switch_queue_create(&EVENT_QUEUE[1], POOL_COUNT_MAX + 10, THRUNTIME_POOL);
|
|
|
|
switch_queue_create(&EVENT_QUEUE[2], POOL_COUNT_MAX + 10, THRUNTIME_POOL);
|
2005-12-22 18:53:33 +00:00
|
|
|
|
2006-04-16 06:05:53 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Activate Eventing Engine.\n");
|
2005-12-22 18:53:33 +00:00
|
|
|
switch_mutex_init(&BLOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL);
|
|
|
|
switch_mutex_init(&POOL_LOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL);
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_init(&EVENT_QUEUE_MUTEX, SWITCH_MUTEX_NESTED, RUNTIME_POOL);
|
|
|
|
switch_mutex_init(&EVENT_QUEUE_HAVEMORE_MUTEX, SWITCH_MUTEX_NESTED, RUNTIME_POOL);
|
|
|
|
switch_thread_cond_create(&EVENT_QUEUE_CONDITIONAL, RUNTIME_POOL);
|
2005-12-22 18:53:33 +00:00
|
|
|
switch_core_hash_init(&CUSTOM_HASH, RUNTIME_POOL);
|
2006-04-26 17:18:33 +00:00
|
|
|
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
|
2006-01-20 15:05:05 +00:00
|
|
|
switch_thread_create(&thread, thd_attr, switch_event_thread, NULL, RUNTIME_POOL);
|
|
|
|
|
|
|
|
while (!THREAD_RUNNING) {
|
2005-12-14 21:29:46 +00:00
|
|
|
switch_yield(1000);
|
|
|
|
}
|
2005-12-14 20:22:19 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
|
2005-12-13 20:52:33 +00:00
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_create_subclass(switch_event_t **event, switch_event_types_t event_id, const char *subclass_name)
|
2005-12-13 20:52:33 +00:00
|
|
|
{
|
2005-12-19 18:55:31 +00:00
|
|
|
|
|
|
|
if (event_id != SWITCH_EVENT_CUSTOM && subclass_name) {
|
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
2005-12-13 20:52:33 +00:00
|
|
|
|
2006-04-29 01:00:52 +00:00
|
|
|
if ((*event = ALLOC(sizeof(switch_event_t))) == 0) {
|
2005-12-14 20:22:19 +00:00
|
|
|
return SWITCH_STATUS_MEMERR;
|
2005-12-13 20:52:33 +00:00
|
|
|
}
|
2006-04-29 01:00:52 +00:00
|
|
|
memset(*event, 0, sizeof(switch_event_t));
|
more event stuff
you should now be able to bind an event handler to a
paticiular file or function not just a paticular event
when using the custom event
like "file:somefile.c"
or "func:somefunc"
also events now have headers which can be added
with varargs and should be created and delivered with api calls
switch_event *event;
regular event:
if (switch_event_create(&event, SWITCH_EVENT_STARTUP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "System Ready");
switch_event_fire(&event);
}
custom event:
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "some_subclass_string") == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "hello world %d", 42);
switch_event_fire(&event);
}
switch_event_add_header(event, "test %d", 42);
also you can serialize and event into a buffer in
a printable/transferrable format with optional body
char buf[1024];
with body:
switch_event_serialize(event, buf, sizeof(buf), "This is a body my favorite number is %d", 42);
no body:
switch_event_serialize(event, buf, sizeof(buf), NULL);
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@173 d0543943-73ff-0310-b7d9-9358b9ac24b2
2005-12-19 19:57:32 +00:00
|
|
|
|
2005-12-19 18:55:31 +00:00
|
|
|
(*event)->event_id = event_id;
|
more event stuff
you should now be able to bind an event handler to a
paticiular file or function not just a paticular event
when using the custom event
like "file:somefile.c"
or "func:somefunc"
also events now have headers which can be added
with varargs and should be created and delivered with api calls
switch_event *event;
regular event:
if (switch_event_create(&event, SWITCH_EVENT_STARTUP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "System Ready");
switch_event_fire(&event);
}
custom event:
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "some_subclass_string") == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "hello world %d", 42);
switch_event_fire(&event);
}
switch_event_add_header(event, "test %d", 42);
also you can serialize and event into a buffer in
a printable/transferrable format with optional body
char buf[1024];
with body:
switch_event_serialize(event, buf, sizeof(buf), "This is a body my favorite number is %d", 42);
no body:
switch_event_serialize(event, buf, sizeof(buf), NULL);
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@173 d0543943-73ff-0310-b7d9-9358b9ac24b2
2005-12-19 19:57:32 +00:00
|
|
|
|
|
|
|
if (subclass_name) {
|
|
|
|
(*event)->subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name);
|
2007-02-13 04:43:49 +00:00
|
|
|
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Subclass", "%s", subclass_name);
|
more event stuff
you should now be able to bind an event handler to a
paticiular file or function not just a paticular event
when using the custom event
like "file:somefile.c"
or "func:somefunc"
also events now have headers which can be added
with varargs and should be created and delivered with api calls
switch_event *event;
regular event:
if (switch_event_create(&event, SWITCH_EVENT_STARTUP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "System Ready");
switch_event_fire(&event);
}
custom event:
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "some_subclass_string") == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "hello world %d", 42);
switch_event_fire(&event);
}
switch_event_add_header(event, "test %d", 42);
also you can serialize and event into a buffer in
a printable/transferrable format with optional body
char buf[1024];
with body:
switch_event_serialize(event, buf, sizeof(buf), "This is a body my favorite number is %d", 42);
no body:
switch_event_serialize(event, buf, sizeof(buf), NULL);
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@173 d0543943-73ff-0310-b7d9-9358b9ac24b2
2005-12-19 19:57:32 +00:00
|
|
|
}
|
|
|
|
|
2005-12-19 18:55:31 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_set_priority(switch_event_t *event, switch_priority_t priority)
|
2006-02-26 00:12:17 +00:00
|
|
|
{
|
|
|
|
event->priority = priority;
|
2007-02-13 04:43:49 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_TOP, "priority", "%s", switch_priority_name(priority));
|
2006-02-26 00:12:17 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_event_get_header(switch_event_t *event, char *header_name)
|
2005-12-19 18:55:31 +00:00
|
|
|
{
|
2006-04-29 01:00:52 +00:00
|
|
|
switch_event_header_t *hp;
|
2005-12-19 18:55:31 +00:00
|
|
|
if (header_name) {
|
2006-01-20 15:05:05 +00:00
|
|
|
for (hp = event->headers; hp; hp = hp->next) {
|
2005-12-19 18:55:31 +00:00
|
|
|
if (!strcasecmp(hp->name, header_name)) {
|
|
|
|
return hp->value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-08-18 01:28:50 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_event_get_body(switch_event_t *event)
|
|
|
|
{
|
|
|
|
if (event) {
|
|
|
|
return event->body;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt, ...)
|
2005-12-19 18:55:31 +00:00
|
|
|
{
|
2006-01-03 01:17:59 +00:00
|
|
|
int ret = 0;
|
2005-12-22 18:53:33 +00:00
|
|
|
char data[2048];
|
2005-12-19 18:55:31 +00:00
|
|
|
|
2006-01-03 01:17:59 +00:00
|
|
|
va_list ap;
|
2005-12-19 18:55:31 +00:00
|
|
|
va_start(ap, fmt);
|
2006-10-16 19:56:42 +00:00
|
|
|
ret = vsnprintf(data, sizeof(data), fmt, ap);
|
2005-12-19 18:55:31 +00:00
|
|
|
va_end(ap);
|
2005-12-22 18:53:33 +00:00
|
|
|
|
2005-12-19 18:55:31 +00:00
|
|
|
if (ret == -1) {
|
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
} else {
|
2006-04-29 01:00:52 +00:00
|
|
|
switch_event_header_t *header, *hp;
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2006-02-20 00:23:25 +00:00
|
|
|
if ((header = ALLOC(sizeof(*header))) == 0) {
|
2005-12-19 18:55:31 +00:00
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
2005-12-22 18:53:33 +00:00
|
|
|
|
2006-03-29 19:11:20 +00:00
|
|
|
memset(header, 0, sizeof(*header));
|
|
|
|
|
2005-12-22 18:53:33 +00:00
|
|
|
header->name = DUP(header_name);
|
|
|
|
header->value = DUP(data);
|
2006-03-30 23:02:50 +00:00
|
|
|
if (stack == SWITCH_STACK_TOP) {
|
2005-12-23 21:09:36 +00:00
|
|
|
header->next = event->headers;
|
2005-12-19 18:55:31 +00:00
|
|
|
event->headers = header;
|
2005-12-23 21:09:36 +00:00
|
|
|
} else {
|
|
|
|
for (hp = event->headers; hp && hp->next; hp = hp->next);
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2005-12-23 21:09:36 +00:00
|
|
|
if (hp) {
|
|
|
|
hp->next = header;
|
|
|
|
} else {
|
|
|
|
event->headers = header;
|
|
|
|
}
|
|
|
|
}
|
2005-12-19 18:55:31 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-23 02:24:56 +00:00
|
|
|
|
2007-02-14 02:53:23 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_add_body(switch_event_t *event, const char *fmt, ...)
|
2005-12-23 02:24:56 +00:00
|
|
|
{
|
2006-01-03 01:17:59 +00:00
|
|
|
int ret = 0;
|
2007-02-03 17:06:57 +00:00
|
|
|
char *data;
|
2005-12-23 02:24:56 +00:00
|
|
|
|
2006-01-03 01:17:59 +00:00
|
|
|
va_list ap;
|
2006-08-15 15:57:20 +00:00
|
|
|
if (fmt) {
|
|
|
|
va_start(ap, fmt);
|
2007-03-09 20:44:13 +00:00
|
|
|
ret = switch_vasprintf(&data, fmt, ap);
|
2006-08-15 15:57:20 +00:00
|
|
|
va_end(ap);
|
2005-12-23 02:24:56 +00:00
|
|
|
|
2007-02-04 19:12:14 +00:00
|
|
|
if (ret == -1) {
|
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
} else {
|
|
|
|
event->body = data;
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2005-12-23 02:24:56 +00:00
|
|
|
} else {
|
2007-02-04 19:12:14 +00:00
|
|
|
return SWITCH_STATUS_GENERR;
|
2005-12-23 02:24:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void) switch_event_destroy(switch_event_t **event)
|
2005-12-19 18:55:31 +00:00
|
|
|
{
|
2006-04-29 01:00:52 +00:00
|
|
|
switch_event_t *ep = *event;
|
|
|
|
switch_event_header_t *hp, *this;
|
2006-03-29 19:11:20 +00:00
|
|
|
|
2006-11-09 05:39:04 +00:00
|
|
|
if (ep) {
|
|
|
|
for (hp = ep->headers; hp;) {
|
|
|
|
this = hp;
|
|
|
|
hp = hp->next;
|
|
|
|
FREE(this->name);
|
|
|
|
FREE(this->value);
|
|
|
|
FREE(this);
|
|
|
|
}
|
|
|
|
FREE(ep->body);
|
|
|
|
FREE(ep);
|
2006-03-29 19:11:20 +00:00
|
|
|
}
|
2005-12-19 18:55:31 +00:00
|
|
|
*event = NULL;
|
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_event_t *todup)
|
2005-12-19 18:55:31 +00:00
|
|
|
{
|
2006-07-22 21:49:52 +00:00
|
|
|
switch_event_header_t *header, *hp, *hp2, *last = NULL;
|
2005-12-19 18:55:31 +00:00
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
if (switch_event_create_subclass(event, todup->event_id, todup->subclass ? todup->subclass->name : NULL) != SWITCH_STATUS_SUCCESS) {
|
2005-12-19 18:55:31 +00:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2005-12-19 18:55:31 +00:00
|
|
|
(*event)->subclass = todup->subclass;
|
2005-12-21 16:24:37 +00:00
|
|
|
(*event)->event_user_data = todup->event_user_data;
|
|
|
|
(*event)->bind_user_data = todup->bind_user_data;
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2006-07-22 21:49:52 +00:00
|
|
|
hp2 = (*event)->headers;
|
|
|
|
|
|
|
|
for (hp = todup->headers; hp; hp = hp->next) {
|
2006-02-20 00:23:25 +00:00
|
|
|
if ((header = ALLOC(sizeof(*header))) == 0) {
|
2005-12-19 18:55:31 +00:00
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
2006-03-29 19:11:20 +00:00
|
|
|
|
|
|
|
memset(header, 0, sizeof(*header));
|
|
|
|
|
2005-12-22 18:53:33 +00:00
|
|
|
header->name = DUP(hp->name);
|
|
|
|
header->value = DUP(hp->value);
|
2005-12-19 18:55:31 +00:00
|
|
|
|
2006-07-22 21:49:52 +00:00
|
|
|
if (last) {
|
|
|
|
last->next = header;
|
2005-12-19 18:55:31 +00:00
|
|
|
} else {
|
|
|
|
(*event)->headers = header;
|
|
|
|
}
|
2006-07-22 21:49:52 +00:00
|
|
|
|
|
|
|
last = header;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (todup->body) {
|
|
|
|
(*event)->body = DUP(todup->body);
|
2005-12-19 18:55:31 +00:00
|
|
|
}
|
|
|
|
|
2006-10-18 22:57:35 +00:00
|
|
|
(*event)->key = todup->key;
|
|
|
|
|
2005-12-19 18:55:31 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-11-11 19:32:45 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char **str)
|
2005-12-19 18:55:31 +00:00
|
|
|
{
|
2006-03-30 23:02:50 +00:00
|
|
|
switch_size_t len = 0;
|
2006-04-29 01:00:52 +00:00
|
|
|
switch_event_header_t *hp;
|
2006-12-15 18:02:54 +00:00
|
|
|
switch_size_t llen = 0, dlen = 0, blocksize = 512, encode_len = 1536, new_len = 0;
|
2006-11-11 19:32:45 +00:00
|
|
|
char *buf;
|
2007-03-29 22:31:56 +00:00
|
|
|
char *encode_buf = NULL; /* used for url encoding of variables to make sure unsafe things stay out of the serialzed copy */
|
|
|
|
|
2006-11-11 19:32:45 +00:00
|
|
|
*str = NULL;
|
2005-12-19 18:55:31 +00:00
|
|
|
|
2006-11-29 17:10:40 +00:00
|
|
|
dlen = blocksize * 2;
|
|
|
|
|
|
|
|
if (!(buf = malloc(dlen))) {
|
2006-11-11 19:32:45 +00:00
|
|
|
return SWITCH_STATUS_MEMERR;
|
2005-12-19 18:55:31 +00:00
|
|
|
}
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
/* go ahead and give ourselves some space to work with, should save a few reallocs */
|
|
|
|
if (!(encode_buf = malloc(encode_len))) {
|
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
2006-11-29 04:57:01 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
/* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hit serialze!.\n"); */
|
2005-12-19 18:55:31 +00:00
|
|
|
for (hp = event->headers; hp; hp = hp->next) {
|
2007-03-29 22:31:56 +00:00
|
|
|
/*
|
|
|
|
* grab enough memory to store 3x the string (url encode takes one char and turns it into %XX)
|
|
|
|
* so we could end up with a string that is 3 times the original's length, unlikely but rather
|
|
|
|
* be safe than destroy the string, also add one for the null. And try to be smart about using
|
|
|
|
* the memory, allocate and only reallocate if we need more. This avoids an alloc, free CPU
|
|
|
|
* destroying loop.
|
|
|
|
*/
|
|
|
|
|
|
|
|
new_len = (strlen(hp->value) * 3) + 1;
|
|
|
|
|
|
|
|
if (encode_len < new_len) {
|
|
|
|
char *tmp;
|
|
|
|
/* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Allocing %d was %d.\n", ((strlen(hp->value) * 3) + 1), encode_len); */
|
|
|
|
/* we can use realloc for initial alloc as well, if encode_buf is zero it treats it as a malloc */
|
|
|
|
|
|
|
|
/* keep track of the size of our allocation */
|
|
|
|
encode_len = new_len;
|
|
|
|
|
|
|
|
if (!(tmp = realloc(encode_buf, encode_len))) {
|
|
|
|
/* oh boy, ram's gone, give back what little we grabbed and bail */
|
|
|
|
switch_safe_free(buf);
|
|
|
|
switch_safe_free(encode_buf);
|
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
encode_buf = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle any bad things in the string like newlines : etc that screw up the serialized format */
|
|
|
|
switch_url_encode(hp->value, encode_buf, encode_len - 1);
|
2006-11-29 04:57:01 +00:00
|
|
|
|
2006-12-15 18:02:54 +00:00
|
|
|
llen = strlen(hp->name) + strlen(encode_buf) + 8;
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-11-11 19:32:45 +00:00
|
|
|
if ((len + llen) > dlen) {
|
2006-11-11 19:40:41 +00:00
|
|
|
char *m;
|
2006-11-11 19:32:45 +00:00
|
|
|
dlen += (blocksize + (len + llen));
|
2006-11-11 19:40:41 +00:00
|
|
|
if ((m = realloc(buf, dlen))) {
|
|
|
|
buf = m;
|
|
|
|
} else {
|
2007-03-29 22:31:56 +00:00
|
|
|
/* we seem to be out of memory trying to resize the serialize string, give back what we already have and give up */
|
2006-11-11 19:40:41 +00:00
|
|
|
switch_safe_free(buf);
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_safe_free(encode_buf);
|
2006-11-11 19:40:41 +00:00
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
2006-11-11 19:32:45 +00:00
|
|
|
}
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2006-11-29 04:57:01 +00:00
|
|
|
snprintf(buf + len, dlen - len, "%s: %s\n", hp->name, encode_buf);
|
2006-11-11 19:32:45 +00:00
|
|
|
len = strlen(buf);
|
2006-11-29 04:57:01 +00:00
|
|
|
|
2005-12-15 19:10:43 +00:00
|
|
|
}
|
2005-12-23 02:24:56 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
/* we are done with the memory we used for encoding, give it back */
|
|
|
|
switch_safe_free(encode_buf);
|
2006-11-29 04:57:01 +00:00
|
|
|
|
2006-11-11 19:32:45 +00:00
|
|
|
if (event->body) {
|
|
|
|
int blen = (int) strlen(event->body);
|
|
|
|
llen = blen;
|
2005-12-23 02:24:56 +00:00
|
|
|
|
|
|
|
if (blen) {
|
2006-11-11 19:32:45 +00:00
|
|
|
llen += 25;
|
2005-12-23 02:24:56 +00:00
|
|
|
} else {
|
2006-11-11 19:32:45 +00:00
|
|
|
llen += 5;
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-11-11 19:32:45 +00:00
|
|
|
if ((len + llen) > dlen) {
|
2006-11-11 19:40:41 +00:00
|
|
|
char *m;
|
2006-11-11 19:32:45 +00:00
|
|
|
dlen += (blocksize + (len + llen));
|
2006-11-11 19:40:41 +00:00
|
|
|
if ((m = realloc(buf, dlen))) {
|
|
|
|
buf = m;
|
|
|
|
} else {
|
|
|
|
switch_safe_free(buf);
|
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
2005-12-23 02:24:56 +00:00
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-11-11 19:32:45 +00:00
|
|
|
if (blen) {
|
|
|
|
snprintf(buf + len, dlen - len, "Content-Length: %d\n\n%s", blen, event->body);
|
|
|
|
} else {
|
|
|
|
snprintf(buf + len, dlen - len, "\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
snprintf(buf + len, dlen - len, "\n");
|
2005-12-23 02:24:56 +00:00
|
|
|
}
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2006-11-11 19:32:45 +00:00
|
|
|
*str = buf;
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2005-12-19 18:55:31 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-10 19:07:38 +00:00
|
|
|
static switch_xml_t add_xml_header(switch_xml_t xml, char *name, char *value, int offset)
|
|
|
|
{
|
|
|
|
switch_xml_t header = NULL;
|
|
|
|
|
|
|
|
if ((header = switch_xml_add_child_d(xml, "header", offset))) {
|
|
|
|
switch_xml_set_attr_d(header, "name", name);
|
2007-03-29 22:31:56 +00:00
|
|
|
switch_xml_set_attr_d(header, "value", value);
|
2006-05-10 19:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const char *fmt,...)
|
2006-05-10 19:07:38 +00:00
|
|
|
{
|
|
|
|
switch_event_header_t *hp;
|
|
|
|
char *data = NULL, *body = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
switch_xml_t xml = NULL;
|
|
|
|
uint32_t off = 0;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (!(xml = switch_xml_new("event"))) {
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fmt) {
|
|
|
|
va_start(ap, fmt);
|
|
|
|
#ifdef HAVE_VASPRINTF
|
|
|
|
ret = vasprintf(&data, fmt, ap);
|
|
|
|
#else
|
|
|
|
data = (char *) malloc(2048);
|
2006-10-16 19:56:42 +00:00
|
|
|
ret = vsnprintf(data, 2048, fmt, ap);
|
2006-05-10 19:07:38 +00:00
|
|
|
#endif
|
|
|
|
va_end(ap);
|
|
|
|
if (ret == -1) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-05-10 19:07:38 +00:00
|
|
|
for (hp = event->headers; hp; hp = hp->next) {
|
|
|
|
add_xml_header(xml, hp->name, hp->value, off++);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
body = data;
|
|
|
|
} else if (event->body) {
|
|
|
|
body = event->body;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (body) {
|
|
|
|
int blen = (int) strlen(body);
|
|
|
|
char blena[25];
|
|
|
|
snprintf(blena, sizeof(blena), "%d", blen);
|
|
|
|
if (blen) {
|
|
|
|
switch_xml_t xbody = NULL;
|
|
|
|
|
|
|
|
add_xml_header(xml, "Content-Length", blena, off++);
|
2006-08-18 01:28:50 +00:00
|
|
|
if ((xbody = switch_xml_add_child_d(xml, "body", off++))) {
|
2006-05-10 19:07:38 +00:00
|
|
|
switch_xml_set_txt_d(xbody, body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-05-10 19:07:38 +00:00
|
|
|
if (data) {
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_fire_detailed(char *file, char *func, int line, switch_event_t **event, void *user_data)
|
2005-12-19 18:55:31 +00:00
|
|
|
{
|
2005-12-15 19:10:43 +00:00
|
|
|
|
2005-12-21 22:25:22 +00:00
|
|
|
switch_time_exp_t tm;
|
|
|
|
char date[80] = "";
|
2006-03-30 23:02:50 +00:00
|
|
|
switch_size_t retsize;
|
2005-12-19 18:55:31 +00:00
|
|
|
|
|
|
|
assert(BLOCK != NULL);
|
2005-12-22 18:53:33 +00:00
|
|
|
assert(RUNTIME_POOL != NULL);
|
2006-09-17 18:03:32 +00:00
|
|
|
assert(EVENT_QUEUE_HAVEMORE_MUTEX != NULL);
|
|
|
|
assert(EVENT_QUEUE_MUTEX != NULL);
|
|
|
|
assert(EVENT_QUEUE_CONDITIONAL != NULL);
|
|
|
|
assert(RUNTIME_POOL != NULL);
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2005-12-22 18:53:33 +00:00
|
|
|
if (THREAD_RUNNING <= 0) {
|
|
|
|
/* sorry we're closed */
|
|
|
|
switch_event_destroy(event);
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
2005-12-19 18:55:31 +00:00
|
|
|
|
2007-02-22 17:38:34 +00:00
|
|
|
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Name", "%s", switch_event_name((*event)->event_id));
|
|
|
|
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Core-UUID", "%s", switch_core_get_uuid());
|
2005-12-22 22:17:25 +00:00
|
|
|
switch_time_exp_lt(&tm, switch_time_now());
|
2006-08-29 23:52:45 +00:00
|
|
|
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
|
2007-02-22 17:38:34 +00:00
|
|
|
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Date-Local", "%s", date);
|
2005-12-23 21:09:36 +00:00
|
|
|
switch_rfc822_date(date, switch_time_now());
|
2007-02-22 17:38:34 +00:00
|
|
|
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Date-GMT", "%s", date);
|
|
|
|
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-File", "%s", switch_cut_path(file));
|
|
|
|
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Function", "%s", func);
|
|
|
|
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Line-Number", "%d", line);
|
|
|
|
|
2005-12-23 21:09:36 +00:00
|
|
|
if ((*event)->subclass) {
|
2007-02-22 17:38:34 +00:00
|
|
|
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Subclass", "%s", (*event)->subclass->name);
|
|
|
|
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Subclass-Owner", "%s", (*event)->subclass->owner);
|
2005-12-23 21:09:36 +00:00
|
|
|
}
|
2005-12-21 22:25:22 +00:00
|
|
|
|
2005-12-21 16:24:37 +00:00
|
|
|
if (user_data) {
|
|
|
|
(*event)->event_user_data = user_data;
|
|
|
|
}
|
2006-01-03 01:17:59 +00:00
|
|
|
|
2006-02-26 00:12:17 +00:00
|
|
|
switch_queue_push(EVENT_QUEUE[(*event)->priority], *event);
|
2006-09-17 18:03:32 +00:00
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* lock on havemore to make sure he event thread, if currently running
|
|
|
|
* doesn't check the HAVEMORE flag before we set it
|
|
|
|
*/
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_lock(EVENT_QUEUE_HAVEMORE_MUTEX);
|
2007-03-04 01:50:52 +00:00
|
|
|
/* see if the event thread is sitting */
|
2007-03-29 22:31:56 +00:00
|
|
|
if (switch_mutex_trylock(EVENT_QUEUE_MUTEX) == SWITCH_STATUS_SUCCESS) {
|
2007-03-04 01:50:52 +00:00
|
|
|
/* we don't need havemore anymore, the thread was sitting already */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_unlock(EVENT_QUEUE_HAVEMORE_MUTEX);
|
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* wake up the event thread */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_thread_cond_signal(EVENT_QUEUE_CONDITIONAL);
|
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* give up our lock */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_unlock(EVENT_QUEUE_MUTEX);
|
2007-03-29 22:31:56 +00:00
|
|
|
} else {
|
2007-03-04 01:50:52 +00:00
|
|
|
/* it wasn't waiting which means we might have updated a queue it already looked at
|
|
|
|
* set a flag so it knows to read the queues again
|
|
|
|
*/
|
2006-09-17 18:03:32 +00:00
|
|
|
EVENT_QUEUE_HAVEMORE = 1;
|
|
|
|
|
2007-03-04 01:50:52 +00:00
|
|
|
/* variable updated, give up the mutex */
|
2006-09-17 18:03:32 +00:00
|
|
|
switch_mutex_unlock(EVENT_QUEUE_HAVEMORE_MUTEX);
|
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-09-17 18:03:32 +00:00
|
|
|
|
2005-12-19 18:55:31 +00:00
|
|
|
*event = NULL;
|
|
|
|
|
2005-12-13 20:52:33 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-06-20 07:15:53 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_event_bind(const char *id, switch_event_types_t event, char *subclass_name, switch_event_callback_t callback,
|
2007-03-30 00:15:25 +00:00
|
|
|
void *user_data)
|
2005-12-13 20:52:33 +00:00
|
|
|
{
|
2006-04-29 06:05:03 +00:00
|
|
|
switch_event_node_t *event_node;
|
|
|
|
switch_event_subclass_t *subclass = NULL;
|
2005-12-13 20:52:33 +00:00
|
|
|
|
2005-12-14 21:29:46 +00:00
|
|
|
assert(BLOCK != NULL);
|
2005-12-22 18:53:33 +00:00
|
|
|
assert(RUNTIME_POOL != NULL);
|
2005-12-13 20:52:33 +00:00
|
|
|
|
2005-12-15 19:10:43 +00:00
|
|
|
if (subclass_name) {
|
2006-02-20 00:23:25 +00:00
|
|
|
if ((subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name)) == 0) {
|
|
|
|
if ((subclass = switch_core_alloc(RUNTIME_POOL, sizeof(*subclass))) == 0) {
|
2005-12-15 23:56:21 +00:00
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
} else {
|
2005-12-22 18:53:33 +00:00
|
|
|
subclass->owner = switch_core_strdup(RUNTIME_POOL, id);
|
|
|
|
subclass->name = switch_core_strdup(RUNTIME_POOL, subclass_name);
|
2005-12-15 23:56:21 +00:00
|
|
|
}
|
2005-12-15 19:10:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-29 06:05:03 +00:00
|
|
|
if (event <= SWITCH_EVENT_ALL && (event_node = switch_core_alloc(RUNTIME_POOL, sizeof(switch_event_node_t))) != 0) {
|
2005-12-14 21:29:46 +00:00
|
|
|
switch_mutex_lock(BLOCK);
|
2006-01-20 15:05:05 +00:00
|
|
|
/* <LOCKED> ----------------------------------------------- */
|
2005-12-22 18:53:33 +00:00
|
|
|
event_node->id = switch_core_strdup(RUNTIME_POOL, id);
|
2005-12-19 18:55:31 +00:00
|
|
|
event_node->event_id = event;
|
2005-12-13 20:52:33 +00:00
|
|
|
event_node->subclass = subclass;
|
|
|
|
event_node->callback = callback;
|
2005-12-15 19:10:43 +00:00
|
|
|
event_node->user_data = user_data;
|
|
|
|
|
2005-12-13 20:52:33 +00:00
|
|
|
if (EVENT_NODES[event]) {
|
|
|
|
event_node->next = EVENT_NODES[event];
|
|
|
|
}
|
2005-12-15 19:10:43 +00:00
|
|
|
|
2005-12-13 20:52:33 +00:00
|
|
|
EVENT_NODES[event] = event_node;
|
2005-12-14 21:29:46 +00:00
|
|
|
switch_mutex_unlock(BLOCK);
|
2006-01-20 15:05:05 +00:00
|
|
|
/* </LOCKED> ----------------------------------------------- */
|
2005-12-13 20:52:33 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
2006-11-27 22:30:48 +00:00
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2007-02-09 02:36:03 +00:00
|
|
|
* indent-tabs-mode:t
|
2006-11-27 22:30:48 +00:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
|
|
|
*/
|