RTS API Documentation  1.10.11
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) }
 

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

◆ init_vars

#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; \

Definition at line 16 of file switch_cpp.h.

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

◆ sanity_check

#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)

◆ sanity_check_noreturn

#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)

◆ this_check

#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)

◆ this_check_void

#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

◆ input_callback_state_t

Enumeration Type Documentation

◆ session_flag_t

Enumerator
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

◆ bridge()

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 1500 of file switch_cpp.cpp.

References CoreSession::allocated, CoreSession::begin_allow_threads(), switch_input_args_t::buf, CoreSession::end_allow_threads(), CoreSession::get_cb_args(), switch_input_args_t::input_callback, CoreSession::session, SWITCH_CALL_DIRECTION_INBOUND, switch_channel_direction(), switch_channel_media_ready, switch_channel_pre_answer, switch_channel_ready, SWITCH_CHANNEL_SESSION_LOG, switch_core_session_get_channel(), switch_ivr_multi_threaded_bridge(), SWITCH_LOG_ERROR, and switch_log_printf().

Referenced by CoreSession::get_cb_args(), and switch_channel_set_timestamps().

1501 {
1502  switch_input_callback_function_t dtmf_func = NULL;
1503  switch_input_args_t args;
1504  switch_channel_t *channel_a = NULL, *channel_b = NULL;
1505  const char *err = "Channels not ready\n";
1506 
1507  if (session_a.allocated && session_a.session && session_b.allocated && session_b.session) {
1508  channel_a = switch_core_session_get_channel(session_a.session);
1509  channel_b = switch_core_session_get_channel(session_b.session);
1510 
1511  if (switch_channel_ready(channel_a) && switch_channel_ready(channel_b)) {
1512  session_a.begin_allow_threads();
1514  switch_channel_pre_answer(channel_a);
1515  }
1516 
1517  if (switch_channel_ready(channel_a) && switch_channel_ready(channel_b)) {
1518  args = session_a.get_cb_args(); // get the cb_args data structure for session a
1519  dtmf_func = args.input_callback; // get the call back function
1520  err = NULL;
1521  switch_ivr_multi_threaded_bridge(session_a.session, session_b.session, dtmf_func, args.buf, args.buf);
1522  }
1523  session_a.end_allow_threads();
1524  }
1525  }
1526 
1527  if (err) {
1529  }
1530 
1531 
1532 }
#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:224
_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_input_callback_function_t input_callback
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)
const switch_input_args_t & get_cb_args() const
Get the callback function arguments associated with this session.
Definition: switch_cpp.h:400
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
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

◆ console_clean_log()

void console_clean_log ( char *  msg)

Definition at line 1481 of file switch_cpp.cpp.

References SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, switch_log_printf(), and switch_str_nil.

Referenced by consoleCleanLog(), and CoreSession::get_cb_args().

1482 {
1484 }
#define SWITCH_CHANNEL_LOG_CLEAN
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:993
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.

◆ console_log()

void console_log ( char *  level_str,
char *  msg 
)

Definition at line 1456 of file switch_cpp.cpp.

References SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, SWITCH_LOG_INVALID, switch_log_printf(), switch_log_str2level(), and switch_str_nil.

Referenced by consoleLog(), and CoreSession::get_cb_args().

1457 {
1459  if (level_str) {
1460  level = switch_log_str2level(level_str);
1461  if (level == SWITCH_LOG_INVALID) {
1462  level = SWITCH_LOG_DEBUG;
1463  }
1464  }
1465 
1467 }
#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:993
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.

◆ console_log2()

void console_log2 ( char *  level_str,
char *  file,
char *  func,
int  line,
char *  msg 
)

Definition at line 1469 of file switch_cpp.cpp.

References SWITCH_CHANNEL_ID_LOG, SWITCH_LOG_DEBUG, SWITCH_LOG_INVALID, switch_log_printf(), switch_log_str2level(), and switch_str_nil.

Referenced by consoleLog2(), and CoreSession::get_cb_args().

1470 {
1472  if (level_str) {
1473  level = switch_log_str2level(level_str);
1474  if (level == SWITCH_LOG_INVALID) {
1475  level = SWITCH_LOG_DEBUG;
1476  }
1477  }
1478  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level, "%s", switch_str_nil(msg));
1479 }
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:993
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.

◆ consoleCleanLog()

void consoleCleanLog ( char *  msg)

Definition at line 1451 of file switch_cpp.cpp.

References console_clean_log().

1452 {
1453  return console_clean_log(msg);
1454 }
void console_clean_log(char *msg)

◆ consoleLog()

void consoleLog ( char *  level_str,
char *  msg 
)

Definition at line 1441 of file switch_cpp.cpp.

References console_log().

Referenced by CoreSession::get_cb_args().

1442 {
1443  return console_log(level_str, msg);
1444 }
void console_log(char *level_str, char *msg)

◆ consoleLog2()

void consoleLog2 ( char *  level_str,
char *  file,
char *  func,
int  line,
char *  msg 
)

Definition at line 1446 of file switch_cpp.cpp.

References console_log2().

Referenced by CoreSession::get_cb_args().

1447 {
1448  return console_log2(level_str, file, func, line, msg);
1449 }
void console_log2(char *level_str, char *file, char *func, int line, char *msg)

◆ dtmf_callback()

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 1557 of file switch_cpp.cpp.

References CoreSession::run_dtmf_callback(), switch_channel_get_private(), switch_core_session_get_channel(), and SWITCH_STATUS_FALSE.

Referenced by CoreSession::get_cb_args(), and CoreSession::setDTMFCallback().

1561  {
1562 
1563  switch_channel_t *channel = switch_core_session_get_channel(session_cb);
1564  CoreSession *coresession = NULL;
1565 
1566  coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession");
1567 
1568  if (!coresession) {
1569  return SWITCH_STATUS_FALSE;
1570  }
1571 
1572  return coresession->run_dtmf_callback(input, itype);
1573 }
_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.

◆ email()

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 1486 of file switch_cpp.cpp.

References switch_simple_email(), and SWITCH_TRUE.

1487 {
1488  if (switch_simple_email(to, from, headers, body, file, convert_cmd, convert_ext) == SWITCH_TRUE) {
1489  return true;
1490  }
1491  return false;
1492 }
cJSON *const to
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)

◆ getGlobalVariable()

char* getGlobalVariable ( char *  var_name)

Definition at line 1430 of file switch_cpp.cpp.

References switch_core_get_variable_dup().

1431 {
1432  return switch_core_get_variable_dup(var_name);
1433 }
char * switch_core_get_variable_dup(_In_z_ const char *varname)

◆ hanguphook()

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 1534 of file switch_cpp.cpp.

References CoreSession::cause, CoreSession::check_hangup_hook(), CoreSession::hook_state, switch_channel_get_cause(), switch_channel_get_private(), switch_channel_get_state(), SWITCH_CHANNEL_LOG, switch_core_session_get_channel(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by CoreSession::get_cb_args(), and CoreSession::setHangupHook().

1535 {
1536  if (session_hungup) {
1537  switch_channel_t *channel = switch_core_session_get_channel(session_hungup);
1538  CoreSession *coresession = NULL;
1540 
1541  if ((coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession"))) {
1542  if (coresession->hook_state != state) {
1543  coresession->cause = switch_channel_get_cause(channel);
1544  coresession->hook_state = state;
1545  coresession->check_hangup_hook();
1546  }
1547  }
1548 
1549  return SWITCH_STATUS_SUCCESS;
1550  } else {
1551  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hangup hook called with null session, something is horribly wrong\n");
1552  return SWITCH_STATUS_FALSE;
1553  }
1554 }
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:231
switch_channel_state_t hook_state
Definition: switch_cpp.h:230
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

◆ running()

bool running ( void  )

Definition at line 1436 of file switch_cpp.cpp.

References switch_core_running(), and true.

1437 {
1438  return switch_core_running() ? true : false;
1439 }
switch_bool_t switch_core_running(void)
Definition: switch_core.c:2993
#define true
Definition: cJSON.c:61

◆ setGlobalVariable()

void setGlobalVariable ( char *  var_name,
char *  var_val 
)

Definition at line 1425 of file switch_cpp.cpp.

References switch_core_set_variable().

1426 {
1427  switch_core_set_variable(var_name, var_val);
1428 }
void switch_core_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value)
Add a global variable to the core.

◆ switch_msleep()

void switch_msleep ( unsigned  ms)

Definition at line 1494 of file switch_cpp.cpp.

References switch_sleep().

Referenced by CoreSession::get_cb_args().

1495 {
1496  switch_sleep(ms * 1000);
1497  return;
1498 }
void switch_sleep(switch_interval_time_t t)
Definition: switch_time.c:640