Changeset 4302


Ignore:
Timestamp:
Nov 28, 2012 3:02:01 AM (11 years ago)
Author:
riza
Message:

Re #1098: Modify help screen, change backspace input character, fix static and dynamic choice type argument handling

Location:
pjproject/branches/projects/cli
Files:
5 edited

Legend:

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

    r4299 r4302  
    561561            } else if (!pj_stricmp2(&choice_attr->name, "desc")) { 
    562562                pj_strassign(&choice_val->desc, &choice_attr->value); 
    563             }                            
     563            } 
     564            choice_attr = choice_attr->next; 
    564565        }                            
    565566        ++(arg->stat_choice_cnt); 
     
    609610            } else if (!pj_stricmp2(&attr->value, "int")) { 
    610611                arg->type = PJ_CLI_ARG_INT; 
    611             } else if (!pj_stricmp2(&attr->value, "CHOICE")) { 
     612            } else if (!pj_stricmp2(&attr->value, "choice")) { 
    612613                /* Get choice value */ 
    613614                pj_cli_add_choice_node(cli, xml_node, arg, get_choice); 
     
    733734        cmd->arg = (pj_cli_arg_spec *)pj_pool_zalloc(cli->pool, cmd->arg_cnt * 
    734735                                                     sizeof(pj_cli_arg_spec)); 
     736         
    735737        for (i = 0; i < cmd->arg_cnt; i++) { 
     738            unsigned j; 
     739 
    736740            pj_strdup(cli->pool, &cmd->arg[i].name, &args[i].name); 
    737741            pj_strdup(cli->pool, &cmd->arg[i].desc, &args[i].desc); 
     742            cmd->arg[i].id = args[i].id; 
    738743            cmd->arg[i].type = args[i].type; 
    739744            cmd->arg[i].optional = args[i].optional; 
     745            cmd->arg[i].get_dyn_choice = args[i].get_dyn_choice; 
     746            cmd->arg[i].stat_choice_cnt = args[i].stat_choice_cnt; 
     747            cmd->arg[i].stat_choice_val = args[i].stat_choice_val; 
    740748        } 
    741749    } 
     
    10641072        PJ_ASSERT_RETURN(arg, PJ_EINVAL); 
    10651073        if (arg->type == PJ_CLI_ARG_CHOICE) {        
    1066             unsigned j;      
    1067             pj_cli_dyn_choice_param dyn_choice_param;        
     1074            unsigned j;              
    10681075 
    10691076            for (j=0; j < arg->stat_choice_cnt; ++j) { 
     
    10811088                } 
    10821089            } 
    1083             /* Get the dynamic choice values */      
    1084             dyn_choice_param.sess = sess; 
    1085             dyn_choice_param.cmd = cmd; 
    1086             dyn_choice_param.arg_id = arg->id; 
    1087             dyn_choice_param.max_cnt = PJ_CLI_MAX_CHOICE_VAL; 
    1088             dyn_choice_param.pool = pool; 
    1089             dyn_choice_param.cnt = 0;        
    1090  
    1091             (*arg->get_dyn_choice)(&dyn_choice_param); 
    1092             for (j=0; j < dyn_choice_param.cnt; ++j) { 
    1093                 pj_cli_arg_choice_val *choice = &dyn_choice_param.choice[j]; 
    1094                 pj_strassign(&info->hint[info->hint_cnt].name, &choice->value); 
    1095                 pj_strassign(&info->hint[info->hint_cnt].desc, &choice->desc); 
    1096                 ++info->hint_cnt; 
     1090            if (arg->get_dyn_choice) { 
     1091                pj_cli_dyn_choice_param dyn_choice_param; 
     1092                static const pj_str_t choice_str = {"choice", 6}; 
     1093 
     1094                /* Get the dynamic choice values */          
     1095                dyn_choice_param.sess = sess; 
     1096                dyn_choice_param.cmd = cmd; 
     1097                dyn_choice_param.arg_id = arg->id; 
     1098                dyn_choice_param.max_cnt = PJ_CLI_MAX_CHOICE_VAL; 
     1099                dyn_choice_param.pool = pool; 
     1100                dyn_choice_param.cnt = 0;            
     1101 
     1102                (*arg->get_dyn_choice)(&dyn_choice_param); 
     1103                for (j=0; j < dyn_choice_param.cnt; ++j) { 
     1104                    pj_cli_arg_choice_val *choice = &dyn_choice_param.choice[j]; 
     1105                    if (!pj_strnicmp(&choice->value, cmd_val, cmd_val->slen)) { 
     1106                        pj_strassign(&info->hint[info->hint_cnt].name, &choice->value); 
     1107                        pj_strassign(&info->hint[info->hint_cnt].type, &choice_str); 
     1108                        pj_strassign(&info->hint[info->hint_cnt].desc, &choice->desc); 
     1109                        ++info->hint_cnt; 
     1110                    } 
     1111                } 
    10971112            } 
    10981113        } else { 
  • pjproject/branches/projects/cli/pjlib-util/src/pjlib-util/cli_console.c

    r4299 r4302  
    7878    ST_ARROWMODE 
    7979} cmd_parse_state; 
     80 
     81/** 
     82 * This specify the state of output character parsing. 
     83 */ 
     84typedef enum out_parse_state 
     85{ 
     86    OP_NORMAL, 
     87    OP_TYPE, 
     88    OP_SHORTCUT, 
     89    OP_CHOICE 
     90} out_parse_state; 
    8091 
    8192/** 
     
    366377    console_recv_buf *recv_buf = &fe->input.recv_buf; 
    367378    const pj_cli_hint_info *hint = info->hint; 
    368     pj_bool_t is_process_sc = PJ_FALSE; 
    369     pj_bool_t valid_type = PJ_FALSE; 
     379    out_parse_state parse_state = OP_NORMAL; 
    370380    pj_ssize_t max_length = 0; 
    371     const pj_str_t sc_type = pj_str("SC"); 
     381    static const pj_str_t sc_type = {"sc", 2}; 
     382    static const pj_str_t choice_type = {"choice", 6}; 
    372383    send_data.ptr = &data[0]; 
    373384    send_data.slen = 0; 
     
    391402 
    392403    for (i=0;i<info->hint_cnt;++i) {     
    393         if ((&hint[i].type) && (hint[i].type.slen > 0)) { 
    394             valid_type = PJ_TRUE; 
     404        pj_strcat2(&send_data, "\r\n  "); 
     405         
     406        if ((&hint[i].type) && (hint[i].type.slen > 0)) {            
    395407            if (pj_stricmp(&hint[i].type, &sc_type) == 0) { 
    396                 if (is_process_sc) { 
    397                     pj_strcat2(&send_data, ", "); 
    398                 } else { 
    399                     pj_strcat2(&send_data, "\r\n\t Shorcut: "); 
    400                     is_process_sc = PJ_TRUE; 
     408                parse_state = OP_SHORTCUT; 
     409            } else if (pj_stricmp(&hint[i].type, &choice_type) == 0) { 
     410                parse_state = OP_CHOICE; 
     411            } else { 
     412                parse_state = OP_TYPE; 
     413            } 
     414        } else {                     
     415            parse_state = OP_NORMAL; 
     416        } 
     417     
     418        switch (parse_state) { 
     419        case OP_CHOICE: 
     420            pj_strcat2(&send_data, "["); 
     421            pj_strcat(&send_data, &hint[i].name); 
     422            pj_strcat2(&send_data, "]");         
     423            break; 
     424        case OP_TYPE: 
     425            pj_strcat2(&send_data, "<"); 
     426            pj_strcat(&send_data, &hint[i].type); 
     427            pj_strcat2(&send_data, ">");         
     428            break; 
     429        default: 
     430            pj_strcat(&send_data, &hint[i].name);            
     431            break; 
     432        } 
     433         
     434        if ((&hint[i].desc) && (hint[i].desc.slen > 0)) { 
     435            if (parse_state != OP_TYPE) { 
     436                for (j=0;j<(max_length-hint[i].name.slen);++j) { 
     437                    pj_strcat2(&send_data, " "); 
    401438                } 
    402                 pj_strcat(&send_data, &hint[i].name); 
    403             } else { 
    404                 is_process_sc = PJ_FALSE; 
    405439            } 
    406         } else {             
    407             valid_type = PJ_FALSE; 
    408             is_process_sc = PJ_FALSE; 
    409         } 
    410  
    411         if (!is_process_sc) { 
    412             pj_strcat2(&send_data, "\r\n\t"); 
    413  
    414             if (valid_type) { 
    415                 pj_strcat2(&send_data, "<"); 
    416                 pj_strcat(&send_data, &hint[i].type); 
    417                 pj_strcat2(&send_data, ">");     
    418             } else { 
    419                 pj_strcat(&send_data, &hint[i].name);        
    420             } 
    421          
    422             if ((&hint[i].desc) && (hint[i].desc.slen > 0)) { 
    423                 if (!valid_type) { 
    424                     for (j=0;j<(max_length-hint[i].name.slen);++j) { 
    425                         pj_strcat2(&send_data, " "); 
    426                     } 
    427                 } 
    428                 pj_strcat2(&send_data, "\t"); 
    429                 pj_strcat(&send_data, &hint[i].desc);        
    430             } 
    431         } 
    432     }         
     440            pj_strcat2(&send_data, "  "); 
     441            pj_strcat(&send_data, &hint[i].desc);            
     442        } 
     443    }   
    433444    pj_strcat2(&send_data, "\r\n"); 
    434445    pj_strcat(&send_data, &fe->cfg.prompt_str); 
  • pjproject/branches/projects/cli/pjlib-util/src/pjlib-util/cli_telnet.c

    r4299 r4302  
    198198 
    199199/** 
     200 * This specify the state of output character parsing. 
     201 */ 
     202typedef enum out_parse_state 
     203{ 
     204    OP_NORMAL, 
     205    OP_TYPE, 
     206    OP_SHORTCUT, 
     207    OP_CHOICE 
     208} out_parse_state; 
     209 
     210/** 
    200211 * This structure contains the command line shown to the user.   
    201212 */ 
     
    755766    struct cli_telnet_fe *fe = (struct cli_telnet_fe *)sess->base.fe; 
    756767    const pj_cli_hint_info *hint = info->hint; 
    757     pj_bool_t is_process_sc = PJ_FALSE; 
    758     pj_bool_t valid_type = PJ_FALSE; 
     768    out_parse_state parse_state = OP_NORMAL; 
    759769    pj_ssize_t max_length = 0; 
    760     const pj_str_t sc_type = pj_str("SC");     
     770    static const pj_str_t sc_type = {"sc", 2}; 
     771    static const pj_str_t choice_type = {"choice", 6}; 
    761772    send_data.ptr = &data[0]; 
    762773    send_data.slen = 0; 
     
    779790 
    780791    for (i=0;i<info->hint_cnt;++i) {     
    781         if ((&hint[i].type) && (hint[i].type.slen > 0)) { 
    782             valid_type = PJ_TRUE; 
     792        pj_strcat2(&send_data, "\r\n  "); 
     793         
     794        if ((&hint[i].type) && (hint[i].type.slen > 0)) {            
    783795            if (pj_stricmp(&hint[i].type, &sc_type) == 0) { 
    784                 if (is_process_sc) { 
    785                     pj_strcat2(&send_data, ", "); 
    786                 } else { 
    787                     pj_strcat2(&send_data, "\r\n\t Shorcut: "); 
    788                     is_process_sc = PJ_TRUE; 
     796                parse_state = OP_SHORTCUT; 
     797            } else if (pj_stricmp(&hint[i].type, &choice_type) == 0) { 
     798                parse_state = OP_CHOICE; 
     799            } else { 
     800                parse_state = OP_TYPE; 
     801            } 
     802        } else {                     
     803            parse_state = OP_NORMAL; 
     804        } 
     805     
     806        switch (parse_state) { 
     807        case OP_CHOICE: 
     808            pj_strcat2(&send_data, "["); 
     809            pj_strcat(&send_data, &hint[i].name); 
     810            pj_strcat2(&send_data, "]");         
     811            break; 
     812        case OP_TYPE: 
     813            pj_strcat2(&send_data, "<"); 
     814            pj_strcat(&send_data, &hint[i].name); 
     815            pj_strcat2(&send_data, ">");         
     816            break; 
     817        default: 
     818            pj_strcat(&send_data, &hint[i].name);            
     819            break; 
     820        } 
     821         
     822        if ((&hint[i].desc) && (hint[i].desc.slen > 0)) { 
     823            if (parse_state != OP_TYPE) { 
     824                for (j=0;j<(max_length-hint[i].name.slen);++j) { 
     825                    pj_strcat2(&send_data, " "); 
    789826                } 
    790                 pj_strcat(&send_data, &hint[i].name); 
    791             } else { 
    792                 is_process_sc = PJ_FALSE; 
    793827            } 
    794         } else {             
    795             valid_type = PJ_FALSE; 
    796             is_process_sc = PJ_FALSE; 
     828            pj_strcat2(&send_data, "  "); 
     829            pj_strcat(&send_data, &hint[i].desc);            
    797830        } 
    798  
    799         if (!is_process_sc) { 
    800             pj_strcat2(&send_data, "\r\n\t"); 
    801  
    802             if (valid_type) { 
    803                 pj_strcat2(&send_data, "<"); 
    804                 pj_strcat(&send_data, &hint[i].type); 
    805                 pj_strcat2(&send_data, ">");     
    806             } else { 
    807                 pj_strcat(&send_data, &hint[i].name);        
    808             } 
    809          
    810             if ((&hint[i].desc) && (hint[i].desc.slen > 0)) { 
    811                 if (!valid_type) { 
    812                     for (j=0;j<(max_length-hint[i].name.slen);++j) { 
    813                         pj_strcat2(&send_data, " "); 
    814                     } 
    815                 } 
    816                 pj_strcat2(&send_data, "\t"); 
    817                 pj_strcat(&send_data, &hint[i].desc);        
    818             } 
    819         } 
    820     }    
     831    }   
    821832    pj_strcat2(&send_data, "\r\n");        
    822833    pj_strcat(&send_data, &fe->cfg.prompt_str); 
     
    12911302            if (*cdata == IAC) { 
    12921303                sess->parse_state = ST_IAC; 
    1293             } else if (*cdata == '\b') { 
     1304            } else if (*cdata == 127) { 
    12941305                is_valid = handle_backspace(sess, cdata); 
    12951306            } else if (*cdata == 27) {               
  • pjproject/branches/projects/cli/pjsip-apps/src/samples/clidemo.c

    r4299 r4302  
    9090} 
    9191 
     92static void get_codec_list(pj_cli_dyn_choice_param *param) 
     93{ 
     94    if (param->arg_id == 3) { 
     95        param->cnt = 2; 
     96        pj_strdup2(param->pool, &param->choice[0].value, "iLbc"); 
     97        pj_strdup2(param->pool, &param->choice[0].desc, "iLbc Codec"); 
     98        pj_strdup2(param->pool, &param->choice[1].value, "g729"); 
     99        pj_strdup2(param->pool, &param->choice[1].desc, "g729 Codec"); 
     100    } 
     101} 
     102 
    92103static struct cmd_xml_t cmd_xmls[] = { 
    93104    {"<CMD name='sayhello' id='1' sc='  ,h , ,, sh  ,' desc='Will say hello'>" 
     
    117128     "</CMD>", 
    118129     NULL}, 
     130    {"<CMD name='disable_codec' id='8' desc='Disable codec'>" 
     131     "  <ARG name='codec_list' type='choice' id='3' desc='Codec list'>" 
     132     "      <CHOICE value='g711' desc='G711 Codec'/>" 
     133     "      <CHOICE value='g722' desc='G722 Codec'/>" 
     134     "  </ARG>" 
     135     "</CMD>", 
     136     NULL}, 
    119137    {"<CMD name='quit_app' id='999' sc='qa' desc='Quit the application'>" 
    120138     "</CMD>", 
     
    159177        xml = pj_str(cmd_xmls[i].xml);   
    160178        status = pj_cli_add_cmd_from_xml(cli, NULL, &xml,  
    161                                          cmd_xmls[i].handler, NULL, NULL); 
     179            cmd_xmls[i].handler, NULL, get_codec_list); 
    162180        if (status != PJ_SUCCESS) 
    163181            goto on_return; 
  • pjproject/branches/projects/cli/pjsip-apps/src/samples/debug.c

    r4299 r4302  
    2929 *  #include "playfile.c" 
    3030 */ 
    31 #include "clidemo.c" 
     31#include "icedemo.c" 
    3232 
Note: See TracChangeset for help on using the changeset viewer.