FreeSWITCH API Documentation  1.7.0
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

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.

References switch_input_args_t::buf, switch_input_args_t::input_callback, 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 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.

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

Referenced by consoleCleanLog().

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.

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

Referenced by consoleLog().

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.

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

Referenced by consoleLog2().

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.

References console_clean_log().

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.

References console_log().

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.

References console_log2().

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_cb,
void *  input,
switch_input_type_t  itype,
void *  buf,
unsigned int  buflen 
)

Definition at line 1451 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::setDTMFCallback().

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

Definition at line 1380 of file switch_cpp.cpp.

References switch_simple_email(), and SWITCH_TRUE.

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
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:187
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1155
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
char* getGlobalVariable ( char *  var_name)

Definition at line 1325 of file switch_cpp.cpp.

References switch_core_get_variable_dup().

1326 {
1327  return switch_core_get_variable_dup(var_name);
1328 }
char * switch_core_get_variable_dup(_In_z_ const char *varname)
int globalSetVariable ( const char *  var,
const char *  val,
const char *  val2 
)

Definition at line 1307 of file switch_cpp.cpp.

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

1308 {
1309  if (zstr(val)) val = NULL;
1310  if (zstr(val2)) val2 = NULL;
1311 
1312  if (val2) {
1313  return switch_core_set_var_conditional(var, val, val2);
1314  } else {
1315  switch_core_set_variable(var, val);
1316  return SWITCH_STATUS_SUCCESS;
1317  }
1318 }
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:281
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 1428 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::setHangupHook().

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.

References switch_core_running().

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.

References switch_core_set_variable().

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.

References switch_sleep().

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