From dda4649fa5a9b6fa986730e372e4d950c0fd373d Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Mon, 7 Jul 2014 17:45:34 -0400 Subject: [PATCH] daemon: move sendTextMessage API to Call class Refs #51555 Change-Id: I9e433dfba59f269973bf40e0f9fad7697ed64803 --- daemon/src/call.h | 11 +++++++ daemon/src/iax/iaxcall.cpp | 13 +++++++++ daemon/src/iax/iaxcall.h | 9 ++++++ daemon/src/iax/iaxvoiplink.cpp | 19 ------------- daemon/src/iax/iaxvoiplink.h | 3 -- daemon/src/managerimpl.cpp | 52 +++++++++++++--------------------- daemon/src/sip/sipcall.cpp | 19 +++++++++++++ daemon/src/sip/sipcall.h | 5 ++++ daemon/src/sip/sipvoiplink.cpp | 20 ------------- daemon/src/sip/sipvoiplink.h | 12 -------- daemon/src/voiplink.h | 13 --------- 11 files changed, 76 insertions(+), 100 deletions(-) diff --git a/daemon/src/call.h b/daemon/src/call.h index cab2800ea3..c0fd2fa689 100644 --- a/daemon/src/call.h +++ b/daemon/src/call.h @@ -289,6 +289,17 @@ class Call : public Recordable { */ virtual void carryingDTMFdigits(char code) = 0; +#if HAVE_INSTANT_MESSAGING + /** + * Send a message to a call identified by its callid + * + * @param The actual message to be transmitted + * @param The sender of this message (could be another participant of a conference) + */ + virtual void sendTextMessage(const std::string &message, + const std::string &from) = 0; +#endif + private: bool validTransition(CallState newState); diff --git a/daemon/src/iax/iaxcall.cpp b/daemon/src/iax/iaxcall.cpp index 76ba156056..3aadb7ca92 100644 --- a/daemon/src/iax/iaxcall.cpp +++ b/daemon/src/iax/iaxcall.cpp @@ -40,6 +40,10 @@ #include "manager.h" #include "iaxvoiplink.h" +#if HAVE_INSTANT_MESSAGING +#include "im/instant_messaging.h" +#endif + static int codecToASTFormat(int c) { @@ -226,3 +230,12 @@ IAXCall::carryingDTMFdigits(char code) std::lock_guard<std::mutex> lock(IAXVoIPLink::mutexIAX); iax_send_dtmf(session, code); } + +#if HAVE_INSTANT_MESSAGING +void +IAXCall::sendTextMessage(const std::string& message, const std::string& /*from*/) +{ + std::lock_guard<std::mutex> lock(IAXVoIPLink::mutexIAX); + sfl::InstantMessaging::send_iax_message(session, getCallId(), message.c_str()); +} +#endif diff --git a/daemon/src/iax/iaxcall.h b/daemon/src/iax/iaxcall.h index 84101fb98a..ffb85b7652 100644 --- a/daemon/src/iax/iaxcall.h +++ b/daemon/src/iax/iaxcall.h @@ -31,6 +31,10 @@ #ifndef IAXCALL_H #define IAXCALL_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "call.h" #include "noncopyable.h" @@ -98,6 +102,11 @@ class IAXCall : public Call { void carryingDTMFdigits(char code); +#if HAVE_INSTANT_MESSAGING + void sendTextMessage(const std::string& message, + const std::string& from); +#endif + private: NON_COPYABLE(IAXCall); diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index 55ad10a23c..8d7f9d7696 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -35,7 +35,6 @@ #include "iaxcall.h" #include "eventthread.h" -#include "im/instant_messaging.h" #include "iaxaccount.h" #include "logger.h" #include "manager.h" @@ -313,24 +312,6 @@ IAXVoIPLink::newOutgoingCall(const std::string& id, const std::string& toUrl, co return call; } -#if HAVE_INSTANT_MESSAGING -void -IAXVoIPLink::sendTextMessage(const std::string& callID, - const std::string& message, - const std::string& /*from*/) -{ - std::lock_guard<std::mutex> lock(iaxCallMapMutex_); - auto call = getIAXCall(callID); - if (!call) - return; - - { - std::lock_guard<std::mutex> lock(mutexIAX); - sfl::InstantMessaging::send_iax_message(call->session, callID, message.c_str()); - } -} -#endif - void IAXVoIPLink::clearIaxCallMap() { diff --git a/daemon/src/iax/iaxvoiplink.h b/daemon/src/iax/iaxvoiplink.h index 6fd8acca27..39c3a03af2 100644 --- a/daemon/src/iax/iaxvoiplink.h +++ b/daemon/src/iax/iaxvoiplink.h @@ -127,9 +127,6 @@ class IAXVoIPLink : public VoIPLink { */ virtual void cancel(const std::string& /*id*/) {} -#if HAVE_INSTANT_MESSAGING - virtual void sendTextMessage(const std::string& callID, const std::string& message, const std::string& from); -#endif static void clearIaxCallMap(); static void addIaxCall(std::shared_ptr<IAXCall>& call); // must be called while holding iaxCallMapMutex diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 909e32e242..4b410ead02 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -1467,18 +1467,14 @@ void ManagerImpl::incomingMessage(const std::string& callID, if (item_p == callID) continue; - std::string accountId(getAccountFromCall(item_p)); + DEBUG("Send message to %s", item_p.c_str()); - DEBUG("Send message to %s, (%s)", item_p.c_str(), accountId.c_str()); - - Account *account = getAccount(accountId); - - if (!account) { - ERROR("Failed to get account while sending instant message"); + if (auto call = getCallFromCallID(item_p)) { + call->sendTextMessage(message, from); + } else { + ERROR("Failed to get call while sending instant message"); return; } - - account->getVoIPLink()->sendTextMessage(callID, message, from); } // in case of a conference we must notify client using conference id @@ -1505,18 +1501,14 @@ bool ManagerImpl::sendTextMessage(const std::string& callID, const std::string& ParticipantSet participants(conf->getParticipantList()); - for (const auto &participant : participants) { - - std::string accountId = getAccountFromCall(participant); + for (const auto &participant_id : participants) { - Account *account = getAccount(accountId); - - if (!account) { - DEBUG("Failed to get account while sending instant message"); + if (auto call = getCallFromCallID(participant_id)) { + call->sendTextMessage(message, from); + } else { + ERROR("Failed to get call while sending instant message"); return false; } - - account->getVoIPLink()->sendTextMessage(participant, message, from); } return true; @@ -1531,28 +1523,22 @@ bool ManagerImpl::sendTextMessage(const std::string& callID, const std::string& ParticipantSet participants(conf->getParticipantList()); - for (const auto &item_p : participants) { + for (const auto &participant_id : participants) { - const std::string accountId(getAccountFromCall(item_p)); - - Account *account = getAccount(accountId); - - if (!account) { - DEBUG("Failed to get account while sending instant message"); + if (auto call = getCallFromCallID(participant_id)) { + call->sendTextMessage(message, from); + } else { + ERROR("Failed to get call while sending instant message"); return false; } - - account->getVoIPLink()->sendTextMessage(item_p, message, from); } } else { - Account *account = getAccount(getAccountFromCall(callID)); - - if (!account) { - DEBUG("Failed to get account while sending instant message"); + if (auto call = getCallFromCallID(callID)) { + call->sendTextMessage(message, from); + } else { + ERROR("Failed to get call while sending instant message"); return false; } - - account->getVoIPLink()->sendTextMessage(callID, message, from); } return true; } diff --git a/daemon/src/sip/sipcall.cpp b/daemon/src/sip/sipcall.cpp index e3a29ba0fb..51c40c0aa0 100644 --- a/daemon/src/sip/sipcall.cpp +++ b/daemon/src/sip/sipcall.cpp @@ -40,6 +40,10 @@ #include "audio/audiortp/audio_rtp_factory.h" // for AudioRtpFactoryException +#if HAVE_INSTANT_MESSAGING +#include "im/instant_messaging.h" +#endif + #ifdef SFL_VIDEO #include "client/videomanager.h" @@ -648,3 +652,18 @@ SIPCall::carryingDTMFdigits(char code) dtmfSend(*this, code, account->getDtmfType()); } + +#if HAVE_INSTANT_MESSAGING +void +SIPCall::sendTextMessage(const std::string &message, const std::string &from) +{ + using namespace sfl::InstantMessaging; + + /* Send IM message */ + UriList list; + UriEntry entry; + entry[sfl::IM_XML_URI] = std::string("\"" + from + "\""); // add double quotes for xml formating + list.push_front(entry); + send_sip_message(inv, getCallId(), appendUriList(message, list)); +} +#endif // HAVE_INSTANT_MESSAGING diff --git a/daemon/src/sip/sipcall.h b/daemon/src/sip/sipcall.h index 9becb5cd0a..076f5bb41a 100644 --- a/daemon/src/sip/sipcall.h +++ b/daemon/src/sip/sipcall.h @@ -132,6 +132,11 @@ class SIPCall : public Call { void carryingDTMFdigits(char code); +#if HAVE_INSTANT_MESSAGING + void sendTextMessage(const std::string& message, + const std::string& from); +#endif + private: // override of Call::createHistoryEntry diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 5d0b91c452..1bdd112603 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -1025,25 +1025,6 @@ stopRtpIfCurrent(const std::string &id, SIPCall &call) } } -#if HAVE_INSTANT_MESSAGING -void SIPVoIPLink::sendTextMessage(const std::string &callID, - const std::string &message, - const std::string &from) -{ - using namespace sfl::InstantMessaging; - auto call = getSipCall(callID); - if (!call) - return; - - /* Send IM message */ - UriList list; - UriEntry entry; - entry[sfl::IM_XML_URI] = std::string("\"" + from + "\""); // add double quotes for xml formating - list.push_front(entry); - send_sip_message(call->inv, callID, appendUriList(message, list)); -} -#endif // HAVE_INSTANT_MESSAGING - void SIPVoIPLink::clearSipCallMap() { @@ -1051,7 +1032,6 @@ SIPVoIPLink::clearSipCallMap() sipCallMap_.clear(); } - std::vector<std::string> SIPVoIPLink::getCallIDs() { diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index 4af99f6e2c..09d64f457f 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -187,18 +187,6 @@ class SIPVoIPLink : public VoIPLink { */ std::string getUseragentName(SIPAccount *) const; - /** - * Send a SIP message to a call identified by its callid - * - * @param The Id of the call to send the message to - * @param The actual message to be transmitted - * @param The sender of this message (could be another participant of a conference) - */ -#if HAVE_INSTANT_MESSAGING - void sendTextMessage(const std::string& callID, - const std::string& message, - const std::string& from); -#endif void clearSipCallMap(); void addSipCall(std::shared_ptr<SIPCall>& call); diff --git a/daemon/src/voiplink.h b/daemon/src/voiplink.h index 248e187a75..627779bc34 100644 --- a/daemon/src/voiplink.h +++ b/daemon/src/voiplink.h @@ -93,19 +93,6 @@ class VoIPLink { */ virtual std::vector<std::shared_ptr<Call> > getCalls(const std::string &account_id) const = 0; - /** - * Send a message to a call identified by its callid - * - * @param The Id of the call to send the message to - * @param The actual message to be transmitted - * @param The sender of this message (could be another participant of a conference) - */ -#if HAVE_INSTANT_MESSAGING - virtual void sendTextMessage(const std::string &callID, - const std::string &message, - const std::string &from) = 0; -#endif - protected: static void unloadAccount(std::pair<const std::string, Account*> &item); bool handlingEvents_; -- GitLab