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

📄 gw.cxx

📁 mgcp协议源代码。支持多种编码:g711
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0  *  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. *  * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. *  * 3. The names "VOCAL", "Vovida Open Communication Application Library", *    and "Vovida Open Communication Application Library (VOCAL)" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor *    may "VOCAL" appear in their name, without prior written *    permission of Vovida Networks, Inc. *  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. *  * ==================================================================== *  * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc.  For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * *//********************************************************************** $Id: gw.cxx,v 1.3.20.1 2001/03/14 19:32:20 icahoon Exp $ $Log: gw.cxx,v $Revision 1.3.20.1  2001/03/14 19:32:20  icahoonGeneral license changesRevision 1.3  2000/09/20 08:01:25  cvsglobal format changeRevision 1.2  2000/01/11 00:55:16  bogawacopyright notice fixes for year 2000 Revision 1.1.1.1  1999/06/17 23:10:40  bogawanew MGCP builder Revision 1.1.1.2  1999/06/17 22:09:32  bogawadocification code Revision 1.1.1.1  1999/06/17 22:07:00  bogawamgcp api builder code Revision 1.4  1999/06/09 08:16:47  bogawa Add copyright notices. Revision 1.3  1999/06/09 04:09:52  bogawa This makefile now correctly does diving makes. In addition, the code has been cleaned up and adds some comments for doc++. doc++ can be invoked by using make doc -- the current version will be shippedwith  appropriate html documentation. Revision 1.2  1999/06/09 01:05:02  bogawa Changes to make the new structure compile correctly, and to allow thecode to use the new hardware structure.  gateway1 is now using thenew structure fully, while gateway2 is using it partially (actuallynot very much). A future version should be much cleaner. Revision 1.1.1.1  1999/06/08 18:12:25  bogawamake file system for cvs  **********************************************************************/// sample gateway code.#include <signal.h>#include <sys/time.h>#include <sys/types.h>#include <unistd.h>//#include "mgcpCoding.hxx"#include "mg.hxx"#include <queue>#include "nullHw.hxx"#include "tpjackHw.hxx"#include <typeinfo>#include <map>/********************************************************************** Data structures **********************************************************************/class StateMachine;class StateEvent;typedef void (*StateHandler)(StateEvent* event, StateMachine* state);void stateUninitialized(StateEvent* event, StateMachine* state);void waitForResponse(StateEvent* event, StateMachine* state);void stateIdle(StateEvent* event, StateMachine* state);void stateRingingIn(StateEvent* event, StateMachine* state);void stateRingingOut(StateEvent* event, StateMachine* state);void stateHalfOpenIn(StateEvent* event, StateMachine* state);void stateHalfOpen(StateEvent* event, StateMachine* state);void stateActiveNoNotifications(StateEvent* event, StateMachine* state);void stateActive(StateEvent* event, StateMachine* state);void stateWaitForClose(StateEvent* event, StateMachine* state);void stateWaitOnHook(StateEvent* event, StateMachine* state);enum StateEventStimulus{    StimulusNULL,    StimulusNewMessage,    StimulusResponse,    StimulusOffHook,    StimulusOnHook,};class StateMachine{    public:        StateMachine()        {}        ;        // yes, this is gross        RequestId CurrentRequestId;        CallId callID;        ConnectionMode callMode;        MgcpTransmitter* callAgent;        UdpReceiver* server;        LocalConnectionDescriptor localDescriptor;        RemoteConnectionDescriptor RemoteDescriptor;        HardwareObject* hardware;        map < StateEventStimulus, Event* > activeEventList;        setState(StateHandler current, StateHandler pending)        {            char* string = "";            if (current == stateUninitialized)                string = "stateUninitialized";            if (current == waitForResponse)                string = "waitForResponse";            if (current == stateIdle)                string = "stateIdle";            if (current == stateRingingOut)                string = "stateRingingOut";            if (current == stateHalfOpen)                string = "stateHalfOpen";            if (current == stateActiveNoNotifications)                string = "stateActiveNoNotifications";            if (current == stateActive)                string = "stateActive";            cout << "State changed to: " << string << "\n";            currentState = current;            pendingState = pending;        };        StateHandler currentState;        StateHandler pendingState;};class StateEvent{    public:        StateEvent() : stimulus(StimulusNULL)        {}        StateEventStimulus getStimulusType()        {            return stimulus;        }        setStimulusType(StateEventStimulus x)        {            stimulus = x;        }        setMessage(MgcpCommand* msg)        {            newMessage = msg;            if (dynamic_cast < MgcpResponse* > (msg))            {                stimulus = StimulusResponse;            }            else            {                stimulus = StimulusNewMessage;            }        }        MgcpCommand* getMessage()        {            return newMessage;        }        void setStimulus(StateEventStimulus stim)        {            stimulus = stim;        }        StateEventStimulus getStimulus()        {            return stimulus;        }    private:        StateEventStimulus stimulus;        MgcpCommand* newMessage;};char* getHost(){    static char buf[256];    gethostname(buf, 256);    return buf;}void wrongMessage(){    cerr << "received invalid message\n";    int parentpid = getpid();    // parent    kill(parentpid, SIGSTOP);    exit(1);}void fatalError(char* errorMsg){    cerr << errorMsg << "\n";    exit(1);}/********************************************************************** Globals **********************************************************************/EndpointId set("testID@localhost:5050");void stateUninitialized(StateEvent* event, StateMachine* state){    if (event->getStimulusType() == StimulusNewMessage)    {        MgcpCommand* test_item = event->getMessage();        //    MgcpCommand* test_item = parseMessage(data->getMessageLocation(), 0);        // state 3 -- receive notification request        NotificationRequest* nrPtr;        nrPtr = dynamic_cast < NotificationRequest* > (test_item);        if (nrPtr == NULL)            wrongMessage();        // check for the right parameters        state->CurrentRequestId = *(nrPtr->getRequestId());        vector < Event* > * eventList((nrPtr->getRequestedEvents())->getVector());        if (!eventList)            wrongMessage();        // get the appropriate events --        vector < Event* > ::iterator eventIter;        eventIter = eventList->begin();        while (eventIter != eventList->end())        {            if (dynamic_cast < LineEventOffHook* > (*eventIter) == NULL)                wrongMessage();  // only accept this event sir            ++eventIter;        }        // reply OK.        MgcpResponse response00(200, nrPtr->getTransactionId(), "OK");        response00.send(*(state->callAgent));        state->setState(stateIdle, NULL);    }    // ignore other messages}void waitForResponse(StateEvent* event, StateMachine* state){    if (state->pendingState == NULL)    {        fatalError("illegal state machine");    }    if (event->getStimulusType() == StimulusResponse)    {        //        state->setState(state->pendingState, NULL);    }    else    {        // this is an event which this state must handle somehow or another.        state->pendingState(event, state);    }}void stateIdle(StateEvent* event, StateMachine* state){    if (event->getStimulusType() == StimulusOffHook)    {        Notify msg8(set);        ObservedEvents events8;        LineEventOffHook offHook;        events8.insert(offHook);        msg8.insert(&events8);        msg8.insert(&(state->CurrentRequestId));        msg8.send(*(state->callAgent));        state->setState(waitForResponse, stateRingingOut);    }    else if (event->getStimulusType() == StimulusNewMessage)    {        MgcpCommand* test_item = event->getMessage();        if (typeid(*test_item) == typeid(NotificationRequest))        {            NotificationRequest* nrPtr;            nrPtr = dynamic_cast < NotificationRequest* > (test_item);            if (nrPtr == NULL)                wrongMessage();            // check for the right parameters            state->CurrentRequestId = *(nrPtr->getRequestId());            vector < Event* > * eventList((nrPtr->getRequestedEvents())->getVector());            if (!eventList)                wrongMessage();            // get the appropriate events --            vector < Event* > ::iterator eventIter;            eventIter = eventList->begin();            bool lookForOffHook(false);            while (eventIter != eventList->end())            {                if (dynamic_cast < LineEventOffHook* > (*eventIter) != NULL)                    lookForOffHook = true;                ++eventIter;            }            if (!lookForOffHook)                wrongMessage();            SignalRequests* signals;            signals = nrPtr->getSignalRequests();            vector < Signal* > * signalList(signals->getList());            if (!signalList)                wrongMessage();            // get the appropriate signals --            vector < Signal* > ::iterator signalIter;            signalIter = signalList->begin();            bool sendRing(false);            bool sendRingback(false);            while (signalIter != signalList->end())            {                if (dynamic_cast < SignalRing* > (*signalIter) != NULL)                {                    sendRing = true;                }                if (dynamic_cast < SignalRingback* > (*signalIter) != NULL)                {                    sendRingback = true;                }                ++signalIter;            }            if (!(sendRing && sendRingback))                wrongMessage();            state->hardware->sendSignal(SignalRingStart);            state->hardware->sendSignal(SignalRemoteRingbackStart);            // reply OK.            MgcpResponse response00(200, nrPtr->getTransactionId(), "OK");            response00.send(*(state->callAgent));            state->CurrentRequestId = (*(nrPtr->getRequestId()));            state->setState(stateRingingIn, NULL);        }    }

⌨️ 快捷键说明

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