⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gateway.cxx

📁 mgcp协议源代码。支持多种编码:g711
💻 CXX
📖 第 1 页 / 共 3 页
字号:
    else if (event->getStimulus() == StimulusDigit6)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgDTMFPackage::notifyDTMF_6()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit7)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgDTMFPackage::notifyDTMF_7()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit8)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgDTMFPackage::notifyDTMF_8()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit9)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgDTMFPackage::notifyDTMF_9()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigitStar)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgDTMFPackage::notifyDTMF_Star()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigitHash)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgDTMFPackage::notifyDTMF_Hash()));        state->callAgent->send(ntfy);        // remain in current state    }#else  // NCS_PROFILEelse if (event->getStimulus() == StimulusDigit0)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_0()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit1)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_1()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit2)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_2()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit3)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_3()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit4)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_4()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit5)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_5()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit6)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_6()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit7)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_7()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit8)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_8()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigit9)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_9()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigitStar)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_Star()));        state->callAgent->send(ntfy);        // remain in current state    }    else if (event->getStimulus() == StimulusDigitHash)    {        MgNotify ntfy(state->endpointId, state->currentRequestId,                      (MgNCSLinePackage::notifyDTMF_Hash()));        state->callAgent->send(ntfy);        // remain in current state    }#endif    else    {        cout << "received hardware input for which no handling exists\n";    }}void stateWaitForClose(StateEvent* event, StateMachine* state){    if (event->getStimulus() == StimulusNewMessage)    {        Sptr < MgCommand > msgPtr = event->getMessage();        Sptr < MgDeleteConnectionAgent > dlcxPtr;        switch (msgPtr->getType())        {            case MgDeleteConnectionAgentType:            dlcxPtr. dynamicCast (msgPtr);            if (dlcxPtr == NULL)                wrongMessage();            // check endpoint and connection id            //if (state->endpointId != dlcxPtr->getEndpointId())            //wrongMessage();            //if (state->connectionId != dlcxPtr->getConnectionId())            //wrongMessage();            // ignore all optional paramters            // reply with successful response code and string,            // transaction id handled by mgcp stack            dlcxPtr->setResponseCode(RSP_CODE_NORMAL);            dlcxPtr->setResponseString("OK");            state->callAgent->reply(dlcxPtr);            state->setState(stateUninitialized);            // close the audio channel            state->hardware->sendSignal(SignalAudioStop);            break;            default:            // ignore other messages            cout << "received message for which no handling exists\n";            break;        } // end switch    }    else        cout << "received hardware input for which no handling exists\n";}void stateWaitOnHook(StateEvent* event, StateMachine* state){    if (event->getStimulus() == StimulusOnHook)    {        // create and send a Notify msg regarding the onHook event        MgNotify ntfy(state->endpointId, state->currentRequestId,#ifndef NCS_PROFILE                      (MgLinePackage::notifyOnHookTransition())#else  // NCS_PROFILE                      (MgNCSLinePackage::notifyOnHookTransition())#endif                     );        state->callAgent->send(ntfy);        state->setState(stateUninitialized);    }    else        cout << "received hardware input or message for which no handling exists\n";}void* process(void* foo){    MgAgent* bar;    //    cout << "entering process loop\n";    bar = static_cast < MgAgent* > (foo);    bar->threadProcess();    //    cout << "exiting process loop\n";    return NULL;}/********************************************************************* mainDescription: Single endpoint residential gateway. *********************************************************************/int main(int argc, char* argv[]){    StateEvent event;    HardwareEvent hwEvent;    int ret_val;    // read configuration parameters    if (argc != 4)    {        // this is an error        cerr << "usage: gateway <device> <agentHostname> <port>\n";        return 0;    }    string device(argv[1]);    char* agent_host = argv[2];    int port = atoi(argv[3]);    // initialize gateway    StateMachine state;#if defined(__linux__)    if (device == "tpjack")    {        // state.hardware = new TpjackHardware("/dev/ixj0");        state.hardware = new TpjackHardware("/dev/phone0");    }    else#endif    {        // state.hardware = new NullHardware("/dev/ixj0");        state.hardware = new NullHardware("/dev/phone0");    }    fd_set test_fd;    state.hardware->addToFdSet(&test_fd);    int callAgentPort;    if (port == 5050)    {        callAgentPort = 5010;    }    else    {        callAgentPort = 5011;    }    MgAgent callAgent(agent_host, callAgentPort, port);    state.callAgent = &callAgent;    state.setState(stateUninitialized);    // set endpointId, this is just temporary, could be done in constructor    if (port == 5050)        state.endpointId = "testID@localhost:5050";    else        state.endpointId = "testID@localhost:5051";    fd_set read_fds;    srand(time(NULL));    FD_SET(0, &read_fds);    // spawn the looping thread    VThread tid;    // int errNum;    tid.spawn(process, state.callAgent);    // loop forever processing inputs from call agent and endpoint hardware    for (; ; )    {        // reset file descriptor        FD_ZERO(&read_fds);        int maxFd = 16;        state.hardware->addToFdSet(&read_fds);        //	state.callAgent->addToFdSet(&read_fds);        // temporarily perform a blocking wait that times out just to        // make sure hardware does get processed        struct timeval tv;        tv.tv_sec = 0;        tv.tv_usec = 300;        // block on select, wait for input event from        // endpoint hardware and/or call agent        ret_val = select(maxFd, &read_fds, NULL, NULL, &tv);        if (ret_val < 0)        {            cerr << "select() returned with an error\n";        }        else        {            if (ret_val == 0)            {                //cerr << "timeout... check hardware\n";            }            if (state.hardware->process(&read_fds))            {                //		cerr << "handle hardware I/O\n";                // endpoint hardware interface                while ((hwEvent = state.hardware->getEvent()) != EventNULL)                {                    switch (hwEvent)                    {                        case EventOffHook:                        event.setStimulus(StimulusOffHook);                        break;                        case EventOnHook:                        event.setStimulus(StimulusOnHook);                        break;                        case EventDigit0:                        event.setStimulus(StimulusDigit0);                        break;                        case EventDigit1:                        event.setStimulus(StimulusDigit1);                        break;                        case EventDigit2:                        event.setStimulus(StimulusDigit2);                        break;                        case EventDigit3:                        event.setStimulus(StimulusDigit3);                        break;                        case EventDigit4:                        event.setStimulus(StimulusDigit4);                        break;                        case EventDigit5:                        event.setStimulus(StimulusDigit5);                        break;                        case EventDigit6:                        event.setStimulus(StimulusDigit6);                        break;                        case EventDigit7:                        event.setStimulus(StimulusDigit7);                        break;                        case EventDigit8:                        event.setStimulus(StimulusDigit8);                        break;                        case EventDigit9:                        event.setStimulus(StimulusDigit9);                        break;                        case EventDigitStar:                        event.setStimulus(StimulusDigitStar);                        break;                        case EventDigitHash:                        event.setStimulus(StimulusDigitHash);                        break;                        case EventAudioFailed:                        cerr << "Event Audio Failed\n";                        break;                        case EventAudioClosed:                        cerr << "Event Audio Closed\n";                        break;                        default:                        break;                    };                    state.currentState(&event, &state);                }            }            while (state.callAgent->checkMsgReady(&read_fds))            {                //		cerr << "handle agent command\n";                // incoming control packet from call agent                Sptr < MgCommand > msg = state.callAgent->receive();                event.setMessage(msg);                state.currentState(&event, &state);            }            if (0)            {                // incoming audio            }        } // end else    }    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -