📄 endpoint.cxx
字号:
/* ==================================================================== * 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/>. * */static const char* const endpoint_cxx_Version = "$Id: endpoint.cxx,v 1.18 2001/01/17 01:52:24 liuhong Exp $";#include "VTime.hxx"#include <sys/types.h>#include <sys/socket.h>#include <errno.h>#include <stdlib.h>#include <stdio.h>#include "endpoint.h"#include "MgcpResponseCode.hxx"extern Endpoint eps [];extern CallData call [];void processEvent (Endpoint*, int);voidstateChange (Endpoint* ep, int newState){ ep->state = newState;} /* stateChange */intinitResponse (Endpoint* ep){ stateChange (ep, Idle); return 1;} /* initResponse */intinitRestart (Endpoint* ep){ sprintf (ep->requestIdentifier, "%X", newRequestIdentifier()); MgcNotificationRequest rqnt ("testID", ep->requestIdentifier); ep->gw->send (rqnt); if (rqnt.getResponseCode() == TransactionExecuted) { initResponse (ep); } return 1;} /* initRestart */intringing (Endpoint* ep){ stateChange (ep, Ringing); return 1;} /* ringing */intreceiveCall (Endpoint* ep){ stateChange (ep, IncomingCall); sprintf (ep->requestIdentifier, "%X", newRequestIdentifier()); MgcNotificationRequest rqnt ("testID", ep->requestIdentifier); ep->gw->send (rqnt); if (rqnt.getResponseCode() == TransactionExecuted) { ringing (ep); } return 1;} /* receiveCall */intconnectionReady (Endpoint* ep){ stateChange (ep, RingBackState); CallData* call1 = ep->call; /* Warning: No locking on shared endpoint and call data */ Endpoint* destEp = &eps[call1->endpoint[1].id]; CallData* call2 = newCallData (destEp); strcpy (call2->callIdentifier, call1->callIdentifier); call2->endpoint[1].id = ep->id; strcpy (call2->endpoint[1].connectionId, call1->endpoint[0].connectionId); call2->endpoint[1].localConnection = call1->endpoint[0].localConnection; destEp->call = call2; notifyEndpoint (destEp, ReceiveCall); return 1;} /* connectionReady */intdialingComplete (Endpoint* ep){ CallData* call = newCallData (ep); sprintf (call->callIdentifier, "%X", newCallIdentifier()); int destEpId; if (ep->id == 0) { destEpId = 1; } else { destEpId = 0; } call->endpoint[1].id = destEpId; ep->call = call; stateChange (ep, NewCall); MgcCreateConnection crcx ("testID", call->callIdentifier, "sendrecv"); ep->gw->send (crcx); if (crcx.getResponseCode() == TransactionExecuted) { strcpy (call->endpoint[0].connectionId, (crcx.getConnectionId ()).data()); call->endpoint[0].localConnection = crcx.getLocalConnectionDescriptor (); connectionReady (ep); } else { cout << "failed TransactionExecuted\n"; } return 1;} /* dialingComplete */intdisconnectResponse (Endpoint* ep){ stateChange (ep, Init); initRestart (ep); return 1;} /* disconnectResponse */intdisconnect (Endpoint* ep){ stateChange (ep, Disconnect); CallData* call = ep->call; assert (call); MgcDeleteConnectionAgent dlcx ("testID"); dlcx.setCallId (call->callIdentifier); dlcx.setConnectionId (call->endpoint[0].connectionId); ep->gw->send (dlcx); if (dlcx.getResponseCode() == ConnectionDeleted || dlcx.getResponseCode() == TransactionExecuted) { notifyEndpoint (&eps[call->endpoint[1].id], ClearCall); callDataInit (ep->call); ep->call = NULL; disconnectResponse (ep); } return 1;} /* disconnect */intclearCall (Endpoint* ep){ stateChange (ep, Disconnect); CallData* call = ep->call; assert (call); MgcDeleteConnectionAgent dlcx ("testID"); dlcx.setCallId (call->callIdentifier); dlcx.setConnectionId (call->endpoint[0].connectionId); ep->gw->send (dlcx); if (dlcx.getResponseCode() == ConnectionDeleted || dlcx.getResponseCode() == TransactionExecuted) { callDataInit (ep->call); ep->call = NULL; } return 1;} /* clearCall */intconnected (Endpoint* ep){ CallData* call = ep->call; assert (call); MgcModifyConnection mdcx ("testID", call->callIdentifier, call->endpoint[0].connectionId, "sendrecv"); mdcx.setRemoteConnectionDescriptor (call->endpoint[1].localConnection); ep->gw->send (mdcx); if (mdcx.getResponseCode() == TransactionExecuted) { sprintf (ep->requestIdentifier, "%X", newRequestIdentifier()); MgcNotificationRequest rqnt ("testID", ep->requestIdentifier); ep->gw->send (rqnt); if (rqnt.getResponseCode() == TransactionExecuted) { stateChange (ep, Connected); } } return 1;} /* connected */intanswer (Endpoint* ep){ CallData* call = ep->call; assert (call); MgcCreateConnection crcx ("testID", call->callIdentifier, "sendrecv"); crcx.setRemoteConnectionDescriptor (call->endpoint[1].localConnection); ep->gw->send (crcx); if (crcx.getResponseCode() == TransactionExecuted) { strcpy (call->endpoint[0].connectionId, (crcx.getConnectionId ()).data()); eps[call->endpoint[1].id].call->endpoint[1].localConnection = call->endpoint[0].localConnection = crcx.getLocalConnectionDescriptor (); notifyEndpoint (&eps[call->endpoint[1].id], Connect); sprintf (ep->requestIdentifier, "%X", newRequestIdentifier()); MgcNotificationRequest rqnt ("testID", ep->requestIdentifier); ep->gw->send (rqnt); if (rqnt.getResponseCode() == TransactionExecuted) { stateChange (ep, Connected); } } return 1;} /* answer */voidaddDTMFSignal (MgcNotificationRequest* rqnt, char digit){ switch (digit) {#ifndef NCS_PROFILE case '0': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_0 ()); } break; case '1': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_1 ()); } break; case '2': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_2 ()); } break; case '3': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_3 ()); } break; case '4': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_4 ()); } break; case '5': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_5 ()); } break; case '6': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_6 ()); } break; case '7': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_7 ()); } break; case '8': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_8 ()); } break; case '9': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_9 ()); } break; case '#': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_Hash ()); } break; case '*': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_Star ()); } break; case 'A': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_A ()); } break; case 'B': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_B ()); } break; case 'C': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_C ()); } break; case 'D': { rqnt->addSignalRequests (MgcDTMFPackage::signalDTMF_D ()); } break;#else // NCS_PROFILEcase '0': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_0 ()); } break; case '1': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_1 ()); } break; case '2': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_2 ()); } break; case '3': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_3 ()); } break; case '4': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_4 ()); } break; case '5': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_5 ()); } break; case '6': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_6 ()); } break; case '7': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_7 ()); } break; case '8': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_8 ()); } break; case '9': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_9 ()); } break; case '#': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_Hash ()); } break; case '*': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_Star ()); } break; case 'A': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_A ()); } break; case 'B': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_B ()); } break; case 'C': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_C ()); } break; case 'D': { rqnt->addSignalRequests (MgcNCSLinePackage::signalDTMF_D ()); } break;#endif default: { cerr << "Invalid digit " << digit << endl; } } /* switch */} /* addDTMFSignal */intdtmfDigit (Endpoint* ep){ CallData* call1 = ep->call; if (call1->playDtmfDigit != 0) { /* Warning: No locking on shared endpoint data */ /* Receiving DTMF digit */ /* Forward DTMF digit to the gateway */ sprintf (ep->requestIdentifier, "%X", newRequestIdentifier()); MgcNotificationRequest rqnt ("testID", ep->requestIdentifier); addDTMFSignal (&rqnt, call1->playDtmfDigit); ep->gw->send (rqnt); if (rqnt.getResponseCode() == TransactionExecuted) { call1->playDtmfDigit = 0; } } if (call1->dtmfDigits[0] != 0) { /* Warning: No locking on shared endpoint data */ /* Sending DTMF digit */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -