look out below

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8221 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2008-04-30 19:42:26 +00:00
parent 069d468137
commit b6d649fc86
34 changed files with 4680 additions and 1159 deletions
+2 -2
View File
@@ -21,8 +21,8 @@ freeswitch_lua.o: freeswitch_lua.h
allclean: clean luaclean
rm -f mod_lua_wrap.* freeswitch_lua.$(DYNAMIC_LIB_EXTEN)
swigclean:
rm mod_lua_wrap.*
swigclean: clean
rm -f mod_lua_wrap.*
mod_lua_wrap.cpp: mod_lua_extra.c
swig -lua -c++ -I../../../../src/include -oh mod_lua_wrap.h -o mod_lua_wrap.cpp freeswitch.i
+2 -1
View File
@@ -12,6 +12,7 @@
/** insert the following includes into generated code so it compiles */
%{
#include "switch.h"
#include "switch_cpp.h"
#include "freeswitch_lua.h"
%}
@@ -23,7 +24,7 @@
* tell swig to grok everything defined in these header files and
* build all sorts of c wrappers and lua shadows of the c wrappers.
*/
%include switch_cpp.h
%include switch_swigable_cpp.h
%include freeswitch_lua.h
+52 -25
View File
@@ -1,26 +1,22 @@
#include <switch.h>
#include "freeswitch_lua.h"
SWITCH_BEGIN_EXTERN_C
#include "lua.h"
#include <lauxlib.h>
#include <lualib.h>
#include "mod_lua_extra.h"
SWITCH_END_EXTERN_C
Session::Session() : CoreSession()
{
cb_function = cb_arg = hangup_func_str = NULL;
hh = mark = 0;
}
Session::Session(char *uuid) : CoreSession(uuid)
{
cb_function = cb_arg = hangup_func_str = NULL;
hh = mark = 0;
}
Session::Session(switch_core_session_t *new_session) : CoreSession(new_session)
{
cb_function = cb_arg = hangup_func_str = NULL;
hh = mark = 0;
}
static switch_status_t lua_hanguphook(switch_core_session_t *session_hungup);
Session::~Session()
@@ -31,31 +27,68 @@ Session::~Session()
switch_core_event_hook_remove_state_change(session, lua_hanguphook);
}
bool Session::begin_allow_threads()
{
do_hangup_hook();
return true;
}
bool Session::end_allow_threads()
{
do_hangup_hook();
return true;
}
void Session::setLUA(lua_State *state)
{
L = state;
}
lua_State *Session::getLUA()
{
if (!L) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
}
return L;
}
bool Session::ready() {
bool r;
sanity_check(false);
r = switch_channel_ready(channel) != 0;
do_hangup_hook();
return r;
}
void Session::check_hangup_hook()
{
if (hangup_func_str && (hook_state == CS_HANGUP || hook_state == CS_RING)) {
lua_State *L;
L = (lua_State *) getPrivate("__L");
hh++;
}
}
if (!L) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
void Session::do_hangup_hook()
{
if (hh && !mark) {
const char *err = NULL;
mark++;
if (!getLUA()) {
return;
}
lua_getfield(L, LUA_GLOBALSINDEX, (char *)hangup_func_str);
lua_pushstring(L, hook_state == CS_HANGUP ? "hangup" : "transfer");
lua_call(L, 1, 0);
lua_call(L, 1, 1);
err = lua_tostring(L, -1);
if (!switch_strlen_zero(err)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
}
}
}
@@ -82,9 +115,6 @@ void Session::setHangupHook(char *func) {
switch_safe_free(hangup_func_str);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Not Currently Available\n");
func = NULL;
if (func) {
hangup_func_str = strdup(func);
switch_channel_set_private(channel, "CoreSession", this);
@@ -106,7 +136,7 @@ void Session::setInputCallback(char *cbfunc, char *funcargs) {
if (funcargs) {
cb_arg = strdup(funcargs);
}
args.buf = this;
switch_channel_set_private(channel, "CoreSession", this);
@@ -116,13 +146,10 @@ void Session::setInputCallback(char *cbfunc, char *funcargs) {
switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype)
{
lua_State *L;
const char *ret;
L = (lua_State *) getPrivate("__L");
if (!L) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
return SWITCH_STATUS_FALSE;
if (!getLUA()) {
return SWITCH_STATUS_FALSE;;
}
switch (itype) {
+18 -2
View File
@@ -1,25 +1,41 @@
#ifndef FREESWITCH_LUA_H
#define FREESWITCH_LUA_H
extern "C" {
#include "lua.h"
#include <lauxlib.h>
#include <lualib.h>
#include "mod_lua_extra.h"
}
#include <switch_cpp.h>
class Session : public CoreSession {
private:
virtual void do_hangup_hook();
lua_State *getLUA();
lua_State *L;
int hh;
int mark;
public:
Session();
Session(char *uuid);
Session(switch_core_session_t *session);
~Session();
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
virtual void check_hangup_hook();
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
void setInputCallback(char *cbfunc, char *funcargs);
void setHangupHook(char *func);
bool ready();
char *cb_function;
char *cb_arg;
char *hangup_func_str;
void setLUA(lua_State *state);
};
#endif
+3 -3
View File
@@ -5,7 +5,7 @@
result = (Session *)new Session();
SWIG_arg=0;
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++;
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setLUA(L);
return SWIG_arg;
if(0) SWIG_fail;
@@ -14,7 +14,7 @@
result = (Session *)new Session(arg1);
SWIG_arg=0;
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++;
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setLUA(L);
return SWIG_arg;
if(0) SWIG_fail;
@@ -23,7 +23,7 @@
result = (Session *)new Session(arg1);
SWIG_arg=0;
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++;
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setLUA(L);
return SWIG_arg;
if(0) SWIG_fail;
+2 -2
View File
@@ -2,8 +2,8 @@
#define MOD_LUA_EXTRA
SWITCH_BEGIN_EXTERN_C
int mod_lua_conjure_event(lua_State *L, switch_event_t *event, const char *name, int destroy_me);
int mod_lua_conjure_stream(lua_State *L, switch_stream_handle_t *stream, const char *name, int destroy_me);
void mod_lua_conjure_event(lua_State *L, switch_event_t *event, const char *name, int destroy_me);
void mod_lua_conjure_stream(lua_State *L, switch_stream_handle_t *stream, const char *name, int destroy_me);
SWITCH_END_EXTERN_C
#endif
File diff suppressed because it is too large Load Diff
+196
View File
@@ -0,0 +1,196 @@
typedef struct input_callback_state {
void *function;
void *threadState;
void *extra;
char *funcargs;
} input_callback_state_t;
typedef enum {
S_HUP = (1 << 0),
S_FREE = (1 << 1),
S_RDLOCK = (1 << 2)
} session_flag_t;
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:
public:
switch_event_t *event;
char *serialized_string;
int mine;
Event(const char *type, const char *subclass_name = NULL);
Event(switch_event_t *wrap_me, int free_me=0);
virtual ~Event();
const char *serialize(const char *format=NULL);
bool setPriority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL);
char *getHeader(char *header_name);
char *getBody(void);
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);
};
class CoreSession {
protected:
switch_input_args_t args;
switch_input_args_t *ap;
switch_caller_profile_t caller_profile;
char *uuid;
char *tts_name;
char *voice_name;
void store_file_handle(switch_file_handle_t *fh);
void *on_hangup;
switch_file_handle_t local_fh;
switch_file_handle_t *fhp;
switch_status_t process_callback_result(char *ret);
public:
CoreSession();
CoreSession(char *uuid);
CoreSession(switch_core_session_t *new_session);
virtual ~CoreSession();
switch_core_session_t *session;
switch_channel_t *channel;
unsigned int flags;
int allocated;
input_callback_state cb_state;
switch_channel_state_t hook_state;
int answer();
int preAnswer();
virtual void hangup(char *cause = "normal_clearing");
void setVariable(char *var, char *val);
void setPrivate(char *var, void *val);
void *getPrivate(char *var);
const char *getVariable(char *var);
int recordFile(char *file_name, int max_len=0, int silence_threshold=0, int silence_secs=0);
void setCallerData(char *var, char *val);
int originate(CoreSession *a_leg_session,
char *dest,
int timeout=60);
void setDTMFCallback(void *cbfunc, char *funcargs);
int speak(char *text);
void set_tts_parms(char *tts_name, char *voice_name);
int collectDigits(int timeout);
int getDigits(char *dtmf_buf,
switch_size_t buflen,
switch_size_t maxdigits,
char *terminators,
char *terminator,
int timeout);
int transfer(char *extensions, char *dialplan, char *context);
int playAndGetDigits(int min_digits,
int max_digits,
int max_tries,
int timeout,
char *terminators,
char *audio_files,
char *bad_input_audio_files,
char *dtmf_buf,
char *digits_regex);
int streamFile(char *file, int starting_sample_count=0);
int flushEvents();
int flushDigits();
int setAutoHangup(bool val);
void setHangupHook(void *hangup_func);
bool ready();
void execute(char *app, char *data);
void sendEvent(Event *sendME);
virtual bool begin_allow_threads() = 0;
virtual bool end_allow_threads() = 0;
char* get_uuid() const { return uuid; };
const switch_input_args_t& get_cb_args() const { return args; };
virtual void check_hangup_hook() = 0;
virtual switch_status_t run_dtmf_callback(void *input,
switch_input_type_t itype) = 0;
};
void console_log(char *level_str, char *msg);
void console_clean_log(char *msg);
char *api_execute(char *cmd, char *arg);
void api_reply_delete(char *reply);
void bridge(CoreSession &session_a, CoreSession &session_b);
switch_status_t hanguphook(switch_core_session_t *session);
switch_status_t dtmf_callback(switch_core_session_t *session,
void *input,
switch_input_type_t itype,
void *buf,
unsigned int buflen);