Commit f37418c8 authored by Ghislain MARY's avatar Ghislain MARY

Improve API lock.

parent b5928987
......@@ -2,6 +2,28 @@
#include "Utils.h"
#ifdef TRACE_LOCKS
#define API_LOCK \
{ \
char *s = ms_strdup_printf("### Locking in %s\r\n", __FUNCTION__); \
OutputDebugStringA(s); \
ms_free(s); \
} \
Linphone::Core::gApiLock.Lock()
#define API_UNLOCK \
{ \
char *s = ms_strdup_printf("### Unlocking in %s\r\n", __FUNCTION__); \
OutputDebugStringA(s); \
ms_free(s); \
} \
Linphone::Core::gApiLock.Unlock()
#else
#define API_LOCK Linphone::Core::gApiLock.Lock()
#define API_UNLOCK Linphone::Core::gApiLock.Unlock()
#endif
namespace Linphone
{
namespace Core
......
......@@ -13,7 +13,7 @@ using namespace Windows::Phone::Networking::Voip;
VoipPhoneCall^ CallController::OnIncomingCallReceived(Linphone::Core::LinphoneCall^ call, Platform::String^ contactName, Platform::String^ contactNumber, IncomingCallViewDismissedCallback^ incomingCallViewDismissedCallback)
{
TRACE; gApiLock.Lock();
API_LOCK;
VoipPhoneCall^ incomingCall = nullptr;
this->call = call;
......@@ -56,7 +56,7 @@ VoipPhoneCall^ CallController::OnIncomingCallReceived(Linphone::Core::LinphoneCa
&incomingCall);
}
catch(...) {
gApiLock.Unlock();
API_UNLOCK;
return nullptr;
}
......@@ -67,13 +67,13 @@ VoipPhoneCall^ CallController::OnIncomingCallReceived(Linphone::Core::LinphoneCa
// StreamsRunning state by calling NewIncomingCallForCustomIncomingCallView()
}
gApiLock.Unlock();
API_UNLOCK;
return incomingCall;
}
void CallController::OnAcceptCallRequested(VoipPhoneCall^ incomingCall, CallAnswerEventArgs^ args)
{
TRACE; gApiLock.Lock();
API_LOCK;
incomingCall->NotifyCallActive();
......@@ -96,12 +96,12 @@ void CallController::OnAcceptCallRequested(VoipPhoneCall^ incomingCall, CallAnsw
#endif
}
gApiLock.Unlock();
API_UNLOCK;
}
void CallController::OnRejectCallRequested(VoipPhoneCall^ incomingCall, CallRejectEventArgs^ args)
{
TRACE; gApiLock.Lock();
API_LOCK;
if (this->onIncomingCallViewDismissed != nullptr) {
this->onIncomingCallViewDismissed();
......@@ -112,12 +112,12 @@ void CallController::OnRejectCallRequested(VoipPhoneCall^ incomingCall, CallReje
if (this->call != nullptr)
Globals::Instance->LinphoneCore->DeclineCall(this->call, this->declineReason);
gApiLock.Unlock();
API_UNLOCK;
}
VoipPhoneCall^ CallController::NewOutgoingCall(Platform::String^ number)
{
TRACE; gApiLock.Lock();
API_LOCK;
VoipPhoneCall^ outgoingCall = nullptr;
this->call = call;
......@@ -139,7 +139,7 @@ VoipPhoneCall^ CallController::NewOutgoingCall(Platform::String^ number)
outgoingCall->NotifyCallActive();
gApiLock.Unlock();
API_UNLOCK;
return outgoingCall;
}
......@@ -168,47 +168,47 @@ void CallController::NotifyMute(bool isMuted)
IncomingCallViewDismissedCallback^ CallController::IncomingCallViewDismissed::get()
{
TRACE; gApiLock.Lock();
API_LOCK;
IncomingCallViewDismissedCallback^ cb = this->onIncomingCallViewDismissed;
gApiLock.Unlock();
API_UNLOCK;
return cb;
}
void CallController::IncomingCallViewDismissed::set(IncomingCallViewDismissedCallback^ cb)
{
TRACE; gApiLock.Lock();
API_LOCK;
this->onIncomingCallViewDismissed = cb;
gApiLock.Unlock();
API_UNLOCK;
}
Platform::Boolean CallController::CustomIncomingCallView::get()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::Boolean value = this->customIncomingCallView;
gApiLock.Unlock();
API_UNLOCK;
return value;
}
void CallController::CustomIncomingCallView::set(Platform::Boolean value)
{
TRACE; gApiLock.Lock();
API_LOCK;
this->customIncomingCallView = value;
gApiLock.Unlock();
API_UNLOCK;
}
Reason CallController::DeclineReason::get()
{
TRACE; gApiLock.Lock();
API_LOCK;
Linphone::Core::Reason value = this->declineReason;
gApiLock.Unlock();
API_UNLOCK;
return value;
}
void CallController::DeclineReason::set(Linphone::Core::Reason value)
{
TRACE; gApiLock.Lock();
API_LOCK;
this->declineReason = value;
gApiLock.Unlock();
API_UNLOCK;
}
CallController::CallController() :
......
......@@ -25,7 +25,7 @@ Globals^ Globals::singleton = nullptr;
void Globals::StartServer(const Platform::Array<Platform::String^>^ outOfProcServerClassNames)
{
// Make sure only one API call is in progress at a time
TRACE; gApiLock.Lock();
API_LOCK;
std::unique_ptr<PFNGETACTIVATIONFACTORY[]> activationFactoryCallbacks;
std::unique_ptr<HSTRING[]> hOutOfProcServerClassNames;
......@@ -38,7 +38,7 @@ void Globals::StartServer(const Platform::Array<Platform::String^>^ outOfProcSer
if (this->started)
{
gApiLock.Unlock();
API_UNLOCK;
return; // Nothing more to be done
}
......@@ -83,7 +83,7 @@ void Globals::StartServer(const Platform::Array<Platform::String^>^ outOfProcSer
}
this->started = true;
gApiLock.Unlock();
API_UNLOCK;
}
unsigned int Globals::GetCurrentProcessId()
......@@ -116,7 +116,7 @@ Globals^ Globals::Instance::get()
if (Globals::singleton == nullptr)
{
// Make sure only one API call is in progress at a time
TRACE; gApiLock.Lock();
API_LOCK;
if (Globals::singleton == nullptr)
{
......@@ -124,7 +124,7 @@ Globals^ Globals::Instance::get()
}
// else: some other thread has created an instance of the call controller
gApiLock.Unlock();
API_UNLOCK;
}
return Globals::singleton;
......@@ -135,14 +135,14 @@ LinphoneCoreFactory^ Globals::LinphoneCoreFactory::get()
if (this->linphoneCoreFactory == nullptr)
{
// Make sure only one API call is in progress at a time
TRACE; gApiLock.Lock();
API_LOCK;
if (this->linphoneCoreFactory == nullptr)
{
this->linphoneCoreFactory = ref new Linphone::Core::LinphoneCoreFactory();
}
gApiLock.Unlock();
API_UNLOCK;
}
return this->linphoneCoreFactory;
......@@ -158,7 +158,7 @@ Linphone::Core::CallController^ Globals::CallController::get()
if (this->callController == nullptr)
{
// Make sure only one API call is in progress at a time
TRACE; gApiLock.Lock();
API_LOCK;
if (this->callController == nullptr)
{
......@@ -166,7 +166,7 @@ Linphone::Core::CallController^ Globals::CallController::get()
}
// else: some other thread has created an instance of the call controller
gApiLock.Unlock();
API_UNLOCK;
}
return this->callController;
......@@ -177,14 +177,14 @@ Linphone::Core::BackgroundModeLogger^ Globals::BackgroundModeLogger::get()
if (this->backgroundModeLogger == nullptr)
{
// Make sure only one API call is in progress at a time
TRACE; gApiLock.Lock();
API_LOCK;
if (this->backgroundModeLogger == nullptr)
{
this->backgroundModeLogger = ref new Linphone::Core::BackgroundModeLogger();
}
gApiLock.Unlock();
API_UNLOCK;
}
return this->backgroundModeLogger;
......@@ -197,9 +197,9 @@ Mediastreamer2::WP8Video::IVideoRenderer^ Globals::VideoRenderer::get()
void Globals::VideoRenderer::set(Mediastreamer2::WP8Video::IVideoRenderer^ value)
{
TRACE; gApiLock.Lock();
API_LOCK;
this->videoRenderer = value;
gApiLock.Unlock();
API_UNLOCK;
}
Globals::Globals() :
......
......@@ -4,92 +4,92 @@
Platform::String^ Linphone::Core::LinphoneAuthInfo::GetUsername()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::String^ username = Utils::cctops(linphone_auth_info_get_username(this->auth_info));
gApiLock.Unlock();
API_UNLOCK;
return username;
}
void Linphone::Core::LinphoneAuthInfo::SetUsername(Platform::String^ username)
{
TRACE; gApiLock.Lock();
API_LOCK;
const char *cc = Linphone::Core::Utils::pstoccs(username);
linphone_auth_info_set_username(this->auth_info, cc);
delete(cc);
gApiLock.Unlock();
API_UNLOCK;
}
Platform::String^ Linphone::Core::LinphoneAuthInfo::GetUserId()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::String^ userid = Utils::cctops(linphone_auth_info_get_userid(this->auth_info));
gApiLock.Unlock();
API_UNLOCK;
return userid;
}
void Linphone::Core::LinphoneAuthInfo::SetUserId(Platform::String^ userid)
{
TRACE; gApiLock.Lock();
API_LOCK;
const char *cc = Linphone::Core::Utils::pstoccs(userid);
linphone_auth_info_set_userid(this->auth_info, cc);
delete(cc);
gApiLock.Unlock();
API_UNLOCK;
}
Platform::String^ Linphone::Core::LinphoneAuthInfo::GetPassword()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::String^ password = Utils::cctops(linphone_auth_info_get_passwd(this->auth_info));
gApiLock.Unlock();
API_UNLOCK;
return password;
}
void Linphone::Core::LinphoneAuthInfo::SetPassword(Platform::String^ password)
{
TRACE; gApiLock.Lock();
API_LOCK;
const char *cc = Linphone::Core::Utils::pstoccs(password);
linphone_auth_info_set_passwd(this->auth_info, cc);
delete(cc);
gApiLock.Unlock();
API_UNLOCK;
}
Platform::String^ Linphone::Core::LinphoneAuthInfo::GetRealm()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::String^ realm = Utils::cctops(linphone_auth_info_get_realm(this->auth_info));
gApiLock.Unlock();
API_UNLOCK;
return realm;
}
void Linphone::Core::LinphoneAuthInfo::SetRealm(Platform::String^ realm)
{
TRACE; gApiLock.Lock();
API_LOCK;
const char *cc = Linphone::Core::Utils::pstoccs(realm);
linphone_auth_info_set_realm(this->auth_info, cc);
delete(cc);
gApiLock.Unlock();
API_UNLOCK;
}
Platform::String^ Linphone::Core::LinphoneAuthInfo::GetHa1()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::String^ ha1 = Utils::cctops(linphone_auth_info_get_ha1(this->auth_info));
gApiLock.Unlock();
API_UNLOCK;
return ha1;
}
void Linphone::Core::LinphoneAuthInfo::SetHa1(Platform::String^ ha1)
{
TRACE; gApiLock.Lock();
API_LOCK;
const char *cc = Linphone::Core::Utils::pstoccs(ha1);
linphone_auth_info_set_ha1(this->auth_info, cc);
delete(cc);
gApiLock.Unlock();
API_UNLOCK;
}
Linphone::Core::LinphoneAuthInfo::LinphoneAuthInfo(Platform::String^ username, Platform::String^ userid, Platform::String^ password, Platform::String^ ha1, Platform::String^ realm, Platform::String^ domain)
{
TRACE; gApiLock.Lock();
API_LOCK;
const char* cc_username = Utils::pstoccs(username);
const char* cc_password = Utils::pstoccs(password);
const char* cc_realm = Utils::pstoccs(realm);
......@@ -103,7 +103,7 @@ Linphone::Core::LinphoneAuthInfo::LinphoneAuthInfo(Platform::String^ username, P
delete(cc_ha1);
delete(cc_realm);
delete(cc_domain);
gApiLock.Unlock();
API_UNLOCK;
}
Linphone::Core::LinphoneAuthInfo::LinphoneAuthInfo(::LinphoneAuthInfo *auth_info) :
......
......@@ -12,246 +12,246 @@ using namespace Windows::Phone::Networking::Voip;
Linphone::Core::LinphoneCallState Linphone::Core::LinphoneCall::GetState()
{
TRACE; gApiLock.Lock();
API_LOCK;
Linphone::Core::LinphoneCallState state = (Linphone::Core::LinphoneCallState)linphone_call_get_state(this->call);
gApiLock.Unlock();
API_UNLOCK;
return state;
}
Linphone::Core::LinphoneAddress^ Linphone::Core::LinphoneCall::GetRemoteAddress()
{
TRACE; gApiLock.Lock();
API_LOCK;
const ::LinphoneAddress *addr = linphone_call_get_remote_address(this->call);
Linphone::Core::LinphoneAddress^ address = (Linphone::Core::LinphoneAddress^)Linphone::Core::Utils::CreateLinphoneAddress((void*)addr);
gApiLock.Unlock();
API_UNLOCK;
return address;
}
Linphone::Core::CallDirection Linphone::Core::LinphoneCall::GetDirection()
{
TRACE; gApiLock.Lock();
API_LOCK;
Linphone::Core::CallDirection direction = (Linphone::Core::CallDirection)linphone_call_get_dir(this->call);
gApiLock.Unlock();
API_UNLOCK;
return direction;
}
Linphone::Core::LinphoneCallLog^ Linphone::Core::LinphoneCall::GetCallLog()
{
TRACE; gApiLock.Lock();
API_LOCK;
Linphone::Core::LinphoneCallLog^ log = (Linphone::Core::LinphoneCallLog^) Linphone::Core::Utils::CreateLinphoneCallLog(linphone_call_get_call_log(this->call));
gApiLock.Unlock();
API_UNLOCK;
return log;
}
Linphone::Core::LinphoneCallStats^ Linphone::Core::LinphoneCall::GetAudioStats()
{
TRACE; gApiLock.Lock();
API_LOCK;
Linphone::Core::LinphoneCallStats^ stats = (Linphone::Core::LinphoneCallStats^) Linphone::Core::Utils::CreateLinphoneCallStats(this->call, (int)Linphone::Core::MediaType::Audio);
gApiLock.Unlock();
API_UNLOCK;
return stats;
}
Linphone::Core::LinphoneCallParams^ Linphone::Core::LinphoneCall::GetRemoteParams()
{
TRACE; gApiLock.Lock();
API_LOCK;
Linphone::Core::LinphoneCallParams^ params = nullptr;
if (linphone_call_get_remote_params(this->call) != nullptr) {
params = (Linphone::Core::LinphoneCallParams^) Linphone::Core::Utils::CreateLinphoneCallParams(linphone_call_params_copy(linphone_call_get_remote_params(this->call)));
}
gApiLock.Unlock();
API_UNLOCK;
return params;
}
Linphone::Core::LinphoneCallParams^ Linphone::Core::LinphoneCall::GetCurrentParamsCopy()
{
TRACE; gApiLock.Lock();
API_LOCK;
Linphone::Core::LinphoneCallParams^ params = (Linphone::Core::LinphoneCallParams^) Linphone::Core::Utils::CreateLinphoneCallParams(linphone_call_params_copy(linphone_call_get_current_params(this->call)));
gApiLock.Unlock();
API_UNLOCK;
return params;
}
void Linphone::Core::LinphoneCall::EnableEchoCancellation(Platform::Boolean enable)
{
TRACE; gApiLock.Lock();
API_LOCK;
linphone_call_enable_echo_cancellation(this->call, enable);
gApiLock.Unlock();
API_UNLOCK;
}
Platform::Boolean Linphone::Core::LinphoneCall::IsEchoCancellationEnabled()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::Boolean enabled = (linphone_call_echo_cancellation_enabled(this->call) == TRUE);
gApiLock.Unlock();
API_UNLOCK;
return enabled;
}
void Linphone::Core::LinphoneCall::EnableEchoLimiter(Platform::Boolean enable)
{
TRACE; gApiLock.Lock();
API_LOCK;
linphone_call_enable_echo_limiter(this->call, enable);
gApiLock.Unlock();
API_UNLOCK;
}
Platform::Boolean Linphone::Core::LinphoneCall::IsEchoLimiterEnabled()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::Boolean enabled = (linphone_call_echo_limiter_enabled(this->call) == TRUE);
gApiLock.Unlock();
API_UNLOCK;
return enabled;
}
int Linphone::Core::LinphoneCall::GetDuration()
{
TRACE; gApiLock.Lock();
API_LOCK;
int duration = linphone_call_get_duration(this->call);
gApiLock.Unlock();
API_UNLOCK;
return duration;
}
float Linphone::Core::LinphoneCall::GetCurrentQuality()
{
TRACE; gApiLock.Lock();
API_LOCK;
float quality = linphone_call_get_current_quality(this->call);
gApiLock.Unlock();
API_UNLOCK;
return quality;
}
float Linphone::Core::LinphoneCall::GetAverageQuality()
{
TRACE; gApiLock.Lock();
API_LOCK;
float quality = linphone_call_get_average_quality(this->call);
gApiLock.Unlock();
API_UNLOCK;
return quality;
}
Platform::String^ Linphone::Core::LinphoneCall::GetAuthenticationToken()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::String^ token = Linphone::Core::Utils::cctops(linphone_call_get_authentication_token(this->call));
gApiLock.Unlock();
API_UNLOCK;
return token;
}
Platform::Boolean Linphone::Core::LinphoneCall::IsAuthenticationTokenVerified()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::Boolean verified = (linphone_call_get_authentication_token_verified(this->call) == TRUE);
gApiLock.Unlock();
API_UNLOCK;
return verified;
}
void Linphone::Core::LinphoneCall::SetAuthenticationTokenVerified(Platform::Boolean verified)
{
TRACE; gApiLock.Lock();
API_LOCK;
linphone_call_set_authentication_token_verified(this->call, verified);
gApiLock.Unlock();
API_UNLOCK;
}
Platform::Boolean Linphone::Core::LinphoneCall::IsInConference()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::Boolean inConference = (linphone_call_is_in_conference(this->call) == TRUE);
gApiLock.Unlock();
API_UNLOCK;
return inConference;
}
float Linphone::Core::LinphoneCall::GetPlayVolume()
{
TRACE; gApiLock.Lock();
API_LOCK;
float volume = linphone_call_get_play_volume(this->call);
gApiLock.Unlock();
API_UNLOCK;
return volume;
}
Platform::String^ Linphone::Core::LinphoneCall::GetRemoteUserAgent()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::String^ userAgent = Linphone::Core::Utils::cctops(linphone_call_get_remote_user_agent(this->call));
gApiLock.Unlock();
API_UNLOCK;
return userAgent;
}
Platform::String^ Linphone::Core::LinphoneCall::GetRemoteContact()
{
TRACE; gApiLock.Lock();
API_LOCK;
Platform::String^ contact = Linphone::Core::Utils::cctops(linphone_call_get_remote_contact(this->call));
gApiLock.Unlock();
API_UNLOCK;
return contact;
}
void Linphone::Core::LinphoneCall::CallContext::set(Windows::Phone::Networking::Voip::VoipPhoneCall^ cc)
{
this->callContext = cc;
}
Platform::Object^ Linphone::Core::LinphoneCall::GetCallStartTimeFromContext()
{
Platform::Object^ result = nullptr;
try {
if (this->callContext != nullptr) {
result = this->callContext->StartTime;
}
}
catch (Platform::COMException^ ex) {
}
return result;
}
Platform::Boolean Linphone::Core::LinphoneCall::IsCameraEnabled()
void Linphone::Core::LinphoneCall::CallContext::set(Windows::Phone::Networking::Voip::VoipPhoneCall^ cc)
{
TRACE; gApiLock.Lock();
Platform::Boolean enabled = (linphone_call_camera_enabled(this->call) == TRUE);
gApiLock.Unlock();
return enabled;
}
void Linphone::Core::LinphoneCall::EnableCamera(Platform::Boolean enable)
this->callContext = cc;
}
Platform::Object^ Linphone::Core::LinphoneCall::GetCallStartTimeFromContext()
{
Platform::Object^ result = nullptr;
try {
if (this->callContext != nullptr) {
result = this->callContext->StartTime;
}
}
catch (Platform::COMException^ ex) {
}
return result;
}
Platform::Boolean Linphone::Core::LinphoneCall::IsCameraEnabled()
{
API_LOCK;
Platform::Boolean enabled = (linphone_call_camera_enabled(this->call) == TRUE);
API_UNLOCK;
return enabled;
}
void Linphone::Core::LinphoneCall::EnableCamera(Platform::Boolean enable)
{
TRACE; gApiLock.Lock();
linphone_call_enable_camera(this->call, enable);
gApiLock.Unlock();
}
API_LOCK;
linphone_call_enable_camera(this->call, enable);
API_UNLOCK;
}
Linphone::Core::LinphoneCallStats^ Linphone::Core::LinphoneCall::GetVideoStats()
{
TRACE; gApiLock.Lock();
API_LOCK;
Linphone::Core::LinphoneCallStats^ stats = (Linphone::Core::LinphoneCallStats^) Linphone::Core::Utils::CreateLinphoneCallStats(this->call, (int)Linphone::Core::MediaType::Video);
gApiLock.Unlock();
API_UNLOCK;
return stats;
}
void Linphone::Core::LinphoneCall::SendVFURequest()
{
TRACE; gApiLock.Lock();
API_LOCK;
linphone_call_send_vfu_request(this->call);
gApiLock.Unlock();
API_UNLOCK;
}
Windows::Phone::Networking::Voip::VoipPhoneCall^ Linphone::Core::LinphoneCall::CallContext::get()
{
return this->callContext;
}
Linphone::Core::Reason Linphone::Core::LinphoneCall::Reason::get()
{
return (Linphone::Core::Reason)linphone_call_get_reason(this->call);
}
Windows::Phone::Networking::Voip::VoipPhoneCall^ Linphone::Core::LinphoneCall::CallContext::get()
{
return this->callContext;
}
Linphone::Core::Reason Linphone::Core::LinphoneCall::Reason::get()
{
return (Linphone::Core::Reason)linphone_call_get_reason(this->call);
}
Linphone::Core::LinphoneCall::LinphoneCall(::LinphoneCall *call) :
call(call)
Linphone::Core::LinphoneCall::LinphoneCall(::LinphoneCall *call) :
call(call)
{
TRACE; gApiLock.Lock();
RefToPtrProxy<LinphoneCall^> *proxy = new RefToPtrProxy<LinphoneCall^>(this);
linphone_call_set_user_data(this->call, proxy);
gApiLock.Unlock();
}
Linphone::Core::LinphoneCall::~LinphoneCall()
API_LOCK;
RefToPtrProxy<LinphoneCall^> *proxy = new RefToPtrProxy<LinphoneCall^>(this);
linphone_call_set_user_data(this->call, proxy);
API_UNLOCK;
}
Linphone::Core::LinphoneCall::~LinphoneCall()
{
TRACE; gApiLock.Lock();
linphone_call_unref(call);
<