mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-17 17:22:21 +00:00
add cleanup method to event consumer
This commit is contained in:
parent
4319bc8bd9
commit
1e22ba2ba5
@ -178,6 +178,7 @@ SWITCH_DECLARE(bool) email(char *to, char *from, char *headers = NULL, char *bod
|
|||||||
class EventConsumer {
|
class EventConsumer {
|
||||||
protected:
|
protected:
|
||||||
switch_memory_pool_t *pool;
|
switch_memory_pool_t *pool;
|
||||||
|
int ready;
|
||||||
public:
|
public:
|
||||||
switch_queue_t *events;
|
switch_queue_t *events;
|
||||||
switch_event_types_t e_event_id;
|
switch_event_types_t e_event_id;
|
||||||
@ -191,6 +192,7 @@ SWITCH_DECLARE(bool) email(char *to, char *from, char *headers = NULL, char *bod
|
|||||||
SWITCH_DECLARE_CONSTRUCTOR ~ EventConsumer();
|
SWITCH_DECLARE_CONSTRUCTOR ~ EventConsumer();
|
||||||
SWITCH_DECLARE(int) bind(const char *event_name, const char *subclass_name = "");
|
SWITCH_DECLARE(int) bind(const char *event_name, const char *subclass_name = "");
|
||||||
SWITCH_DECLARE(Event *) pop(int block = 0, int timeout = 0);
|
SWITCH_DECLARE(Event *) pop(int block = 0, int timeout = 0);
|
||||||
|
SWITCH_DECLARE(void) cleanup();
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef SWIG
|
#ifdef SWIG
|
||||||
|
@ -46,6 +46,7 @@ static void event_handler(switch_event_t *event)
|
|||||||
|
|
||||||
if (switch_queue_trypush(E->events, dup) != SWITCH_STATUS_SUCCESS) {
|
if (switch_queue_trypush(E->events, dup) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot queue any more events.....\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot queue any more events.....\n");
|
||||||
|
switch_event_destroy(&dup);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -61,6 +62,7 @@ SWITCH_DECLARE_CONSTRUCTOR EventConsumer::EventConsumer(const char *event_name,
|
|||||||
bind(event_name, subclass_name);
|
bind(event_name, subclass_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ready = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(int) EventConsumer::bind(const char *event_name, const char *subclass_name)
|
SWITCH_DECLARE(int) EventConsumer::bind(const char *event_name, const char *subclass_name)
|
||||||
@ -68,6 +70,10 @@ SWITCH_DECLARE(int) EventConsumer::bind(const char *event_name, const char *subc
|
|||||||
switch_event_types_t event_id = SWITCH_EVENT_CUSTOM;
|
switch_event_types_t event_id = SWITCH_EVENT_CUSTOM;
|
||||||
switch_name_event(event_name, &event_id);
|
switch_name_event(event_name, &event_id);
|
||||||
|
|
||||||
|
if (!ready) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (zstr(subclass_name)) {
|
if (zstr(subclass_name)) {
|
||||||
subclass_name = NULL;
|
subclass_name = NULL;
|
||||||
@ -90,6 +96,10 @@ SWITCH_DECLARE(Event *) EventConsumer::pop(int block, int timeout)
|
|||||||
void *pop = NULL;
|
void *pop = NULL;
|
||||||
Event *ret = NULL;
|
Event *ret = NULL;
|
||||||
switch_event_t *event;
|
switch_event_t *event;
|
||||||
|
|
||||||
|
if (!ready) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (block) {
|
if (block) {
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
@ -108,19 +118,42 @@ SWITCH_DECLARE(Event *) EventConsumer::pop(int block, int timeout)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE_CONSTRUCTOR EventConsumer::~EventConsumer()
|
SWITCH_DECLARE(void) EventConsumer::cleanup()
|
||||||
{
|
{
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
void *pop;
|
||||||
|
|
||||||
|
if (!ready) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ready = 0;
|
||||||
|
|
||||||
for (i = 0; i < node_index; i++) {
|
for (i = 0; i < node_index; i++) {
|
||||||
switch_event_unbind(&enodes[i]);
|
switch_event_unbind(&enodes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node_index = 0;
|
||||||
|
|
||||||
if (events) {
|
if (events) {
|
||||||
switch_queue_interrupt_all(events);
|
switch_queue_interrupt_all(events);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while(switch_queue_trypop(events, &pop) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_event_t *event = (switch_event_t *) pop;
|
||||||
|
switch_event_destroy(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
switch_core_destroy_memory_pool(&pool);
|
switch_core_destroy_memory_pool(&pool);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SWITCH_DECLARE_CONSTRUCTOR EventConsumer::~EventConsumer()
|
||||||
|
{
|
||||||
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE_CONSTRUCTOR IVRMenu::IVRMenu(IVRMenu *main,
|
SWITCH_DECLARE_CONSTRUCTOR IVRMenu::IVRMenu(IVRMenu *main,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user