RTS API Documentation  1.10.11
Public Member Functions | Protected Attributes
API Class Reference

#include <switch_cpp.h>

+ Collaboration diagram for API:

Public Member Functions

 API (CoreSession *s=NULL)
 
virtual ~ API ()
 
const char * execute (const char *command, const char *data=NULL)
 
const char * executeString (const char *command)
 
char * getTime (void)
 

Protected Attributes

char time_buf [64]
 
switch_core_session_tsession
 

Detailed Description

Definition at line 107 of file switch_cpp.h.

Constructor & Destructor Documentation

◆ API()

API::API ( CoreSession s = NULL)

Definition at line 222 of file switch_cpp.cpp.

References CoreSession::session, and SWITCH_DECLARE_CONSTRUCTOR.

223 {
224  if (s) {
225  session = s->session;
226  } else {
227  session = NULL;
228  }
229 }
switch_core_session_t * session
Definition: switch_cpp.h:224
switch_core_session_t * session
Definition: switch_cpp.h:110

◆ ~ API()

virtual API::~ API ( )
virtual

Member Function Documentation

◆ execute()

const char * API::execute ( const char *  command,
const char *  data = NULL 
)

Definition at line 237 of file switch_cpp.cpp.

References switch_stream_handle::data, switch_api_execute(), SWITCH_CHANNEL_SESSION_LOG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STANDARD_STREAM, this_check, switch_stream_handle::write_function, and zstr.

238 {
239  switch_stream_handle_t stream = { 0 };
240  this_check("");
241 
242  SWITCH_STANDARD_STREAM(stream);
243 
244  if (zstr(cmd)) {
245  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No application specified\n");
246  stream.write_function(&stream, "-ERR No application specified");
247  } else {
248  switch_api_execute(cmd, arg, session, &stream);
249  }
250 
251  return (char *) stream.data;
252 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_status_t switch_api_execute(const char *cmd, const char *arg, switch_core_session_t *session, switch_stream_handle_t *stream)
Execute a registered API command.
#define this_check(x)
Definition: switch_cpp.h:12
#define zstr(x)
Definition: switch_utils.h:314
#define SWITCH_STANDARD_STREAM(s)
switch_stream_handle_write_function_t write_function
switch_core_session_t * session
Definition: switch_cpp.h:110
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.

◆ executeString()

const char * API::executeString ( const char *  command)

Definition at line 265 of file switch_cpp.cpp.

References switch_stream_handle::data, switch_api_execute(), switch_assert, SWITCH_CHANNEL_SESSION_LOG, SWITCH_LOG_ERROR, switch_log_printf(), switch_safe_free, SWITCH_STANDARD_STREAM, this_check, switch_stream_handle::write_function, and zstr.

266 {
267  char *arg;
268  switch_stream_handle_t stream = { 0 };
269  char *mycmd = NULL;
270 
271  this_check("");
272 
273  SWITCH_STANDARD_STREAM(stream);
274 
275  if (zstr(cmd)) {
276  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No application specified\n");
277  stream.write_function(&stream, "-ERR No application specified");
278  } else {
279  mycmd = strdup(cmd);
280 
281  switch_assert(mycmd);
282 
283  if ((arg = strchr(mycmd, ' '))) {
284  *arg++ = '\0';
285  }
286 
287  switch_api_execute(mycmd, arg, session, &stream);
288  switch_safe_free(mycmd);
289  }
290 
291  return (char *) stream.data;
292 }
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_status_t switch_api_execute(const char *cmd, const char *arg, switch_core_session_t *session, switch_stream_handle_t *stream)
Execute a registered API command.
#define this_check(x)
Definition: switch_cpp.h:12
#define zstr(x)
Definition: switch_utils.h:314
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
#define SWITCH_STANDARD_STREAM(s)
switch_stream_handle_write_function_t write_function
switch_core_session_t * session
Definition: switch_cpp.h:110
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_assert(expr)

◆ getTime()

char * API::getTime ( void  )

Definition at line 256 of file switch_cpp.cpp.

References switch_micro_time_now(), and SWITCH_TIME_T_FMT.

257 {
258  switch_time_t now = switch_micro_time_now() / 1000;
259  snprintf(time_buf, sizeof(time_buf), "%" SWITCH_TIME_T_FMT, now);
260  return time_buf;
261 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
int64_t switch_time_t
Definition: switch_apr.h:188
#define SWITCH_TIME_T_FMT
char time_buf[64]
Definition: switch_cpp.h:109

Field Documentation

◆ session

switch_core_session_t* API::session
protected

Definition at line 110 of file switch_cpp.h.

◆ time_buf

char API::time_buf[64]
protected

Definition at line 109 of file switch_cpp.h.


The documentation for this class was generated from the following files: