📄 resgwdevice.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 version = "$Id: ResGwDevice.cxx,v 1.26 2002/03/19 21:40:16 jason Exp $";#include "global.h"#include "ResGwDevice.hxx"#include "UaConfiguration.hxx"#ifndef NO_POLICY#include "PepAgent.hxx"#endifusing namespace Vocal;ResGwDevice::ResGwDevice( const char* deviceName, Sptr < Fifo < Sptr < SipProxyEvent > > > inputQ, Sptr < Fifo < Sptr < SipProxyEvent > > > outputQ ) : callId(0), audioActive( false ), audioHalfActive( false ), myEntryState( EntryStateTelephoneUI ){ digitCollector = new DigitCollector( outputQ ); callWaitingIdList = new CallWaitingIdList;#ifndef NO_POLICY if ( UaConfiguration::instance()->getUsePolicyServer() ) { try { string psHost = UaConfiguration::instance()->getProvisioningHost(); int psPort = UaConfiguration::instance()->getProvisioningPort(); PepAgent::instance( psHost.c_str(), psPort, psHost.c_str(), psPort); } catch (VNetworkException & e) { cpLog(LOG_DEBUG, "SUA PEPAgent error"); } }#endif}ResGwDevice::~ResGwDevice(){}voidResGwDevice::setCallId( const Sptr<SipCallId> newCallId ){ if( newCallId == 0 ) cpLog(LOG_DEBUG, "Clear Call Id"); callId = newCallId; if( callId == 0 ) cpLog(LOG_DEBUG, "Call Id is cleared");}Sptr<SipCallId>ResGwDevice::getCallId() const{ return callId;}voidResGwDevice::addCallWaitingId( const Sptr<SipCallId> newCallId ){ if( newCallId == 0 ) { cpLog( LOG_DEBUG, "No null id is added" ); return ; } callWaitingIdList->push_back( newCallId ); cpLog(LOG_DEBUG, "added callId %s", newCallId->encode().logData());}Sptr<SipCallId>ResGwDevice::getCallWaitingId() const{ if ( callWaitingIdList->empty() ) { cpLog( LOG_DEBUG, "call waiting list empty" ); return 0; } return callWaitingIdList->front();}voidResGwDevice::removeCallWaitingId( const SipCallId& callId ){ cpLog( LOG_DEBUG, "try to remove callId %s", callId.encode().logData() ); CallWaitingIdList::iterator iter = callWaitingIdList->begin(); while ( iter != callWaitingIdList->end() ) { if ( *(*iter) == callId ) { callWaitingIdList->erase(iter); cpLog( LOG_DEBUG, "callId %s removed", callId.encode().logData() ); break; } iter++; } return ;}Sptr < DigitCollector >ResGwDevice::getDigitCollector(){ return digitCollector;}HardwareStatusTypeResGwDevice::getHardwareStatus(){ HardwareStatusType hardwareStatus = HARDWARE_UNAVAILABLE; if ( audioActive == true ) cpLog( LOG_DEBUG, "audio active true" ); else cpLog( LOG_DEBUG, "audio active false" ); if ( audioHalfActive == true ) cpLog( LOG_DEBUG, "audio half active true" ); else cpLog( LOG_DEBUG, "audio half active false" ); if ( callWaitingIdList->empty() ) { cpLog( LOG_DEBUG, "call waiting list empty" ); if ( callId == 0 ) { hardwareStatus = HARDWARE_AVAILABLE; } else { if ( audioActive && !audioHalfActive ) hardwareStatus = HARDWARE_CALLWAITING_ALLOWED; else if ( !audioActive && audioHalfActive ) hardwareStatus = HARDWARE_UNAVAILABLE; } } else { if ( callId == 0 ) hardwareStatus = HARDWARE_CALLWAITING_ALLOWED; } return hardwareStatus;}boolResGwDevice::isMyHardware(const SipCallId &callid){ if ( callId == 0 ) return false; return ( *callId == callid );}boolResGwDevice::isOnCallWaiting(const SipCallId &callid){ bool ret = false; CallWaitingIdList::iterator iter = callWaitingIdList->begin(); while ( iter != callWaitingIdList->end() ) { if ( *(*iter) == *callId ) { ret = true; break; } iter++; } return ret;}voidResGwDevice::processSessionMsg( Sptr<SipProxyEvent> event ){ Sptr<UaHardwareEvent> msg; msg.dynamicCast( event ); if( msg != 0 ) { cpLog( LOG_DEBUG, "Got message type: %d", msg->type ); switch( msg->type ) { case HardwareSignalType: if( msg->signalOrRequest.signal == DeviceSignalFwding ) { if ( msg->dataList.size() != 3 ) { cpLog( LOG_ERR, "message size is wrong: %d", msg->dataList.size() ); } else { /** This was done for voicemail loadgen * testing. We can remove this in future * releases. (Just let it be for now.) */ string calleeNum = msg->dataList[2]; string callerNum = msg->dataList[1]; string reason = msg->dataList[0]; provideCallInfo(callerNum, calleeNum, reason); } } else { provideSignal((msg->signalOrRequest).signal); } break; case HardwareAudioType: switch ((msg->signalOrRequest).request.type) { case AudioStart: audioStart((msg->signalOrRequest).request); break; case AudioStop: audioStop(); break; case AudioSuspend: audioSuspend(); break; case AudioResume: audioResume((msg->signalOrRequest).request); break; default: cpLog( LOG_ERR, "Unknown audio request: %d", (msg->signalOrRequest).request.type ); } break; default: cpLog( LOG_ERR, "Unknown session message: %d", msg->type ); break; } }}intResGwDevice::provideSignal( DeviceSignalType signal ){ cpLog(LOG_DEBUG, "Checking signal %d", signal); switch( signal ) { case DeviceSignalDialToneStart: provideDialToneStart(); break; case DeviceSignalDialToneStop: provideDialToneStop(); break; case DeviceSignalRingStart: provideRingStart(); break; case DeviceSignalRingStop: provideRingStop(); break; case DeviceSignalLocalRingbackStart: provideLocalRingbackStart(); break; case DeviceSignalLocalRingbackStop: provideLocalRingbackStop(); break; case DeviceSignalBusyStart: provideBusyToneStart(); break; case DeviceSignalBusyStop: provideBusyToneStop(); break; case DeviceSignalFastBusyStart: provideFastBusyToneStart(); break; case DeviceSignalFastBusyStop: provideFastBusyToneStop(); break; case DeviceSignalStartCallWaitingBeep: provideCallWaitingBeepStart(); break; case DeviceSignalStopCallWaitingBeep: provideCallWaitingBeepStop(); break; case DeviceSignalDigit0: case DeviceSignalDigit1: case DeviceSignalDigit2: case DeviceSignalDigit3: case DeviceSignalDigit4: case DeviceSignalDigit5: case DeviceSignalDigit6: case DeviceSignalDigit7: case DeviceSignalDigit8: case DeviceSignalDigit9: case DeviceSignalDigitStar: case DeviceSignalDigitHash: provideDtmf( signal ); break; default: cpLog(LOG_ERR, "Requested signal %d not supported by hardware", signal); return -1; } return 0;}voidResGwDevice::reportEvent( Sptr < Fifo < Sptr<SipProxyEvent> > > outputQ, DeviceEventType eventType ){ cpLog( LOG_INFO, "Got device event: %d", eventType ); Sptr < UaDeviceEvent > event = new UaDeviceEvent( outputQ ); event->type = eventType; event->callId = callId; outputQ->add( event );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -