[Freeswitch-svn] [commit] r8197 - in freeswitch/trunk/src: . include

Freeswitch SVN anthm at freeswitch.org
Fri Apr 25 18:11:18 EDT 2008


Author: anthm
Date: Fri Apr 25 18:11:17 2008
New Revision: 8197

Modified:
   freeswitch/trunk/src/include/switch_cpp.h
   freeswitch/trunk/src/switch_cpp.cpp

Log:
update cpp wrapper

Modified: freeswitch/trunk/src/include/switch_cpp.h
==============================================================================
--- freeswitch/trunk/src/include/switch_cpp.h	(original)
+++ freeswitch/trunk/src/include/switch_cpp.h	Fri Apr 25 18:11:17 2008
@@ -90,14 +90,34 @@
 	S_RDLOCK = (1 << 2)
 } session_flag_t;
 
-#if 0
-class switchEvent {
+class Stream {
+ protected: 
+	switch_stream_handle_t mystream;
+	switch_stream_handle_t *stream_p;
+	int mine;
+ public: 
+	Stream(void);
+	Stream(switch_stream_handle_t *);
+	virtual ~Stream();
+	void write(const char *data);	
+	const char *get_data(void);
+};
+
+class Event {
  protected:
 	switch_event_t *event;
  public:
-	switchEvent(switch_event_types_t event_id, const char *subclass_name);
+	Event(const char *type, const char *subclass_name = NULL);
+	virtual ~Event();
+	bool set_priority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL);
+	char *get_header(char *header_name);
+	char *get_body(void);
+	bool add_body(const char *value);
+	bool add_header(const char *header_name, const char *value);
+	bool del_header(const char *header_name);
+	bool fire(void);
 };
-#endif
+
 
 class CoreSession {
  protected:

Modified: freeswitch/trunk/src/switch_cpp.cpp
==============================================================================
--- freeswitch/trunk/src/switch_cpp.cpp	(original)
+++ freeswitch/trunk/src/switch_cpp.cpp	Fri Apr 25 18:11:17 2008
@@ -41,6 +41,117 @@
 #define sanity_check_noreturn do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return;}} while(0)
 #define init_vars() do { session = NULL; channel = NULL; uuid = NULL; tts_name = NULL; voice_name = NULL; memset(&args, 0, sizeof(args)); ap = NULL; caller_profile.source = "mod_unknown";  caller_profile.dialplan = ""; caller_profile.context = ""; caller_profile.caller_id_name = ""; caller_profile.caller_id_number = ""; caller_profile.network_addr = ""; caller_profile.ani = ""; caller_profile.aniii = ""; caller_profile.rdnis = "";  caller_profile.username = ""; on_hangup = NULL; cb_state.function = NULL; } while(0)
 
+Event::Event(const char *type, const char *subclass_name)
+{
+	switch_event_types_t event_id;
+
+	if (switch_name_event(type, &event_id) != SWITCH_STATUS_SUCCESS) {
+		event_id = SWITCH_EVENT_MESSAGE;
+	}
+
+	switch_event_create_subclass(&event, event_id, subclass_name);
+}
+
+Event::~Event()
+{
+	if (event) {
+		switch_event_destroy(&event);
+	}
+}
+
+bool Event::fire(void)
+{
+	if (event) {
+		switch_event_fire(&event);
+		return true;
+	}
+	return false;
+}
+
+bool Event::set_priority(switch_priority_t priority)
+{
+	if (event) {
+        switch_event_set_priority(event, priority);
+		return true;
+    }
+	return false;
+}
+
+char *Event::get_header(char *header_name)
+{
+	if (event) {
+		return switch_event_get_header(event, header_name);
+	}
+	return NULL;
+}
+
+bool Event::add_header(const char *header_name, const char *value)
+{
+	if (event) {
+		return switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, value) == SWITCH_STATUS_SUCCESS ? true : false;
+	}
+
+	return false;
+}
+
+bool Event::del_header(const char *header_name)
+{
+	if (event) {
+		return switch_event_del_header(event, header_name) == SWITCH_STATUS_SUCCESS ? true : false;
+	}
+
+	return false;
+}
+
+
+bool Event::add_body(const char *value)
+{
+	if (event) {
+		return switch_event_add_body(event, "%s", value) == SWITCH_STATUS_SUCCESS ? true : false;
+	}
+	
+	return false;
+}
+
+char *Event::get_body(void)
+{
+	if (event) {
+		return switch_event_get_body(event);
+	}
+	
+	return NULL;
+}
+
+Stream::Stream()
+{
+	SWITCH_STANDARD_STREAM(mystream);
+	stream_p = &mystream;
+	mine = 1;
+}
+
+Stream::Stream(switch_stream_handle_t *sp)
+{
+	stream_p = sp;
+	mine = 0;
+}
+
+
+Stream::~Stream()
+{
+	if (mine) {
+		switch_safe_free(mystream.data);
+	}
+}
+
+void Stream::write(const char *data)
+{
+	stream_p->write_function(stream_p, "%s", data);
+}
+
+const char *Stream::get_data()
+{
+	return stream_p ? (const char *)stream_p->data : NULL;
+}
 
 
 CoreSession::CoreSession()
@@ -77,7 +188,15 @@
 		channel = switch_core_session_get_channel(session);
 		uuid = strdup(nuuid);
 		allocated = 1;
-    }
+    } else {
+		switch_call_cause_t cause;
+		if (switch_ivr_originate(NULL, &session, &cause, nuuid, 60, NULL, NULL, NULL, NULL, SOF_NONE) == SWITCH_STATUS_SUCCESS) {
+			allocated = 1;
+			switch_set_flag(this, S_HUP);
+			uuid = strdup(switch_core_session_get_uuid(session));
+			switch_channel_set_state(switch_core_session_get_channel(session), CS_TRANSMIT);
+		}
+	}
 }
 
 CoreSession::CoreSession(switch_core_session_t *new_session)
@@ -376,6 +495,8 @@
 
     if (a_leg_session) a_leg_session->end_allow_threads();
 	allocated = 1;
+	switch_channel_set_state(switch_core_session_get_channel(session), CS_TRANSMIT);
+
 	return SWITCH_STATUS_SUCCESS;
 
  failed:
@@ -506,13 +627,12 @@
 			level = SWITCH_LOG_DEBUG;
 		}
     }
-    switch_log_printf(SWITCH_CHANNEL_LOG, level, msg);
-	fflush(stdout); // TEMP ONLY!! SHOULD NOT BE CHECKED IN!!
+    switch_log_printf(SWITCH_CHANNEL_LOG, level, "%s", switch_str_nil(msg));
 }
 
 void console_clean_log(char *msg)
 {
-    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN,SWITCH_LOG_DEBUG, msg);
+    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN,SWITCH_LOG_DEBUG, "%s", switch_str_nil(msg));
 }
 
 



More information about the Freeswitch-svn mailing list