diff --git a/src/config/config.cpp b/src/config/config.cpp index 525a23044693a077c69562252b4c208bcba25ec7..3be86fc1a4c3b2826005e1fbd66546b5df8ddfcc 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -150,6 +150,8 @@ ConfigTree::setConfigTreeItem(const std::string& section, const std::string& ite } // Save config to a file (ini format) +// return false if empty, no config, or enable to open +// return true if everything is ok bool ConfigTree::saveConfigTree(const std::string& fileName) { if (fileName.empty() && _sections.begin() == _sections.end() ) { @@ -178,7 +180,7 @@ ConfigTree::saveConfigTree(const std::string& fileName) { } file.close(); - return false; + return true; } // Create the tree from an existing ini file diff --git a/src/gui/guiframework.h b/src/gui/guiframework.h index 9a9f1e815c36e53e5db555a338f15c4eaccf805f..9c4a4411e9d3667ca9c897c7a00dfe1ba864bc46 100644 --- a/src/gui/guiframework.h +++ b/src/gui/guiframework.h @@ -51,11 +51,10 @@ public: virtual void sendVoiceNbMessage(const std::string& nb_msg) = 0; virtual void sendMessage(const std::string& code, const std::string& seqId, TokenList& arg) = 0; - virtual void sendCallMessage(const std::string& seqId, - short id, - const std::string& accountId, - const std::string& status - ) = 0; + virtual void sendCallMessage(const std::string& code, + const std::string& sequenceId, + short id, + TokenList arg) = 0; /* Child class to parent class */ int outgoingCall (const std::string& to); diff --git a/src/gui/qt/qtGUImainwindow.cpp b/src/gui/qt/qtGUImainwindow.cpp index 4e05615a4baa6fe5282516870b5d81fb0dbd9987..578258c3fe95606b17e60459674a664a8fa2ae87 100644 --- a/src/gui/qt/qtGUImainwindow.cpp +++ b/src/gui/qt/qtGUImainwindow.cpp @@ -1677,7 +1677,7 @@ QtGUIMainWindow::pressedKeySlot (int id) { _lcd->setIsScrolling(false); phLines[getCurrentLine()]->setScrolling(false); } - + AudioLayer* audiolayer = Manager::instance().getAudioDriver(); // To generate the dtmf if there is no error in configuration if (Manager::instance().error()->getError() == 0) { // Handle dtmf @@ -1697,19 +1697,19 @@ QtGUIMainWindow::pressedKeySlot (int id) { buf_ctrl_vol[k] = buf_ctrl_vol[k+1] = _buf[j] * spkrVolume/100; } - Manager::instance().getAudioDriver()->urgentRingBuffer().flush(); + audiolayer->urgentRingBuffer().flush(); // Put buffer to urgentRingBuffer - Manager::instance().getAudioDriver()->urgentRingBuffer().Put(buf_ctrl_vol, + audiolayer->urgentRingBuffer().Put(buf_ctrl_vol, size * CHANNELS); // We activate the stream if it's not active yet. - if (!Manager::instance().getAudioDriver()->isStreamActive()) { - Manager::instance().getAudioDriver()->startStream(); - Manager::instance().getAudioDriver()->sleep(pulselen); - Manager::instance().getAudioDriver()->stopStream(); - Manager::instance().getAudioDriver()->urgentRingBuffer().flush(); + if (!audiolayer->isStreamActive()) { + audiolayer->startStream(); + audiolayer->sleep(pulselen); + audiolayer->stopStream(); + audiolayer->urgentRingBuffer().flush(); } else { - Manager::instance().getAudioDriver()->sleep(pulselen); + audiolayer->sleep(pulselen); } delete[] buf_ctrl_vol; diff --git a/src/gui/qt/qtGUImainwindow.h b/src/gui/qt/qtGUImainwindow.h index 8c8b9121b359ee91c5e971cfebdac72b9208792c..a0508ee599c919237e5fee14a8acfa7c66796533 100644 --- a/src/gui/qt/qtGUImainwindow.h +++ b/src/gui/qt/qtGUImainwindow.h @@ -97,11 +97,10 @@ public: virtual std::string getRingtoneFile (void); virtual void setup (void); virtual void sendMessage(const std::string& code, const std::string& seqId, TokenList& arg) {} - virtual void sendCallMessage(const std::string& seqId, - short id, - const std::string& accountId, - const std::string& status - ) {} + virtual void sendCallMessage(const std::string& code, + const std::string& sequenceId, + short id, + TokenList arg) {} diff --git a/src/gui/server/guiserverimpl.cpp b/src/gui/server/guiserverimpl.cpp index b54f5b5b00966f1e191961fd51b5eeb1d2f4f472..e8c1641ec6c09a5dc93e574ab1ece0364581a974 100644 --- a/src/gui/server/guiserverimpl.cpp +++ b/src/gui/server/guiserverimpl.cpp @@ -389,19 +389,15 @@ GUIServerImpl::sendMessage(const std::string& code, const std::string& seqId, To } void -GUIServerImpl::sendCallMessage(const std::string& seqId, - short id, - const std::string& accountId, - const std::string& status - ) +GUIServerImpl::sendCallMessage(const std::string& code, + const std::string& sequenceId, + short id, + TokenList arg) { try { std::string callid = getCallIdFromId(id); - TokenList arg; - arg.push_back(callid); - arg.push_back(accountId); - arg.push_back(status); - _requestManager.sendResponse(ResponseMessage("100", seqId, arg)); + arg.push_front(callid); + _requestManager.sendResponse(ResponseMessage(code, sequenceId, arg)); } catch(...) { // no callid found } diff --git a/src/gui/server/guiserverimpl.h b/src/gui/server/guiserverimpl.h index 443e072572586a75108042c62809bfeee2ae0400..6f4e952462e16440107c3b0e10bc20e174cae8bb 100644 --- a/src/gui/server/guiserverimpl.h +++ b/src/gui/server/guiserverimpl.h @@ -59,11 +59,10 @@ public: void sendMessage(const std::string& code, const std::string& seqId, TokenList& arg); - void sendCallMessage(const std::string& seqId, - short id, - const std::string& accountId, - const std::string& status - ); + void sendCallMessage(const std::string& code, + const std::string& sequenceId, + short id, + TokenList arg); bool getEvents(const std::string& sequenceId); bool sendGetEventsEnd(); diff --git a/src/gui/server/requestconfig.cpp b/src/gui/server/requestconfig.cpp index 5c5dd62d720f708b9a47bdb640923381d86399dd..e0cdab5aad26ed9f0c9acee6b8b5a56875250783 100644 --- a/src/gui/server/requestconfig.cpp +++ b/src/gui/server/requestconfig.cpp @@ -52,16 +52,18 @@ ResponseMessage RequestCallStatus::execute() { GUIServer::instance().sendGetEventsEnd(); + TokenList tk; + tk.push_back("OK"); + std::string code = "205"; + GUIServer::instance().getCallStatus(_sequenceId); + std::string callid; if (GUIServer::instance().getCurrentCallId(callid)) { - GUIServer::instance().getCallStatus(_sequenceId); - TokenList tk; - tk.push_back(callid); - tk.push_back("OK"); - return message("205", tk); + tk.push_front(callid); } else { - return message("206","OK"); + code = "206"; } + return message(code, tk); } ResponseMessage diff --git a/src/gui/server/requestmanager.cpp b/src/gui/server/requestmanager.cpp index f7e86bb2f582e226b722647f65ffb306cdab1250..0ee3725ea19bedc9019229026fbfa6bc5169e3e8 100644 --- a/src/gui/server/requestmanager.cpp +++ b/src/gui/server/requestmanager.cpp @@ -87,7 +87,7 @@ RequestManager::exec() } // end while } catch(ost::Socket *e) { - std::cerr << e->getErrorString() << std::endl; + std::cerr << "Exception: " << e->getErrorString() << std::endl; } return 0; } diff --git a/src/gui/server/tcpsessionio.cpp b/src/gui/server/tcpsessionio.cpp index 0abd4f9f422151c8244604c1372c2731be2cf689..4acf996a247bdb1efec6deb613ccff30628c41da 100644 --- a/src/gui/server/tcpsessionio.cpp +++ b/src/gui/server/tcpsessionio.cpp @@ -20,10 +20,10 @@ TCPSessionIO::TCPSessionIO() : SessionIO() ost::InetAddress addr(IP); //Creating a listening socket - _serverSocket = new ost::TCPSocket(addr, PORT); - if (_serverSocket == 0 ) { - throw new ost::SockException(ost::String("Unable to bind port"), -ost::Socket::errBindingFailed); + try { + _serverSocket = new ost::TCPSocket(addr, PORT); + } catch( ost::Socket *e ) { + throw e; } } diff --git a/src/main.cpp b/src/main.cpp index 79a69849675d08d377826b3c5efdfa1582bc2cde..d91fc491cd7c1c3f28bcc1731f03601b8b7e1d82 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,21 +42,25 @@ main (int argc, char **argv) { #if defined(ENABLE_MAINTENER) { - Manager::instance().initConfigFile(); + bool initOK = false; try { + Manager::instance().initConfigFile(); Manager::instance().init(); + initOK = true; } catch (...) { std::cerr << - "An unknown exception occured when initializing the system." << - std::endl; + "An exception occured when initializing the system." << + std::endl; } - GUI = &(GUIServer::instance()); - Manager::instance().setGui(GUI); - exit_code = GUIServer::instance().exec(); - Manager::instance().terminate(); - delete GUI; - } + if (initOK) { + GUI = &(GUIServer::instance()); + Manager::instance().setGui(GUI); + exit_code = GUIServer::instance().exec(); + Manager::instance().terminate(); + delete GUI; + } + } #elif defined(GUI_QT) { QApplication a(argc, argv); diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 16c5582b293611999ba9bf5e5e6335ec241276d7..0dc578b259635e7e541b77cfb2fce8a0aca16ec2 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -114,9 +114,12 @@ ManagerImpl::~ManagerImpl (void) delete *pos; } + unloadAudioCodec(); + delete _error; delete _tone; delete _audiodriverPA; + #ifdef USE_ZEROCONF delete _DNSService; #endif @@ -129,15 +132,10 @@ ManagerImpl::init (void) initZeroconf(); initVolume(); - // Set a sip voip link by default - _voIPLinkVector.push_back(new SipVoIPLink(DFT_VOIP_LINK)); - if (_exist == 0) { _debug("Cannot create config file in your home directory\n"); } - initAudioCodec(); - try { selectAudioDriver(); loaded(true); @@ -145,23 +143,29 @@ ManagerImpl::init (void) catch (const portaudio::PaException &e) { displayError(e.paErrorText()); + throw e; } catch (const portaudio::PaCppException &e) { displayError(e.what()); + throw e; } catch (const exception &e) { displayError(e.what()); + throw e; } catch (...) { displayError("An unknown exception occured."); + throw; } - _voIPLinkVector.at(DFT_VOIP_LINK)->init(); - + initAudioCodec(); + // Set a sip voip link by default + _voIPLinkVector.push_back(new SipVoIPLink(DFT_VOIP_LINK)); + _voIPLinkVector.at(DFT_VOIP_LINK)->init(); if (_voIPLinkVector.at(DFT_VOIP_LINK)->checkNetwork()) { // If network is available @@ -336,6 +340,7 @@ ManagerImpl::outgoingCall (const string& to) call->setStatus(string(TRYING_STATUS)); call->setState(Progressing); + call->setCallerIdNumber(to); if (call->outgoingCall(to) == 0) { return id; } else { @@ -438,6 +443,7 @@ ManagerImpl::transferCall (short id, const string& to) return -1; call->setStatus(string(TRANSFER_STATUS)); call->setState(Transfered); + setCurrentCallId(0); return call->transfer(to); } void @@ -480,13 +486,18 @@ ManagerImpl::refuseCall (short id) call = getCall(id); if (call == NULL) return -1; - call->setStatus(string(HUNGUP_STATUS)); - call->setState(Refused); - ringtone(false); - _mutex.enterMutex(); - _nCalls -= 1; - _mutex.leaveMutex(); - deleteCall(id); + // don't cause a very bad segmentation fault + // we refuse the call when we are trying to establish connection + if ( call->getState() != Progressing ) + return -1; + + call->setStatus(string(HUNGUP_STATUS)); + call->setState(Refused); + ringtone(false); + _mutex.enterMutex(); + _nCalls -= 1; + _mutex.leaveMutex(); + deleteCall(id); setCurrentCallId(0); return call->refuse(); } @@ -665,6 +676,7 @@ ManagerImpl::peerAnsweredCall (short id) call->setState(Answered); //if (isCurrentId(id)) { + setCurrentCallId(id); _gui->peerAnsweredCall(id); //} } @@ -979,8 +991,6 @@ ManagerImpl::createSettingsPath (void) { void ManagerImpl::initConfigFile (void) { - _exist = createSettingsPath(); - std::string type_str("string"); std::string type_int("int"); @@ -1020,6 +1030,8 @@ ManagerImpl::initConfigFile (void) fill_config_str(VOICEMAIL_NUM, DFT_VOICEMAIL); fill_config_int(CONFIG_ZEROCONF, CONFIG_ZEROCONF_DEFAULT_STR); + _exist = createSettingsPath(); + // old way fill_config_fields_int(SIGNALISATION, VOIP_LINK_ID, DFT_VOIP_LINK); fill_config_fields_str(SIGNALISATION, FULL_NAME, EMPTY_FIELD); @@ -1074,13 +1086,30 @@ ManagerImpl::initAudioCodec (void) get_config_fields_str(AUDIO, CODEC3))); } +void +ManagerImpl::unloadAudioCodec() +{ + CodecDescriptorVector::iterator iter = _codecDescVector.begin(); + while(iter!=_codecDescVector.end()) { + delete *iter; + *iter = NULL; + _codecDescVector.erase(iter); + iter++; + } +} + + void ManagerImpl::selectAudioDriver (void) { #if defined(AUDIO_PORTAUDIO) + try { _audiodriverPA = new AudioLayer(); _audiodriverPA->openDevice(get_config_fields_int(AUDIO, DRIVER_NAME)); + } catch(...) { + throw; + } #else # error You must define one AUDIO driver to use. #endif @@ -1170,11 +1199,52 @@ ManagerImpl::getCallStatus(const std::string& sequenceId) { // TODO: implement account std::string accountId = "acc1"; + std::string code; + TokenList tk; + Call* call; + if (_gui!=NULL) { CallVector::iterator iter = _callVector.begin(); while(iter!=_callVector.end()){ - _gui->sendCallMessage(sequenceId, (*iter)->getId(), accountId, (*iter)->getStatus()); + call = (*iter); + std::string status = call->getStatus(); + switch( call->getState() ) { + case Busy: + code="113"; + break; + + case Answered: + code="112"; + status = "Established"; + break; + + case Ringing: + code="111"; + break; + + case Progressing: + code="110"; + status="Trying"; + break; + default: + code="115"; + } + // No Congestion + // No Wrong Number + // 116 <CSeq> <call-id> <acc> <destination> Busy + std::string destination = call->getCallerIdName(); + std::string number = call->getCallerIdNumber(); + if (number!="") { + destination.append(" <"); + destination.append(number); + destination.append(">"); + } + tk.push_back(accountId); + tk.push_back(destination); + tk.push_back(status); + _gui->sendCallMessage(code, sequenceId, (*iter)->getId(), tk); iter++; + tk.clear(); } } return true; diff --git a/src/managerimpl.h b/src/managerimpl.h index 2251b08dc4020ffe03a801e7db3c242c56681d0d..5ba2947b113e9eef1a4f9a90d984792d8e912214 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -290,6 +290,7 @@ private: * Initialize audiocodec */ void initAudioCodec(void); + void unloadAudioCodec(void); /* * Initialize audiodriver