Beispiel #1
0
PJ_DEF(pj_status_t) pj_cli_create(pj_cli_cfg *cfg,
                                  pj_cli_t **p_cli)
{
    pj_pool_t *pool;
    pj_cli_t *cli;    
    unsigned i;

    /* This is an example of the command structure */
    char* cmd_xmls[] = {
     "<CMD name='log' id='30000' sc='' desc='Change log level'>"
     "    <ARG name='level' type='int' optional='0' desc='Log level'/>"
     "</CMD>",     
     "<CMD name='exit' id='30001' sc='' desc='Exit session'>"     
     "</CMD>",
    };

    PJ_ASSERT_RETURN(cfg && cfg->pf && p_cli, PJ_EINVAL);

    pool = pj_pool_create(cfg->pf, "cli", PJ_CLI_POOL_SIZE, 
                          PJ_CLI_POOL_INC, NULL);
    if (!pool)
        return PJ_ENOMEM;
    cli = PJ_POOL_ZALLOC_T(pool, struct pj_cli_t);

    pj_memcpy(&cli->cfg, cfg, sizeof(*cfg));
    cli->pool = pool;
    pj_list_init(&cli->fe_head);

    cli->cmd_name_hash = pj_hash_create(pool, CMD_HASH_TABLE_SIZE);
    cli->cmd_id_hash = pj_hash_create(pool, CMD_HASH_TABLE_SIZE);

    cli->root.sub_cmd = PJ_POOL_ZALLOC_T(pool, pj_cli_cmd_spec);
    pj_list_init(cli->root.sub_cmd);

    /* Register some standard commands. */
    for (i = 0; i < sizeof(cmd_xmls)/sizeof(cmd_xmls[0]); i++) {
        pj_str_t xml = pj_str(cmd_xmls[i]);

        if (pj_cli_add_cmd_from_xml(cli, NULL, &xml, 
				    &cmd_handler, NULL, NULL) != PJ_SUCCESS) 
	{
            TRACE_((THIS_FILE, "Failed to add command #%d", i));
	}
    }

    *p_cli = cli;

    return PJ_SUCCESS;
}
Beispiel #2
0
int main()
{
    pj_caching_pool cp;
    pj_cli_cfg cli_cfg;
    pj_cli_telnet_cfg tcfg;
    pj_str_t xml;
    pj_status_t status;
    int i;        

    pj_init();
    pj_caching_pool_init(&cp, NULL, 0);
    pjlib_util_init();

    /*
     * Create CLI app.
     */
    pj_cli_cfg_default(&cli_cfg);
    cli_cfg.pf = &cp.factory;
    cli_cfg.name = pj_str("mycliapp");
    cli_cfg.title = pj_str("My CLI Application");

    status = pj_cli_create(&cli_cfg, &cli);
    if (status != PJ_SUCCESS)
	goto on_return;

    /*
     * Register some commands.
     */
    for (i = 0; i < sizeof(cmd_xmls)/sizeof(cmd_xmls[0]); i++) {
        xml = pj_str(cmd_xmls[i].xml);	
        status = pj_cli_add_cmd_from_xml(cli, NULL, &xml, 
	    cmd_xmls[i].handler, NULL, get_codec_list);
        if (status != PJ_SUCCESS)
	    goto on_return;
    }

    /*
     * Start telnet daemon
     */
    pj_cli_telnet_cfg_default(&tcfg);
//    tcfg.passwd = pj_str("pjsip");
#if USE_RANDOM_PORT
    tcfg.port = 0;
#else
    tcfg.port = 2233;
#endif    
    tcfg.prompt_str = pj_str("CoolWater% ");
    status = pj_cli_telnet_create(cli, &tcfg, NULL);
    if (status != PJ_SUCCESS)
	goto on_return;

    /*
     * Run the system specific main loop.
     */
    status = app_main(cli);

on_return:

    /*
     * Destroy
     */
    pj_cli_destroy(cli);
    cli = NULL;
    pj_caching_pool_destroy(&cp);
    pj_shutdown();

    return (status != PJ_SUCCESS ? 1 : 0);
}
Beispiel #3
0
int main() {
    pj_caching_pool cp;
    pj_cli_cfg cli_cfg;
    pj_cli_telnet_cfg tcfg;
    pj_str_t xml;
    pj_status_t status;
    pj_status_t cli_status;
    int i;
    pj_log_set_level(LOG_LEVEL);
    print_msg(("", "INITING .... \n"));
    status = pj_init();
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);

    if (status != PJ_SUCCESS) {
        print_msg(("", "PJ INIT FAILED \n"));
    }

    pj_caching_pool_init(&cp, NULL, 0);
    pjlib_util_init();
    /*
     * Create CLI app.
     */
    pj_cli_cfg_default(&cli_cfg);

    print_msg(("", "INITING CLI CFG....  \n"));
    cli_cfg.pf = &cp.factory;
    cli_cfg.name = pj_str("tinysipcli");
    cli_cfg.title = pj_str("TINYSIP");

    cli_status = pj_cli_create(&cli_cfg, &cli);
    print_msg(("", "AFTER INITING CLI CFG....  \n"));

    if (cli_status != PJ_SUCCESS) {
        print_msg(("", "CLI FAILED \n"));
        goto on_return;
    }

    /*
     * Register some commands.
     */
    for (i = 0; i < sizeof(cmd_xmls) / sizeof(cmd_xmls[0]); i++) {
        xml = pj_str(cmd_xmls[i].xml);
//        print_msg(("",cmd_xmls[i].xml));
        status = pj_cli_add_cmd_from_xml(cli, NULL, &xml, cmd_xmls[i].handler,
                                         NULL, get_cmd_list);
        if (status != PJ_SUCCESS)
            continue;
//        goto on_return;
    }
    /* Create pjsua first! */
    status = pjsua_create();
    if (status != PJ_SUCCESS)
        error_exit("Error in pjsua_create()", status);

    /* Init pjsua */
    {
        pjsua_logging_config log_cfg;
        pjsua_logging_config_default(&log_cfg);
        log_cfg.console_level = LOG_LEVEL;

        pjsua_config cfg;
        pjsua_config_default(&cfg);


        cfg.cb.on_incoming_call = &on_incoming_call;
        cfg.cb.on_call_media_state = &on_call_media_state;
        cfg.cb.on_call_state = &on_call_state;

        status = pjsua_init(&cfg, &log_cfg, NULL);
        if (status != PJ_SUCCESS)
            error_exit("Error in pjsua_init()", status);
    }

    /* Add UDP transport. */
    {
        pjsua_transport_config cfg;

        pjsua_transport_config_default(&cfg);
        cfg.port = 5060;
        status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
        if (status != PJ_SUCCESS)
            error_exit("Error creating transport", status);
    }


    /*
     * Start telnet daemon
     */
    pj_cli_telnet_cfg_default(&tcfg);
//    tcfg.passwd = pj_str("pjsip");
#if USE_RANDOM_PORT
    tcfg.port = 0;
#else
    tcfg.port = 2233;
#endif
    tcfg.prompt_str = pj_str("CMD % ");
    status = pj_cli_telnet_create(cli, &tcfg, NULL);
    if (status != PJ_SUCCESS)
        goto on_return;

    /*
     * Run the system specific main loop.
     */
    status = app_main(cli);

on_return:

    print_msg(("", "There're some issues, application is going down now!\n"));
    /*
     * Destroy
     */
    pj_cli_destroy(cli);
    cli = NULL;
    pj_caching_pool_destroy(&cp);
    pj_shutdown();

    return (status != PJ_SUCCESS ? 1 : 0);
}