cli_imp.h 5.2 KB

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