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
This commit is contained in:
Anthony Minessale
2005-12-19 19:57:32 +00:00
parent 2a58e2038a
commit ab0b99eb00
2 changed files with 38 additions and 12 deletions
+2 -3
View File
@@ -71,7 +71,7 @@ struct switch_event_node {
SWITCH_DECLARE(switch_status) switch_event_shutdown(void);
SWITCH_DECLARE(switch_status) switch_event_init(switch_memory_pool *pool);
SWITCH_DECLARE(switch_status) switch_event_create_detailed(switch_event **event, switch_event_t event_id, char *subclass_name);
SWITCH_DECLARE(switch_status) switch_event_create_subclass(switch_event **event, switch_event_t event_id, char *subclass_name);
SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header_name);
SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, char *header_name, char *fmt, ...);
SWITCH_DECLARE(void) switch_event_destroy(switch_event **event);
@@ -83,8 +83,7 @@ SWITCH_DECLARE(switch_status) switch_event_reserve_subclass_detailed(char *owner
SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *buf, size_t buflen, char *fmt, ...);
#define switch_event_reserve_subclass(subclass_name) switch_event_reserve_subclass_detailed(__FILE__, subclass_name)
#define switch_event_create(event, id) switch_event_create_detailed(event, id, SWITCH_EVENT_SUBCLASS_ANY)
#define switch_event_create_subclass(event, id, subclass) switch_event_create_detailed(event, id, subclass)
#define switch_event_create(event, id) switch_event_create_subclass(event, id, SWITCH_EVENT_SUBCLASS_ANY)
#define switch_event_fire(event) switch_event_fire_detailed(__FILE__, __FUNCTION__, __LINE__, event)
#endif