Ignore:
Timestamp:
Jun 30, 2010 5:29:59 AM (14 years ago)
Author:
ming
Message:

Implemented CLI (re #1098)

  • pjlib-util:
    • implement telnet CLI
  • pjsip-apps/samples:
    • sample CLI demo application
  • build:
    • VS6 and Makefile
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/cli/pjlib-util/src/pjlib-util/cli_console.c

    r3211 r3231  
    2222#include <pj/assert.h> 
    2323#include <pj/errno.h> 
     24#include <pj/log.h> 
    2425#include <pj/os.h> 
    2526#include <pj/pool.h> 
     
    4445}; 
    4546 
     47static void cli_console_write_log(pj_cli_front_end *fe, int level, 
     48                                  const char *data, int len) 
     49{ 
     50    struct cli_console_fe * cfe = (struct cli_console_fe *)fe; 
     51 
     52    if (cfe->sess->log_level > level) 
     53        printf("%.*s", len, data); 
     54} 
     55 
     56 
    4657static void cli_console_quit(pj_cli_front_end *fe, pj_cli_sess *req) 
    4758{ 
     
    6576    cli_console_quit(fe, NULL); 
    6677 
     78    if (cfe->input_thread) 
     79        pj_thread_destroy(cfe->input_thread); 
    6780    pj_sem_destroy(cfe->thread_sem); 
    6881    pj_sem_destroy(cfe->input.sem); 
     
    90103 
    91104    pool = pj_pool_create(pj_cli_get_param(cli)->pf, "console_fe", 
    92                           256, 256, NULL); 
     105                          PJ_CLI_CONSOLE_POOL_SIZE, PJ_CLI_CONSOLE_POOL_INC, 
     106                          NULL); 
     107    if (!pool) 
     108        return PJ_ENOMEM; 
    93109    sess = PJ_POOL_ZALLOC_T(pool, pj_cli_sess); 
    94110    fe = PJ_POOL_ZALLOC_T(pool, struct cli_console_fe); 
    95     if (!sess || !fe) 
    96         return PJ_ENOMEM; 
    97111 
    98112    if (!param) { 
     
    102116    sess->fe = &fe->base; 
    103117    sess->log_level = param->log_level; 
     118    sess->op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_sess_op); 
     119    fe->base.op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_front_end_op); 
    104120    fe->base.cli = cli; 
    105121    fe->base.type = PJ_CLI_CONSOLE_FRONT_END; 
    106     fe->base.op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_front_end_op); 
     122    fe->base.op->on_write_log = &cli_console_write_log; 
    107123    fe->base.op->on_quit = &cli_console_quit; 
    108124    fe->base.op->on_destroy = &cli_console_destroy; 
     
    128144        fgets(fe->input.buf, fe->input.maxlen, stdin); 
    129145        for (i = pj_ansi_strlen(fe->input.buf) - 1; i >= 0; i--) { 
    130             if (fe->input.buf[i] == '\n') 
     146            if (fe->input.buf[i] == '\n' || fe->input.buf[i] == '\r') 
    131147                fe->input.buf[i] = 0; 
    132148            else 
     
    137153        pj_sem_wait(fe->thread_sem); 
    138154    } 
    139     pj_sem_post(fe->input.sem); 
    140155    fe->input_thread = NULL; 
    141156 
     
    155170 
    156171    if (!fe->input_thread) { 
    157         if (pj_thread_create(fe->pool, NULL, &readline_thread, fe, 
    158                              0, 0, &fe->input_thread) != PJ_SUCCESS) 
    159         { 
    160             return PJ_EUNKNOWN; 
    161         } 
     172        pj_status_t status; 
     173 
     174        status = pj_thread_create(fe->pool, NULL, &readline_thread, fe, 
     175                                  0, 0, &fe->input_thread); 
     176        if (status != PJ_SUCCESS) 
     177            return status; 
    162178    } else { 
    163179        /* Wake up readline thread */ 
     
    166182 
    167183    pj_sem_wait(fe->input.sem); 
    168      
    169     return (fe->thread_quit ? PJ_CLI_EEXIT : PJ_SUCCESS); 
     184 
     185    return (pj_cli_is_quitting(fe->base.cli)? PJ_CLI_EEXIT : PJ_SUCCESS); 
    170186} 
Note: See TracChangeset for help on using the changeset viewer.