Skip to content
Snippets Groups Projects
Commit 733775d1 authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Andreas Traczyk
Browse files

manager: split detachParticipant method


move the code dedicated to local participant
(i.e. callId = DEFAULT_ID), into the dedicated method
detachLocalParticipant.
This decreases the cyclomatic complexity and
make a more clear distinction on both methods usage.

Change-Id: I5f76f60a8e8b776b8c16ad1f438a0f77e42fc0fb
Reviewed-by: default avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 96262044
No related branches found
No related tags found
No related merge requests found
...@@ -242,6 +242,16 @@ ...@@ -242,6 +242,16 @@
<arg type="b" name="addSucceeded" direction="out"/> <arg type="b" name="addSucceeded" direction="out"/>
</method> </method>
<method name="detachLocalParticipant" tp:name-for-bindings="detachLocalParticipant">
<tp:added version="3.0.0"/>
<tp:docstring>
Detach local participant from the conference.
Remote participants are placed in hold.
The signal <tp:member-ref>conferenceChanged</tp:member-ref> is emited.
</tp:docstring>
<arg type="b" name="detachSucceeded" direction="out"/>
</method>
<method name="detachParticipant" tp:name-for-bindings="detachParticipant"> <method name="detachParticipant" tp:name-for-bindings="detachParticipant">
<tp:added version="0.9.7"/> <tp:added version="0.9.7"/>
<tp:docstring> <tp:docstring>
......
...@@ -128,6 +128,12 @@ DBusCallManager::addMainParticipant(const std::string& confID) -> decltype(DRing ...@@ -128,6 +128,12 @@ DBusCallManager::addMainParticipant(const std::string& confID) -> decltype(DRing
return DRing::addMainParticipant(confID); return DRing::addMainParticipant(confID);
} }
auto
DBusCallManager::detachLocalParticipant() -> decltype(DRing::detachLocalParticipant())
{
return DRing::detachLocalParticipant();
}
auto auto
DBusCallManager::detachParticipant(const std::string& callID) -> decltype(DRing::detachParticipant(callID)) DBusCallManager::detachParticipant(const std::string& callID) -> decltype(DRing::detachParticipant(callID))
{ {
......
...@@ -71,6 +71,7 @@ class DBusCallManager : ...@@ -71,6 +71,7 @@ class DBusCallManager :
bool isConferenceParticipant(const std::string& call_id); bool isConferenceParticipant(const std::string& call_id);
bool addParticipant(const std::string& callID, const std::string& confID); bool addParticipant(const std::string& callID, const std::string& confID);
bool addMainParticipant(const std::string& confID); bool addMainParticipant(const std::string& confID);
bool detachLocalParticipant();
bool detachParticipant(const std::string& callID); bool detachParticipant(const std::string& callID);
bool joinConference(const std::string& sel_confID, const std::string& drag_confID); bool joinConference(const std::string& sel_confID, const std::string& drag_confID);
bool hangUpConference(const std::string& confID); bool hangUpConference(const std::string& confID);
......
...@@ -168,6 +168,12 @@ addMainParticipant(const std::string& confID) ...@@ -168,6 +168,12 @@ addMainParticipant(const std::string& confID)
return ring::Manager::instance().addMainParticipant(confID); return ring::Manager::instance().addMainParticipant(confID);
} }
bool
detachLocalParticipant()
{
return ring::Manager::instance().detachLocalParticipant();
}
bool bool
detachParticipant(const std::string& callID) detachParticipant(const std::string& callID)
{ {
......
...@@ -56,6 +56,7 @@ void createConfFromParticipantList(const std::vector<std::string>& participants) ...@@ -56,6 +56,7 @@ void createConfFromParticipantList(const std::vector<std::string>& participants)
bool isConferenceParticipant(const std::string& call_id); bool isConferenceParticipant(const std::string& call_id);
bool addParticipant(const std::string& callID, const std::string& confID); bool addParticipant(const std::string& callID, const std::string& confID);
bool addMainParticipant(const std::string& confID); bool addMainParticipant(const std::string& confID);
bool detachLocalParticipant();
bool detachParticipant(const std::string& callID); bool detachParticipant(const std::string& callID);
bool joinConference(const std::string& sel_confID, const std::string& drag_confID); bool joinConference(const std::string& sel_confID, const std::string& drag_confID);
bool hangUpConference(const std::string& confID); bool hangUpConference(const std::string& confID);
......
...@@ -509,7 +509,7 @@ Manager::outgoingCall(const std::string& preferred_account_id, ...@@ -509,7 +509,7 @@ Manager::outgoingCall(const std::string& preferred_account_id,
if (not isConference(current_call_id) and not isConferenceParticipant(current_call_id)) if (not isConference(current_call_id) and not isConferenceParticipant(current_call_id))
onHoldCall(current_call_id); onHoldCall(current_call_id);
else if (isConference(current_call_id) and not isConferenceParticipant(call_id)) else if (isConference(current_call_id) and not isConferenceParticipant(call_id))
detachParticipant(RingBufferPool::DEFAULT_ID); detachLocalParticipant();
} }
switchCall(call); switchCall(call);
...@@ -547,7 +547,7 @@ Manager::answerCall(const std::string& call_id) ...@@ -547,7 +547,7 @@ Manager::answerCall(const std::string& call_id)
} else if (isConference(current_call_id) and not isConferenceParticipant(call_id)) { } else if (isConference(current_call_id) and not isConferenceParticipant(call_id)) {
// if we are talking to a conference and we are answering an incoming call // if we are talking to a conference and we are answering an incoming call
RING_DBG("Detach main participant from conference"); RING_DBG("Detach main participant from conference");
detachParticipant(RingBufferPool::DEFAULT_ID); detachLocalParticipant();
} }
} }
...@@ -706,7 +706,7 @@ Manager::offHoldCall(const std::string& callId) ...@@ -706,7 +706,7 @@ Manager::offHoldCall(const std::string& callId)
onHoldCall(currentCallId); onHoldCall(currentCallId);
} else if (isConference(currentCallId) and not isConferenceParticipant(callId)) { } else if (isConference(currentCallId) and not isConferenceParticipant(callId)) {
holdConference(currentCallId); holdConference(currentCallId);
detachParticipant(RingBufferPool::DEFAULT_ID); detachLocalParticipant();
} }
} }
...@@ -971,7 +971,7 @@ Manager::addParticipant(const std::string& callId, ...@@ -971,7 +971,7 @@ Manager::addParticipant(const std::string& callId,
// detach from prior communication and switch to this conference // detach from prior communication and switch to this conference
if (current_call_id != callId) { if (current_call_id != callId) {
if (isConference(current_call_id)) if (isConference(current_call_id))
detachParticipant(RingBufferPool::DEFAULT_ID); detachLocalParticipant();
else else
onHoldCall(current_call_id); onHoldCall(current_call_id);
} }
...@@ -1022,7 +1022,7 @@ Manager::addMainParticipant(const std::string& conference_id) ...@@ -1022,7 +1022,7 @@ Manager::addMainParticipant(const std::string& conference_id)
std::string current_call_id(getCurrentCallId()); std::string current_call_id(getCurrentCallId());
if (isConference(current_call_id)) if (isConference(current_call_id))
detachParticipant(RingBufferPool::DEFAULT_ID); detachLocalParticipant();
else else
onHoldCall(current_call_id); onHoldCall(current_call_id);
} }
...@@ -1127,7 +1127,7 @@ Manager::joinParticipant(const std::string& callId1, const std::string& callId2) ...@@ -1127,7 +1127,7 @@ Manager::joinParticipant(const std::string& callId1, const std::string& callId2)
auto current_call_id = getCurrentCallId(); auto current_call_id = getCurrentCallId();
if ((current_call_id != callId1) and (current_call_id != callId2)) { if ((current_call_id != callId1) and (current_call_id != callId2)) {
if (isConference(current_call_id)) if (isConference(current_call_id))
detachParticipant(RingBufferPool::DEFAULT_ID); detachLocalParticipant();
else else
onHoldCall(current_call_id); // currently in a call onHoldCall(current_call_id); // currently in a call
} }
...@@ -1191,67 +1191,63 @@ Manager::createConfFromParticipantList(const std::vector< std::string > &partici ...@@ -1191,67 +1191,63 @@ Manager::createConfFromParticipantList(const std::vector< std::string > &partici
} }
bool bool
Manager::detachParticipant(const std::string& call_id) Manager::detachLocalParticipant()
{ {
const std::string current_call_id(getCurrentCallId()); RING_DBG("Unbind local participant from conference");
const auto& current_call_id = getCurrentCallId();
if (call_id != RingBufferPool::DEFAULT_ID) { if (not isConference(current_call_id)) {
auto call = getCallFromCallID(call_id); RING_ERR("Current call id (%s) is not a conference", current_call_id.c_str());
if (!call) {
RING_ERR("Could not find call %s", call_id.c_str());
return false; return false;
} }
auto conf = getConferenceFromCallID(call_id); auto iter = conferenceMap_.find(current_call_id);
if (iter == conferenceMap_.end() or iter->second == nullptr) {
if (conf == nullptr) { RING_ERR("Conference is NULL");
RING_ERR("Call is not conferencing, cannot detach");
return false; return false;
} }
std::map<std::string, std::string> call_details(getCallDetails(call_id)); getRingBufferPool().unBindAll(RingBufferPool::DEFAULT_ID);
std::map<std::string, std::string>::iterator iter_details(call_details.find("CALL_STATE"));
if (iter_details == call_details.end()) { auto conf = iter->second;
RING_ERR("Could not find CALL_STATE"); switch (conf->getState()) {
return false; case Conference::ACTIVE_ATTACHED:
conf->setState(Conference::ACTIVE_DETACHED);
break;
case Conference::ACTIVE_ATTACHED_REC:
conf->setState(Conference::ACTIVE_DETACHED_REC);
break;
default:
RING_WARN("Undefined behavior, invalid conference state in detach participant");
} }
// Don't hold ringing calls when detaching them from conferences emitSignal<DRing::CallSignal::ConferenceChanged>(conf->getConfID(), conf->getStateStr());
if (iter_details->second != "RINGING")
onHoldCall(call_id);
removeParticipant(call_id); unsetCurrentCall();
}
} else { bool
RING_DBG("Unbind main participant from conference"); Manager::detachParticipant(const std::string& call_id)
getRingBufferPool().unBindAll(RingBufferPool::DEFAULT_ID); {
RING_DBG("Detach participant %s", call_id.c_str());
if (not isConference(current_call_id)) { auto call = getCallFromCallID(call_id);
RING_ERR("Current call id (%s) is not a conference", current_call_id.c_str()); if (!call) {
RING_ERR("Could not find call %s", call_id.c_str());
return false; return false;
} }
ConferenceMap::iterator iter = conferenceMap_.find(current_call_id); auto conf = getConferenceFromCallID(call_id);
if (!conf) {
auto conf = iter->second; RING_ERR("Call is not conferencing, cannot detach");
if (iter == conferenceMap_.end() or conf == 0) {
RING_DBG("Conference is NULL");
return false; return false;
} }
if (conf->getState() == Conference::ACTIVE_ATTACHED) // Don't hold ringing calls when detaching them from conferences
conf->setState(Conference::ACTIVE_DETACHED); if (call->getStateStr() != "RINGING")
else if (conf->getState() == Conference::ACTIVE_ATTACHED_REC) onHoldCall(call_id);
conf->setState(Conference::ACTIVE_DETACHED_REC);
else
RING_WARN("Undefined behavior, invalid conference state in detach participant");
emitSignal<DRing::CallSignal::ConferenceChanged>(conf->getConfID(), conf->getStateStr());
unsetCurrentCall();
}
removeParticipant(call_id);
return true; return true;
} }
......
...@@ -308,6 +308,12 @@ class Manager { ...@@ -308,6 +308,12 @@ class Manager {
*/ */
bool detachParticipant(const std::string& call_id); bool detachParticipant(const std::string& call_id);
/**
* Detach the local participant from curent conference.
* Remote participants are placed in hold.
*/
bool detachLocalParticipant();
/** /**
* Remove the conference participant from a conference * Remove the conference participant from a conference
* @param call id * @param call id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment