提交 a1cf7067 authored 作者: Anthony Minessale's avatar Anthony Minessale

add EventConsumer obj to cpp

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8884 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 36e01385
......@@ -138,13 +138,17 @@ SWITCH_DECLARE(void) consoleCleanLog(char *msg);
class EventConsumer {
protected:
switch_memory_pool_t *pool;
public:
switch_queue_t *events;
switch_event_types_t e_event_id;
switch_event_node_t *node;
char *e_callback;
char *e_subclass_name;
public:
SWITCH_DECLARE_CONSTRUCTOR EventConsumer(switch_event_types_t event_id, const char *subclass_name = "", const char *callback = "event_consumer");
char *e_cb_arg;
SWITCH_DECLARE_CONSTRUCTOR EventConsumer(const char *event_name, const char *subclass_name = "");
SWITCH_DECLARE_CONSTRUCTOR ~ EventConsumer();
SWITCH_DECLARE(Event *) pop(int block = 0);
};
class CoreSession {
......
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.35
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package org.freeswitch.swig;
public class EventConsumer {
private long swigCPtr;
protected boolean swigCMemOwn;
protected EventConsumer(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr(EventConsumer obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected void finalize() {
delete();
}
public synchronized void delete() {
if(swigCPtr != 0 && swigCMemOwn) {
swigCMemOwn = false;
freeswitchJNI.delete_EventConsumer(swigCPtr);
}
swigCPtr = 0;
}
public void setEvents(SWIGTYPE_p_switch_queue_t value) {
freeswitchJNI.EventConsumer_events_set(swigCPtr, this, SWIGTYPE_p_switch_queue_t.getCPtr(value));
}
public SWIGTYPE_p_switch_queue_t getEvents() {
long cPtr = freeswitchJNI.EventConsumer_events_get(swigCPtr, this);
return (cPtr == 0) ? null : new SWIGTYPE_p_switch_queue_t(cPtr, false);
}
public void setE_event_id(SWIGTYPE_p_switch_event_types_t value) {
freeswitchJNI.EventConsumer_e_event_id_set(swigCPtr, this, SWIGTYPE_p_switch_event_types_t.getCPtr(value));
}
public SWIGTYPE_p_switch_event_types_t getE_event_id() {
return new SWIGTYPE_p_switch_event_types_t(freeswitchJNI.EventConsumer_e_event_id_get(swigCPtr, this), true);
}
public void setNode(SWIGTYPE_p_switch_event_node_t value) {
freeswitchJNI.EventConsumer_node_set(swigCPtr, this, SWIGTYPE_p_switch_event_node_t.getCPtr(value));
}
public SWIGTYPE_p_switch_event_node_t getNode() {
long cPtr = freeswitchJNI.EventConsumer_node_get(swigCPtr, this);
return (cPtr == 0) ? null : new SWIGTYPE_p_switch_event_node_t(cPtr, false);
}
public void setE_callback(String value) {
freeswitchJNI.EventConsumer_e_callback_set(swigCPtr, this, value);
}
public String getE_callback() {
return freeswitchJNI.EventConsumer_e_callback_get(swigCPtr, this);
}
public void setE_subclass_name(String value) {
freeswitchJNI.EventConsumer_e_subclass_name_set(swigCPtr, this, value);
}
public String getE_subclass_name() {
return freeswitchJNI.EventConsumer_e_subclass_name_get(swigCPtr, this);
}
public void setE_cb_arg(String value) {
freeswitchJNI.EventConsumer_e_cb_arg_set(swigCPtr, this, value);
}
public String getE_cb_arg() {
return freeswitchJNI.EventConsumer_e_cb_arg_get(swigCPtr, this);
}
public EventConsumer(String event_name, String subclass_name) {
this(freeswitchJNI.new_EventConsumer__SWIG_0(event_name, subclass_name), true);
}
public EventConsumer(String event_name) {
this(freeswitchJNI.new_EventConsumer__SWIG_1(event_name), true);
}
public Event pop(int block) {
long cPtr = freeswitchJNI.EventConsumer_pop__SWIG_0(swigCPtr, this, block);
return (cPtr == 0) ? null : new Event(cPtr, false);
}
public Event pop() {
long cPtr = freeswitchJNI.EventConsumer_pop__SWIG_1(swigCPtr, this);
return (cPtr == 0) ? null : new Event(cPtr, false);
}
}
......@@ -59,6 +59,23 @@ class freeswitchJNI {
public final static native boolean Event_addHeader(long jarg1, Event jarg1_, String jarg2, String jarg3);
public final static native boolean Event_delHeader(long jarg1, Event jarg1_, String jarg2);
public final static native boolean Event_fire(long jarg1, Event jarg1_);
public final static native void EventConsumer_events_set(long jarg1, EventConsumer jarg1_, long jarg2);
public final static native long EventConsumer_events_get(long jarg1, EventConsumer jarg1_);
public final static native void EventConsumer_e_event_id_set(long jarg1, EventConsumer jarg1_, long jarg2);
public final static native long EventConsumer_e_event_id_get(long jarg1, EventConsumer jarg1_);
public final static native void EventConsumer_node_set(long jarg1, EventConsumer jarg1_, long jarg2);
public final static native long EventConsumer_node_get(long jarg1, EventConsumer jarg1_);
public final static native void EventConsumer_e_callback_set(long jarg1, EventConsumer jarg1_, String jarg2);
public final static native String EventConsumer_e_callback_get(long jarg1, EventConsumer jarg1_);
public final static native void EventConsumer_e_subclass_name_set(long jarg1, EventConsumer jarg1_, String jarg2);
public final static native String EventConsumer_e_subclass_name_get(long jarg1, EventConsumer jarg1_);
public final static native void EventConsumer_e_cb_arg_set(long jarg1, EventConsumer jarg1_, String jarg2);
public final static native String EventConsumer_e_cb_arg_get(long jarg1, EventConsumer jarg1_);
public final static native long new_EventConsumer__SWIG_0(String jarg1, String jarg2);
public final static native long new_EventConsumer__SWIG_1(String jarg1);
public final static native void delete_EventConsumer(long jarg1);
public final static native long EventConsumer_pop__SWIG_0(long jarg1, EventConsumer jarg1_, int jarg2);
public final static native long EventConsumer_pop__SWIG_1(long jarg1, EventConsumer jarg1_);
public final static native void delete_CoreSession(long jarg1);
public final static native void CoreSession_session_set(long jarg1, CoreSession jarg1_, long jarg2);
public final static native long CoreSession_session_get(long jarg1, CoreSession jarg1_);
......
......@@ -1113,6 +1113,310 @@ SWIGEXPORT jboolean JNICALL Java_org_freeswitch_swig_freeswitchJNI_Event_1fire(J
}
SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1events_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
EventConsumer *arg1 = (EventConsumer *) 0 ;
switch_queue_t *arg2 = (switch_queue_t *) 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
arg2 = *(switch_queue_t **)&jarg2;
if (arg1) (arg1)->events = arg2;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1events_1get(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jlong jresult = 0 ;
EventConsumer *arg1 = (EventConsumer *) 0 ;
switch_queue_t *result = 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
result = (switch_queue_t *) ((arg1)->events);
*(switch_queue_t **)&jresult = result;
return jresult;
}
SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1e_1event_1id_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
EventConsumer *arg1 = (EventConsumer *) 0 ;
switch_event_types_t arg2 ;
switch_event_types_t *argp2 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
argp2 = *(switch_event_types_t **)&jarg2;
if (!argp2) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null switch_event_types_t");
return ;
}
arg2 = *argp2;
if (arg1) (arg1)->e_event_id = arg2;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1e_1event_1id_1get(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jlong jresult = 0 ;
EventConsumer *arg1 = (EventConsumer *) 0 ;
switch_event_types_t result;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
result = ((arg1)->e_event_id);
*(switch_event_types_t **)&jresult = new switch_event_types_t((switch_event_types_t &)result);
return jresult;
}
SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1node_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
EventConsumer *arg1 = (EventConsumer *) 0 ;
switch_event_node_t *arg2 = (switch_event_node_t *) 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
arg2 = *(switch_event_node_t **)&jarg2;
if (arg1) (arg1)->node = arg2;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1node_1get(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jlong jresult = 0 ;
EventConsumer *arg1 = (EventConsumer *) 0 ;
switch_event_node_t *result = 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
result = (switch_event_node_t *) ((arg1)->node);
*(switch_event_node_t **)&jresult = result;
return jresult;
}
SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1e_1callback_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) {
EventConsumer *arg1 = (EventConsumer *) 0 ;
char *arg2 = (char *) 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
arg2 = 0;
if (jarg2) {
arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0);
if (!arg2) return ;
}
{
if (arg1->e_callback) delete [] arg1->e_callback;
if (arg2) {
arg1->e_callback = (char *) (new char[strlen((const char *)arg2)+1]);
strcpy((char *)arg1->e_callback, (const char *)arg2);
} else {
arg1->e_callback = 0;
}
}
if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2);
}
SWIGEXPORT jstring JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1e_1callback_1get(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jstring jresult = 0 ;
EventConsumer *arg1 = (EventConsumer *) 0 ;
char *result = 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
result = (char *) ((arg1)->e_callback);
if(result) jresult = jenv->NewStringUTF((const char *)result);
return jresult;
}
SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1e_1subclass_1name_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) {
EventConsumer *arg1 = (EventConsumer *) 0 ;
char *arg2 = (char *) 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
arg2 = 0;
if (jarg2) {
arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0);
if (!arg2) return ;
}
{
if (arg1->e_subclass_name) delete [] arg1->e_subclass_name;
if (arg2) {
arg1->e_subclass_name = (char *) (new char[strlen((const char *)arg2)+1]);
strcpy((char *)arg1->e_subclass_name, (const char *)arg2);
} else {
arg1->e_subclass_name = 0;
}
}
if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2);
}
SWIGEXPORT jstring JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1e_1subclass_1name_1get(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jstring jresult = 0 ;
EventConsumer *arg1 = (EventConsumer *) 0 ;
char *result = 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
result = (char *) ((arg1)->e_subclass_name);
if(result) jresult = jenv->NewStringUTF((const char *)result);
return jresult;
}
SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1e_1cb_1arg_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) {
EventConsumer *arg1 = (EventConsumer *) 0 ;
char *arg2 = (char *) 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
arg2 = 0;
if (jarg2) {
arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0);
if (!arg2) return ;
}
{
if (arg1->e_cb_arg) delete [] arg1->e_cb_arg;
if (arg2) {
arg1->e_cb_arg = (char *) (new char[strlen((const char *)arg2)+1]);
strcpy((char *)arg1->e_cb_arg, (const char *)arg2);
} else {
arg1->e_cb_arg = 0;
}
}
if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2);
}
SWIGEXPORT jstring JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1e_1cb_1arg_1get(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jstring jresult = 0 ;
EventConsumer *arg1 = (EventConsumer *) 0 ;
char *result = 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
result = (char *) ((arg1)->e_cb_arg);
if(result) jresult = jenv->NewStringUTF((const char *)result);
return jresult;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1EventConsumer_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2) {
jlong jresult = 0 ;
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
EventConsumer *result = 0 ;
(void)jenv;
(void)jcls;
arg1 = 0;
if (jarg1) {
arg1 = (char *)jenv->GetStringUTFChars(jarg1, 0);
if (!arg1) return 0;
}
arg2 = 0;
if (jarg2) {
arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0);
if (!arg2) return 0;
}
result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2);
*(EventConsumer **)&jresult = result;
if (arg1) jenv->ReleaseStringUTFChars(jarg1, (const char *)arg1);
if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2);
return jresult;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1EventConsumer_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jstring jarg1) {
jlong jresult = 0 ;
char *arg1 = (char *) 0 ;
EventConsumer *result = 0 ;
(void)jenv;
(void)jcls;
arg1 = 0;
if (jarg1) {
arg1 = (char *)jenv->GetStringUTFChars(jarg1, 0);
if (!arg1) return 0;
}
result = (EventConsumer *)new EventConsumer((char const *)arg1);
*(EventConsumer **)&jresult = result;
if (arg1) jenv->ReleaseStringUTFChars(jarg1, (const char *)arg1);
return jresult;
}
SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_delete_1EventConsumer(JNIEnv *jenv, jclass jcls, jlong jarg1) {
EventConsumer *arg1 = (EventConsumer *) 0 ;
(void)jenv;
(void)jcls;
arg1 = *(EventConsumer **)&jarg1;
delete arg1;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1pop_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
jlong jresult = 0 ;
EventConsumer *arg1 = (EventConsumer *) 0 ;
int arg2 ;
Event *result = 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
arg2 = (int)jarg2;
result = (Event *)(arg1)->pop(arg2);
*(Event **)&jresult = result;
return jresult;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1pop_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jlong jresult = 0 ;
EventConsumer *arg1 = (EventConsumer *) 0 ;
Event *result = 0 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(EventConsumer **)&jarg1;
result = (Event *)(arg1)->pop();
*(Event **)&jresult = result;
return jresult;
}
SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_delete_1CoreSession(JNIEnv *jenv, jclass jcls, jlong jarg1) {
CoreSession *arg1 = (CoreSession *) 0 ;
......
......@@ -270,6 +270,56 @@ sub ACQUIRE {
}
############# Class : freeswitch::EventConsumer ##############
package freeswitch::EventConsumer;
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
@ISA = qw( freeswitch );
%OWNER = ();
%ITERATORS = ();
*swig_events_get = *freeswitchc::EventConsumer_events_get;
*swig_events_set = *freeswitchc::EventConsumer_events_set;
*swig_e_event_id_get = *freeswitchc::EventConsumer_e_event_id_get;
*swig_e_event_id_set = *freeswitchc::EventConsumer_e_event_id_set;
*swig_node_get = *freeswitchc::EventConsumer_node_get;
*swig_node_set = *freeswitchc::EventConsumer_node_set;
*swig_e_callback_get = *freeswitchc::EventConsumer_e_callback_get;
*swig_e_callback_set = *freeswitchc::EventConsumer_e_callback_set;
*swig_e_subclass_name_get = *freeswitchc::EventConsumer_e_subclass_name_get;
*swig_e_subclass_name_set = *freeswitchc::EventConsumer_e_subclass_name_set;
*swig_e_cb_arg_get = *freeswitchc::EventConsumer_e_cb_arg_get;
*swig_e_cb_arg_set = *freeswitchc::EventConsumer_e_cb_arg_set;
sub new {
my $pkg = shift;
my $self = freeswitchc::new_EventConsumer(@_);
bless $self, $pkg if defined($self);
}
sub DESTROY {
return unless $_[0]->isa('HASH');
my $self = tied(%{$_[0]});
return unless defined $self;
delete $ITERATORS{$self};
if (exists $OWNER{$self}) {
freeswitchc::delete_EventConsumer($self);
delete $OWNER{$self};
}
}
*pop = *freeswitchc::EventConsumer_pop;
sub DISOWN {
my $self = shift;
my $ptr = tied(%$self);
delete $OWNER{$ptr};
}
sub ACQUIRE {
my $self = shift;
my $ptr = tied(%$self);
$OWNER{$ptr} = 1;
}
############# Class : freeswitch::CoreSession ##############
package freeswitch::CoreSession;
......
......@@ -164,6 +164,40 @@ class Event(_object):
Event_swigregister = _freeswitch.Event_swigregister
Event_swigregister(Event)
class EventConsumer(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, EventConsumer, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, EventConsumer, name)
__repr__ = _swig_repr
__swig_setmethods__["events"] = _freeswitch.EventConsumer_events_set
__swig_getmethods__["events"] = _freeswitch.EventConsumer_events_get
if _newclass:events = _swig_property(_freeswitch.EventConsumer_events_get, _freeswitch.EventConsumer_events_set)
__swig_setmethods__["e_event_id"] = _freeswitch.EventConsumer_e_event_id_set
__swig_getmethods__["e_event_id"] = _freeswitch.EventConsumer_e_event_id_get
if _newclass:e_event_id = _swig_property(_freeswitch.EventConsumer_e_event_id_get, _freeswitch.EventConsumer_e_event_id_set)
__swig_setmethods__["node"] = _freeswitch.EventConsumer_node_set
__swig_getmethods__["node"] = _freeswitch.EventConsumer_node_get
if _newclass:node = _swig_property(_freeswitch.EventConsumer_node_get, _freeswitch.EventConsumer_node_set)
__swig_setmethods__["e_callback"] = _freeswitch.EventConsumer_e_callback_set
__swig_getmethods__["e_callback"] = _freeswitch.EventConsumer_e_callback_get
if _newclass:e_callback = _swig_property(_freeswitch.EventConsumer_e_callback_get, _freeswitch.EventConsumer_e_callback_set)
__swig_setmethods__["e_subclass_name"] = _freeswitch.EventConsumer_e_subclass_name_set
__swig_getmethods__["e_subclass_name"] = _freeswitch.EventConsumer_e_subclass_name_get
if _newclass:e_subclass_name = _swig_property(_freeswitch.EventConsumer_e_subclass_name_get, _freeswitch.EventConsumer_e_subclass_name_set)
__swig_setmethods__["e_cb_arg"] = _freeswitch.EventConsumer_e_cb_arg_set
__swig_getmethods__["e_cb_arg"] = _freeswitch.EventConsumer_e_cb_arg_get
if _newclass:e_cb_arg = _swig_property(_freeswitch.EventConsumer_e_cb_arg_get, _freeswitch.EventConsumer_e_cb_arg_set)
def __init__(self, *args):
this = _freeswitch.new_EventConsumer(*args)
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _freeswitch.delete_EventConsumer
__del__ = lambda self : None;
def pop(*args): return _freeswitch.EventConsumer_pop(*args)
EventConsumer_swigregister = _freeswitch.EventConsumer_swigregister
EventConsumer_swigregister(EventConsumer)
class CoreSession(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, CoreSession, name, value)
......
......@@ -39,37 +39,65 @@
static void event_handler(switch_event_t *event)
{
EventConsumer *E = (EventConsumer *) event->bind_user_data;
switch_event_t *dup;
switch_event_dup(&dup, event);
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_DECLARE_CONSTRUCTOR EventConsumer::EventConsumer(switch_event_types_t event_id, const char *subclass_name, const char *callback)
SWITCH_DECLARE_CONSTRUCTOR EventConsumer::EventConsumer(const char *event_name, const char *subclass_name)
{
e_event_id = event_id;
switch_name_event(event_name, &e_event_id);
switch_core_new_memory_pool(&pool);
if (!switch_strlen_zero(subclass_name)) {
e_subclass_name = strdup(subclass_name);
e_subclass_name = switch_core_strdup(pool, subclass_name);
} else {
e_subclass_name = "";
e_subclass_name = NULL;
}
if (switch_strlen_zero(callback)) {
callback = "event_consumer";
switch_queue_create(&events, 5000, pool);
if (switch_event_bind_removable(__FILE__, e_event_id, e_subclass_name, event_handler, this, &node) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "bound to %s %s\n", event_name, switch_str_nil(e_subclass_name));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind to %s %s\n", event_name, switch_str_nil(e_subclass_name));
}
e_callback = strdup(callback);
}
SWITCH_DECLARE(Event *) EventConsumer::pop(int block)
{
void *pop = NULL;
Event *ret = NULL;
switch_event_t *event;
switch_event_bind_removable(__FILE__, e_event_id, subclass_name, event_handler, this, &node);
}
if (block) {
switch_queue_pop(events, &pop);
} else {
switch_queue_trypop(events, &pop);
}
if ((event = (switch_event_t *) pop)) {
ret = new Event(event);
}
return ret;
}
SWITCH_DECLARE_CONSTRUCTOR EventConsumer::~EventConsumer()
{
switch_safe_free(e_subclass_name);
switch_safe_free(e_callback);
if (node) {
switch_event_unbind(&node);
}
switch_core_destroy_memory_pool(&pool);
}
SWITCH_DECLARE_CONSTRUCTOR IVRMenu::IVRMenu(IVRMenu *main,
......@@ -210,10 +238,9 @@ SWITCH_DECLARE(const char *)Event::serialize(const char *format)
this_check("");
if (serialized_string) {
free(serialized_string);
}
switch_safe_free(serialized_string);
if (!event) {
return "";
}
......@@ -233,6 +260,7 @@ SWITCH_DECLARE(const char *)Event::serialize(const char *format)
}
} else {
if (switch_event_serialize(event, &serialized_string, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
serialized_string = switch_mprintf("'%s'", serialized_string);
return serialized_string;
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论