· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Asterisk Source/Command Line Interface

AsteriskSource/CommandLineInterface


* version 0.2.0
struct ast_cli_entry {
        /*! Null terminated list of the words of the command */
        char *cmda[AST_MAX_CMD_LEN];
        /*! Handler for the command (fd for output, # of arguments, argument list).  Returns RESULT_SHOWUSAGE for improper arguments */
        int (*handler)(int fd, int argc, char *argv[]);
        /*! Summary of the command (< 60 characters) */
        char *summary;
        /*! Detailed usage information */
        char *usage;
        /*! Generate a list of possible completions for a given word */
        char *(*generator)(char *line, char *word, int pos, int state);
        /*! For linking */
        struct ast_cli_entry *next;
        /*! For keeping track of usage */
        int inuse;
};

* int main(int argc, char *argv[])
  • ast_ulaw_init(); ast_alaw_init(); callerid_init(); tdd_init();
  • Check for options
  • term_init();
  • if (ast_tryconnect()) {
    • if (option_remote) {
      • exit(0);
    • } else {
      • exit(1);
    • }
  • } else if (option_remote || option_exec) {
    • Unable to connect to remote asterisk
    • exit(1);
  • }
  • if (!option_verbose && !option_debug && !option_nofork && !option_console) {
    • daemon(0,0);
  • }
  • ast_makesocket();
  • if (option_console || option_verbose || option_remote)
    • ast_register_verbose(console_verboser);
  • init_logger()
  • init_manager()
  • ast_image_init()
  • load_pbx()
  • load_modules()
  • init_framer()
  • ast_cli_register(&astshutdownnow);
  • ast_cli_register(&astshutdowngracefully);
  • ast_cli_register(&astrestartnow);
  • ast_cli_register(&astrestartgracefully);
  • ast_cli_register(&astrestartwhenconvenient);
  • ast_cli_register(&aborthalt);
  • if (option_console) {
    • consolethread = pthread_self();
    • rl_callback_handler_install(tmp, consolehandler);
    • rl_completion_entry_function = (void *)(Function *)cli_generator;
    • for(;;) {
      • res = select(STDIN_FILENO + 1, &rfds, NULL, NULL, NULL);
      • if (res > 0) {
        • rl_callback_read_char();
          • enter key 가 입력되면, consolhandler 을 call 한다.
      • } else if (res < 1) {
        • rl_forced_update_display();
      • }
  • } else {
    • select(0,NULL,NULL,NULL,NULL);
  • }
  • return 0;

* int ast_cli_register(struct ast_cli_entry *e)

* static void consolehandler(char *s)
  • add_history(s);
  • if (s0 == '!') {
    • shell command 를 수행하거나, shell 을 수행시킨다.
  • } else
    • ast_cli_command(STDOUT_FILENO, s);

* int ast_cli_command(int fd, char *s)
  • struct ast_cli_entry *e;
  • e = find_cli(argv, 0);
  • switch(e->handler(fd, x, argv)) {
  • case RESULT_SHOWUSAGE:
    • ast_cli(fd, e->usage);
  • }

static struct ast_cli_entry aborthalt = { { "abort", "halt", NULL }, handle_abort_halt, "Cancel a running halt", abort_halt_help };

* ast_cli_register 에 의해 static 으로 설정된 ast_cli_entry 를 linked list 에 넣는다.

* linked list 에서 해당하는 ast_cli_entry 를 찾아 handler 를 수행한다.

* handler 는 필요에 따라 각 channel, 각 application 등에서 설정한다.



sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-06-27 16:26:04
Processing time 0.0242 sec