- Timestamp:
- Nov 28, 2012 3:02:01 AM (12 years ago)
- 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 561 561 } else if (!pj_stricmp2(&choice_attr->name, "desc")) { 562 562 pj_strassign(&choice_val->desc, &choice_attr->value); 563 } 563 } 564 choice_attr = choice_attr->next; 564 565 } 565 566 ++(arg->stat_choice_cnt); … … 609 610 } else if (!pj_stricmp2(&attr->value, "int")) { 610 611 arg->type = PJ_CLI_ARG_INT; 611 } else if (!pj_stricmp2(&attr->value, " CHOICE")) {612 } else if (!pj_stricmp2(&attr->value, "choice")) { 612 613 /* Get choice value */ 613 614 pj_cli_add_choice_node(cli, xml_node, arg, get_choice); … … 733 734 cmd->arg = (pj_cli_arg_spec *)pj_pool_zalloc(cli->pool, cmd->arg_cnt * 734 735 sizeof(pj_cli_arg_spec)); 736 735 737 for (i = 0; i < cmd->arg_cnt; i++) { 738 unsigned j; 739 736 740 pj_strdup(cli->pool, &cmd->arg[i].name, &args[i].name); 737 741 pj_strdup(cli->pool, &cmd->arg[i].desc, &args[i].desc); 742 cmd->arg[i].id = args[i].id; 738 743 cmd->arg[i].type = args[i].type; 739 744 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; 740 748 } 741 749 } … … 1064 1072 PJ_ASSERT_RETURN(arg, PJ_EINVAL); 1065 1073 if (arg->type == PJ_CLI_ARG_CHOICE) { 1066 unsigned j; 1067 pj_cli_dyn_choice_param dyn_choice_param; 1074 unsigned j; 1068 1075 1069 1076 for (j=0; j < arg->stat_choice_cnt; ++j) { … … 1081 1088 } 1082 1089 } 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 } 1097 1112 } 1098 1113 } else { -
pjproject/branches/projects/cli/pjlib-util/src/pjlib-util/cli_console.c
r4299 r4302 78 78 ST_ARROWMODE 79 79 } cmd_parse_state; 80 81 /** 82 * This specify the state of output character parsing. 83 */ 84 typedef enum out_parse_state 85 { 86 OP_NORMAL, 87 OP_TYPE, 88 OP_SHORTCUT, 89 OP_CHOICE 90 } out_parse_state; 80 91 81 92 /** … … 366 377 console_recv_buf *recv_buf = &fe->input.recv_buf; 367 378 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; 370 380 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}; 372 383 send_data.ptr = &data[0]; 373 384 send_data.slen = 0; … … 391 402 392 403 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)) { 395 407 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, " "); 401 438 } 402 pj_strcat(&send_data, &hint[i].name);403 } else {404 is_process_sc = PJ_FALSE;405 439 } 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 } 433 444 pj_strcat2(&send_data, "\r\n"); 434 445 pj_strcat(&send_data, &fe->cfg.prompt_str); -
pjproject/branches/projects/cli/pjlib-util/src/pjlib-util/cli_telnet.c
r4299 r4302 198 198 199 199 /** 200 * This specify the state of output character parsing. 201 */ 202 typedef enum out_parse_state 203 { 204 OP_NORMAL, 205 OP_TYPE, 206 OP_SHORTCUT, 207 OP_CHOICE 208 } out_parse_state; 209 210 /** 200 211 * This structure contains the command line shown to the user. 201 212 */ … … 755 766 struct cli_telnet_fe *fe = (struct cli_telnet_fe *)sess->base.fe; 756 767 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; 759 769 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}; 761 772 send_data.ptr = &data[0]; 762 773 send_data.slen = 0; … … 779 790 780 791 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)) { 783 795 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, " "); 789 826 } 790 pj_strcat(&send_data, &hint[i].name);791 } else {792 is_process_sc = PJ_FALSE;793 827 } 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); 797 830 } 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 } 821 832 pj_strcat2(&send_data, "\r\n"); 822 833 pj_strcat(&send_data, &fe->cfg.prompt_str); … … 1291 1302 if (*cdata == IAC) { 1292 1303 sess->parse_state = ST_IAC; 1293 } else if (*cdata == '\b') {1304 } else if (*cdata == 127) { 1294 1305 is_valid = handle_backspace(sess, cdata); 1295 1306 } else if (*cdata == 27) { -
pjproject/branches/projects/cli/pjsip-apps/src/samples/clidemo.c
r4299 r4302 90 90 } 91 91 92 static 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, ¶m->choice[0].value, "iLbc"); 97 pj_strdup2(param->pool, ¶m->choice[0].desc, "iLbc Codec"); 98 pj_strdup2(param->pool, ¶m->choice[1].value, "g729"); 99 pj_strdup2(param->pool, ¶m->choice[1].desc, "g729 Codec"); 100 } 101 } 102 92 103 static struct cmd_xml_t cmd_xmls[] = { 93 104 {"<CMD name='sayhello' id='1' sc=' ,h , ,, sh ,' desc='Will say hello'>" … … 117 128 "</CMD>", 118 129 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}, 119 137 {"<CMD name='quit_app' id='999' sc='qa' desc='Quit the application'>" 120 138 "</CMD>", … … 159 177 xml = pj_str(cmd_xmls[i].xml); 160 178 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); 162 180 if (status != PJ_SUCCESS) 163 181 goto on_return; -
pjproject/branches/projects/cli/pjsip-apps/src/samples/debug.c
r4299 r4302 29 29 * #include "playfile.c" 30 30 */ 31 #include " clidemo.c"31 #include "icedemo.c" 32 32
Note: See TracChangeset
for help on using the changeset viewer.