linphone之linphonec_main_loop分析

这里写图片描述

static int
linphonec_main_loop (LinphoneCore * opm)
{
    char *input;

    print_prompt(opm);


    while (linphonec_running && (input=linphonec_readline(prompt)))
    {
        char *iptr; /* input and input pointer */
        size_t input_len;

        /* Strip blanks */
        iptr=lpc_strip_blanks(input);

        input_len = strlen(iptr);

        /*
         * Do nothing but release memory
         * if only blanks are read
         */
        if ( ! input_len )
        {
            free(input);
            continue;
        }

#ifdef HAVE_READLINE
        /*
         * Only add to history if not already
         * last item in it, and only if the command
         * doesn't start with a space (to allow for
         * hiding passwords)
         */
        if ( iptr == input && strcmp(last_in_history, iptr) )
        {
            strncpy(last_in_history,iptr,sizeof(last_in_history));
            last_in_history[sizeof(last_in_history)-1]='\0';
            add_history(iptr);
        }
#endif
        linphonec_parse_command_line(linphonec, iptr);
        linphonec_command_finished();
        free(input);
    }

    return 0;
}
/***************************************************************************
 *
 *  Public interface
 *
 ***************************************************************************/

/*
 * Main command dispatcher.
 * WARNING: modifies second argument!
 *
 * Always return 1 currently.
 */
int
linphonec_parse_command_line(LinphoneCore *lc, char *cl)
{
    char *ptr=cl;
    char *args=NULL;
    LPC_COMMAND *cmd;

    /* Isolate first word and args */
    while(*ptr && !isspace(*ptr)) ++ptr;
    if (*ptr)
    {
        *ptr='\0';
        /* set args to first nonblank */
        args=ptr+1;
        while(*args && isspace(*args)) ++args;
    }

    /* Handle DTMF */
    if ( isdigit(*cl) || *cl == '#' || *cl == '*' )
    {
        while ( isdigit(*cl) || *cl == '#' || *cl == '*' )
        {
            linphone_core_send_dtmf(lc, *cl);
            linphone_core_play_dtmf (lc,*cl,100);
            ms_sleep(1); // be nice
            ++cl;
        }

        // discard spurious trailing chars
        return 1;
    }

    /* Handle other kind of commands */
    cmd=lpc_find_command(cl);
    if ( !cmd )
    {
        linphonec_out("'%s': Cannot understand this.\n", cl);
        return 1;
    }

    if ( ! cmd->func(lc, args) )
    {
        linphonec_out("Syntax error.\n");
        linphonec_display_command_help(cmd);
    }

    return 1;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值