1 /* 2 * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application 3 * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org> 4 * 5 * Version: MPL 1.1 6 * 7 * The contents of this file are subject to the Mozilla Public License Version 8 * 1.1 (the "License"); you may not use this file except in compliance with 9 * the License. You may obtain a copy of the License at 10 * http://www.mozilla.org/MPL/ 11 * 12 * Software distributed under the License is distributed on an "AS IS" basis, 13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 14 * for the specific language governing rights and limitations under the 15 * License. 16 * 17 * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application 18 * 19 * The Initial Developer of the Original Code is 20 * Anthony Minessale II <anthm@freeswitch.org> 21 * Portions created by the Initial Developer are Copyright (C) 22 * the Initial Developer. All Rights Reserved. 23 * 24 * Contributor(s): 25 * 26 * Anthony Minessale II <anthm@freeswitch.org> 27 * 28 * 29 * switch_console.h -- Simple Console 30 * 31 */ 32 /*! \file switch_console.h 33 \brief Simple Console 34 35 This module implements a basic console i/o and by basic I mean, um yeah, basic 36 Right now the primary function of this portion of the program is to keep it from exiting. 37 */ 38 39 #ifndef SWITCH_CONSOLE_H 40 #define SWITCH_CONSOLE_H 41 42 #include <switch.h> 43 44 SWITCH_BEGIN_EXTERN_C 45 #define SWITCH_CMD_CHUNK_LEN 1024 46 #define SWITCH_STANDARD_STREAM(s) memset(&s, 0, sizeof(s)); s.data = malloc(SWITCH_CMD_CHUNK_LEN); \ 47 switch_assert(s.data); \ 48 memset(s.data, 0, SWITCH_CMD_CHUNK_LEN); \ 49 s.end = s.data; \ 50 s.data_size = SWITCH_CMD_CHUNK_LEN; \ 51 s.write_function = switch_console_stream_write; \ 52 s.raw_write_function = switch_console_stream_raw_write; \ 53 s.alloc_len = SWITCH_CMD_CHUNK_LEN; \ 54 s.alloc_chunk = SWITCH_CMD_CHUNK_LEN 55 /*! 56 \brief A simple comand loop that reads input from the terminal 57 */ 58 SWITCH_DECLARE(void) switch_console_loop(void); 59 60 #ifndef SWIG 61 /*! 62 \brief A method akin to printf that allows you to redirect output to a specific console "channel" 63 */ 64 SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const char *file, const char *func, int line, 65 const char *fmt, ...) PRINTF_FUNCTION(5, 6); 66 #endif 67 68 SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_raw_write(switch_stream_handle_t *handle, uint8_t *data, switch_size_t datalen); 69 70 #ifndef SWIG 71 /*! 72 \brief A method akin to printf for dealing with api streams 73 */ 74 SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_write(switch_stream_handle_t *handle, const char *fmt, ...) PRINTF_FUNCTION(2, 3); 75 #endif 76 77 SWITCH_DECLARE(switch_status_t) switch_stream_write_file_contents(switch_stream_handle_t *stream, const char *path); 78 79 80 SWITCH_DECLARE(switch_status_t) switch_console_init(switch_memory_pool_t *pool); 81 SWITCH_DECLARE(switch_status_t) switch_console_shutdown(void); 82 SWITCH_DECLARE(switch_status_t) switch_console_add_complete_func(const char *name, switch_console_complete_callback_t cb); 83 SWITCH_DECLARE(switch_status_t) switch_console_del_complete_func(const char *name); 84 SWITCH_DECLARE(switch_status_t) switch_console_run_complete_func(const char *func, const char *line, 85 const char *last_word, switch_console_callback_match_t **matches); 86 SWITCH_DECLARE(void) switch_console_push_match_unique(switch_console_callback_match_t **matches, const char *new_val); 87 SWITCH_DECLARE(void) switch_console_push_match(switch_console_callback_match_t **matches, const char *new_val); 88 SWITCH_DECLARE(void) switch_console_free_matches(switch_console_callback_match_t **matches); 89 SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *last_word, 90 FILE * console_out, switch_stream_handle_t *stream, switch_xml_t xml); 91 SWITCH_DECLARE(void) switch_console_sort_matches(switch_console_callback_match_t *matches); 92 SWITCH_DECLARE(void) switch_console_save_history(void); 93 SWITCH_DECLARE(char *) switch_console_expand_alias(char *cmd, char *arg); 94 SWITCH_DECLARE(switch_status_t) switch_console_execute(char *xcmd, int rec, switch_stream_handle_t *istream); 95 96 SWITCH_END_EXTERN_C 97 #endif 98 /* For Emacs: 99 * Local Variables: 100 * mode:c 101 * indent-tabs-mode:t 102 * tab-width:4 103 * c-basic-offset:4 104 * End: 105 * For VIM: 106 * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: 107 */ 108