· 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 µî¿¡¼­ ¼³Á¤ÇÑ´Ù.

ID
Password
Join
Do not clog intellect's sluices with bits of knowledge of questionable uses.


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.0053 sec