Example #1
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);
}
Example #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;
    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);
}