FreeSWITCH API Documentation  1.7.0
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)
 
 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 ( CoreSession s = NULL)

Definition at line 221 of file switch_cpp.cpp.

References session, and CoreSession::session.

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

Definition at line 230 of file switch_cpp.cpp.

231 {
232  return;
233 }
API::API ( CoreSession s = NULL)
virtual API::~API ( )
virtual

Member Function Documentation

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

Definition at line 236 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.

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

Definition at line 264 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.

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

Definition at line 255 of file switch_cpp.cpp.

References switch_micro_time_now(), and SWITCH_TIME_T_FMT.

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

Field Documentation

switch_core_session_t * API::session
protected

Definition at line 110 of file switch_cpp.h.

Referenced by API().

char API::time_buf
protected

Definition at line 109 of file switch_cpp.h.


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