diff --git a/src/config/config.cpp b/src/config/config.cpp index 08b33daca2ebaeff4520d5334928ab7cc7cb5254..525a23044693a077c69562252b4c208bcba25ec7 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -168,8 +168,8 @@ ConfigTree::saveConfigTree(const std::string& fileName) { while(iter != _sections.end()) { file << "[" << iter->first << "]" << std::endl; ItemMap::iterator iterItem = iter->second->begin(); - while ( iterItem == iter->second->end() ) { - file << iterItem->first << iterItem->second.getValue() << std::endl; + while ( iterItem != iter->second->end() ) { + file << iterItem->first << "=" << iterItem->second.getValue() << std::endl; iterItem++; } file << std::endl; diff --git a/src/gui/guiframework.cpp b/src/gui/guiframework.cpp index f6c6653f9b89ab7159d87811ac4c7b54c0d80e6f..b3ac45db05257e95bfd2145d123e94c152d0e6ab 100644 --- a/src/gui/guiframework.cpp +++ b/src/gui/guiframework.cpp @@ -226,6 +226,11 @@ GuiFramework::getCallStatus(const std::string& sequenceId) { return Manager::instance().getCallStatus(sequenceId); } +short +GuiFramework::getCurrentId() +{ + return Manager::instance().getCurrentCallId(); +} bool GuiFramework::getConfigAll(const std::string& sequenceId) diff --git a/src/gui/guiframework.h b/src/gui/guiframework.h index 459fe35f96f1adc4640812106cce16994fe03334..9a9f1e815c36e53e5db555a338f15c4eaccf805f 100644 --- a/src/gui/guiframework.h +++ b/src/gui/guiframework.h @@ -46,8 +46,9 @@ public: virtual void setup (void) = 0; //virtual int selectedCall (void) = 0; //virtual bool isCurrentId (short) = 0; - virtual void startVoiceMessageNotification (void) = 0; - virtual void stopVoiceMessageNotification (void) = 0; + virtual void startVoiceMessageNotification (void) {} + virtual void stopVoiceMessageNotification (void) {} + 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, @@ -91,6 +92,7 @@ public: // Observer methods virtual void update() {} + short getCurrentId(); protected: std::string _message; diff --git a/src/gui/qt/qtGUImainwindow.h b/src/gui/qt/qtGUImainwindow.h index ecef1f3b2f1662e352516acd3e15a59b95be3eab..8c8b9121b359ee91c5e971cfebdac72b9208792c 100644 --- a/src/gui/qt/qtGUImainwindow.h +++ b/src/gui/qt/qtGUImainwindow.h @@ -177,6 +177,7 @@ public: */ void stopVoiceMessageNotification (void); void startVoiceMessageNotification (void); + void sendVoiceNbMessage(const std::string& nb_msg) {} /* * Manage if you selected a line before dialing diff --git a/src/gui/server/guiserverimpl.cpp b/src/gui/server/guiserverimpl.cpp index 35ad1936e37009f97032d2810a91aa98201751ca..8734483c98c1684f83d8deb86e3c68e8e2271eb7 100644 --- a/src/gui/server/guiserverimpl.cpp +++ b/src/gui/server/guiserverimpl.cpp @@ -27,7 +27,7 @@ #include "responsemessage.h" // default constructor -GUIServerImpl::GUIServerImpl() +GUIServerImpl::GUIServerImpl() : _getEventsSequenceId("seq0") { } @@ -58,7 +58,7 @@ GUIServerImpl::removeSubCall(short id) { } /** - * Retreive the sequenceId or send seq0 + * Retreive the sequenceId or send default sequenceId */ std::string GUIServerImpl::getSequenceIdFromId(short id) { @@ -66,7 +66,7 @@ GUIServerImpl::getSequenceIdFromId(short id) { if (iter != _callMap.end()) { return iter->second.sequenceId(); } - return "seq0"; + return _getEventsSequenceId; } /** * Retreive the string callid from the id @@ -80,6 +80,20 @@ GUIServerImpl::getCallIdFromId(short id) { throw std::runtime_error("No match for this id"); } +bool +GUIServerImpl::getCurrentCallId(std::string& callId) { + try { + short id = GuiFramework::getCurrentId(); + if (id!=0) { + callId = getCallIdFromId(id); + } + return true; + } catch(...) { + return false; + } + return false; +} + short GUIServerImpl::getIdFromCallId(const std::string& callId) { @@ -93,6 +107,20 @@ GUIServerImpl::getIdFromCallId(const std::string& callId) throw std::runtime_error("No match for this CallId"); } +bool +GUIServerImpl::getEvents(const std::string& sequenceId) +{ + _getEventsSequenceId=sequenceId; + return true; +} +bool +GUIServerImpl::sendGetEventsEnd() +{ + _requestManager.sendResponse(ResponseMessage("202", _getEventsSequenceId, +"getcallstatus request stopped me")); + return true; +} + bool GUIServerImpl::outgoingCall (const std::string& seq, const std::string& callid, const std::string& to) { @@ -240,11 +268,12 @@ GUIServerImpl::incomingCall (short id, const std::string& accountId, const std:: arg.push_back(from); arg.push_back("call"); - SubCall subcall("seq0", callId.str()); + SubCall subcall(_getEventsSequenceId, callId.str()); insertSubCall(id, subcall); - _requestManager.sendResponse(ResponseMessage("001", "seq0", arg)); + _requestManager.sendResponse(ResponseMessage("001", _getEventsSequenceId, +arg)); return 0; } @@ -258,7 +287,8 @@ GUIServerImpl::peerAnsweredCall (short id) } else { std::ostringstream responseMessage; responseMessage << "Peer Answered Call: " << id; - _requestManager.sendResponse(ResponseMessage("500", "seq0", responseMessage.str())); + _requestManager.sendResponse(ResponseMessage("500", _getEventsSequenceId, +responseMessage.str())); } } @@ -280,7 +310,8 @@ GUIServerImpl::peerHungupCall (short id) std::ostringstream responseMessage; responseMessage << iter->second.callId() << " hangup"; - _requestManager.sendResponse(ResponseMessage("002", "seq0", responseMessage.str())); + _requestManager.sendResponse(ResponseMessage("002", _getEventsSequenceId, +responseMessage.str())); // remove this call... _callMap.erase(id); @@ -311,7 +342,8 @@ GUIServerImpl::displayError (const std::string& error) { std::ostringstream responseMessage; responseMessage << "error: " << error; - _requestManager.sendResponse(ResponseMessage("700", "seq0", responseMessage.str())); + _requestManager.sendResponse(ResponseMessage("700", _getEventsSequenceId, +responseMessage.str())); } void @@ -319,7 +351,8 @@ GUIServerImpl::displayStatus (const std::string& status) { std::ostringstream responseMessage; responseMessage << "status: " + status; - _requestManager.sendResponse(ResponseMessage("700", "seq0", responseMessage.str())); + _requestManager.sendResponse(ResponseMessage("700", _getEventsSequenceId, +responseMessage.str())); } void @@ -342,16 +375,10 @@ GUIServerImpl::setup (void) { } -void -GUIServerImpl::startVoiceMessageNotification (void) -{ - _requestManager.sendResponse(ResponseMessage("020", "seq0", "voice message")); -} - -void -GUIServerImpl::stopVoiceMessageNotification (void) +void +GUIServerImpl::sendVoiceNbMessage(const std::string& nb_msg) { - _requestManager.sendResponse(ResponseMessage("021", "seq0", "no voice message")); + _requestManager.sendResponse(ResponseMessage("020", _getEventsSequenceId, nb_msg)); } void diff --git a/src/gui/server/guiserverimpl.h b/src/gui/server/guiserverimpl.h index 9f8103ad4f4e4e5e3b5c4e31db7dfc082f6158ce..443e072572586a75108042c62809bfeee2ae0400 100644 --- a/src/gui/server/guiserverimpl.h +++ b/src/gui/server/guiserverimpl.h @@ -38,13 +38,6 @@ public: // exec loop int exec(void); - 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); - - // Reimplementation of virtual functions // TODO: remove incomingCall with one parameter int incomingCall (short id); @@ -60,16 +53,21 @@ public: void displayContext (short id); std::string getRingtoneFile (void); void setup (void); - void startVoiceMessageNotification (void); - void stopVoiceMessageNotification (void); + //void startVoiceMessageNotification (void); + //void stopVoiceMessageNotification (void); + void sendVoiceNbMessage(const std::string& nb_msg); - void sendMessage(const std::string& code, const std::string& seqId, TokenList& arg); + 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 ); + bool getEvents(const std::string& sequenceId); + bool sendGetEventsEnd(); + bool outgoingCall (const std::string& seq, const std::string& callid, const std::string& to); @@ -80,6 +78,7 @@ public: bool hangupCall(const std::string& callId); bool dtmfCall(const std::string& callId, const std::string& dtmfKey); bool hangupAll(); + bool getCurrentCallId(std::string& callId); std::string version(); void quit() { _requestManager.quit(); } @@ -88,6 +87,11 @@ public: 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); /** * This callMap is necessary because @@ -100,6 +104,8 @@ private: // RequestManager execute received request // and send response RequestManager _requestManager; + + std::string _getEventsSequenceId; // default is seq0 }; #endif // __GUI_SERVER_H__ diff --git a/src/gui/server/requestconfig.cpp b/src/gui/server/requestconfig.cpp index d43dd42edc579b5fc029aab6fbf5b0614d1d1ad3..5c5dd62d720f708b9a47bdb640923381d86399dd 100644 --- a/src/gui/server/requestconfig.cpp +++ b/src/gui/server/requestconfig.cpp @@ -21,6 +21,13 @@ #include "guiserver.h" #include "subcall.h" +ResponseMessage +RequestGetEvents::execute() +{ + GUIServer::instance().getEvents(_sequenceId); + return message("000", "OK"); +} + ResponseMessage RequestZeroconf::execute() { @@ -44,10 +51,16 @@ RequestZeroconfEvent::execute() ResponseMessage RequestCallStatus::execute() { - if (GUIServer::instance().getCallStatus(_sequenceId)) { - return message("200", "OK"); + GUIServer::instance().sendGetEventsEnd(); + 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); } else { - return message("500","Server Error"); + return message("206","OK"); } } diff --git a/src/gui/server/requestconfig.h b/src/gui/server/requestconfig.h index 62dc65aacd133fcea814ff6c4c9fbb7d5940112f..8566453c2471cb258e5c275aca48d7ba7ad9508d 100644 --- a/src/gui/server/requestconfig.h +++ b/src/gui/server/requestconfig.h @@ -23,6 +23,12 @@ #include "request.h" +class RequestGetEvents : public RequestGlobal { +public: + RequestGetEvents(const std::string &sequenceId, const TokenList& argList) : RequestGlobal(sequenceId,argList) {} + ResponseMessage execute(); +}; + class RequestZeroconf : public RequestGlobal { public: RequestZeroconf(const std::string &sequenceId, const TokenList& argList) : RequestGlobal(sequenceId,argList) {} diff --git a/src/gui/server/requestfactory.cpp b/src/gui/server/requestfactory.cpp index a388eedd279399e5313a24397a9e42a760b0f0c2..51d0954ea7f9e3d27893bc2f26499d2b02796d5a 100644 --- a/src/gui/server/requestfactory.cpp +++ b/src/gui/server/requestfactory.cpp @@ -103,6 +103,7 @@ RequestFactory::registerAll() { registerRequest<RequestQuit> ("quit"); // request config + registerRequest<RequestGetEvents> ("getevents"); registerRequest<RequestZeroconf> ("getzeroconf"); registerRequest<RequestZeroconfEvent>("getzeroconfevents"); registerRequest<RequestCallStatus> ("getcallstatus"); diff --git a/src/gui/server/requestmanager.cpp b/src/gui/server/requestmanager.cpp index 184426548a3fe5253e625a32242e045433eee327..703e0cd94c0407f18a2c43872df7974b17074af5 100644 --- a/src/gui/server/requestmanager.cpp +++ b/src/gui/server/requestmanager.cpp @@ -43,36 +43,49 @@ RequestManager::exec() // waiting for a new connection std::cout << "waiting for a new connection..." << std::endl; - // TCPSessionIO start a thread for the stream socket - _sessionIO = new TCPSessionIO(); - - // wait for the first message - std::cout << "accepting connection..." << std::endl; - - ResponseMessage outputResponse; // TCPStream output line - std::string input; - std::string output; - Request *request; - - _sessionIO->init(); - - // std::cin.good() is only there to close the server when - // we do a CTRL+D - while(_sessionIO && _sessionIO->good() && std::cin.good() && !_quit) { - - if (_sessionIO->receive(input)) { - _debug("Receive Input...: %s\n", input.c_str()); - request = _factory.create(input); - outputResponse = request->execute(); - - _sessionIO->send(outputResponse.toString()); - - handleExecutedRequest(request, outputResponse); - } // end pop - } // end streaming - delete _sessionIO; - _sessionIO = 0; - + while(std::cin.good()) { + + // TCPSessionIO start a thread for the stream socket + { + _sessionMutex.enterMutex(); + _sessionIO = new TCPSessionIO(); + _sessionMutex.leaveMutex(); + } + // wait for the first message + std::cout << "accepting connection..." << std::endl; + + ResponseMessage outputResponse; // TCPStream output line + std::string input; + std::string output; + Request *request; + + _sessionIO->init(); + + // std::cin.good() is only there to close the server when + // we do a CTRL+D + quit = false; + while(_sessionIO && _sessionIO->good() && std::cin.good() && !_quit) { + + if (_sessionIO->receive(input)) { + _debug("Receive Input...: %s\n", input.c_str()); + request = _factory.create(input); + outputResponse = request->execute(); + + _sessionIO->send(outputResponse.toString()); + + handleExecutedRequest(request, outputResponse); + } // end pop + } // end streaming + + { // session mutex block + _sessionMutex.enterMutex(); + delete _sessionIO; + _sessionIO = 0; + _sessionMutex.leaveMutex(); + } + + } // end while + } catch(ost::Socket *e) { std::cerr << e->getErrorString() << std::endl; } @@ -122,10 +135,11 @@ RequestManager::flushWaitingRequest() */ void RequestManager::sendResponse(const ResponseMessage& response) { + _sessionMutex.enterMutex(); if (_sessionIO) { - _debug("Sending output...\n"); _sessionIO->send(response.toString()); } + _sessionMutex.leaveMutex(); // remove the request from the waiting requests list if (response.isFinal()) { diff --git a/src/gui/server/requestmanager.h b/src/gui/server/requestmanager.h index babfb7f91d55cd23bec4ee04fafa486e6079dce9..c20a4db63d856a79c83665dd6cdff67d363d6d5f 100644 --- a/src/gui/server/requestmanager.h +++ b/src/gui/server/requestmanager.h @@ -43,7 +43,8 @@ private: void handleExecutedRequest(Request * const request, const ResponseMessage& response); RequestFactory _factory; - SessionIO* _sessionIO; + SessionIO* _sessionIO; + ost::Mutex _sessionMutex; // waiting requests ost::Mutex _waitingRequestsMutex; diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 31dee12ad4414a059dfb6641cf0ec26bd85d5bf7..16c5582b293611999ba9bf5e5e6335ec241276d7 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -400,6 +400,7 @@ ManagerImpl::answerCall (short id) call->setStatus(string(CONNECTED_STATUS)); call->setState(Answered); ringtone(false); + setCurrentCallId(id); return call->answer(); } @@ -412,7 +413,6 @@ ManagerImpl::onHoldCall (short id) return -1; call->setStatus(string(ONHOLD_STATUS)); call->setState(OnHold); - return call->onHold(); } @@ -425,6 +425,7 @@ ManagerImpl::offHoldCall (short id) return -1; call->setStatus(string(CONNECTED_STATUS)); call->setState(OffHold); + setCurrentCallId(id); return call->offHold(); } @@ -486,6 +487,7 @@ ManagerImpl::refuseCall (short id) _nCalls -= 1; _mutex.leaveMutex(); deleteCall(id); + setCurrentCallId(0); return call->refuse(); } @@ -647,7 +649,6 @@ ManagerImpl::incomingCall (short id) from.append(number); from.append(">"); } - return _gui->incomingCall(id, accountId, from); } @@ -702,6 +703,7 @@ ManagerImpl::peerHungupCall (short id) _nCalls -= 1; _mutex.leaveMutex(); deleteCall(id); + setCurrentCallId(0); return 1; } @@ -762,15 +764,17 @@ ManagerImpl::displayStatus (const string& status) //} // void -ManagerImpl::startVoiceMessageNotification (void) +ManagerImpl::startVoiceMessageNotification (const std::string& nb_msg) { - _gui->startVoiceMessageNotification(); + //_gui->startVoiceMessageNotification(); + _gui->sendVoiceNbMessage(nb_msg); } void ManagerImpl::stopVoiceMessageNotification (void) { - _gui->stopVoiceMessageNotification(); + //_gui->stopVoiceMessageNotification(); + _gui->sendVoiceNbMessage(std::string("0")); } void @@ -1164,7 +1168,6 @@ ManagerImpl::attachZeroconfEvents(const std::string& sequenceId, const Pattern:: bool ManagerImpl::getCallStatus(const std::string& sequenceId) { - bool returnValue = false; // TODO: implement account std::string accountId = "acc1"; if (_gui!=NULL) { @@ -1173,9 +1176,8 @@ ManagerImpl::getCallStatus(const std::string& sequenceId) _gui->sendCallMessage(sequenceId, (*iter)->getId(), accountId, (*iter)->getStatus()); iter++; } - returnValue = true; } - return returnValue; + return true; } bool diff --git a/src/managerimpl.h b/src/managerimpl.h index 99bb464ffbac9f8fc41c328fc90a971709b83cc1..2251b08dc4020ffe03a801e7db3c242c56681d0d 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -190,7 +190,7 @@ public: void displayStatus (const std::string& status); // int selectedCall (void); // bool isCurrentId (short id); - void startVoiceMessageNotification (void); + void startVoiceMessageNotification (const std::string& nb_msg); void stopVoiceMessageNotification (void); // configuration function requests diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index d10f7c240c145c167bf66aec985134d5a5a504fe..7a14441ba0f5121667fb50354041c9d45617ef15 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -809,7 +809,7 @@ SipVoIPLink::getEvent (void) unsigned int pos; unsigned int pos_slash; string *str; - string nb_msg; + std::string nb_msg; osip_body_t *body; // Get the message body @@ -838,7 +838,7 @@ SipVoIPLink::getEvent (void) if (getMsgVoicemail() != 0) { // If there is at least one voice-message, start notification - Manager::instance().startVoiceMessageNotification(); + Manager::instance().startVoiceMessageNotification(nb_msg); } else { // Stop notification when there is 0 voice message Manager::instance().stopVoiceMessageNotification();