diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp index 0b420f450ec102f3eff933ab0d7e085abfc2f7c1..b22b7da30817f26642e776c4cdf9f2c6b8603b47 100644 --- a/src/audio/audiortp.cpp +++ b/src/audio/audiortp.cpp @@ -81,14 +81,19 @@ AudioRtp::createNewSession (SipCall *ca) { void AudioRtp::closeRtpSession (SipCall *ca) { // This will make RTP threads finish. - if (ca->enable_audio > 0) { - ca->enable_audio = -1; - - if (_RTXThread != NULL) { - _debug("Thread: stop AudioRTP for sipcall: %d\n", ca->getId()); - delete _RTXThread; _RTXThread = NULL; - } - } + if (ca) { + if (ca->enable_audio > 0) { + ca->enable_audio = -1; + + if (_RTXThread != NULL) { + _debug("Thread: stop AudioRTP for sipcall: %d\n", ca->getId()); + delete _RTXThread; _RTXThread = NULL; + } + } + } else { + _debug("Thread: stop AudioRTP for no sipcall\n"); + delete _RTXThread; _RTXThread = NULL; + } } //////////////////////////////////////////////////////////////////////////////// @@ -236,8 +241,8 @@ AudioRtpRTX::receiveSessionForSpkr (int16* data_for_speakers, adu = _session->getData(_session->getFirstTimestamp()); } if (adu == NULL) { - Manager::instance().getAudioDriver()->mainSndRingBuffer().flush(); - Manager::instance().getAudioDriver()->stopStream(); +// Manager::instance().getAudioDriver()->mainSndRingBuffer().flush(); +// Manager::instance().getAudioDriver()->stopStream(); return; } @@ -258,7 +263,6 @@ AudioRtpRTX::receiveSessionForSpkr (int16* data_for_speakers, } // If the current call is the call which is answered - //if (Manager::instance().isCurrentId(_ca->getId())) { // Set decoded data to sound device Manager::instance().getAudioDriver()->putMain(data_for_speakers_tmp, SAMPLES_SIZE(RTP_FRAMES2SEND)); //} diff --git a/src/call.cpp b/src/call.cpp index c278a67745eb28867eae00d7d8683e69d4c9786a..3804e160d325db2c497c8c13d0f714c192bc4dfc 100644 --- a/src/call.cpp +++ b/src/call.cpp @@ -23,8 +23,7 @@ #include "call.h" #include "voIPLink.h" - -Call::Call (short id, CallType type, VoIPLink* voiplink) +Call::Call (CALLID id, CallType type, VoIPLink* voiplink) { initConstructor(); _id = id; @@ -47,14 +46,14 @@ Call::~Call (void) { } -short +CALLID Call::getId (void) { return _id; } void -Call::setId (short id) +Call::setId (CALLID id) { _id = id; } @@ -176,16 +175,17 @@ Call::isRefused (void) return (_state == Refused) ? true : false; } + bool -Call::isCancelled (void) +Call::isAnswered (void) { - return (_state == Cancelled) ? true : false; + return (_state == Answered) ? true : false; } bool -Call::isAnswered (void) +Call::isNotAnswered (void) { - return (_state == Answered) ? true : false; + return (_state == Error || _state == NotExist ) ? true : false; } bool @@ -216,6 +216,7 @@ int Call::hangup (void) { int i = _voIPLink->hangup(_id); + setState(Hungup); return i; } @@ -223,6 +224,7 @@ int Call::cancel (void) { int i = _voIPLink->cancel(_id); + setState(Hungup); return i; } @@ -230,6 +232,7 @@ int Call::answer (void) { int i = _voIPLink->answer(_id); + setState(Answered); return i; } @@ -237,6 +240,7 @@ int Call::onHold (void) { int i = _voIPLink->onhold(_id); + setState(OnHold); return i; } @@ -244,6 +248,7 @@ int Call::offHold (void) { int i = _voIPLink->offhold(_id); + setState(OffHold); return i; } @@ -251,6 +256,7 @@ int Call::transfer (const std::string& to) { int i = _voIPLink->transfer(_id, to); + setState(Transfered); return i; } diff --git a/src/call.h b/src/call.h index 5b36db83fa1de690006724fd8b8ae3ff05587d03..b1c7aa41baf638d76812b9d77908591b43ce73b8 100644 --- a/src/call.h +++ b/src/call.h @@ -23,6 +23,7 @@ #include <string> +typedef unsigned int CALLID; enum CallType { Null = 0, @@ -47,20 +48,19 @@ public: Answered, Ringing, Progressing, - Cancelled, // for cancel outgoing ringing call Refused, // for refuse incoming ringing call Error // when a error occur }; // Constructor - Call(short id, CallType type, VoIPLink* voiplink); + Call(CALLID id, CallType type, VoIPLink* voiplink); // Destructor ~Call(void); // Handle call-id - short getId (void); - void setId (short id); + CALLID getId (void); + void setId (CALLID id); // Accessor and modifior of VoIPLink VoIPLink* getVoIPLink(void); @@ -80,7 +80,8 @@ public: enum CallType getType (void); void setType (enum CallType type); - bool isBusy (void); + bool isNotAnswered(void); + bool isBusy (void); bool isOnHold (void); bool isOffHold (void); bool isOnMute (void); @@ -89,7 +90,6 @@ public: bool isHungup (void); bool isRinging (void); bool isRefused (void); - bool isCancelled (void); bool isAnswered (void); bool isProgressing (void); bool isOutgoingType (void); @@ -108,7 +108,7 @@ private: void initConstructor (void); VoIPLink *_voIPLink; - short _id; + CALLID _id; enum CallState _state; enum CallType _type; std::string _callerIdName; diff --git a/src/global.h b/src/global.h index 3b78c7ae57a36ea63449a7f3e108fd0d12e5963b..9eb5a8482b55712b1d8b9583b7b2456ea8dc1514 100644 --- a/src/global.h +++ b/src/global.h @@ -27,11 +27,10 @@ typedef float float32; typedef short int16; - #define DEBUG #ifdef DEBUG - #define _debug(...) fprintf(stderr, "[debug] " __VA_ARGS__) + #define _debug(...) fprintf(stderr, "[sflphoned] " __VA_ARGS__) #else #define _debug(...) #endif @@ -39,7 +38,6 @@ typedef short int16; #define VERSION "0.5" #define VERSIONNUM 0x000500 - #define PROGNAME "sflphoned" #define PROGDIR "sflphone" #define RINGDIR "ringtones" diff --git a/src/gui/guiframework.cpp b/src/gui/guiframework.cpp index aaa86543fdbbc347f363ee9082b0520d898ddf88..00d013c679bb91c3e53b90ad032d710ea83cd1e1 100644 --- a/src/gui/guiframework.cpp +++ b/src/gui/guiframework.cpp @@ -36,7 +36,7 @@ GuiFramework::outgoingCall (const string& to) } int -GuiFramework::hangupCall (short id) +GuiFramework::hangupCall (CALLID id) { if (Manager::instance().hangupCall(id) == 0) { return 1; @@ -46,7 +46,7 @@ GuiFramework::hangupCall (short id) } int -GuiFramework::cancelCall (short id) +GuiFramework::cancelCall (CALLID id) { if (Manager::instance().cancelCall(id) == 0) { return 1; @@ -56,7 +56,7 @@ GuiFramework::cancelCall (short id) } int -GuiFramework::answerCall (short id) +GuiFramework::answerCall (CALLID id) { if (Manager::instance().answerCall(id) == 0) { return 1; @@ -66,7 +66,7 @@ GuiFramework::answerCall (short id) } int -GuiFramework::onHoldCall (short id) +GuiFramework::onHoldCall (CALLID id) { if (Manager::instance().onHoldCall(id) == 0) { return 1; @@ -76,7 +76,7 @@ GuiFramework::onHoldCall (short id) } int -GuiFramework::offHoldCall (short id) +GuiFramework::offHoldCall (CALLID id) { if (Manager::instance().offHoldCall(id) == 0) { return 1; @@ -86,7 +86,7 @@ GuiFramework::offHoldCall (short id) } int -GuiFramework::transferCall (short id, const string& to) +GuiFramework::transferCall (CALLID id, const string& to) { if (Manager::instance().transferCall(id, to) == 0) { return 1; @@ -107,7 +107,7 @@ GuiFramework::unmute() } int -GuiFramework::refuseCall (short id) +GuiFramework::refuseCall (CALLID id) { if (Manager::instance().refuseCall(id) == 0) { return 1; @@ -143,7 +143,7 @@ GuiFramework::unregisterVoIPLink (void) } bool -GuiFramework::sendDtmf (short id, char code) +GuiFramework::sendDtmf (CALLID id, char code) { return Manager::instance().sendDtmf(id, code); } @@ -193,7 +193,8 @@ GuiFramework::getCallStatus(const std::string& sequenceId) { return Manager::instance().getCallStatus(sequenceId); } -short + +CALLID GuiFramework::getCurrentId() { return Manager::instance().getCurrentCallId(); diff --git a/src/gui/guiframework.h b/src/gui/guiframework.h index d3b86cad284bd3cd01ff43dc3dee7f54415d57c9..ce3e7bc670f1bdfead747cd3546da5132d14aa1a 100644 --- a/src/gui/guiframework.h +++ b/src/gui/guiframework.h @@ -26,6 +26,7 @@ #include <string> #include "server/argtokenizer.h" #include "../observer.h" +#include "../call.h" class GuiFramework { public: @@ -33,14 +34,14 @@ public: virtual ~GuiFramework (void); /* Parent class to child class */ - virtual int incomingCall (short id, const std::string& accountId, const std::string& from) = 0; - virtual void peerAnsweredCall (short id) = 0; - virtual void peerRingingCall (short id) = 0; - virtual void peerHungupCall (short id) = 0; + virtual int incomingCall (CALLID id, const std::string& accountId, const std::string& from) = 0; + virtual void peerAnsweredCall (CALLID id) = 0; + virtual void peerRingingCall (CALLID id) = 0; + virtual void peerHungupCall (CALLID id) = 0; virtual void displayStatus (const std::string& status) = 0; virtual void displayConfigError (const std::string& error) = 0; - virtual void displayTextMessage (short id, const std::string& message) = 0; - virtual void displayErrorText (short id, const std::string& message) = 0; + virtual void displayTextMessage (CALLID id, const std::string& message) = 0; + virtual void displayErrorText (CALLID id, const std::string& message) = 0; virtual void displayError (const std::string& error) = 0; virtual void startVoiceMessageNotification (void) {} virtual void stopVoiceMessageNotification (void) {} @@ -49,27 +50,27 @@ public: virtual void sendMessage(const std::string& code, const std::string& seqId, TokenList& arg) = 0; virtual void sendCallMessage(const std::string& code, const std::string& sequenceId, - short id, + CALLID id, TokenList arg) = 0; - virtual void callFailure(short id) = 0; + virtual void callFailure(CALLID id) = 0; /* Child class to parent class */ int outgoingCall (const std::string& to); - int hangupCall (short id); - int cancelCall (short id); - int answerCall (short id); - int onHoldCall (short id); - int offHoldCall (short id); - int transferCall (short id, const std::string& to); + int hangupCall (CALLID id); + int cancelCall (CALLID id); + int answerCall (CALLID id); + int onHoldCall (CALLID id); + int offHoldCall (CALLID id); + int transferCall (CALLID id, const std::string& to); void mute (); void unmute (); - int refuseCall (short id); + int refuseCall (CALLID id); bool saveConfig (void); int registerVoIPLink (void); int unregisterVoIPLink (void); - bool sendDtmf (short id, char code); + bool sendDtmf (CALLID id, char code); bool playDtmf (char code); bool playTone (); bool stopTone (); @@ -89,8 +90,7 @@ public: int getMicVolume(); bool hasLoadedSetup(); - // Observer methods - short getCurrentId(); + CALLID getCurrentId(); protected: std::string _message; diff --git a/src/gui/server/guiserverimpl.cpp b/src/gui/server/guiserverimpl.cpp index cfd0367ca8b839cdaa908730c07796b9eec0ec97..171e9e5a2fbf65d3576f857fcca459dd102efdfd 100644 --- a/src/gui/server/guiserverimpl.cpp +++ b/src/gui/server/guiserverimpl.cpp @@ -47,12 +47,12 @@ GUIServerImpl::exec() { * remove */ void -GUIServerImpl::insertSubCall(short id, SubCall& subCall) { +GUIServerImpl::insertSubCall(CALLID id, SubCall& subCall) { _callMap[id] = subCall; } void -GUIServerImpl::removeSubCall(short id) { +GUIServerImpl::removeSubCall(CALLID id) { _callMap.erase(id); } @@ -60,7 +60,7 @@ GUIServerImpl::removeSubCall(short id) { * Retreive the sequenceId or send default sequenceId */ std::string -GUIServerImpl::getSequenceIdFromId(short id) { +GUIServerImpl::getSequenceIdFromId(CALLID id) { CallMap::iterator iter = _callMap.find(id); if (iter != _callMap.end()) { return iter->second.sequenceId(); @@ -71,7 +71,7 @@ GUIServerImpl::getSequenceIdFromId(short id) { * Retreive the string callid from the id */ std::string -GUIServerImpl::getCallIdFromId(short id) { +GUIServerImpl::getCallIdFromId(CALLID id) { CallMap::iterator iter = _callMap.find(id); if (iter != _callMap.end()) { return iter->second.callId(); @@ -83,7 +83,7 @@ bool GUIServerImpl::getCurrentCallId(std::string& callId) { bool returnValue = false; try { - short id = GuiFramework::getCurrentId(); + CALLID id = GuiFramework::getCurrentId(); if (id!=0) { callId = getCallIdFromId(id); returnValue = true; @@ -94,7 +94,7 @@ GUIServerImpl::getCurrentCallId(std::string& callId) { return returnValue; } -short +CALLID GUIServerImpl::getIdFromCallId(const std::string& callId) { CallMap::iterator iter = _callMap.begin(); @@ -150,7 +150,7 @@ GUIServerImpl::sendGetEventsEnd() bool GUIServerImpl::outgoingCall (const std::string& seq, const std::string& callid, const std::string& to) { - short serverCallId = GuiFramework::outgoingCall(to); + CALLID serverCallId = GuiFramework::outgoingCall(to); if ( serverCallId ) { SubCall subcall(seq, callid); insertSubCall(serverCallId, subcall); @@ -164,7 +164,7 @@ bool GUIServerImpl::answerCall(const std::string& callId) { try { - short id = getIdFromCallId(callId); + CALLID id = getIdFromCallId(callId); if (GuiFramework::answerCall(id)) { return true; } @@ -178,7 +178,7 @@ bool GUIServerImpl::refuseCall(const std::string& callId) { try { - short id = getIdFromCallId(callId); + CALLID id = getIdFromCallId(callId); if (GuiFramework::refuseCall(id)) { return true; } @@ -191,7 +191,7 @@ bool GUIServerImpl::transferCall(const std::string& callId, const std::string& to) { try { - short id = getIdFromCallId(callId); + CALLID id = getIdFromCallId(callId); if (GuiFramework::transferCall(id, to)) { return true; } @@ -205,7 +205,7 @@ bool GUIServerImpl::holdCall(const std::string& callId) { try { - short id = getIdFromCallId(callId); + CALLID id = getIdFromCallId(callId); if (GuiFramework::onHoldCall(id)) { return true; } @@ -219,7 +219,7 @@ bool GUIServerImpl::unholdCall(const std::string& callId) { try { - short id = getIdFromCallId(callId); + CALLID id = getIdFromCallId(callId); if (GuiFramework::offHoldCall(id)) { return true; } @@ -233,7 +233,7 @@ bool GUIServerImpl::hangupCall(const std::string& callId) { try { - short id = getIdFromCallId(callId); + CALLID id = getIdFromCallId(callId); if (GuiFramework::hangupCall(id)) { _callMap.erase(id); return true; @@ -252,7 +252,7 @@ bool GUIServerImpl::hangupAll() { bool result = true; - short id; + CALLID id; CallMap::iterator iter = _callMap.begin(); // try to hangup every call, even if one fail while(iter!=_callMap.end()) { @@ -270,7 +270,7 @@ bool GUIServerImpl::dtmfCall(const std::string& callId, const std::string& dtmfKey) { try { - short id = getIdFromCallId(callId); + CALLID id = getIdFromCallId(callId); char code = dtmfKey[0]; return GuiFramework::sendDtmf(id, code); } catch(...) { @@ -293,7 +293,7 @@ GUIServerImpl::version() int -GUIServerImpl::incomingCall (short id, const std::string& accountId, const std::string& from) +GUIServerImpl::incomingCall (CALLID id, const std::string& accountId, const std::string& from) { TokenList arg; std::ostringstream callId; @@ -313,7 +313,7 @@ GUIServerImpl::incomingCall (short id, const std::string& accountId, const std:: } void -GUIServerImpl::peerAnsweredCall (short id) +GUIServerImpl::peerAnsweredCall (CALLID id) { CallMap::iterator iter = _callMap.find(id); if ( iter != _callMap.end() ) { @@ -322,7 +322,7 @@ GUIServerImpl::peerAnsweredCall (short id) } void -GUIServerImpl::peerRingingCall (short id) +GUIServerImpl::peerRingingCall (CALLID id) { CallMap::iterator iter = _callMap.find(id); if ( iter != _callMap.end() ) { @@ -331,7 +331,7 @@ GUIServerImpl::peerRingingCall (short id) } void -GUIServerImpl::peerHungupCall (short id) +GUIServerImpl::peerHungupCall (CALLID id) { CallMap::iterator iter = _callMap.find(id); if ( iter != _callMap.end() ) { @@ -365,7 +365,7 @@ GUIServerImpl::displayConfigError (const std::string& error) } void -GUIServerImpl::displayTextMessage (short id, const std::string& message) +GUIServerImpl::displayTextMessage (CALLID id, const std::string& message) { try { std::string callId = getCallIdFromId(id); @@ -383,7 +383,7 @@ GUIServerImpl::displayTextMessage (short id, const std::string& message) } void -GUIServerImpl::displayErrorText (short id, const std::string& message) +GUIServerImpl::displayErrorText (CALLID id, const std::string& message) { try { std::string callId = getCallIdFromId(id); @@ -426,7 +426,7 @@ GUIServerImpl::sendMessage(const std::string& code, const std::string& seqId, To void GUIServerImpl::sendCallMessage(const std::string& code, const std::string& sequenceId, - short id, + CALLID id, TokenList arg) { try { @@ -445,7 +445,7 @@ GUIServerImpl::update() } void -GUIServerImpl::callFailure(short id) +GUIServerImpl::callFailure(CALLID id) { CallMap::iterator iter = _callMap.find(id); if ( iter != _callMap.end() ) { diff --git a/src/gui/server/guiserverimpl.h b/src/gui/server/guiserverimpl.h index 648fb66e3a73589748e0cc19fd495ad0f14675e9..b5822bdfbd089417cf9e08887a670c99c97574a6 100644 --- a/src/gui/server/guiserverimpl.h +++ b/src/gui/server/guiserverimpl.h @@ -26,7 +26,7 @@ #include "subcall.h" #include "requestmanager.h" -typedef std::map<short, SubCall> CallMap; +typedef std::map<CALLID, SubCall> CallMap; class GUIServerImpl : public GuiFramework { public: @@ -40,16 +40,16 @@ public: // Reimplementation of virtual functions // TODO: remove incomingCall with one parameter - int incomingCall (short id); - int incomingCall(short id, const std::string& accountId, const std::string& from); + int incomingCall (CALLID id); + int incomingCall(CALLID id, const std::string& accountId, const std::string& from); - void peerAnsweredCall (short id); - void peerRingingCall (short id); - void peerHungupCall (short id); + void peerAnsweredCall (CALLID id); + void peerRingingCall (CALLID id); + void peerHungupCall (CALLID id); void displayStatus (const std::string& status); void displayConfigError(const std::string& error); - void displayTextMessage (short id, const std::string& message); - void displayErrorText (short id, const std::string& message); + void displayTextMessage (CALLID id, const std::string& message); + void displayErrorText (CALLID id, const std::string& message); void displayError (const std::string& error); //void startVoiceMessageNotification (void); //void stopVoiceMessageNotification (void); @@ -60,9 +60,9 @@ public: arg); void sendCallMessage(const std::string& code, const std::string& sequenceId, - short id, + CALLID id, TokenList arg); - void callFailure(short id); + void callFailure(CALLID id); bool getEvents(const std::string& sequenceId); bool sendGetEventsEnd(); @@ -88,11 +88,11 @@ arg); void update(); private: - void insertSubCall(short id, SubCall& subCall); - void removeSubCall(short id); - std::string getSequenceIdFromId(short id); - std::string getCallIdFromId(short id); - short getIdFromCallId(const std::string& callId); + void insertSubCall(CALLID id, SubCall& subCall); + void removeSubCall(CALLID id); + std::string getSequenceIdFromId(CALLID id); + std::string getCallIdFromId(CALLID id); + CALLID getIdFromCallId(const std::string& callId); /** * This callMap is necessary because diff --git a/src/gui/server/tcpsessionio.cpp b/src/gui/server/tcpsessionio.cpp index 19cfd1b0ec0890c7b9c93dcba7a13fbd3d6950cd..c2de67c0995cc3263849b18b279b4955b1df4f25 100644 --- a/src/gui/server/tcpsessionio.cpp +++ b/src/gui/server/tcpsessionio.cpp @@ -17,7 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "tcpsessionio.h" -#include "../../global.h" const int TCPSessionIO::PORT = 3999; const char * const TCPSessionIO::IP = "127.0.0.1"; @@ -56,7 +55,6 @@ TCPSessionIO::send(const std::string& response) { if (_clientStream) { // just in case _clientStream->send(response); - _debug("SessionIO: Sending: %s\n", response.c_str()); } } @@ -66,7 +64,6 @@ TCPSessionIO::receive(std::string& request) bool returnValue = false; if (_clientStream) { // just in case returnValue = _clientStream->receive(request); - if (returnValue) _debug("SessionIO: Receiving: %s\n", request.c_str()); } return returnValue; } diff --git a/src/gui/server/tcpstreampool.cpp b/src/gui/server/tcpstreampool.cpp index 5932471498ffe3e7d3be1e710f3eb514364e2e9d..10a0bbd85ff86849f73bdb129de9f2c6dfaf7e3a 100644 --- a/src/gui/server/tcpstreampool.cpp +++ b/src/gui/server/tcpstreampool.cpp @@ -29,12 +29,13 @@ TCPStreamPool::run() { while(!testCancel() && good()) { if (isPending(ost::TCPSocket::pendingInput, 2LU)) { std::getline(*this, input); + _debug("TCPStreamPool getline %s\n", input.c_str()); if (input != null && input[0]!=cr13) { - _debug("%d", input[0]); _inputPool.push(input); } } if (_outputPool.pop(output, 2LU)) { + _debug("TCPStreamPool send %s\n", output.c_str()); *this << output << std::endl; } } @@ -49,10 +50,7 @@ TCPStreamPool::send(const std::string& response) bool TCPStreamPool::receive(std::string& request) { - if ( _inputPool.pop(request, 2LU) ) { - return true; - } - return false; + return _inputPool.pop(request, 2LU); } diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 51267d4314d199f4766dd9c81d3c7d1e7ff9ffcf..6aa65dddf20ba71da6fe553f44242229ebdf1e42 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -147,7 +147,7 @@ ManagerImpl::init (void) initAudioCodec(); // Set a sip voip link by default - _voIPLinkVector.push_back(new SipVoIPLink(DFT_VOIP_LINK)); + _voIPLinkVector.push_back(new SipVoIPLink()); _voIPLinkVector.at(DFT_VOIP_LINK)->init(); if (_voIPLinkVector.at(DFT_VOIP_LINK)->checkNetwork()) { @@ -170,12 +170,14 @@ void ManagerImpl::terminate() } _voIPLinkVector.clear(); + _mutex.enterMutex(); for(CallVector::iterator pos = _callVector.begin(); pos != _callVector.end(); pos++) { delete *pos; *pos = NULL; } _callVector.clear(); + _mutex.leaveMutex(); unloadAudioCodec(); @@ -192,7 +194,7 @@ ManagerImpl::setGui (GuiFramework* gui) * Multi Thread with _mutex for callVector */ Call * -ManagerImpl::pushBackNewCall (short id, enum CallType type) +ManagerImpl::pushBackNewCall (CALLID id, enum CallType type) { Call* call = new Call(id, type, _voIPLinkVector.at(DFT_VOIP_LINK)); // Set the wanted voip-link (first of the list) @@ -205,16 +207,16 @@ ManagerImpl::pushBackNewCall (short id, enum CallType type) * Multi Thread with _mutex for callVector */ Call* -ManagerImpl::getCall (short id) +ManagerImpl::getCall (CALLID id) { Call* call = NULL; unsigned int size = _callVector.size(); - if (id > 0) { - for (unsigned int i = 0; i < size; i++) { - if (_callVector.at(i)->getId() == id) { - call = _callVector.at(i); - break; - } + for (unsigned int i = 0; i < size; i++) { + call = _callVector.at(i); + if (call && call->getId() == id) { + break; + } else { + call = NULL; } } return call; @@ -224,13 +226,13 @@ ManagerImpl::getCall (short id) * Multi Thread with _mutex for callVector */ void -ManagerImpl::deleteCall (short id) +ManagerImpl::deleteCall (CALLID id) { CallVector::iterator iter = _callVector.begin(); while(iter!=_callVector.end()) { Call *call = *iter; - if (call->getId() == id) { - if (call->isIncomingType() && call->getState()!=Call::Ringing) { + if (call != NULL && call->getId() == id) { + if (call->isIncomingType() && call->isNotAnswered()) { decWaitingCall(); } delete (*iter); *iter = NULL; @@ -251,7 +253,7 @@ ManagerImpl::deleteCall (short id) int ManagerImpl::outgoingCall (const std::string& to) { - short id = generateNewCallId(); + CALLID id = generateNewCallId(); Call *call = pushBackNewCall(id, Outgoing); _debug("Outgoing Call with identifiant %d\n", id); @@ -269,14 +271,13 @@ ManagerImpl::outgoingCall (const std::string& to) * Every Call */ int -ManagerImpl::hangupCall (short id) +ManagerImpl::hangupCall (CALLID id) { ost::MutexLock m(_mutex); Call* call = getCall(id); - if (call == NULL) { + if (call == NULL && call->getState() != Call::Error) { return -1; } - call->setState(Call::Hungup); int result = call->hangup(); deleteCall(id); @@ -291,14 +292,13 @@ ManagerImpl::hangupCall (short id) * 0 : already in this state... */ int -ManagerImpl::cancelCall (short id) +ManagerImpl::cancelCall (CALLID id) { ost::MutexLock m(_mutex); Call* call = getCall(id); if (call == NULL) { return -1; } - call->setState(Call::Hungup); int result = call->cancel(); deleteCall(id); @@ -311,14 +311,13 @@ ManagerImpl::cancelCall (short id) * Incoming Call */ int -ManagerImpl::answerCall (short id) +ManagerImpl::answerCall (CALLID id) { ost::MutexLock m(_mutex); Call* call = getCall(id); if (call == NULL) { return -1; } - call->setState(Call::Answered); if (call->isIncomingType()) { decWaitingCall(); } @@ -333,7 +332,7 @@ ManagerImpl::answerCall (short id) * @return 0 if it fails, -1 if not present */ int -ManagerImpl::onHoldCall (short id) +ManagerImpl::onHoldCall (CALLID id) { ost::MutexLock m(_mutex); Call* call = getCall(id); @@ -343,7 +342,6 @@ ManagerImpl::onHoldCall (short id) if ( call->getState() == Call::OnHold) { return 1; } - call->setState(Call::OnHold); return call->onHold(); } @@ -352,7 +350,7 @@ ManagerImpl::onHoldCall (short id) * Every Call */ int -ManagerImpl::offHoldCall (short id) +ManagerImpl::offHoldCall (CALLID id) { ost::MutexLock m(_mutex); Call* call = getCall(id); @@ -362,7 +360,6 @@ ManagerImpl::offHoldCall (short id) if (call->getState() == Call::OffHold) { return 1; } - call->setState(Call::OffHold); setCurrentCallId(id); int returnValue = call->offHold(); if (returnValue) { @@ -376,14 +373,13 @@ ManagerImpl::offHoldCall (short id) * Every Call */ int -ManagerImpl::transferCall (short id, const std::string& to) +ManagerImpl::transferCall (CALLID id, const std::string& to) { ost::MutexLock m(_mutex); Call* call = getCall(id); if (call == NULL) { return -1; } - call->setState(Call::Transfered); setCurrentCallId(0); return call->transfer(to); } @@ -412,7 +408,7 @@ ManagerImpl::unmute() { * Call Incoming */ int -ManagerImpl::refuseCall (short id) +ManagerImpl::refuseCall (CALLID id) { ost::MutexLock m(_mutex); Call *call = getCall(id); @@ -423,7 +419,6 @@ ManagerImpl::refuseCall (short id) if ( call->getState() != Call::Progressing ) { return -1; } - call->setState(Call::Refused); int refuse = call->refuse(); setCurrentCallId(0); @@ -482,7 +477,7 @@ ManagerImpl::unregisterVoIPLink (void) * User action (main thread) */ bool -ManagerImpl::sendDtmf (short id, char code) +ManagerImpl::sendDtmf (CALLID id, char code) { int sendType = getConfigInt(SIGNALISATION, SEND_DTMF_AS); int returnValue = false; @@ -582,27 +577,28 @@ ManagerImpl::decWaitingCall() { _debug("decWaitingCall: %d\n", _nbIncomingWaitingCall); } + /** * SipEvent Thread - * ask if it can hangup the call + * Set the call info for incoming call */ -bool -ManagerImpl::callCanHangup(short id) { - bool returnValue = false; +void +ManagerImpl::callSetInfo(CALLID id, const std::string& name, const std::string& number) +{ ost::MutexLock m(_mutex); Call* call = getCall(id); - if (call != NULL && call->getState() != Call::Error) { - returnValue = true; + if (call != NULL) { + call->setCallerIdName(name); + call->setCallerIdNumber(number); } - return returnValue; } /** * SipEvent Thread - * ask if it can hangup the call + * ask if it can close the call */ bool -ManagerImpl::callCanClose(short id) { +ManagerImpl::callCanBeClosed(CALLID id) { bool returnValue = false; ost::MutexLock m(_mutex); Call* call = getCall(id); @@ -617,7 +613,7 @@ ManagerImpl::callCanClose(short id) { * ask if it can answer the call */ bool -ManagerImpl::callCanAnswer(short id) { +ManagerImpl::callCanBeAnswered(CALLID id) { bool returnValue = false; ost::MutexLock m(_mutex); Call* call = getCall(id); @@ -633,7 +629,7 @@ ManagerImpl::callCanAnswer(short id) { * SipEvent Thread */ int -ManagerImpl::incomingCall (short id) +ManagerImpl::incomingCall (CALLID id) { ost::MutexLock m(_mutex); Call* call = getCall(id); @@ -643,6 +639,8 @@ ManagerImpl::incomingCall (short id) call->setType(Incoming); call->setState(Call::Progressing); + switchCall(id); + incWaitingCall(); ringtone(); @@ -663,7 +661,7 @@ ManagerImpl::incomingCall (short id) * for outgoing call, send by SipEvent */ void -ManagerImpl::peerAnsweredCall (short id) +ManagerImpl::peerAnsweredCall (CALLID id) { ost::MutexLock m(_mutex); Call* call = getCall(id); @@ -680,7 +678,7 @@ ManagerImpl::peerAnsweredCall (short id) * for outgoing call, send by SipEvent */ int -ManagerImpl::peerRingingCall (short id) +ManagerImpl::peerRingingCall (CALLID id) { ost::MutexLock m(_mutex); Call* call = getCall(id); @@ -697,7 +695,7 @@ ManagerImpl::peerRingingCall (short id) * for outgoing call, send by SipEvent */ int -ManagerImpl::peerHungupCall (short id) +ManagerImpl::peerHungupCall (CALLID id) { ost::MutexLock m(_mutex); Call* call = getCall(id); @@ -719,7 +717,7 @@ ManagerImpl::peerHungupCall (short id) * for outgoing call, send by SipEvent */ void -ManagerImpl::displayTextMessage (short id, const std::string& message) +ManagerImpl::displayTextMessage (CALLID id, const std::string& message) { if(_gui) { _gui->displayTextMessage(id, message); @@ -731,7 +729,7 @@ ManagerImpl::displayTextMessage (short id, const std::string& message) * for outgoing call, send by SipEvent */ void -ManagerImpl::displayErrorText (short id, const std::string& message) +ManagerImpl::displayErrorText (CALLID id, const std::string& message) { if(_gui) { _gui->displayErrorText(id, message); @@ -852,7 +850,7 @@ ManagerImpl::ringback () { * Multi Thread */ void -ManagerImpl::callBusy(short id) { +ManagerImpl::callBusy(CALLID id) { playATone(ZT_TONE_BUSY); Call* call = getCall(id); if (call != NULL) { @@ -864,7 +862,7 @@ ManagerImpl::callBusy(short id) { * Multi Thread */ void -ManagerImpl::callFailure(short id) { +ManagerImpl::callFailure(CALLID id) { playATone(ZT_TONE_BUSY); Call* call = getCall(id); if (call != NULL) { @@ -968,13 +966,13 @@ ManagerImpl::useStun (void) /** * Multi Thread */ -short +CALLID ManagerImpl::generateNewCallId (void) { - short random_id = rand(); + CALLID random_id = (unsigned)rand(); // Check if already a call with this id exists - while (getCall(random_id) != NULL or random_id == 0) { + while (getCall(random_id) != NULL && random_id != 0) { random_id = rand(); } // If random_id is not attributed, returns it. @@ -1204,6 +1202,7 @@ ManagerImpl::detachZeroconfEvents(Pattern::Observer& observer) bool ManagerImpl::getCallStatus(const std::string& sequenceId) { + ost::MutexLock m(_mutex); // TODO: implement account std::string accountId = "acc1"; std::string code; @@ -1459,9 +1458,9 @@ ManagerImpl::getDirListing(const std::string& sequenceId, const std::string& pat * Multi Thread */ void -ManagerImpl::switchCall(short id) +ManagerImpl::switchCall(CALLID id) { - short currentCallId = getCurrentCallId(); + CALLID currentCallId = getCurrentCallId(); if (currentCallId!=0 && id!=currentCallId) { onHoldCall(currentCallId); } diff --git a/src/managerimpl.h b/src/managerimpl.h index 07a172e4d68b1a62c6de51f4c71bf08d1cb08123..3a631a9b24e7cf824e9869af74085817dddba93d 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -103,12 +103,12 @@ public: AudioLayer* getAudioDriver(void) const { return _audiodriverPA ;} // Accessor to current call id - short getCurrentCallId (void) { + CALLID getCurrentCallId (void) { ost::MutexLock m(_mutex); return _currentCallId; } // Modifior of current call id - void setCurrentCallId (short currentCallId) { - ost::MutexLock m(_mutex);_currentCallId = currentCallId; + void setCurrentCallId (CALLID id) { + ost::MutexLock m(_mutex); _currentCallId = id; } // Accessor to VoIPLinkVector @@ -120,31 +120,30 @@ public: * Attribute a new random id for a new call * and check if it's already attributed to existing calls. * If not exists, returns 'id' otherwise return 0 - */ - short generateNewCallId (void); + */ + CALLID generateNewCallId (void); /* * Add a new call at the end of the CallVector with identifiant 'id' */ - Call* pushBackNewCall (short id, enum CallType type); - - bool callCanHangup(short id); - bool callCanAnswer(short id); - bool callCanClose(short id); + Call* pushBackNewCall (CALLID id, enum CallType type); + void callSetInfo(CALLID id, const std::string& name, const std::string& number); + bool callCanBeAnswered(CALLID id); + bool callCanBeClosed(CALLID id); /* * Functions which occur with a user's action */ int outgoingCall (const std::string& to); - int hangupCall (short id); - int cancelCall (short id); - int answerCall (short id); - int onHoldCall (short id); - int offHoldCall (short id); - int transferCall (short id, const std::string& to); + int hangupCall (CALLID id); + int cancelCall (CALLID id); + int answerCall (CALLID id); + int onHoldCall (CALLID id); + int offHoldCall (CALLID id); + int transferCall (CALLID id, const std::string& to); void mute(); void unmute(); - int refuseCall (short id); + int refuseCall (CALLID id); bool saveConfig (void); int registerVoIPLink (void); @@ -156,23 +155,21 @@ public: * @param id: callid of the line. * @param code: pressed key. */ - bool sendDtmf (short id, char code); + bool sendDtmf (CALLID id, char code); bool playDtmf (char code); bool playTone (); void stopTone(); - int incomingCall (short id); - void peerAnsweredCall (short id); - int peerRingingCall (short id); - int peerHungupCall (short id); - void displayTextMessage (short id, const std::string& message); - void displayErrorText (short id, const std::string& message); + int incomingCall (CALLID id); + void peerAnsweredCall (CALLID id); + int peerRingingCall (CALLID id); + int peerHungupCall (CALLID id); + void displayTextMessage (CALLID id, const std::string& message); + void displayErrorText (CALLID id, const std::string& message); void displayError (const std::string& error); void displayStatus (const std::string& status); void displayConfigError(const std::string& message); -// int selectedCall (void); -// bool isCurrentId (short id); void startVoiceMessageNotification (const std::string& nb_msg); void stopVoiceMessageNotification (void); @@ -205,8 +202,8 @@ name); */ void ringtone (); void congestion (); - void callBusy(short callId); - void callFailure(short callId); + void callBusy(CALLID id); + void callFailure(CALLID id); /** * @return true is there is one or many incoming call waiting @@ -312,8 +309,8 @@ private: /* * Erase the Call(id) from the CallVector */ - void deleteCall (short id); - Call* getCall (short id); + void deleteCall (CALLID id); + Call* getCall (CALLID id); /* * Play one tone @@ -365,7 +362,7 @@ private: void decWaitingCall(void); // Current callid - short _currentCallId; + CALLID _currentCallId; /* * For the call timer @@ -396,7 +393,7 @@ private: // tell if we have zeroconf is enabled int _hasZeroconf; - void switchCall(short id); + void switchCall(CALLID id); #ifdef USE_ZEROCONF // DNSService contain every zeroconf services diff --git a/src/sipcall.cpp b/src/sipcall.cpp index f3e73d03f4405f5375774a1e6d8134dcc9f2148c..6917fbef1e9d5feacaeaf5142a4ad5ac18b68980 100644 --- a/src/sipcall.cpp +++ b/src/sipcall.cpp @@ -35,7 +35,7 @@ using namespace std; -SipCall::SipCall (short id, CodecDescriptorVector* cdv) : _localIp("127.0.0.1") +SipCall::SipCall (CALLID id, CodecDescriptorVector* cdv) : _localIp("127.0.0.1") { _id = id; // Same id of Call object _cid = 0; // call id, from the sipvoiplink @@ -77,12 +77,12 @@ SipCall::getLocalAudioPort (void) } void -SipCall::setId (short id) +SipCall::setId (CALLID id) { _id = id; } -short +CALLID SipCall::getId (void) { return _id; diff --git a/src/sipcall.h b/src/sipcall.h index deeecb3d58e5d1d48ba334a0720860a67c27c0ab..0b3cf478cdaffed39a46c8dd1e5f606a67a6f6a0 100644 --- a/src/sipcall.h +++ b/src/sipcall.h @@ -26,6 +26,7 @@ #include <eXosip2/eXosip.h> #include <vector> #include <string> +#include "call.h" class CodecDescriptor; class AudioCodec; @@ -39,21 +40,21 @@ typedef std::vector<CodecDescriptor*, allocator<CodecDescriptor*> > CodecDescrip class SipCall { public: - SipCall (short id, CodecDescriptorVector* cdv); + SipCall (CALLID id, CodecDescriptorVector* cdv); ~SipCall (void); - int payload; - int enable_audio; /* 1 started, -1 stopped */ + int payload; + int enable_audio; /* 1 started, -1 stopped */ /* * Store information about incoming call and negociate payload */ - int newIncomingCall (eXosip_event_t *); + int newIncomingCall (eXosip_event_t *); /* * Use to answer to a ONHOLD/OFFHOLD event */ - int answeredCall (eXosip_event_t *); + int answeredCall (eXosip_event_t *); /* * Use to answer to an incoming call @@ -76,8 +77,8 @@ public: * Manage id, did (dialog-id), cid (call-id) and tid (transaction-id) * for each sipcall */ - void setId (short id); - short getId (void); + void setId (CALLID id); + CALLID getId (void); void setDid (int did); int getDid (void); void setCid (int cid); @@ -123,7 +124,7 @@ private: CodecDescriptorVector* _cdv; AudioCodec* _audiocodec; - short _id; + CALLID _id; int _cid; // call id int _did; // dialog id int _tid; // transaction id diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index 891d5af82ff196d7e49f2b67849655e0c20c0e19..3936a1a7d089f3a4349b61f645e3c96159d63928 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -31,9 +31,6 @@ #include "user_cfg.h" #include "eventthread.h" -using namespace ost; -using namespace std; - #define DEFAULT_SIP_PORT 5060 #define RANDOM_SIP_PORT rand() % 64000 + 1024 #define DEFAULT_LOCAL_PORT 10500 @@ -42,8 +39,7 @@ using namespace std; #define VOICE_MSG "Voice-Message" #define LENGTH_VOICE_MSG 15 -SipVoIPLink::SipVoIPLink (short id) - : VoIPLink (id) +SipVoIPLink::SipVoIPLink() { // default _audioRTP object initialization _evThread = new EventThread(this); @@ -280,7 +276,7 @@ SipVoIPLink::setUnregister (void) } int -SipVoIPLink::outgoingInvite (short id, const std::string& to_url) +SipVoIPLink::outgoingInvite (CALLID id, const std::string& to_url) { std::string from; std::string to; @@ -334,7 +330,7 @@ SipVoIPLink::outgoingInvite (short id, const std::string& to_url) * @return 0 is good, -1 is bad */ int -SipVoIPLink::answer (short id) +SipVoIPLink::answer (CALLID id) { int i; int port; @@ -384,46 +380,41 @@ SipVoIPLink::answer (short id) } int -SipVoIPLink::hangup (short id) +SipVoIPLink::hangup (CALLID id) { int i = 0; - if (Manager::instance().callCanHangup(id)) { - SipCall *sipcall = getSipCall(id); - _debug("Hang up call [id = %d, cid = %d, did = %d]\n", - id, sipcall->getCid(), sipcall->getDid()); - // Release SIP stack. - eXosip_lock(); - i = eXosip_call_terminate (sipcall->getCid(), sipcall->getDid()); - eXosip_unlock(); + SipCall* sipcall = getSipCall(id); + _debug("Hang up call [id = %d, cid = %d, did = %d]\n", + id, sipcall->getCid(), sipcall->getDid()); + // Release SIP stack. + eXosip_lock(); + i = eXosip_call_terminate (sipcall->getCid(), sipcall->getDid()); + eXosip_unlock(); - // Release RTP channels - _audiortp.closeRtpSession(sipcall); - } else { - _debug("The call was in error state, so delete it"); - } + // Release RTP channels + _audiortp.closeRtpSession(sipcall); deleteSipCall(id); return i; } int -SipVoIPLink::cancel (short id) +SipVoIPLink::cancel (CALLID id) { int i = 0; - if (Manager::instance().callCanHangup(id)) { - SipCall *sipcall = getSipCall(id); - _debug("Cancel call [id = %d, cid = %d]\n", id, sipcall->getCid()); - // Release SIP stack. - eXosip_lock(); - i = eXosip_call_terminate (sipcall->getCid(), -1); - eXosip_unlock(); - } + SipCall* sipcall = getSipCall(id); + _debug("Cancel call [id = %d, cid = %d]\n", id, sipcall->getCid()); + // Release SIP stack. + eXosip_lock(); + i = eXosip_call_terminate (sipcall->getCid(), -1); + eXosip_unlock(); + deleteSipCall(id); return i; } int -SipVoIPLink::onhold (short id) +SipVoIPLink::onhold (CALLID id) { osip_message_t *invite; int i; @@ -488,7 +479,7 @@ SipVoIPLink::onhold (short id) * @return 0 is good, -1 is bad */ int -SipVoIPLink::offhold (short id) +SipVoIPLink::offhold (CALLID id) { osip_message_t *invite; int i; @@ -551,7 +542,7 @@ SipVoIPLink::offhold (short id) } int -SipVoIPLink::transfer (short id, const std::string& to) +SipVoIPLink::transfer (CALLID id, const std::string& to) { osip_message_t *refer; int i; @@ -575,7 +566,7 @@ HOST_PART); } int -SipVoIPLink::refuse (short id) +SipVoIPLink::refuse (CALLID id) { int i; char tmpbuf[64]; @@ -597,13 +588,7 @@ SipVoIPLink::refuse (short id) int SipVoIPLink::getEvent (void) { - eXosip_event_t *event; - short id; - char *name; - Call *call = NULL; - SipCall *sipcall = NULL; - - event = eXosip_event_wait (0, 50); + eXosip_event_t* event = eXosip_event_wait (0, 50); eXosip_lock(); eXosip_automatic_action(); eXosip_unlock(); @@ -612,8 +597,11 @@ SipVoIPLink::getEvent (void) return -1; } + SipCall* sipcall = NULL; + CALLID id = 0; int returnValue = 0; - _debug("GetEvent : %d ", event->type); + + //_debug("GetEvent : %d ", event->type); switch (event->type) { // IP-Phone user receives a new call case EXOSIP_CALL_INVITE: // @@ -634,8 +622,8 @@ SipVoIPLink::getEvent (void) // Generate id id = Manager::instance().generateNewCallId(); - call = Manager::instance().pushBackNewCall(id, Incoming); - _debug("Incoming Call with id %d [cid = %d, did = %d]\n", + Manager::instance().pushBackNewCall(id, Incoming); + _debug("Incoming call with id %d [cid = %d, did = %d]\n", id, event->cid, event->did); _debug("Local audio port: %d\n", _localPort); @@ -654,23 +642,19 @@ SipVoIPLink::getEvent (void) } } osip_from_parse(from, sipcall->getRemoteUri()); - name = osip_from_get_displayname(from); - - //Don't need this display text message now that we send the name - //inside the Manager to the gui - //Manager::instance().displayTextMessage(id, name); - if ( call != NULL) { - call->setCallerIdName(name); - osip_uri_t* url = osip_from_get_url(from); + { + std::string name = osip_from_get_displayname(from); + std::string urlUsername(""); + osip_uri_t* url = osip_from_get_url(from); if ( url != NULL ) { - call->setCallerIdNumber(url->username); + urlUsername = url->username; } - } else { - osip_from_free(from); - returnValue = -1; - break; + Manager::instance().callSetInfo(id, name, urlUsername); + _debug("From: %s\n", name.c_str()); } - _debug("From: %s\n", name); + //Don't need this display text message now that we send the name + //inside the Manager to the gui + //Manager::instance().displayTextMessage(id, name); osip_from_free(from); // Associate an audio port with a call @@ -694,54 +678,46 @@ SipVoIPLink::getEvent (void) // The peer-user answers case EXOSIP_CALL_ANSWERED: // 10 { - id = findCallId(event); - if (id == 0) { - id = findCallIdInitial(event); - } - sipcall = getSipCall(id); - if ( sipcall ) { - _debug("Call is answered [id = %d, cid = %d, did = %d], localport=%d\n", - id, event->cid, event->did,sipcall->getLocalAudioPort()); - } - - // Answer - if (id > 0 && Manager::instance().callCanAnswer(id)) { - sipcall->setStandBy(false); - if (sipcall->answeredCall(event) != -1) { - sipcall->answeredCall_without_hold(event); - Manager::instance().peerAnsweredCall(id); - - // Outgoing call is answered, start the sound channel. - if (_audiortp.createNewSession (sipcall) < 0) { - _debug("FATAL: Unable to start sound (%s:%d)\n", - __FILE__, __LINE__); - returnValue = -1; - break; - } + id = findCallIdInitial(event); + if ( id != 0) { + sipcall = getSipCall(id); + if ( sipcall ) { + _debug("Call is answered [id = %d, cid = %d, did = %d], localport=%d\n", + id, event->cid, event->did,sipcall->getLocalAudioPort()); } - } else { - // Answer to on/off hold to send ACK - if (id > 0) { + + // Answer + if (Manager::instance().callCanBeAnswered(id)) { + sipcall->setStandBy(false); + if (sipcall->answeredCall(event) != -1) { + sipcall->answeredCall_without_hold(event); + Manager::instance().peerAnsweredCall(id); + + // Outgoing call is answered, start the sound channel. + if (_audiortp.createNewSession (sipcall) < 0) { + _debug("FATAL: Unable to start sound (%s:%d)\n", + __FILE__, __LINE__); + returnValue = -1; + break; + } + } + } else { + // Answer to on/off hold to send ACK sipcall->answeredCall(event); - _debug("-----------------------\n"); } + break; + } else { + returnValue = -1; } - break; - } + } case EXOSIP_CALL_RINGING: //peer call is ringing - id = findCallId(event); - if (id == 0) { - id = findCallIdInitial(event); - } - _debug("Call is ringing [id = %d, cid = %d, did = %d]\n", - id, event->cid, event->did); - - if (id > 0) { + id = findCallIdInitial(event); + _debug("Call is ringing [id = %d, cid = %d, did = %d]\n", id, event->cid, event->did); + if (id != 0) { getSipCall(id)->ringingCall(event); Manager::instance().peerRingingCall(id); } else { returnValue = -1; - break; } break; @@ -750,37 +726,29 @@ SipVoIPLink::getEvent (void) case EXOSIP_CALL_ACK: id = findCallId(event); - _debug("ACK received [id = %d, cid = %d, did = %d]\n", - id, event->cid, event->did); - if (id > 0) { + _debug("ACK received [id = %d, cid = %d, did = %d]\n", id, event->cid, event->did); + if (id != 0) { getSipCall(id)->receivedAck(event); } else { returnValue = -1; - break; } break; // The peer-user closed the phone call(we received BYE). case EXOSIP_CALL_CLOSED: id = findCallId(event); - _debug("Call is closed [id = %d, cid = %d, did = %d]\n", - id, event->cid, event->did); - - if (id > 0) { - if (Manager::instance().callCanClose(id)) { + _debug("Call is closed [id = %d, cid = %d, did = %d]\n", id, event->cid, event->did); + if (id != 0) { + if (Manager::instance().callCanBeClosed(id)) { _audiortp.closeRtpSession(getSipCall(id)); } Manager::instance().peerHungupCall(id); deleteSipCall(id); } else { returnValue = -1; - break; } break; case EXOSIP_CALL_RELEASED: - //id = findCallIdInitial(event); - //_debug("Id Released: %d\n", id); - break; case EXOSIP_CALL_REQUESTFAILURE: id = findCallId(event); @@ -947,7 +915,7 @@ SipVoIPLink::getEvent (void) returnValue = -1; break; } - _debug(" : end event : %d / %d\n", event->type, returnValue); + //_debug(" : end event : %d / %d\n", event->type, returnValue); eXosip_event_free(event); return returnValue; @@ -966,7 +934,7 @@ SipVoIPLink::setLocalPort (int port) } void -SipVoIPLink::carryingDTMFdigits (short id, char code) { +SipVoIPLink::carryingDTMFdigits (CALLID id, char code) { int duration = Manager::instance().getConfigInt(SIGNALISATION, PULSE_LENGTH); osip_message_t *info; const int body_len = 1000; @@ -991,9 +959,9 @@ SipVoIPLink::carryingDTMFdigits (short id, char code) { } void -SipVoIPLink::newOutgoingCall (short callid) +SipVoIPLink::newOutgoingCall (CALLID id) { - SipCall *sipcall = new SipCall(callid, Manager::instance().getCodecDescVector()); + SipCall* sipcall = new SipCall(id, Manager::instance().getCodecDescVector()); if (sipcall != NULL) { _sipcallVector.push_back(sipcall); sipcall->setStandBy(true); @@ -1001,21 +969,21 @@ SipVoIPLink::newOutgoingCall (short callid) } void -SipVoIPLink::newIncomingCall (short callid) +SipVoIPLink::newIncomingCall (CALLID id) { - SipCall* sipcall = new SipCall(callid, Manager::instance().getCodecDescVector()); + SipCall* sipcall = new SipCall(id, Manager::instance().getCodecDescVector()); if (sipcall != NULL) { _sipcallVector.push_back(sipcall); } } void -SipVoIPLink::deleteSipCall (short callid) +SipVoIPLink::deleteSipCall (CALLID id) { - std::vector< SipCall * >::iterator iter = _sipcallVector.begin(); + std::vector< SipCall* >::iterator iter = _sipcallVector.begin(); while(iter != _sipcallVector.end()) { - if ((*iter)->getId() == callid) { + if (*iter && (*iter)->getId() == id) { delete *iter; *iter = NULL; _sipcallVector.erase(iter); return; @@ -1027,31 +995,43 @@ SipVoIPLink::deleteSipCall (short callid) void SipVoIPLink::endSipCalls() { - std::vector< SipCall * >::iterator iter = _sipcallVector.begin(); - std::vector< SipCall * >::iterator tmp; + std::vector< SipCall* >::iterator iter = _sipcallVector.begin(); while(iter != _sipcallVector.end()) { - tmp = iter; tmp++; // go to next - hangup( (*iter)->getId() ); // we delete the call here... - iter = tmp; + if ( *iter ) { + + // Release SIP stack. + eXosip_lock(); + eXosip_call_terminate ((*iter)->getCid(), (*iter)->getDid()); + eXosip_unlock(); + + // Release RTP channels + _audiortp.closeRtpSession(*iter); + delete *iter; *iter = NULL; + } + iter++; } + _sipcallVector.clear(); } SipCall* -SipVoIPLink::getSipCall (short callid) +SipVoIPLink::getSipCall (CALLID id) { + SipCall* sipcall = NULL; for (unsigned int i = 0; i < _sipcallVector.size(); i++) { - if (_sipcallVector.at(i)->getId() == callid) { - return _sipcallVector.at(i); + sipcall = _sipcallVector.at(i); + if (sipcall && sipcall->getId() == id) { + return sipcall; } } return NULL; } AudioCodec* -SipVoIPLink::getAudioCodec (short callid) +SipVoIPLink::getAudioCodec (CALLID id) { - if (getSipCall(callid)) { - return getSipCall(callid)->getAudioCodec(); + SipCall* sipcall = getSipCall(id); + if (sipcall != NULL) { + return sipcall->getAudioCodec(); } else { return NULL; } @@ -1340,10 +1320,10 @@ SipVoIPLink::toHeader(const string& to) } int -SipVoIPLink::startCall (short id, const std::string& from, const std::string& to, +SipVoIPLink::startCall (CALLID id, const std::string& from, const std::string& to, const std::string& subject, const std::string& route) { - SipCall *sipcall = getSipCall(id); + SipCall* sipcall = getSipCall(id); if ( sipcall == NULL) { return -1; // error, we can't find the sipcall } @@ -1461,14 +1441,14 @@ SipVoIPLink::startCall (short id, const std::string& from, const std::string& to return cid; // this is the Cid } -short +CALLID SipVoIPLink::findCallId (eXosip_event_t *e) { for (unsigned int k = 0; k < _sipcallVector.size(); k++) { - SipCall *call = _sipcallVector.at(k); - if (call->getCid() == e->cid && - call->getDid() == e->did) { - return call->getId(); + SipCall* sipcall = _sipcallVector.at(k); + if (sipcall && sipcall->getCid() == e->cid && + sipcall->getDid() == e->did) { + return sipcall->getId(); } } return 0; @@ -1480,41 +1460,17 @@ SipVoIPLink::findCallId (eXosip_event_t *e) * can be use when anwsering a new call or * when cancelling a call */ -short +CALLID SipVoIPLink::findCallIdInitial (eXosip_event_t *e) { for (unsigned int k = 0; k < _sipcallVector.size(); k++) { - SipCall *call = _sipcallVector.at(k); + SipCall* sipcall = _sipcallVector.at(k); // the dialog id is not set when you do a new call // so you can't check it when you want to retreive it // for the first call anwser - if (call->getCid() == e->cid) { - return call->getId(); - } - } - return 0; -} -/** - * YM: (2005-09-21) This function is really really bad.. - * Should be removed ! - * Don't ask the GUI which call it use... - */ -/* -short -SipVoIPLink::findCallIdWhenRinging (void) -{ - unsigned int k; - int i = Manager::instance().selectedCall(); - - if (i != -1) { - return i; - } else { - for (k = 0; k < _sipcallVector.size(); k++) { - if (_sipcallVector.at(k)->getStandBy()) { - return _sipcallVector.at(k)->getId(); - } + if (sipcall && sipcall->getCid() == e->cid) { + return sipcall->getId(); } } return 0; } -*/ diff --git a/src/sipvoiplink.h b/src/sipvoiplink.h index cb3c65c6318b594a64f1cd59b641e8365f699bbe..1e79dbebe7555309742bc1cbba6e3fe6713c69ab 100644 --- a/src/sipvoiplink.h +++ b/src/sipvoiplink.h @@ -29,6 +29,7 @@ #include "voIPLink.h" #include "audio/audiortp.h" +#include "call.h" // for CALLID #define EXPIRES_VALUE 180 // To build request @@ -68,7 +69,7 @@ typedef std::vector< CodecDescriptor* > CodecDescriptorVector; class SipVoIPLink : public VoIPLink { public: - SipVoIPLink (short id); + SipVoIPLink(); virtual ~SipVoIPLink(); virtual int init (void); @@ -76,16 +77,16 @@ public: virtual void terminate (void); virtual int setRegister (void); virtual int setUnregister (void); - virtual int outgoingInvite (short id, const std::string& to_url); - virtual int answer (short id); - virtual int hangup (short id); - virtual int cancel (short id); - virtual int onhold (short id); - virtual int offhold (short id); - virtual int transfer (short id, const std::string& to); - virtual int refuse (short id); + virtual int outgoingInvite (CALLID id, const std::string& to_url); + virtual int answer (CALLID id); + virtual int hangup (CALLID id); + virtual int cancel (CALLID id); + virtual int onhold (CALLID id); + virtual int offhold (CALLID id); + virtual int transfer (CALLID id, const std::string& to); + virtual int refuse (CALLID id); virtual int getEvent (void); - virtual void carryingDTMFdigits (short id, char code); + virtual void carryingDTMFdigits (CALLID id, char code); /* * To handle the local port @@ -96,23 +97,23 @@ public: /* * Add a new SipCall at the end of the SipCallVector with identifiant 'id' */ - void newOutgoingCall(short callid); - void newIncomingCall(short callid); + void newOutgoingCall(CALLID callid); + void newIncomingCall(CALLID callid); /* * Erase the SipCall(id) from the SipCallVector */ - void deleteSipCall(short callid); + void deleteSipCall(CALLID callid); /* * Return a pointer to the SipCall with identifiant 'id' */ - SipCall* getSipCall(short callid); + SipCall* getSipCall(CALLID callid); /* * Accessor to the audio codec of SipCall with identifiant 'id' */ - AudioCodec* getAudioCodec(short callid); + AudioCodec* getAudioCodec(CALLID callid); // Handle voice-message inline void setMsgVoicemail (int nMsg) { _nMsgVoicemail = nMsg; } @@ -168,16 +169,15 @@ private: * Build SDP body. * Return -1 if an error occured and 0 if no error */ - int startCall (short id, const std::string& from, const std::string& to, + int startCall (CALLID id, const std::string& from, const std::string& to, const std::string& subject, const std::string& route); /* * Look for call with same cid/did * Return the id of the found call */ - short findCallId (eXosip_event_t *e); - short findCallIdInitial (eXosip_event_t *e); - //short findCallIdWhenRinging (void); + CALLID findCallId (eXosip_event_t *e); + CALLID findCallIdInitial (eXosip_event_t *e); /* * Return true if payload is already in the rtpmap and false if not diff --git a/src/voIPLink.cpp b/src/voIPLink.cpp index 9ad71e03167f585ab710d9d453c608dd284f7180..b74cb20fe0c85dd2aa160b079bf2d396469d1380 100644 --- a/src/voIPLink.cpp +++ b/src/voIPLink.cpp @@ -28,9 +28,8 @@ using namespace std; -VoIPLink::VoIPLink (short id) +VoIPLink::VoIPLink () { - _id = id; initConstructor(); } @@ -38,18 +37,6 @@ VoIPLink::~VoIPLink (void) { } -void -VoIPLink::setId (short id) -{ - _id = id; -} - -short -VoIPLink::getId (void) -{ - return _id; -} - void VoIPLink::setType (VoIPLinkType type) { diff --git a/src/voIPLink.h b/src/voIPLink.h index c9c6209c77a937ca2a27f2c0352ac613b01661a0..03b3360136ae79e8fee359010d20c919adffb7ea 100644 --- a/src/voIPLink.h +++ b/src/voIPLink.h @@ -22,6 +22,7 @@ #define __VOIP_LINK_H__ #include <string> +#include "call.h" enum VoIPLinkType { Sip = 0, @@ -33,7 +34,7 @@ class Call; class VoIPLink { public: - VoIPLink (short id); + VoIPLink (); virtual ~VoIPLink (void); // Pure virtual functions @@ -41,23 +42,21 @@ public: virtual int init (void) = 0; virtual bool checkNetwork (void) = 0; virtual void terminate (void) = 0; - virtual void newOutgoingCall (short callid) = 0; - virtual void newIncomingCall (short callid) = 0; - virtual int outgoingInvite (short id, const std::string& to_url) = 0; - virtual int answer (short id) = 0; - virtual int hangup (short id) = 0; - virtual int cancel (short id) = 0; - virtual int onhold (short id) = 0; - virtual int offhold (short id) = 0; - virtual int transfer (short id, const std::string& to) = 0; - virtual int refuse (short id) = 0; + virtual void newOutgoingCall (CALLID id) = 0; + virtual void newIncomingCall (CALLID id) = 0; + virtual int outgoingInvite (CALLID id, const std::string& to_url) = 0; + virtual int answer (CALLID id) = 0; + virtual int hangup (CALLID id) = 0; + virtual int cancel (CALLID id) = 0; + virtual int onhold (CALLID id) = 0; + virtual int offhold (CALLID id) = 0; + virtual int transfer (CALLID id, const std::string& to) = 0; + virtual int refuse (CALLID id) = 0; virtual int setRegister (void) = 0; virtual int setUnregister (void) = 0; - virtual void carryingDTMFdigits(short id, char code) = 0; - virtual AudioCodec* getAudioCodec (short callid) = 0; - - void setId (short id); - short getId (void); + virtual void carryingDTMFdigits(CALLID id, char code) = 0; + virtual AudioCodec* getAudioCodec (CALLID id) = 0; + void setType (VoIPLinkType type); VoIPLinkType getType (void); void setFullName (const std::string& fullname); @@ -73,7 +72,6 @@ protected: private: void initConstructor(void); - short _id; VoIPLinkType _type; std::string _fullname; std::string _hostname; diff --git a/src/zeroconf/DNSService.cpp b/src/zeroconf/DNSService.cpp index 5b7dd758a22124eb7217045275720cfe6ac9a82b..03f1a0d96ed13513fa2197c82dc8a29ad4f8a483 100644 --- a/src/zeroconf/DNSService.cpp +++ b/src/zeroconf/DNSService.cpp @@ -98,22 +98,6 @@ void DNSService::removeService(const std::string &service) notify(); } -/** - * Display the list of available services - * run() method should be call before - */ -void -DNSService::listServices() -{ - _debug("Number of services detected: %d\n", _services.size()); - DNSServiceMap::iterator iterTR; - for (iterTR = _services.begin(); iterTR != _services.end(); iterTR++) { - _debug("name: %s\n", iterTR->first.c_str()); - _debug("size: %d\n", iterTR->second.size()); - iterTR->second.listValue(); - } -} - /** * Return every services */ @@ -200,9 +184,9 @@ DNSService::addTXTRecord(const char *fullname, uint16_t rdlen, const void *rdata } void -DNSServiceAddServicesCallback(DNSServiceRef sdRef, +DNSServiceAddServicesCallback(DNSServiceRef, DNSServiceFlags flags, - uint32_t interfaceIndex, + uint32_t, DNSServiceErrorType errorCode, const char *serviceName, const char *replyType, @@ -230,16 +214,16 @@ DNSServiceAddServicesCallback(DNSServiceRef sdRef, void DNSServiceQueryRecordCallback( - DNSServiceRef DNSServiceRef, + DNSServiceRef, DNSServiceFlags flags, - uint32_t interfaceIndex, + uint32_t, DNSServiceErrorType errorCode, const char *fullname, - uint16_t rrtype, - uint16_t rrclass, + uint16_t, + uint16_t, uint16_t rdlen, const void *rdata, - uint32_t ttl, + uint32_t, void *context) { if (errorCode==kDNSServiceErr_NoError) { diff --git a/src/zeroconf/DNSService.h b/src/zeroconf/DNSService.h index a721173686c3fff1b6283f7744576fecc9f9927d..6df1d46582ae207752021b562e42c19e5a52d839 100644 --- a/src/zeroconf/DNSService.h +++ b/src/zeroconf/DNSService.h @@ -41,7 +41,6 @@ public: void startScanServices(); // looking for services void addService(const std::string &service); // adding every services void removeService(const std::string &service); // remove a service - void listServices(); // listing services (call addService before) DNSServiceMap getServices(); // get all DNS Service void stop(); // after the browsing loop stop diff --git a/src/zeroconf/DNSServiceTXTRecord.cpp b/src/zeroconf/DNSServiceTXTRecord.cpp index 910fa97cf7bff6333aa4e043d251339ebb1b9b34..e4c6fff35a6fbe21efc20fc8d150a84e79bbd79d 100644 --- a/src/zeroconf/DNSServiceTXTRecord.cpp +++ b/src/zeroconf/DNSServiceTXTRecord.cpp @@ -17,8 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "DNSServiceTXTRecord.h" -#include "../global.h" // for _debug - /** * Simple constructor @@ -76,12 +74,3 @@ DNSServiceTXTRecord::getValue(const char* key) { return getValue(std::string(key)); } - -void -DNSServiceTXTRecord::listValue() -{ - TXTRecordMap::iterator iter; - for (iter=_map.begin(); iter != _map.end(); iter++) { - _debug ( "\t%s:%s\n", iter->first.c_str(), iter->second.c_str()); - } -} diff --git a/src/zeroconf/DNSServiceTXTRecord.h b/src/zeroconf/DNSServiceTXTRecord.h index 907fee3ced76de6b5941dbe2dd9b4144620cd4ed..5c4b8ac1fa51e7ca597c0ba334b04822dabd4558 100644 --- a/src/zeroconf/DNSServiceTXTRecord.h +++ b/src/zeroconf/DNSServiceTXTRecord.h @@ -34,7 +34,6 @@ public: const std::string &getValue(const char *key); inline void clear(void) { _map.clear(); }; inline int size(void) { return _map.size(); }; - void listValue(); TXTRecordMap getTXTRecords() { return _map; } private: