Tristan Matthews | 0a329cc | 2013-07-17 13:20:14 -0400 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2010 Teluu Inc. (http://www.teluu.com) |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | #ifndef __PJLIB_UTIL_CLI_IMP_H__ |
| 20 | #define __PJLIB_UTIL_CLI_IMP_H__ |
| 21 | |
| 22 | /** |
| 23 | * @file cli_imp.h |
| 24 | * @brief Command Line Interface Implementor's API |
| 25 | */ |
| 26 | |
| 27 | #include <pjlib-util/cli.h> |
| 28 | |
| 29 | |
| 30 | PJ_BEGIN_DECL |
| 31 | |
| 32 | /** |
| 33 | * @defgroup PJLIB_UTIL_CLI_IMP Command Line Interface Implementor's API |
| 34 | * @ingroup PJLIB_UTIL_CLI |
| 35 | * @{ |
| 36 | * |
| 37 | */ |
| 38 | |
| 39 | /** |
| 40 | * Default log level for console sessions. |
| 41 | */ |
| 42 | #ifndef PJ_CLI_CONSOLE_LOG_LEVEL |
| 43 | # define PJ_CLI_CONSOLE_LOG_LEVEL PJ_LOG_MAX_LEVEL |
| 44 | #endif |
| 45 | |
| 46 | /** |
| 47 | * Default log level for telnet sessions. |
| 48 | */ |
| 49 | #ifndef PJ_CLI_TELNET_LOG_LEVEL |
| 50 | # define PJ_CLI_TELNET_LOG_LEVEL 4 |
| 51 | #endif |
| 52 | |
| 53 | /** |
| 54 | * Default port number for telnet daemon. |
| 55 | */ |
| 56 | #ifndef PJ_CLI_TELNET_PORT |
| 57 | # define PJ_CLI_TELNET_PORT 0 |
| 58 | #endif |
| 59 | |
| 60 | /** |
| 61 | * This enumeration specifies front end types. |
| 62 | */ |
| 63 | typedef enum pj_cli_front_end_type |
| 64 | { |
| 65 | PJ_CLI_CONSOLE_FRONT_END, /**< Console front end. */ |
| 66 | PJ_CLI_TELNET_FRONT_END, /**< Telnet front end. */ |
| 67 | PJ_CLI_HTTP_FRONT_END, /**< HTTP front end. */ |
| 68 | PJ_CLI_GUI_FRONT_END /**< GUI front end. */ |
| 69 | } pj_cli_front_end_type; |
| 70 | |
| 71 | |
| 72 | /** |
| 73 | * Front end operations. Only the CLI should call these functions |
| 74 | * directly. |
| 75 | */ |
| 76 | typedef struct pj_cli_front_end_op |
| 77 | { |
| 78 | /** |
| 79 | * Callback to write a log message to the appropriate sessions belonging |
| 80 | * to this front end. The front end would only send the log message to |
| 81 | * the session if the session's log verbosity level is greater than the |
| 82 | * level of this log message. |
| 83 | * |
| 84 | * @param fe The front end. |
| 85 | * @param level Verbosity level of this message message. |
| 86 | * @param data The message itself. |
| 87 | * @param len Length of this message. |
| 88 | */ |
| 89 | void (*on_write_log)(pj_cli_front_end *fe, int level, |
| 90 | const char *data, pj_size_t len); |
| 91 | |
| 92 | /** |
| 93 | * Callback to be called when the application is quitting, to signal the |
| 94 | * front-end to end its main loop or any currently blocking functions, |
| 95 | * if any. |
| 96 | * |
| 97 | * @param fe The front end. |
| 98 | * @param req The session which requested the application quit. |
| 99 | */ |
| 100 | void (*on_quit)(pj_cli_front_end *fe, pj_cli_sess *req); |
| 101 | |
| 102 | /** |
| 103 | * Callback to be called to close and self destroy the front-end. This |
| 104 | * must also close any active sessions created by this front-ends. |
| 105 | * |
| 106 | * @param fe The front end. |
| 107 | */ |
| 108 | void (*on_destroy)(pj_cli_front_end *fe); |
| 109 | |
| 110 | } pj_cli_front_end_op; |
| 111 | |
| 112 | |
| 113 | /** |
| 114 | * This structure describes common properties of CLI front-ends. A front- |
| 115 | * end is a mean to interact with end user, for example the CLI application |
| 116 | * may interact with console, telnet, web, or even a GUI. |
| 117 | * |
| 118 | * Each end user's interaction will create an instance of pj_cli_sess. |
| 119 | * |
| 120 | * Application instantiates the front end by calling the appropriate |
| 121 | * function to instantiate them. |
| 122 | */ |
| 123 | struct pj_cli_front_end |
| 124 | { |
| 125 | /** |
| 126 | * Linked list members |
| 127 | */ |
| 128 | PJ_DECL_LIST_MEMBER(struct pj_cli_front_end); |
| 129 | |
| 130 | /** |
| 131 | * Front end type. |
| 132 | */ |
| 133 | pj_cli_front_end_type type; |
| 134 | |
| 135 | /** |
| 136 | * The CLI application. |
| 137 | */ |
| 138 | pj_cli_t *cli; |
| 139 | |
| 140 | /** |
| 141 | * Front end operations. |
| 142 | */ |
| 143 | pj_cli_front_end_op *op; |
| 144 | }; |
| 145 | |
| 146 | |
| 147 | /** |
| 148 | * Session operations. |
| 149 | */ |
| 150 | typedef struct pj_cli_sess_op |
| 151 | { |
| 152 | /** |
| 153 | * Callback to be called to close and self destroy the session. |
| 154 | * |
| 155 | * @param sess The session to destroy. |
| 156 | */ |
| 157 | void (*destroy)(pj_cli_sess *sess); |
| 158 | |
| 159 | } pj_cli_sess_op; |
| 160 | |
| 161 | |
| 162 | /** |
| 163 | * This structure describes common properties of a CLI session. A CLI session |
| 164 | * is the interaction of an end user to the CLI application via a specific |
| 165 | * renderer, where the renderer can be console, telnet, web, or a GUI app for |
| 166 | * mobile. A session is created by its renderer, and it's creation procedures |
| 167 | * vary among renderer (for example, a telnet session is created when the |
| 168 | * end user connects to the application, while a console session is always |
| 169 | * instantiated once the program is run). |
| 170 | */ |
| 171 | struct pj_cli_sess |
| 172 | { |
| 173 | /** |
| 174 | * Linked list members |
| 175 | */ |
| 176 | PJ_DECL_LIST_MEMBER(struct pj_cli_sess); |
| 177 | |
| 178 | /** |
| 179 | * Pointer to the front-end instance which created this session. |
| 180 | */ |
| 181 | pj_cli_front_end *fe; |
| 182 | |
| 183 | /** |
| 184 | * Session operations. |
| 185 | */ |
| 186 | pj_cli_sess_op *op; |
| 187 | |
| 188 | /** |
| 189 | * Text containing session info, which is filled by the renderer when |
| 190 | * the session is created. |
| 191 | */ |
| 192 | pj_str_t info; |
| 193 | |
| 194 | /** |
| 195 | * Log verbosity of this session. |
| 196 | */ |
| 197 | int log_level; |
| 198 | |
| 199 | }; |
| 200 | |
| 201 | /** |
| 202 | * @} |
| 203 | */ |
| 204 | |
| 205 | |
| 206 | PJ_END_DECL |
| 207 | |
| 208 | #endif /* __PJLIB_UTIL_CLI_IMP_H__ */ |