1 %module freeswitch
2 %include ../../../../swig_common.i
3 //%include "cstring.i"
4 %include std_string.i
5 
6 /**
7  * tell swig to treat these variables as mutable so they
8  * can be used to return values.
9  * See http://www.swig.org/Doc1.3/Library.html
10  */
11 //%cstring_bounded_mutable(char *dtmf_buf, 128);
12 //%cstring_bounded_mutable(char *terminator, 8);
13 
14 
15 /** insert the following includes into generated code so it compiles */
16 %{
17 #include "switch.h"
18 #include "switch_cpp.h"
19 #include "freeswitch_lua.h"
20 %}
21 
22 
23 %typemap(in, checkfn="lua_istable") SWIGLUA_TABLE {
24   $1.L = L;
25   $1.idx = $input;
26 }
27 
28 %typemap(typecheck) SWIGLUA_TABLE {
29   $1 = lua_istable(L, $input);
30 }
31 
32 %typemap(out) cJSON * {
33   SWIG_arg += LUA::JSON::cJSON2LuaTable(L, result);
34   cJSON_Delete(result);
35 }
36 
37 /* Lua function typemap */
38 %typemap(in, checkfn = "lua_isfunction") SWIGLUA_FN {
39   $1.L = L;
40   $1.idx = $input;
41 }
42 
43 %typemap(default) SWIGLUA_FN {
44   SWIGLUA_FN default_swiglua_fn = { 0 };
45   $1 = default_swiglua_fn;
46 }
47 
48 %ignore SwitchToMempool;
49 %newobject EventConsumer::pop;
50 %newobject Session;
51 %newobject CoreSession;
52 %newobject Event;
53 %newobject Stream;
54 %newobject Dbh;
55 %newobject API::execute;
56 %newobject API::executeString;
57 %newobject CoreSession::playAndDetectSpeech;
58 %newobject JSON;
59 %newobject JSON::decode;
60 
61 %include "typemaps.i"
62 %apply int *OUTPUT { int *len };
63 
64 /**
65  * tell swig to grok everything defined in these header files and
66  * build all sorts of c wrappers and lua shadows of the c wrappers.
67  */
68 %include switch_swigable_cpp.h
69 
70 
71 namespace LUA {
72 class Session : public CoreSession {
73  private:
74 	virtual void do_hangup_hook();
75 	lua_State *getLUA();
76 	lua_State *L;
77 	int hh;
78 	int mark;
79  public:
80     Session();
81     Session(char *uuid, CoreSession *a_leg = NULL);
82     Session(switch_core_session_t *session);
83     ~Session();
84 	virtual void destroy(const char *err = NULL);
85 
86 	virtual bool begin_allow_threads();
87 	virtual bool end_allow_threads();
88 	virtual void check_hangup_hook();
89 
90 	virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
91 	void unsetInputCallback(void);
92 	void setInputCallback(char *cbfunc, char *funcargs = NULL);
93 	void setHangupHook(char *func, char *arg = NULL);
94 	bool ready();
95 	int originate(CoreSession *a_leg_session, char *dest, int timeout);
96 
97 	char *cb_function;
98 	char *cb_arg;
99 	char *hangup_func_str;
100 	char *hangup_func_arg;
101 	void setLUA(lua_State *state);
102 
103 };
104 
105 class Dbh {
106   private:
107     switch_cache_db_handle_t *dbh;
108     char *err;
109     bool m_connected;
110     static int query_callback(void *pArg, int argc, char **argv, char **cargv);
111   public:
112     Dbh(char *dsn, char *user = NULL, char *pass = NULL);
113     ~Dbh();
114     bool release();
115     bool connected();
116     bool test_reactive(char *test_sql, char *drop_sql = NULL, char *reactive_sql = NULL);
117     bool query(char *sql, SWIGLUA_FN lua_fun);
118     int affected_rows();
119     char *last_error();
120     void clear_error();
121     int load_extension(const char *extension);
122 };
123 
124 class JSON {
125   private:
126   public:
127     JSON();
128     ~JSON();
129     cJSON *decode(const char *str);
130     std::string encode(SWIGLUA_TABLE lua_table);
131     cJSON *execute(const char *);
132     cJSON *execute(SWIGLUA_TABLE table);
133     std::string execute2(const char *);
134     std::string execute2(SWIGLUA_TABLE table);
135     void encode_empty_table_as_object(bool flag);
136     void return_unformatted_json(bool flag);
137 };
138 
139 }
140 
141