cli_console.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_CONSOLE_H__
  19. #define __PJLIB_UTIL_CLI_CONSOLE_H__
  20. /**
  21. * @file cli_console.h
  22. * @brief Command Line Interface Console Front End API
  23. */
  24. #include <pjlib-util/cli_imp.h>
  25. PJ_BEGIN_DECL
  26. /**
  27. * @ingroup PJLIB_UTIL_CLI_IMP
  28. * @{
  29. *
  30. */
  31. /**
  32. * This structure contains various options for CLI console front-end.
  33. * Application must call pj_cli_console_cfg_default() to initialize
  34. * this structure with its default values.
  35. */
  36. typedef struct pj_cli_console_cfg
  37. {
  38. /**
  39. * Default log verbosity level for the session.
  40. *
  41. * Default value: PJ_CLI_CONSOLE_LOG_LEVEL
  42. */
  43. int log_level;
  44. /**
  45. * Specify text message as a prompt string to user.
  46. *
  47. * Default: empty
  48. */
  49. pj_str_t prompt_str;
  50. /**
  51. * Specify the command to quit the application.
  52. *
  53. * Default: empty
  54. */
  55. pj_str_t quit_command;
  56. } pj_cli_console_cfg;
  57. /**
  58. * Initialize pj_cli_console_cfg with its default values.
  59. *
  60. * @param param The structure to be initialized.
  61. */
  62. PJ_DECL(void) pj_cli_console_cfg_default(pj_cli_console_cfg *param);
  63. /**
  64. * Create a console front-end for the specified CLI application, and return
  65. * the only session instance for the console front end. On Windows operating
  66. * system, this may open a new console window.
  67. *
  68. * @param cli The CLI application instance.
  69. * @param param Optional console CLI parameters. If this value is
  70. * NULL, default parameters will be used.
  71. * @param p_sess Pointer to receive the session instance for the
  72. * console front end.
  73. * @param p_fe Optional pointer to receive the front-end instance
  74. * of the console front-end just created.
  75. *
  76. * @return PJ_SUCCESS on success, or the appropriate error code.
  77. */
  78. PJ_DECL(pj_status_t) pj_cli_console_create(pj_cli_t *cli,
  79. const pj_cli_console_cfg *param,
  80. pj_cli_sess **p_sess,
  81. pj_cli_front_end **p_fe);
  82. /**
  83. * Retrieve a cmdline from console stdin and process the input accordingly.
  84. *
  85. * @param sess The CLI session.
  86. * @param buf Pointer to receive the buffer.
  87. * @param maxlen Maximum length to read.
  88. *
  89. * @return PJ_SUCCESS if an input was read
  90. */
  91. PJ_DECL(pj_status_t) pj_cli_console_process(pj_cli_sess *sess,
  92. char *buf,
  93. unsigned maxlen);
  94. /**
  95. * @}
  96. */
  97. PJ_END_DECL
  98. #endif /* __PJLIB_UTIL_CLI_CONSOLE_H__ */