Commit 35f48398 authored by Ghislain MARY's avatar Ghislain MARY

Improve check for acceptation handling when receiving an incoming INVITE.

parent d0e48986
......@@ -34,6 +34,7 @@ public:
virtual void onCallSetReleased () = 0;
virtual void onCallSetTerminated () = 0;
virtual void onCallStateChanged (LinphoneCallState state, const std::string &message) = 0;
virtual void onCheckForAcceptation () = 0;
virtual void onIncomingCallStarted () = 0;
virtual void onIncomingCallToBeAdded () = 0;
......
......@@ -60,6 +60,7 @@ private:
void onCallSetReleased () override;
void onCallSetTerminated () override;
void onCallStateChanged (LinphoneCallState state, const std::string &message) override;
void onCheckForAcceptation () override;
void onIncomingCallStarted () override;
void onIncomingCallToBeAdded () override;
void onEncryptionChanged (bool activated, const std::string &authToken) override;
......
......@@ -142,6 +142,27 @@ void CallPrivate::onCallStateChanged (LinphoneCallState state, const string &mes
linphone_call_notify_state_changed(lcall, state, message.c_str());
}
void CallPrivate::onCheckForAcceptation () {
bctbx_list_t *copy = bctbx_list_copy(linphone_core_get_calls(core));
for (bctbx_list_t *it = copy; it != nullptr; it = bctbx_list_next(it)) {
LinphoneCall *call = reinterpret_cast<LinphoneCall *>(bctbx_list_get_data(it));
if (call == lcall) continue;
switch (linphone_call_get_state(call)) {
case LinphoneCallOutgoingInit:
case LinphoneCallOutgoingProgress:
case LinphoneCallOutgoingRinging:
case LinphoneCallOutgoingEarlyMedia:
lInfo() << "Already existing call [" << call << "] in state [" << linphone_call_state_to_string(linphone_call_get_state(call))
<< "], canceling it before accepting new call [" << lcall << "]";
linphone_call_terminate(call);
break;
default:
break; /* Nothing to do */
}
}
bctbx_list_free(copy);
}
void CallPrivate::onIncomingCallStarted () {
if (lcall)
linphone_core_notify_incoming_call(core, lcall);
......
......@@ -107,6 +107,11 @@ void Conference::onCallSessionStateChanged (const CallSession &session, Linphone
callListener->onCallStateChanged(state, message);
}
void Conference::onCheckForAcceptation (const CallSession &session) {
if (callListener)
callListener->onCheckForAcceptation();
}
void Conference::onIncomingCallSessionStarted (const CallSession &session) {
if (callListener)
callListener->onIncomingCallStarted();
......
......@@ -64,6 +64,7 @@ private:
void onCallSessionSetReleased (const CallSession &session) override;
void onCallSessionSetTerminated (const CallSession &session) override;
void onCallSessionStateChanged (const CallSession &session, LinphoneCallState state, const std::string &message) override;
void onCheckForAcceptation (const CallSession &session) override;
void onIncomingCallSessionStarted (const CallSession &session) override;
void onEncryptionChanged (const CallSession &session, bool activated, const std::string &authToken) override;
void onStatsUpdated (const LinphoneCallStats *stats) override;
......
......@@ -33,6 +33,7 @@ public:
virtual void onCallSessionSetReleased (const CallSession &session) = 0;
virtual void onCallSessionSetTerminated (const CallSession &session) = 0;
virtual void onCallSessionStateChanged (const CallSession &session, LinphoneCallState state, const std::string &message) = 0;
virtual void onCheckForAcceptation (const CallSession &session) = 0;
virtual void onIncomingCallSessionStarted (const CallSession &session) = 0;
virtual void onEncryptionChanged (const CallSession &session, bool activated, const std::string &authToken) = 0;
......
......@@ -451,25 +451,8 @@ LinphoneStatus CallSessionPrivate::checkForAcceptation () const {
lError() << "checkForAcceptation() CallSession [" << q << "] is in state [" << linphone_call_state_to_string(state) << "], operation not permitted";
return -1;
}
bctbx_list_t *copy = bctbx_list_copy(linphone_core_get_calls(core));
for (bctbx_list_t *it = copy; it != nullptr; it = bctbx_list_next(it)) {
LinphoneCall *call = reinterpret_cast<LinphoneCall *>(bctbx_list_get_data(it));
shared_ptr<CallSession> session = L_GET_PRIVATE_FROM_C_OBJECT(call)->getActiveSession();
if (session.get() == q) continue;
switch (session->getState()) {
case LinphoneCallOutgoingInit:
case LinphoneCallOutgoingProgress:
case LinphoneCallOutgoingRinging:
case LinphoneCallOutgoingEarlyMedia:
lInfo() << "Already existing CallSession [" << session << "] in state [" << linphone_call_state_to_string(session->getState())
<< "], canceling it before accepting new CallSession [" << q << "]";
session->terminate();
break;
default:
break; /* Nothing to do */
}
}
bctbx_list_free(copy);
if (listener)
listener->onCheckForAcceptation(*q);
/* Check if this call is supposed to replace an already running one */
SalOp *replaced = sal_call_get_replaces(op);
......@@ -822,14 +805,14 @@ void CallSession::startIncomingNotification () {
call->bg_task_id=sal_begin_background_task("liblinphone call notification", NULL, NULL);
#endif
if (d->deferIncomingNotification) {
lInfo() << "Defer ringing";
lInfo() << "Defer incoming notification";
return;
}
if (d->listener)
d->listener->onIncomingCallSessionStarted(*this);
d->setState(LinphoneCallIncomingReceived, "Incoming call");
d->setState(LinphoneCallIncomingReceived, "Incoming CallSession");
/* From now on, the application is aware of the call and supposed to take background task or already submitted notification to the user.
* We can then drop our background task. */
......
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