RTS API Documentation  1.10.11
Functions
switch_cpp.cpp File Reference
#include <switch.h>
#include <switch_cpp.h>
+ Include dependency graph for switch_cpp.cpp:

Go to the source code of this file.

Functions

static void event_handler (switch_event_t *event)
 
int globalSetVariable (const char *var, const char *val, const char *val2)
 
void setGlobalVariable (char *var_name, char *var_val)
 
char * getGlobalVariable (char *var_name)
 
bool running (void)
 
void consoleLog (char *level_str, char *msg)
 
void consoleLog2 (char *level_str, char *file, char *func, int line, char *msg)
 
void consoleCleanLog (char *msg)
 
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)
 
bool email (char *to, char *from, char *headers, char *body, char *file, char *convert_cmd, char *convert_ext)
 
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_hungup)
 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_cb, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
 

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_cb,
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,
char *  body,
char *  file,
char *  convert_cmd,
char *  convert_ext 
)

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)

◆ event_handler()

static void event_handler ( switch_event_t event)
static

Definition at line 40 of file switch_cpp.cpp.

References switch_event::bind_user_data, EventConsumer::events, SWITCH_CHANNEL_LOG, switch_event_destroy(), switch_event_dup(), SWITCH_LOG_ERROR, switch_log_printf(), switch_queue_trypush(), and SWITCH_STATUS_SUCCESS.

Referenced by EventConsumer::bind().

41 {
43  switch_event_t *dup;
44 
45  switch_event_dup(&dup, event);
46 
48  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot queue any more events.....\n");
50  }
51 
52 }
#define SWITCH_CHANNEL_LOG
Representation of an event.
Definition: switch_event.h:80
switch_status_t switch_event_dup(switch_event_t **event, switch_event_t *todup)
Duplicate an event.
switch_queue_t * events
Definition: switch_cpp.h:188
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1279
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 switch_event_destroy(switch_event_t **event)
Destroy an event.
void * bind_user_data
Definition: switch_event.h:96

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

◆ globalSetVariable()

int globalSetVariable ( const char *  var,
const char *  val,
const char *  val2 
)

Definition at line 1412 of file switch_cpp.cpp.

References switch_core_set_var_conditional(), switch_core_set_variable(), SWITCH_STATUS_SUCCESS, and zstr.

1413 {
1414  if (zstr(val)) val = NULL;
1415  if (zstr(val2)) val2 = NULL;
1416 
1417  if (val2) {
1418  return switch_core_set_var_conditional(var, val, val2);
1419  } else {
1420  switch_core_set_variable(var, val);
1421  return SWITCH_STATUS_SUCCESS;
1422  }
1423 }
switch_bool_t switch_core_set_var_conditional(_In_z_ const char *varname, _In_opt_z_ const char *value, _In_opt_z_ const char *val2)
Conditionally add a global variable to the core.
void switch_core_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value)
Add a global variable to the core.
#define zstr(x)
Definition: switch_utils.h:314

◆ hanguphook()

switch_status_t hanguphook ( switch_core_session_t session_hungup)

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