#include <switch_cpp.h>
Collaboration diagram for EventConsumer:
Public Member Functions | |
| EventConsumer (const char *event_name=NULL, const char *subclass_name="") | |
| ~EventConsumer () | |
| int | bind (const char *event_name, const char *subclass_name="") |
| Event * | pop (int block=0, int timeout=0) |
Data Fields | |
| switch_queue_t * | events |
| switch_event_types_t | e_event_id |
| char * | e_callback |
| char * | e_subclass_name |
| char * | e_cb_arg |
| switch_event_node_t * | enodes [SWITCH_EVENT_ALL+1] |
| uint32_t | node_index |
Protected Attributes | |
| switch_memory_pool_t * | pool |
Definition at line 177 of file switch_cpp.h.
| EventConsumer::EventConsumer | ( | const char * | event_name = NULL, |
|
| const char * | subclass_name = "" | |||
| ) |
Definition at line 53 of file switch_cpp.cpp.
References bind(), events, node_index, pool, switch_core_new_memory_pool, switch_queue_create(), and zstr.
00054 { 00055 00056 switch_core_new_memory_pool(&pool); 00057 switch_queue_create(&events, 5000, pool); 00058 node_index = 0; 00059 00060 if (!zstr(event_name)) { 00061 bind(event_name, subclass_name); 00062 } 00063 00064 }
| EventConsumer::~EventConsumer | ( | ) |
Definition at line 111 of file switch_cpp.cpp.
References enodes, events, node_index, pool, switch_core_destroy_memory_pool, switch_event_unbind(), and switch_queue_interrupt_all().
00112 { 00113 uint32_t i; 00114 00115 for (i = 0; i < node_index; i++) { 00116 switch_event_unbind(&enodes[i]); 00117 } 00118 00119 if (events) { 00120 switch_queue_interrupt_all(events); 00121 } 00122 00123 switch_core_destroy_memory_pool(&pool); 00124 }
| int EventConsumer::bind | ( | const char * | event_name, | |
| const char * | subclass_name = "" | |||
| ) |
Definition at line 66 of file switch_cpp.cpp.
References event_handler(), SWITCH_CHANNEL_LOG, SWITCH_EVENT_ALL, switch_event_bind_removable(), SWITCH_EVENT_CUSTOM, SWITCH_LOG_ERROR, SWITCH_LOG_NOTICE, switch_log_printf(), switch_name_event(), SWITCH_STATUS_SUCCESS, switch_str_nil, and zstr.
Referenced by EventConsumer().
00067 { 00068 switch_event_types_t event_id = SWITCH_EVENT_CUSTOM; 00069 switch_name_event(event_name, &event_id); 00070 00071 00072 if (zstr(subclass_name)) { 00073 subclass_name = NULL; 00074 } 00075 00076 if (node_index <= SWITCH_EVENT_ALL && 00077 switch_event_bind_removable(__FILE__, event_id, subclass_name, event_handler, this, &enodes[node_index]) == SWITCH_STATUS_SUCCESS) { 00078 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "bound to %s %s\n", event_name, switch_str_nil(subclass_name)); 00079 node_index++; 00080 return 1; 00081 } else { 00082 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind to %s %s\n", event_name, switch_str_nil(subclass_name)); 00083 return 0; 00084 } 00085 }
| Event * EventConsumer::pop | ( | int | block = 0, |
|
| int | timeout = 0 | |||
| ) |
Definition at line 88 of file switch_cpp.cpp.
References switch_queue_pop(), switch_queue_pop_timeout(), and switch_queue_trypop().
00089 { 00090 void *pop = NULL; 00091 Event *ret = NULL; 00092 switch_event_t *event; 00093 00094 if (block) { 00095 if (timeout > 0) { 00096 switch_queue_pop_timeout(events, &pop, (switch_interval_time_t) timeout * 1000); // millisec rather than microsec 00097 } else { 00098 switch_queue_pop(events, &pop); 00099 } 00100 } else { 00101 switch_queue_trypop(events, &pop); 00102 } 00103 00104 if ((event = (switch_event_t *) pop)) { 00105 ret = new Event(event, 1); 00106 } 00107 00108 return ret; 00109 }
Definition at line 183 of file switch_cpp.h.
| char* EventConsumer::e_cb_arg |
Definition at line 185 of file switch_cpp.h.
Definition at line 182 of file switch_cpp.h.
Definition at line 184 of file switch_cpp.h.
| switch_event_node_t* EventConsumer::enodes[SWITCH_EVENT_ALL+1] |
Definition at line 181 of file switch_cpp.h.
Referenced by event_handler(), EventConsumer(), and ~EventConsumer().
| uint32_t EventConsumer::node_index |
switch_memory_pool_t* EventConsumer::pool [protected] |
1.4.7