Event Class Reference

#include <switch_cpp.h>

Collaboration diagram for Event:

[legend]

Public Member Functions

 Event (const char *type, const char *subclass_name=NULL)
 Event (switch_event_t *wrap_me, int free_me=0)
virtual ~Event ()
int chat_execute (const char *app, const char *data=NULL)
int chat_send (const char *dest_proto=NULL)
const char * serialize (const char *format=NULL)
bool setPriority (switch_priority_t priority=SWITCH_PRIORITY_NORMAL)
const char * getHeader (const char *header_name)
char * getBody (void)
const char * getType (void)
bool addBody (const char *value)
bool addHeader (const char *header_name, const char *value)
bool delHeader (const char *header_name)
bool fire (void)

Data Fields

switch_event_tevent
char * serialized_string
int mine

Detailed Description

Definition at line 153 of file switch_cpp.h.


Constructor & Destructor Documentation

Event::Event ( const char *  type,
const char *  subclass_name = NULL 
)

Definition at line 241 of file switch_cpp.cpp.

References event, mine, serialized_string, SWITCH_CHANNEL_LOG, switch_event_create_json(), switch_event_create_subclass, SWITCH_EVENT_CUSTOM, SWITCH_EVENT_MESSAGE, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_name_event(), SWITCH_STATUS_SUCCESS, and zstr.

00242 {
00243         switch_event_types_t event_id;
00244 
00245         if (!strcasecmp(type, "json") && !zstr(subclass_name)) {
00246         if (switch_event_create_json(&event, subclass_name) != SWITCH_STATUS_SUCCESS) {
00247                         return;
00248                 }
00249                 
00250                 event_id = event->event_id;
00251 
00252     } else {
00253                 if (switch_name_event(type, &event_id) != SWITCH_STATUS_SUCCESS) {
00254                         event_id = SWITCH_EVENT_MESSAGE;
00255                 }
00256 
00257                 if (!zstr(subclass_name) && event_id != SWITCH_EVENT_CUSTOM) {
00258                         switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_WARNING, "Changing event type to custom because you specified a subclass name!\n");
00259                         event_id = SWITCH_EVENT_CUSTOM;
00260                 }
00261 
00262                 if (switch_event_create_subclass(&event, event_id, subclass_name) != SWITCH_STATUS_SUCCESS) {
00263                         switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Failed to create event!\n");
00264                         event = NULL;
00265                 }
00266         }
00267 
00268         serialized_string = NULL;
00269         mine = 1;
00270 }

Event::Event ( switch_event_t wrap_me,
int  free_me = 0 
)

Definition at line 272 of file switch_cpp.cpp.

References event, mine, and serialized_string.

00273 {
00274         event = wrap_me;
00275         mine = free_me;
00276         serialized_string = NULL;
00277 }

Event::~Event (  )  [virtual]

Definition at line 279 of file switch_cpp.cpp.

References event, mine, serialized_string, and switch_event_destroy().

00280 {
00281 
00282         if (serialized_string) {
00283                 free(serialized_string);
00284         }
00285 
00286         if (event && mine) {
00287                 switch_event_destroy(&event);
00288         }
00289 }


Member Function Documentation

bool Event::addBody ( const char *  value  ) 

Definition at line 421 of file switch_cpp.cpp.

References SWITCH_CHANNEL_LOG, switch_event_add_body(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STATUS_SUCCESS, and this_check.

00422 {
00423         this_check(false);
00424 
00425         if (event) {
00426                 return switch_event_add_body(event, "%s", value) == SWITCH_STATUS_SUCCESS ? true : false;
00427         } else {
00428                 switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to addBody an event that does not exist!\n");
00429         }
00430         
00431         return false;
00432 }

bool Event::addHeader ( const char *  header_name,
const char *  value 
)

Definition at line 394 of file switch_cpp.cpp.

References SWITCH_CHANNEL_LOG, switch_event_add_header_string(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, and this_check.

00395 {
00396         this_check(false);
00397 
00398         if (event) {
00399                 return switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, value) == SWITCH_STATUS_SUCCESS ? true : false;
00400         } else {
00401                 switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to addHeader an event that does not exist!\n");
00402         }
00403 
00404         return false;
00405 }

int Event::chat_execute ( const char *  app,
const char *  data = NULL 
)

Definition at line 291 of file switch_cpp.cpp.

References switch_core_execute_chat_app().

00292 {
00293         return (int) switch_core_execute_chat_app(event, app, data);
00294 }

int Event::chat_send ( const char *  dest_proto = NULL  ) 

Definition at line 296 of file switch_cpp.cpp.

References switch_core_chat_send(), switch_event_get_header, and zstr.

00297 {
00298         if (zstr(dest_proto)) {
00299                 dest_proto = switch_event_get_header(event, "dest_proto");
00300         }
00301 
00302         return (int) switch_core_chat_send(dest_proto, event);
00303 }

bool Event::delHeader ( const char *  header_name  ) 

Definition at line 407 of file switch_cpp.cpp.

References SWITCH_CHANNEL_LOG, switch_event_del_header, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STATUS_SUCCESS, and this_check.

00408 {
00409         this_check(false);
00410 
00411         if (event) {
00412                 return switch_event_del_header(event, header_name) == SWITCH_STATUS_SUCCESS ? true : false;
00413         } else {
00414                 switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to delHeader an event that does not exist!\n");
00415         }
00416 
00417         return false;
00418 }

bool Event::fire ( void   ) 

Definition at line 341 of file switch_cpp.cpp.

References SWITCH_CHANNEL_LOG, switch_event_destroy(), switch_event_dup(), switch_event_fire, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STATUS_SUCCESS, and this_check.

00342 {
00343 
00344         this_check(false);
00345 
00346         if (!mine) {
00347                 switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Not My event!\n");
00348                 return false;
00349         }
00350 
00351         if (event) {
00352                 switch_event_t *new_event;
00353                 if (switch_event_dup(&new_event, event) == SWITCH_STATUS_SUCCESS) {
00354                         if (switch_event_fire(&new_event) != SWITCH_STATUS_SUCCESS) {
00355                                 switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Failed to fire the event!\n");
00356                                 switch_event_destroy(&new_event);
00357                                 return false;
00358                         }
00359                         return true;
00360                 } else {
00361                         switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Failed to dup the event!\n");
00362                 }
00363         } else {
00364                 switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to fire an event that does not exist!\n");
00365         }
00366         return false;
00367 }

char * Event::getBody ( void   ) 

Definition at line 434 of file switch_cpp.cpp.

References SWITCH_CHANNEL_LOG, switch_event_get_body(), SWITCH_LOG_ERROR, switch_log_printf(), and this_check.

00435 {
00436         
00437         this_check((char *)"");
00438 
00439         if (event) {
00440                 return switch_event_get_body(event);
00441         } else {
00442                 switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to getBody an event that does not exist!\n");
00443         }
00444         
00445         return NULL;
00446 }

const char * Event::getHeader ( const char *  header_name  ) 

Definition at line 382 of file switch_cpp.cpp.

References SWITCH_CHANNEL_LOG, switch_event_get_header, SWITCH_LOG_ERROR, switch_log_printf(), and this_check.

00383 {
00384         this_check("");
00385 
00386         if (event) {
00387                 return switch_event_get_header(event, header_name);
00388         } else {
00389                 switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to getHeader an event that does not exist!\n");
00390         }
00391         return NULL;
00392 }

const char * Event::getType ( void   ) 

Definition at line 448 of file switch_cpp.cpp.

References SWITCH_CHANNEL_LOG, switch_event_name(), SWITCH_LOG_ERROR, switch_log_printf(), and this_check.

00449 {
00450         this_check("");
00451 
00452         if (event) {
00453                 return switch_event_name(event->event_id);
00454         } else {
00455                 switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to getType an event that does not exist!\n");
00456         }
00457         
00458         return (char *) "invalid";
00459 }

const char * Event::serialize ( const char *  format = NULL  ) 

Definition at line 305 of file switch_cpp.cpp.

References switch_event_serialize(), switch_event_serialize_json(), switch_event_xmlize(), SWITCH_FALSE, switch_mprintf(), switch_safe_free, SWITCH_STATUS_SUCCESS, SWITCH_TRUE, SWITCH_VA_NONE, switch_xml_free(), switch_xml_toxml(), and this_check.

00306 {
00307         this_check("");
00308 
00309 
00310         switch_safe_free(serialized_string);
00311         
00312         if (!event) {
00313                 return "";
00314         }
00315 
00316         if (format && !strcasecmp(format, "xml")) {
00317                 switch_xml_t xml;
00318                 if ((xml = switch_event_xmlize(event, SWITCH_VA_NONE))) {
00319                         serialized_string = switch_xml_toxml(xml, SWITCH_FALSE);
00320                         switch_xml_free(xml);
00321                         return serialized_string;
00322                 } else {
00323                         return "";
00324                 }
00325         } else if (format && !strcasecmp(format, "json")) {
00326                 switch_event_serialize_json(event, &serialized_string);
00327                 return serialized_string;
00328         } else {
00329                 if (switch_event_serialize(event, &serialized_string, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
00330                         char *new_serialized_string = switch_mprintf("'%s'", serialized_string);
00331                         free(serialized_string);
00332                         serialized_string = new_serialized_string;
00333                         return serialized_string;
00334                 }
00335         }
00336         
00337         return "";
00338 
00339 }

bool Event::setPriority ( switch_priority_t  priority = SWITCH_PRIORITY_NORMAL  ) 

Definition at line 369 of file switch_cpp.cpp.

References SWITCH_CHANNEL_LOG, switch_event_set_priority(), SWITCH_LOG_ERROR, switch_log_printf(), and this_check.

00370 {
00371         this_check(false);
00372 
00373         if (event) {
00374         switch_event_set_priority(event, priority);
00375                 return true;
00376         } else {
00377                 switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to setPriority an event that does not exist!\n");
00378     }
00379         return false;
00380 }


Field Documentation

switch_event_t* Event::event

Definition at line 156 of file switch_cpp.h.

Referenced by Event(), and ~Event().

int Event::mine

Definition at line 158 of file switch_cpp.h.

Referenced by Event(), and ~Event().

char* Event::serialized_string

Definition at line 157 of file switch_cpp.h.

Referenced by Event(), and ~Event().


The documentation for this class was generated from the following files:
Generated on Wed May 16 04:00:22 2012 for FreeSWITCH API Documentation by  doxygen 1.4.7