Commit 733775d1 authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Andreas Traczyk

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