FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | Typedefs | Enumerations | Functions
switch_cpp.h File Reference
#include <switch.h>
+ Include dependency graph for switch_cpp.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

class  IVRMenu
 
class  API
 
struct  input_callback_state
 
class  DTMF
 
class  Stream
 
class  Event
 
class  EventConsumer
 
class  CoreSession
 

Macros

#define this_check(x)   do { if (!this) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "object is not initalized\n"); return x;}} while(0)
 
#define this_check_void()   do { if (!this) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "object is not initalized\n"); return;}} while(0)
 
#define sanity_check(x)   do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid),SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
 
#define sanity_check_noreturn   do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid),SWITCH_LOG_ERROR, "session is not initalized\n"); return;}} while(0)
 
#define init_vars()
 

Typedefs

typedef struct input_callback_state input_callback_state_t
 

Enumerations

enum  session_flag_t {
  S_HUP = (1 << 0), S_FREE = (1 << 1), S_RDLOCK = (1 << 2), S_HUP = (1 << 0),
  S_FREE = (1 << 1), S_RDLOCK = (1 << 2)
}
 

Functions

void setGlobalVariable (char *var_name, char *var_val)
 
char * getGlobalVariable (char *var_name)
 
void consoleLog (char *level_str, char *msg)
 
void consoleLog2 (char *level_str, char *file, char *func, int line, char *msg)
 
void consoleCleanLog (char *msg)
 
bool running (void)
 
bool email (char *to, char *from, char *headers=NULL, char *body=NULL, char *file=NULL, char *convert_cmd=NULL, char *convert_ext=NULL)
 
void console_log (char *level_str, char *msg)
 
void console_log2 (char *level_str, char *file, char *func, int line, char *msg)
 
void console_clean_log (char *msg)
 
void switch_msleep (unsigned ms)
 
void bridge (CoreSession &session_a, CoreSession &session_b)
 bridge the audio of session_b into session_a More...
 
switch_status_t hanguphook (switch_core_session_t *session)
 the actual hangup hook called back by freeswitch core which in turn gets the session and calls the appropriate instance method to complete the callback. More...
 
switch_status_t dtmf_callback (switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
 

Macro Definition Documentation

#define init_vars ( )
Value:
allocated = 0; \
session = NULL; \
channel = NULL; \
uuid = NULL; \
tts_name = NULL; \
voice_name = NULL; \
xml_cdr_text = NULL; \
memset(&args, 0, sizeof(args)); \
ap = NULL; \
flags = 0; \
on_hangup = NULL; \
memset(&cb_state, 0, sizeof(cb_state)); \
hook_state = CS_NEW; \
fhp = NULL; \
memset(buf, 0, buflen)

Definition at line 16 of file switch_cpp.h.

Referenced by CoreSession::CoreSession(), and CoreSession::destroy().

#define sanity_check (   x)    do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid),SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
#define sanity_check_noreturn   do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid),SWITCH_LOG_ERROR, "session is not initalized\n"); return;}} while(0)
#define this_check (   x)    do { if (!this) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "object is not initalized\n"); return x;}} while(0)
#define this_check_void ( )    do { if (!this) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "object is not initalized\n"); return;}} while(0)

Typedef Documentation

Enumeration Type Documentation

Enumerator
S_HUP 
S_FREE 
S_RDLOCK 
S_HUP 
S_FREE 
S_RDLOCK 

Definition at line 129 of file switch_cpp.h.

129  {
130  S_HUP = (1 << 0),
131  S_FREE = (1 << 1),
132  S_RDLOCK = (1 << 2)
133  } session_flag_t;
session_flag_t
Definition: switch_cpp.h:129

Function Documentation

void bridge ( CoreSession session_a,
CoreSession session_b 
)

bridge the audio of session_b into session_a

NOTE: the stuff regarding the dtmf callback might be completely wrong and has not been reviewed or tested

Definition at line 1394 of file switch_cpp.cpp.

Referenced by switch_channel_set_timestamps().

1395 {
1396  switch_input_callback_function_t dtmf_func = NULL;
1397  switch_input_args_t args;
1398  switch_channel_t *channel_a = NULL, *channel_b = NULL;
1399  const char *err = "Channels not ready\n";
1400 
1401  if (session_a.allocated && session_a.session && session_b.allocated && session_b.session) {
1402  channel_a = switch_core_session_get_channel(session_a.session);
1403  channel_b = switch_core_session_get_channel(session_b.session);
1404 
1405  if (switch_channel_ready(channel_a) && switch_channel_ready(channel_b)) {
1406  session_a.begin_allow_threads();
1408  switch_channel_pre_answer(channel_a);
1409  }
1410 
1411  if (switch_channel_ready(channel_a) && switch_channel_ready(channel_b)) {
1412  args = session_a.get_cb_args(); // get the cb_args data structure for session a
1413  dtmf_func = args.input_callback; // get the call back function
1414  err = NULL;
1415  switch_ivr_multi_threaded_bridge(session_a.session, session_b.session, dtmf_func, args.buf, args.buf);
1416  }
1417  session_a.end_allow_threads();
1418  }
1419  }
1420 
1421  if (err) {
1423  }
1424 
1425 
1426 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define switch_channel_ready(_channel)
#define switch_channel_media_ready(_channel)
virtual bool begin_allow_threads()=0
switch_core_session_t * session
Definition: switch_cpp.h:223
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
switch_status_t switch_ivr_multi_threaded_bridge(_In_ switch_core_session_t *session, _In_ switch_core_session_t *peer_session, switch_input_callback_function_t dtmf_callback, void *session_data, void *peer_session_data)
Bridge Audio from one session to another.
switch_status_t(* switch_input_callback_function_t)(switch_core_session_t *session, void *input, switch_input_type_t input_type, void *buf, unsigned int buflen)
switch_input_callback_function_t input_callback
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
const switch_input_args_t & get_cb_args() const
Get the callback function arguments associated with this session.
Definition: switch_cpp.h:385
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
#define switch_channel_pre_answer(channel)
Indicate progress on a channel to attempt early media.
virtual bool end_allow_threads()=0
void console_clean_log ( char *  msg)

Definition at line 1375 of file switch_cpp.cpp.

1376 {
1378 }
#define SWITCH_CHANNEL_LOG_CLEAN
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:903
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
void console_log ( char *  level_str,
char *  msg 
)

Definition at line 1351 of file switch_cpp.cpp.

1352 {
1354  if (level_str) {
1355  level = switch_log_str2level(level_str);
1356  if (level == SWITCH_LOG_INVALID) {
1357  level = SWITCH_LOG_DEBUG;
1358  }
1359  }
1361 }
#define SWITCH_CHANNEL_LOG
switch_log_level_t switch_log_str2level(_In_z_ const char *str)
Return the level number of the specified log level name.
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:903
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_log_level_t
Log Level Enumeration.
void console_log2 ( char *  level_str,
char *  file,
char *  func,
int  line,
char *  msg 
)

Definition at line 1363 of file switch_cpp.cpp.

1364 {
1366  if (level_str) {
1367  level = switch_log_str2level(level_str);
1368  if (level == SWITCH_LOG_INVALID) {
1369  level = SWITCH_LOG_DEBUG;
1370  }
1371  }
1372  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level, "%s", switch_str_nil(msg));
1373 }
switch_log_level_t switch_log_str2level(_In_z_ const char *str)
Return the level number of the specified log level name.
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:903
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_log_level_t
Log Level Enumeration.
void consoleCleanLog ( char *  msg)

Definition at line 1346 of file switch_cpp.cpp.

1347 {
1348  return console_clean_log(msg);
1349 }
void console_clean_log(char *msg)
void consoleLog ( char *  level_str,
char *  msg 
)

Definition at line 1336 of file switch_cpp.cpp.

1337 {
1338  return console_log(level_str, msg);
1339 }
void console_log(char *level_str, char *msg)
void consoleLog2 ( char *  level_str,
char *  file,
char *  func,
int  line,
char *  msg 
)

Definition at line 1341 of file switch_cpp.cpp.

1342 {
1343  return console_log2(level_str, file, func, line, msg);
1344 }
void console_log2(char *level_str, char *file, char *func, int line, char *msg)
switch_status_t dtmf_callback ( switch_core_session_t session,
void *  input,
switch_input_type_t  itype,
void *  buf,
unsigned int  buflen 
)

Definition at line 1451 of file switch_cpp.cpp.

1455  {
1456 
1457  switch_channel_t *channel = switch_core_session_get_channel(session_cb);
1458  CoreSession *coresession = NULL;
1459 
1460  coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession");
1461 
1462  if (!coresession) {
1463  return SWITCH_STATUS_FALSE;
1464  }
1465 
1466  return coresession->run_dtmf_callback(input, itype);
1467 }
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype)=0
void * switch_channel_get_private(switch_channel_t *channel, const char *key)
Retrieve private from a given channel.
bool email ( char *  to,
char *  from,
char *  headers = NULL,
char *  body = NULL,
char *  file = NULL,
char *  convert_cmd = NULL,
char *  convert_ext = NULL 
)

Definition at line 1380 of file switch_cpp.cpp.

1381 {
1382  if (switch_simple_email(to, from, headers, body, file, convert_cmd, convert_ext) == SWITCH_TRUE) {
1383  return true;
1384  }
1385  return false;
1386 }
switch_bool_t switch_simple_email(const char *to, const char *from, const char *headers, const char *body, const char *file, const char *convert_cmd, const char *convert_ext)
Definition: switch_utils.c:981
char* getGlobalVariable ( char *  var_name)

Definition at line 1325 of file switch_cpp.cpp.

1326 {
1327  return switch_core_get_variable_dup(var_name);
1328 }
char * switch_core_get_variable_dup(_In_z_ const char *varname)
switch_status_t hanguphook ( switch_core_session_t session)

the actual hangup hook called back by freeswitch core which in turn gets the session and calls the appropriate instance method to complete the callback.

Definition at line 1428 of file switch_cpp.cpp.

1429 {
1430  if (session_hungup) {
1431  switch_channel_t *channel = switch_core_session_get_channel(session_hungup);
1432  CoreSession *coresession = NULL;
1434 
1435  if ((coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession"))) {
1436  if (coresession->hook_state != state) {
1437  coresession->cause = switch_channel_get_cause(channel);
1438  coresession->hook_state = state;
1439  coresession->check_hangup_hook();
1440  }
1441  }
1442 
1443  return SWITCH_STATUS_SUCCESS;
1444  } else {
1445  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hangup hook called with null session, something is horribly wrong\n");
1446  return SWITCH_STATUS_FALSE;
1447  }
1448 }
switch_channel_state_t switch_channel_get_state(switch_channel_t *channel)
Get the current state of a channel in the state engine.
#define SWITCH_CHANNEL_LOG
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
switch_call_cause_t cause
Definition: switch_cpp.h:230
switch_channel_state_t hook_state
Definition: switch_cpp.h:229
switch_channel_state_t
Channel States (these are the defaults, CS_SOFT_EXECUTE, CS_EXCHANGE_MEDIA, and CS_CONSUME_MEDIA are ...
void * switch_channel_get_private(switch_channel_t *channel, const char *key)
Retrieve private from a given channel.
virtual void check_hangup_hook()=0
Callback to the language specific hangup callback.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_call_cause_t switch_channel_get_cause(_In_ switch_channel_t *channel)
return the cause code for a given channel
bool running ( void  )

Definition at line 1331 of file switch_cpp.cpp.

1332 {
1333  return switch_core_running() ? true : false;
1334 }
switch_bool_t switch_core_running(void)
Definition: switch_core.c:2857
void setGlobalVariable ( char *  var_name,
char *  var_val 
)

Definition at line 1320 of file switch_cpp.cpp.

1321 {
1322  switch_core_set_variable(var_name, var_val);
1323 }
void switch_core_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value)
Add a global variable to the core.
void switch_msleep ( unsigned  ms)

Definition at line 1388 of file switch_cpp.cpp.

1389 {
1390  switch_sleep(ms * 1000);
1391  return;
1392 }
void switch_sleep(switch_interval_time_t t)
Definition: switch_time.c:620