Commit d519a823 authored by Ghislain MARY's avatar Ghislain MARY

Improve API lock.

parent a34cb3be
......@@ -6,6 +6,7 @@ namespace Linphone
namespace Core
{
GlobalApiLock *GlobalApiLock::instance = nullptr;
std::mutex GlobalApiLock::instance_mutex;
GlobalApiLock::GlobalApiLock() : count(0), pool(nullptr)
{}
......@@ -16,14 +17,18 @@ namespace Linphone
GlobalApiLock * GlobalApiLock::Instance()
{
if (instance == nullptr) {
instance = new GlobalApiLock();
instance_mutex.lock();
if (instance == nullptr) {
instance = new GlobalApiLock();
}
instance_mutex.unlock();
}
return instance;
}
void GlobalApiLock::Lock()
{
mut.lock();
mutex.lock();
if (count == 0) {
pool = belle_sip_object_pool_push();
}
......@@ -37,41 +42,28 @@ namespace Linphone
belle_sip_object_unref(pool);
pool = nullptr;
}
mut.unlock();
mutex.unlock();
}
bool GlobalApiLock::TryLock()
{
bool ok = mut.try_lock();
if (ok) {
if (count == 0) {
pool = belle_sip_object_pool_push();
}
count++;
}
return ok;
}
//#define TRACE_LOCKS
ApiLock::ApiLock(const char *function)
{
#ifdef TRACE_LOCKS
if (function != NULL) {
this->function = ms_strdup(function);
}
char *s = ms_strdup_printf("### Locking in %s [%ul] at %ul\r\n", this->function, WIN_thread_self(), (unsigned long)ortp_get_cur_time_ms());
OutputDebugStringA(s);
ms_free(s);
ms_error("### Locking in %s [%ul]", this->function, WIN_thread_self());
#endif
GlobalApiLock::Instance()->Lock();
#ifdef TRACE_LOCKS
ms_error("### Locked in %s [%ul]", this->function, WIN_thread_self());
#endif
}
ApiLock::~ApiLock()
{
#ifdef TRACE_LOCKS
char *s = ms_strdup_printf("### Unlocking in %s [%ul] at %ul\r\n", this->function, WIN_thread_self(), (unsigned long)ortp_get_cur_time_ms());
OutputDebugStringA(s);
ms_free(s);
ms_error("### Unlocking in %s [%ul]", this->function, WIN_thread_self());
if (this->function != NULL) {
ms_free(this->function);
}
......
......@@ -11,7 +11,7 @@
#include "Utils.h"
#define API_LOCK ApiLock apiLock(__FUNCTION__)
#define API_LOCK Linphone::Core::ApiLock apiLock(__FUNCTION__)
namespace Linphone
......@@ -24,14 +24,14 @@ namespace Linphone
static GlobalApiLock * Instance();
void Lock();
void Unlock();
bool TryLock();
private:
GlobalApiLock();
~GlobalApiLock();
static GlobalApiLock *instance;
std::recursive_mutex mut;
static std::mutex instance_mutex;
std::recursive_mutex mutex;
int count;
belle_sip_object_pool_t *pool;
};
......
......@@ -14,8 +14,6 @@ using namespace Windows::Phone::Networking::Voip;
VoipPhoneCall^ CallController::OnIncomingCallReceived(Linphone::Core::LinphoneCall^ call, Platform::String^ contactName, Platform::String^ contactNumber, IncomingCallViewDismissedCallback^ incomingCallViewDismissedCallback)
{
API_LOCK;
VoipPhoneCall^ incomingCall = nullptr;
this->call = call;
......@@ -72,8 +70,6 @@ VoipPhoneCall^ CallController::OnIncomingCallReceived(Linphone::Core::LinphoneCa
void CallController::OnAcceptCallRequested(VoipPhoneCall^ incomingCall, CallAnswerEventArgs^ args)
{
API_LOCK;
incomingCall->NotifyCallActive();
if (this->onIncomingCallViewDismissed != nullptr) {
......@@ -98,8 +94,6 @@ void CallController::OnAcceptCallRequested(VoipPhoneCall^ incomingCall, CallAnsw
void CallController::OnRejectCallRequested(VoipPhoneCall^ incomingCall, CallRejectEventArgs^ args)
{
API_LOCK;
if (this->onIncomingCallViewDismissed != nullptr) {
this->onIncomingCallViewDismissed();
this->onIncomingCallViewDismissed = nullptr;
......@@ -112,8 +106,6 @@ void CallController::OnRejectCallRequested(VoipPhoneCall^ incomingCall, CallReje
VoipPhoneCall^ CallController::NewOutgoingCall(Platform::String^ number)
{
API_LOCK;
VoipPhoneCall^ outgoingCall = nullptr;
this->call = call;
......@@ -161,7 +153,6 @@ void CallController::NotifyMute(bool isMuted)
IncomingCallViewDismissedCallback^ CallController::IncomingCallViewDismissed::get()
{
API_LOCK;
return this->onIncomingCallViewDismissed;
}
......@@ -173,7 +164,6 @@ void CallController::IncomingCallViewDismissed::set(IncomingCallViewDismissedCal
Platform::Boolean CallController::CustomIncomingCallView::get()
{
API_LOCK;
return this->customIncomingCallView;
}
......@@ -185,7 +175,6 @@ void CallController::CustomIncomingCallView::set(Platform::Boolean value)
Reason CallController::DeclineReason::get()
{
API_LOCK;
return this->declineReason;
}
......@@ -217,5 +206,4 @@ CallController::CallController() :
CallController::~CallController()
{
}
#include "ApiLock.h"
#include "LinphoneAddress.h"
#include "Server.h"
Platform::String^ Linphone::Core::LinphoneAddress::DisplayName::get()
{
API_LOCK;
return Linphone::Core::Utils::cctops(linphone_address_get_display_name(this->address));
}
Platform::String^ Linphone::Core::LinphoneAddress::UserName::get()
{
API_LOCK;
return Linphone::Core::Utils::cctops(linphone_address_get_username(this->address));
}
Platform::String^ Linphone::Core::LinphoneAddress::Domain::get()
{
API_LOCK;
return Linphone::Core::Utils::cctops(linphone_address_get_domain(this->address));
}
int Linphone::Core::LinphoneAddress::Port::get()
{
API_LOCK;
return linphone_address_get_port(this->address);
}
Linphone::Core::LinphoneTransport Linphone::Core::LinphoneAddress::Transport::get()
{
API_LOCK;
LinphoneTransportType transport = linphone_address_get_transport(this->address);
switch (transport)
{
......@@ -41,11 +47,13 @@ Linphone::Core::LinphoneTransport Linphone::Core::LinphoneAddress::Transport::ge
Platform::String^ Linphone::Core::LinphoneAddress::Scheme::get()
{
API_LOCK;
return Linphone::Core::Utils::cctops(linphone_address_get_scheme(this->address));
}
void Linphone::Core::LinphoneAddress::DisplayName::set(Platform::String^ name)
{
API_LOCK;
const char *cc = Linphone::Core::Utils::pstoccs(name);
linphone_address_set_display_name(this->address, cc);
delete(cc);
......@@ -53,6 +61,7 @@ void Linphone::Core::LinphoneAddress::DisplayName::set(Platform::String^ name)
void Linphone::Core::LinphoneAddress::UserName::set(Platform::String^ username)
{
API_LOCK;
const char *cc = Linphone::Core::Utils::pstoccs(username);
linphone_address_set_username(this->address, cc);
delete(cc);
......@@ -60,6 +69,7 @@ void Linphone::Core::LinphoneAddress::UserName::set(Platform::String^ username)
void Linphone::Core::LinphoneAddress::Domain::set(Platform::String^ domain)
{
API_LOCK;
const char *cc = Linphone::Core::Utils::pstoccs(domain);
linphone_address_set_domain(this->address, cc);
delete(cc);
......@@ -67,11 +77,13 @@ void Linphone::Core::LinphoneAddress::Domain::set(Platform::String^ domain)
void Linphone::Core::LinphoneAddress::Port::set(int port)
{
API_LOCK;
linphone_address_set_port(this->address, port);
}
void Linphone::Core::LinphoneAddress::Transport::set(Linphone::Core::LinphoneTransport transport)
{
API_LOCK;
LinphoneTransportType transportType = LinphoneTransportUdp;
if (transport == LinphoneTransport::LinphoneTransportTCP)
{
......@@ -91,16 +103,19 @@ void Linphone::Core::LinphoneAddress::Transport::set(Linphone::Core::LinphoneTra
void Linphone::Core::LinphoneAddress::Clean()
{
API_LOCK;
linphone_address_clean(this->address);
}
Platform::String^ Linphone::Core::LinphoneAddress::AsString()
{
API_LOCK;
return Linphone::Core::Utils::cctops(linphone_address_as_string(this->address));
}
Platform::String^ Linphone::Core::LinphoneAddress::AsStringUriOnly()
{
API_LOCK;
return Linphone::Core::Utils::cctops(linphone_address_as_string_uri_only(this->address));
}
......@@ -112,7 +127,6 @@ Platform::String^ Linphone::Core::LinphoneAddress::ToString()
Linphone::Core::LinphoneAddress::LinphoneAddress(::LinphoneAddress *addr) :
address(addr)
{
}
Linphone::Core::LinphoneAddress::LinphoneAddress(const char *uri)
......@@ -122,5 +136,4 @@ Linphone::Core::LinphoneAddress::LinphoneAddress(const char *uri)
Linphone::Core::LinphoneAddress::~LinphoneAddress()
{
}
\ No newline at end of file
......@@ -74,7 +74,6 @@ void Linphone::Core::LinphoneAuthInfo::Ha1::set(Platform::String^ ha1)
Linphone::Core::LinphoneAuthInfo::LinphoneAuthInfo(Platform::String^ username, Platform::String^ userid, Platform::String^ password, Platform::String^ ha1, Platform::String^ realm, Platform::String^ domain)
{
API_LOCK;
const char* cc_username = Utils::pstoccs(username);
const char* cc_password = Utils::pstoccs(password);
const char* cc_realm = Utils::pstoccs(realm);
......
......@@ -143,11 +143,13 @@ Platform::String^ Linphone::Core::LinphoneCall::RemoteContact::get()
void Linphone::Core::LinphoneCall::CallContext::set(Windows::Phone::Networking::Voip::VoipPhoneCall^ cc)
{
API_LOCK;
this->callContext = cc;
}
Platform::Object^ Linphone::Core::LinphoneCall::CallStartTimeFromContext::get()
{
API_LOCK;
Platform::Object^ result = nullptr;
try {
if (this->callContext != nullptr) {
......@@ -155,7 +157,6 @@ Platform::Object^ Linphone::Core::LinphoneCall::CallStartTimeFromContext::get()
}
}
catch (Platform::COMException^ ex) {
}
return result;
}
......@@ -191,6 +192,7 @@ Windows::Phone::Networking::Voip::VoipPhoneCall^ Linphone::Core::LinphoneCall::C
Linphone::Core::Reason Linphone::Core::LinphoneCall::Reason::get()
{
API_LOCK;
return (Linphone::Core::Reason)linphone_call_get_reason(this->call);
}
......
......@@ -7,53 +7,63 @@
Linphone::Core::LinphoneAddress^ Linphone::Core::LinphoneCallLog::From::get()
{
API_LOCK;
return (Linphone::Core::LinphoneAddress^)Linphone::Core::Utils::CreateLinphoneAddress((void*)linphone_call_log_get_from(this->callLog));
}
Linphone::Core::LinphoneAddress^ Linphone::Core::LinphoneCallLog::To::get()
{
API_LOCK;
return (Linphone::Core::LinphoneAddress^)Linphone::Core::Utils::CreateLinphoneAddress((void*)linphone_call_log_get_to(this->callLog));
}
Linphone::Core::CallDirection Linphone::Core::LinphoneCallLog::Direction::get()
{
API_LOCK;
return (Linphone::Core::CallDirection)linphone_call_log_get_dir(this->callLog);
}
Linphone::Core::LinphoneCallStatus Linphone::Core::LinphoneCallLog::Status::get()
{
API_LOCK;
return (Linphone::Core::LinphoneCallStatus)linphone_call_log_get_status(this->callLog);
}
int64 Linphone::Core::LinphoneCallLog::StartDate::get()
{
API_LOCK;
return linphone_call_log_get_start_date(this->callLog);
}
int Linphone::Core::LinphoneCallLog::Duration::get()
{
API_LOCK;
return linphone_call_log_get_duration(this->callLog);
}
Platform::String^ Linphone::Core::LinphoneCallLog::CallId::get()
{
API_LOCK;
return Linphone::Core::Utils::cctops(linphone_call_log_get_call_id(this->callLog));
}
Platform::Boolean Linphone::Core::LinphoneCallLog::VideoEnabled::get()
{
API_LOCK;
return (linphone_call_log_video_enabled(this->callLog) == TRUE);
}
Linphone::Core::LinphoneCallLog::LinphoneCallLog(::LinphoneCallLog *cl) :
callLog(cl)
{
API_LOCK;
RefToPtrProxy<LinphoneCallLog^> *log = new RefToPtrProxy<LinphoneCallLog^>(this);
linphone_call_log_set_user_pointer(this->callLog, log);
}
Linphone::Core::LinphoneCallLog::~LinphoneCallLog()
{
API_LOCK;
RefToPtrProxy<LinphoneCallLog^> *log = reinterpret_cast< RefToPtrProxy<LinphoneCallLog^> *>(linphone_call_log_get_user_pointer(this->callLog));
delete log;
}
\ No newline at end of file
......@@ -94,31 +94,26 @@ Linphone::Core::LinphoneCallStats::~LinphoneCallStats()
float Linphone::Core::LinphoneCallStats::GetSenderLossRate(const ::LinphoneCallStats *stats)
{
API_LOCK;
return linphone_call_stats_get_sender_loss_rate(stats);
}
float Linphone::Core::LinphoneCallStats::GetReceiverLossRate(const ::LinphoneCallStats *stats)
{
API_LOCK;
return linphone_call_stats_get_receiver_loss_rate(stats);
}
float Linphone::Core::LinphoneCallStats::GetSenderInterarrivalJitter(const ::LinphoneCallStats *stats)
{
API_LOCK;
return linphone_call_stats_get_sender_interarrival_jitter(stats, this->call);
}
float Linphone::Core::LinphoneCallStats::GetReceiverInterarrivalJitter(const ::LinphoneCallStats *stats)
{
API_LOCK;
return linphone_call_stats_get_receiver_interarrival_jitter(stats, this->call);
}
int64 Linphone::Core::LinphoneCallStats::GetLatePacketsCumulativeNumber(const ::LinphoneCallStats *stats)
{
API_LOCK;
return linphone_call_stats_get_late_packets_cumulative_number(stats, this->call);
}
......
......@@ -126,12 +126,12 @@ namespace Linphone
LinphoneCallStats(::LinphoneCallStats *callStats);
~LinphoneCallStats();
float Linphone::Core::LinphoneCallStats::GetSenderLossRate(const ::LinphoneCallStats *stats);
float Linphone::Core::LinphoneCallStats::GetReceiverLossRate(const ::LinphoneCallStats *stats);
float Linphone::Core::LinphoneCallStats::GetSenderInterarrivalJitter(const ::LinphoneCallStats *stats);
float Linphone::Core::LinphoneCallStats::GetReceiverInterarrivalJitter(const ::LinphoneCallStats *stats);
int64 Linphone::Core::LinphoneCallStats::GetLatePacketsCumulativeNumber(const ::LinphoneCallStats *stats);
void Linphone::Core::LinphoneCallStats::FillStats(const ::LinphoneCallStats *stats);
float GetSenderLossRate(const ::LinphoneCallStats *stats);
float GetReceiverLossRate(const ::LinphoneCallStats *stats);
float GetSenderInterarrivalJitter(const ::LinphoneCallStats *stats);
float GetReceiverInterarrivalJitter(const ::LinphoneCallStats *stats);
int64 GetLatePacketsCumulativeNumber(const ::LinphoneCallStats *stats);
void FillStats(const ::LinphoneCallStats *stats);
::LinphoneCall *call;
Linphone::Core::MediaType mediaType;
......
......@@ -4,21 +4,25 @@
Platform::String^ Linphone::Core::LinphoneChatMessage::Text::get()
{
API_LOCK;
return Linphone::Core::Utils::cctops(linphone_chat_message_get_text(this->message));
}
Linphone::Core::LinphoneAddress^ Linphone::Core::LinphoneChatMessage::PeerAddress::get()
{
API_LOCK;
return (Linphone::Core::LinphoneAddress^) Linphone::Core::Utils::CreateLinphoneAddress((void*)linphone_chat_message_get_peer_address(this->message));
}
Linphone::Core::LinphoneAddress^ Linphone::Core::LinphoneChatMessage::From::get()
{
API_LOCK;
return (Linphone::Core::LinphoneAddress^) Linphone::Core::Utils::CreateLinphoneAddress((void*)linphone_chat_message_get_from(this->message));
}
Platform::String^ Linphone::Core::LinphoneChatMessage::ExternalBodyUrl::get()
{
API_LOCK;
return Linphone::Core::Utils::cctops(linphone_chat_message_get_external_body_url(this->message));
}
......@@ -32,11 +36,13 @@ void Linphone::Core::LinphoneChatMessage::ExternalBodyUrl::set(Platform::String^
int64 Linphone::Core::LinphoneChatMessage::Time::get()
{
API_LOCK;
return linphone_chat_message_get_time(this->message);
}
Linphone::Core::LinphoneChatMessageState Linphone::Core::LinphoneChatMessage::State::get()
{
API_LOCK;
return (Linphone::Core::LinphoneChatMessageState) linphone_chat_message_get_state(this->message);
}
......@@ -111,6 +117,7 @@ void Linphone::Core::LinphoneChatMessage::StartFileDownload(Linphone::Core::Linp
Linphone::Core::LinphoneChatMessage::LinphoneChatMessage(::LinphoneChatMessage *cm) :
message(cm)
{
API_LOCK;
message = linphone_chat_message_ref(message);
RefToPtrProxy<LinphoneChatMessage^> *chat_message = new RefToPtrProxy<LinphoneChatMessage^>(this);
linphone_chat_message_set_user_data(this->message, chat_message);
......@@ -118,6 +125,7 @@ Linphone::Core::LinphoneChatMessage::LinphoneChatMessage(::LinphoneChatMessage *
Linphone::Core::LinphoneChatMessage::~LinphoneChatMessage()
{
API_LOCK;
linphone_chat_message_unref(message);
RefToPtrProxy<LinphoneChatMessage^> *chat_message = reinterpret_cast< RefToPtrProxy<LinphoneChatMessage^> *>(linphone_chat_message_get_user_data(this->message));
delete chat_message;
......
......@@ -10,6 +10,7 @@ using namespace Windows::Foundation::Collections;
Linphone::Core::LinphoneAddress^ Linphone::Core::LinphoneChatRoom::PeerAddress::get()
{
API_LOCK;
return (Linphone::Core::LinphoneAddress^) Linphone::Core::Utils::CreateLinphoneAddress((void*)linphone_chat_room_get_peer_address(this->room));
}
......@@ -132,12 +133,14 @@ void Linphone::Core::LinphoneChatRoom::DeleteMessageFromHistory(Linphone::Core::
Linphone::Core::LinphoneChatRoom::LinphoneChatRoom(::LinphoneChatRoom *cr) :
room(cr)
{
API_LOCK;
RefToPtrProxy<LinphoneChatRoom^> *chat_room = new RefToPtrProxy<LinphoneChatRoom^>(this);
linphone_chat_room_set_user_data(this->room, chat_room);
}
Linphone::Core::LinphoneChatRoom::~LinphoneChatRoom()
{
API_LOCK;
RefToPtrProxy<LinphoneChatRoom^> *chat_room = reinterpret_cast< RefToPtrProxy<LinphoneChatRoom^> *>(linphone_chat_room_get_user_data(this->room));
delete chat_room;
}
\ No newline at end of file
......@@ -38,6 +38,7 @@ Linphone::Core::OutputTraceLevel Linphone::Core::LinphoneCore::LogLevel::get()
void Linphone::Core::LinphoneCore::LogLevel::set(OutputTraceLevel logLevel)
{
API_LOCK;
int coreLogLevel = 0;
if (logLevel == OutputTraceLevel::Error) {
coreLogLevel = ORTP_ERROR | ORTP_FATAL;
......@@ -87,7 +88,7 @@ void Linphone::Core::LinphoneCore::AddProxyConfig(Linphone::Core::LinphoneProxyC
void Linphone::Core::LinphoneCore::DefaultProxyConfig::set(Linphone::Core::LinphoneProxyConfig^ proxyCfg)
{
API_LOCK;
linphone_core_set_default_proxy(this->lc, proxyCfg->proxy_config);
linphone_core_set_default_proxy_config(this->lc, proxyCfg->proxy_config);
}
Linphone::Core::LinphoneProxyConfig^ Linphone::Core::LinphoneCore::DefaultProxyConfig::get()
......@@ -1038,8 +1039,8 @@ Windows::Foundation::Collections::IVector<Platform::Object^>^ Linphone::Core::Li
Linphone::Core::VideoSize^ Linphone::Core::LinphoneCore::PreferredVideoSize::get()
{
Linphone::Core::VideoSize^ size = nullptr;
API_LOCK;
Linphone::Core::VideoSize^ size = nullptr;
const MSVideoSizeDef *sizesList = linphone_core_get_supported_video_sizes(this->lc);
MSVideoSize vsize = linphone_core_get_preferred_video_size(this->lc);
while (sizesList->name != NULL) {
......@@ -1067,9 +1068,9 @@ Platform::String^ Linphone::Core::LinphoneCore::GetPreferredVideoSizeName()
void Linphone::Core::LinphoneCore::PreferredVideoSize::set(Linphone::Core::VideoSize^ size)
{
API_LOCK;
if (size->Name != nullptr) {
const char *ccname = Utils::pstoccs(size->Name);
API_LOCK;
linphone_core_set_preferred_video_size_by_name(this->lc, ccname);
delete ccname;
} else {
......@@ -1079,10 +1080,10 @@ void Linphone::Core::LinphoneCore::PreferredVideoSize::set(Linphone::Core::Video
void Linphone::Core::LinphoneCore::SetPreferredVideoSize(int width, int height)
{
API_LOCK;
MSVideoSize vsize;
vsize.width = width;
vsize.height = height;
API_LOCK;
linphone_core_set_preferred_video_size(this->lc, vsize);
}
......@@ -1107,8 +1108,8 @@ Windows::Foundation::Collections::IVector<Platform::Object^>^ Linphone::Core::Li
Platform::String^ Linphone::Core::LinphoneCore::VideoDevice::get()
{
Platform::String^ device = nullptr;
API_LOCK;
Platform::String^ device = nullptr;
const char *ccname = linphone_core_get_video_device(this->lc);
if (ccname != NULL) {
device = Utils::cctops(ccname);
......@@ -1118,8 +1119,8 @@ Platform::String^ Linphone::Core::LinphoneCore::VideoDevice::get()
void Linphone::Core::LinphoneCore::VideoDevice::set(Platform::String^ device)
{
const char *ccname = Utils::pstoccs(device);
API_LOCK;
const char *ccname = Utils::pstoccs(device);
linphone_core_set_video_device(this->lc, ccname);
delete ccname;
}
......@@ -1283,11 +1284,12 @@ Linphone::Core::LinphoneCoreListener^ Linphone::Core::LinphoneCore::CoreListener
void Linphone::Core::LinphoneCore::CoreListener::set(LinphoneCoreListener^ listener)
{
API_LOCK;
this->listener = listener;
}
void call_state_changed(::LinphoneCore *lc, ::LinphoneCall *call, ::LinphoneCallState cstate, const char *msg)
{
{
Linphone::Core::LinphoneCallState state = (Linphone::Core::LinphoneCallState) cstate;
Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *proxy = reinterpret_cast< Linphone::Core::RefToPtrProxy<Linphone::Core::LinphoneCall^> *>(linphone_call_get_user_pointer(call));
Linphone::Core::LinphoneCall^ lCall = (proxy) ? proxy->Ref() : nullptr;
......@@ -1452,7 +1454,8 @@ void composing_received(LinphoneCore *lc, LinphoneChatRoom *room)
}
}
void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent *content, size_t offset, size_t total) {
void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent *content, size_t offset, size_t total)
{
Linphone::Core::LinphoneCoreListener^ listener = Linphone::Core::Globals::Instance->LinphoneCore->CoreListener;
if (listener != nullptr)
{
......@@ -1465,7 +1468,8 @@ void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *me
}
}
void log_collection_upload_progress_indication(LinphoneCore *lc, size_t offset, size_t total) {
void log_collection_upload_progress_indication(LinphoneCore *lc, size_t offset, size_t total)
{
Linphone::Core::LinphoneCoreListener^ listener = Linphone::Core::Globals::Instance->LinphoneCore->CoreListener;
if (listener != nullptr)
{
......@@ -1473,7 +1477,8 @@ void log_collection_upload_progress_indication(LinphoneCore *lc, size_t offset,
}
}
void log_collection_upload_state_changed(LinphoneCore *lc, ::LinphoneCoreLogCollectionUploadState state, const char *info) {
void log_collection_upload_state_changed(LinphoneCore *lc, ::LinphoneCoreLogCollectionUploadState state, const char *info)
{
Linphone::Core::LinphoneCoreListener^ listener = Linphone::Core::Globals::Instance->LinphoneCore->CoreListener;
if (listener != nullptr)
{
......@@ -1485,7 +1490,6 @@ Linphone::Core::LinphoneCore::LinphoneCore(LinphoneCoreListener^ coreListener) :
lc(nullptr),
listener(coreListener)
{
}
Linphone::Core::LinphoneCore::LinphoneCore(LinphoneCoreListener^ coreListener, LpConfig^ config) :
......@@ -1499,26 +1503,22 @@ Linphone::Core::LinphoneCore::LinphoneCore(LinphoneCoreListener^ coreListener, L
void Linphone::Core::LinphoneCore::IterateEnabled::set(Platform::Boolean value)
{
API_LOCK;
if (isIterateEnabled && !value && IterateTimer)
if (isIterateEnabled && !value && IterateWorkItem)
{
// Disable the iterate
IterateTimer->Cancel();
IterateWorkItem->Cancel();
IterateWorkItem = nullptr;
}
else if (!isIterateEnabled && value)
{
// Enable the iterate
TimeSpan period;
period.Duration = 20 * 10000;
IterateTimer = ThreadPoolTimer::CreatePeriodicTimer(
ref new TimerElapsedHandler([this](ThreadPoolTimer^ source)
IAsyncAction^ IterateWorkItem = ThreadPool::RunAsync(ref new WorkItemHandler([this](IAsyncAction^ action)
{
if (source == IterateTimer) {
if (GlobalApiLock::Instance()->TryLock()) {
linphone_core_iterate(this->lc);
GlobalApiLock::Instance()->Unlock();
}
while (true) {
GlobalApiLock::Instance()->Lock();
linphone_core_iterate(this->lc);
GlobalApiLock::Instance()->Unlock();
ms_usleep(20000);
}
}), period);
}), WorkItemPriority::Low);
}
isIterateEnabled = value;
}
......
......@@ -1048,7 +1048,7 @@ namespace Linphone
::LinphoneCore *lc;
LinphoneCoreListener^ listener;
LpConfig^ config;
Windows::System::Threading::ThreadPoolTimer ^IterateTimer;
Windows::Foundation::IAsyncAction^ IterateWorkItem;
Platform::Boolean isIterateEnabled;
static OutputTraceLevel logLevel;
};
......
......@@ -22,10 +22,14 @@ void LinphoneCoreFactory::CreateLinphoneCore(Linphone::Core::LinphoneCoreListene
void LinphoneCoreFactory::CreateLinphoneCore(Linphone::Core::LinphoneCoreListener^ listener, Linphone::Core::LpConfig^ config)
{
API_LOCK;
Utils::LinphoneCoreEnableLogCollection(true);
this->linphoneCore = ref new Linphone::Core::LinphoneCore(listener, config);
this->linphoneCore->Init();
if (this->linphoneCore == nullptr) {
API_LOCK;
if (this->linphoneCore == nullptr) {
Utils::LinphoneCoreEnableLogCollection(true);
this->linphoneCore = ref new Linphone::Core::LinphoneCore(listener, config);
this->linphoneCore->Init();
}
}
}
Linphone::Core::LpConfig^ LinphoneCoreFactory::CreateLpConfig(Platform::String^ configPath, Platform::String^ factoryConfigPath)
......@@ -117,6 +121,7 @@ Linphone::Core::LinphoneCore^ LinphoneCoreFactory::LinphoneCore::get()
void LinphoneCoreFactory::Destroy()
{
API_LOCK;
this->linphoneCore->Destroy();
delete this->linphoneCore;
this->linphoneCore = nullptr;
......@@ -125,10 +130,8 @@ void LinphoneCoreFactory::Destroy()
LinphoneCoreFactory::LinphoneCoreFactory() :
linphoneCore(nullptr)
{
}
LinphoneCoreFactory::~LinphoneCoreFactory()
{
}
\ No newline at end of file
......@@ -126,7 +126,6 @@ void Linphone::Core::LpConfig::SetRange(Platform::String^ section, Platform::Str
Linphone::Core::LpConfig::LpConfig(::LpConfig *config) :
config(config)
{
}
Linphone::Core::LpConfig::LpConfig(Platform::String^ configPath, Platform::String^ factoryConfigPath)
......@@ -141,5 +140,4 @@ Linphone::Core::LpConfig::LpConfig(Platform::String^ configPath, Platform::Strin
Linphone::Core::LpConfig::~LpConfig()
{
}
\ No newline at end of file
......@@ -25,6 +25,7 @@ Platform::String^ Linphone::Core::TunnelConfig::Host::get()
void Linphone::Core::TunnelConfig::Host::set(Platform::String^ value)
{
API_LOCK;
this->host = value;
}
......@@ -35,6 +36,7 @@ int Linphone::Core::TunnelConfig::Port::get()
void Linphone::Core::TunnelConfig::Port::set(int value)
{