Core.cpp 40 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
Core.cpp
Copyright (C) 2015  Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "Address.h"
#include "ApiLock.h"
#include "AuthInfo.h"
#include "Call.h"
#include "CallLog.h"
#include "CallParams.h"
#include "ChatRoom.h"
#include "Core.h"
#include "CoreListener.h"
#include "Enums.h"
#include "LpConfig.h"
#include "PayloadType.h"
#include "ProxyConfig.h"
#include "Transports.h"
#include "Tunnel.h"
#include "VideoPolicy.h"
#include "VideoSize.h"
34
#include "VoipCallController.h"
35 36 37

#include <collection.h>

38
using namespace BelledonneCommunications::Linphone::Native;
39 40 41 42 43
using namespace Microsoft::WRL;
using namespace Platform;
using namespace Platform::Collections;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
44
using namespace Windows::ApplicationModel::Calls;
45
using namespace Windows::Phone::Media::Devices;
46 47 48



49
OutputTraceLevel Core::logLevel = OutputTraceLevel::Error;
50 51 52



53
void Core::CPUCount::set(int count)
54 55 56 57 58
{
	API_LOCK;
	ms_set_cpu_count(count);
}

59
int Core::CPUCount::get()
60 61 62 63 64
{
	API_LOCK;
	return ms_get_cpu_count();
}

65
LogCollectionState Core::LogCollectionEnabled::get()
66 67
{
	API_LOCK;
68
	return (LogCollectionState) linphone_core_log_collection_enabled();
69 70
}

71
void Core::LogCollectionEnabled::set(LogCollectionState value)
72 73 74 75 76
{
	API_LOCK;
	linphone_core_enable_log_collection((LinphoneLogCollectionState)value);
}

77
Platform::String^ Core::LogCollectionPath::get()
78 79
{
	API_LOCK;
80
	return Utils::cctops(linphone_core_get_log_collection_path());
81 82
}

83
void Core::LogCollectionPath::set(Platform::String^ value)
84 85
{
	API_LOCK;
86
	const char *cvalue = Utils::pstoccs(value);
87 88 89 90
	linphone_core_set_log_collection_path(cvalue);
	delete(cvalue);
}

91
OutputTraceLevel Core::LogLevel::get()
92
{
93
	return Core::logLevel;
94 95
}

96
void Core::LogLevel::set(OutputTraceLevel logLevel)
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
{
	API_LOCK;
	int coreLogLevel = 0;
	if (logLevel == OutputTraceLevel::Error) {
		coreLogLevel = ORTP_ERROR | ORTP_FATAL;
	}
	else if (logLevel == OutputTraceLevel::Warning) {
		coreLogLevel = ORTP_WARNING | ORTP_ERROR | ORTP_FATAL;
	}
	else if (logLevel == OutputTraceLevel::Message) {
		coreLogLevel = ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL;
	}
	else if (logLevel == OutputTraceLevel::Debug) {
		coreLogLevel = ORTP_DEBUG | ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL;
	}
	Utils::SetLogLevel(coreLogLevel);
}

115
Platform::Boolean Core::TunnelAvailable::get()
116 117 118 119 120
{
	API_LOCK;
	return (linphone_core_tunnel_available() == TRUE);
}

121
Platform::String^ Core::Version::get()
122 123
{
	API_LOCK;
124
	return Utils::cctops(linphone_core_get_version());
125 126 127 128 129
}




130
void Core::ResetLogCollection()
131 132
{
	API_LOCK;
133
	linphone_core_reset_log_collection();
134 135 136 137
}



138 139

static void AddPayloadTypeToVector(void *vCodec, void *vector)
140
{
141 142 143 144
	::PayloadType *pt = (::PayloadType *)vCodec;
	RefToPtrProxy<IVector<BelledonneCommunications::Linphone::Native::PayloadType^>^> *list = reinterpret_cast<RefToPtrProxy<IVector<BelledonneCommunications::Linphone::Native::PayloadType^>^> *>(vector);
	IVector<BelledonneCommunications::Linphone::Native::PayloadType^>^ codecs = (list) ? list->Ref() : nullptr;
	BelledonneCommunications::Linphone::Native::PayloadType^ codec = (BelledonneCommunications::Linphone::Native::PayloadType^)Utils::CreatePayloadType(pt);
145
	codecs->Append(codec);
146 147
}

148
IVector<BelledonneCommunications::Linphone::Native::PayloadType^>^ Core::AudioCodecs::get()
149 150
{
	API_LOCK;
151
	IVector<PayloadType^>^ codecs = ref new Vector<PayloadType^>();
152
	const MSList *codecslist = linphone_core_get_audio_codecs(this->lc);
153
	RefToPtrProxy<IVector<PayloadType^>^> *codecsPtr = new RefToPtrProxy<IVector<PayloadType^>^>(codecs);
154 155
	ms_list_for_each2(codecslist, AddPayloadTypeToVector, codecsPtr);
	return codecs;
156 157
}

158
int Core::AudioPort::get()
159
{
160 161
	API_LOCK;
	return linphone_core_get_audio_port(this->lc);
162 163
}

164
void Core::AudioPort::set(int port)
165 166
{
	API_LOCK;
167
	linphone_core_set_audio_port(this->lc, port);
168 169
}

170
static void AddAuthInfoToVector(void *vAuthInfo, void *vector)
171
{
172
	::LinphoneAuthInfo *ai = (::LinphoneAuthInfo *)vAuthInfo;
173 174
	RefToPtrProxy<IVector<AuthInfo^>^> *list = reinterpret_cast< RefToPtrProxy<IVector<AuthInfo^>^> *>(vector);
	IVector<AuthInfo^>^ authInfos = (list) ? list->Ref() : nullptr;
175

176
	AuthInfo^ authInfo = (AuthInfo^)Utils::CreateAuthInfo(ai);
177
	authInfos->Append(authInfo);
178 179
}

180
IVector<AuthInfo^>^ Core::AuthInfoList::get()
181 182
{
	API_LOCK;
183
	IVector<AuthInfo^>^ authInfos = ref new Vector<AuthInfo^>();
184
	const MSList *authlist = linphone_core_get_auth_info_list(this->lc);
185
	RefToPtrProxy<IVector<AuthInfo^>^> *authInfosPtr = new RefToPtrProxy<IVector<AuthInfo^>^>(authInfos);
186 187
	ms_list_for_each2(authlist, AddAuthInfoToVector, authInfosPtr);
	return authInfos;
188 189
}

190
static void AddCallLogToVector(void* nLog, void* vector)
191
{
192
	::LinphoneCallLog *cl = (::LinphoneCallLog*)nLog;
193 194 195
	RefToPtrProxy<IVector<CallLog^>^> *list = reinterpret_cast<RefToPtrProxy<IVector<CallLog^>^> *>(vector);
	IVector<CallLog^>^ logs = (list) ? list->Ref() : nullptr;
	CallLog^ log = (CallLog^)Utils::GetCallLog(cl);
196
	logs->Append(log);
197 198
}

199
IVector<CallLog^>^ Core::CallLogs::get()
200 201
{
	API_LOCK;
202
	IVector<CallLog^>^ logs = ref new Vector<CallLog^>();
203
	const MSList* logslist = linphone_core_get_call_logs(this->lc);
204
	RefToPtrProxy<IVector<CallLog^>^> *logsptr = new RefToPtrProxy<IVector<CallLog^>^>(logs);
205 206
	ms_list_for_each2(logslist, AddCallLogToVector, logsptr);
	return logs;
207 208
}

209
static void AddCallToVector(void *vCall, void *vector)
210
{
211
	::LinphoneCall* c = (::LinphoneCall *)vCall;
212 213 214
	RefToPtrProxy<IVector<Call^>^> *list = reinterpret_cast< RefToPtrProxy<IVector<Call^>^> *>(vector);
	IVector<Call^>^ calls = (list) ? list->Ref() : nullptr;
	Call^ lCall = (Call^)Utils::GetCall(vCall);
215
	calls->Append(lCall);
216 217
}

218
IVector<Call^>^ Core::Calls::get()
219 220
{
	API_LOCK;
221
	Vector<Call^>^ calls = ref new Vector<Call^>();
222
	const MSList *callsList = linphone_core_get_calls(this->lc);
223
	RefToPtrProxy<IVector<Call^>^> *callsPtr = new RefToPtrProxy<IVector<Call^>^>(calls);
224 225
	ms_list_for_each2(callsList, AddCallToVector, callsPtr);
	return calls;
226 227
}

228
int Core::CallsNb::get()
229 230
{
	API_LOCK;
231
	return linphone_core_get_calls_nb(this->lc);
232 233
}

234
int Core::CameraSensorRotation::get()
235 236
{
	API_LOCK;
237
	return linphone_core_get_camera_sensor_rotation(this->lc);
238 239
}

240
Platform::String^ Core::ChatDatabasePath::get()
241
{
242 243 244
	// TODO
	throw ref new NotImplementedException();
	return nullptr;
245 246
}

247
void Core::ChatDatabasePath::set(Platform::String^ chatDatabasePath)
248 249
{
	API_LOCK;
250
	linphone_core_set_chat_database_path(this->lc, Utils::pstoccs(chatDatabasePath));
251 252
}

253
static void AddChatRoomListToVector(void *vRoom, void *vector)
254
{
255
	::LinphoneChatRoom *chatRoom = (LinphoneChatRoom*)vRoom;
256 257 258
	RefToPtrProxy<IVector<ChatRoom^>^> *list = reinterpret_cast<RefToPtrProxy<IVector<ChatRoom^>^> *>(vector);
	IVector<ChatRoom^>^ rooms = (list) ? list->Ref() : nullptr;
	ChatRoom^ room = (ChatRoom^) Utils::GetChatRoom(chatRoom);
259
	rooms->Append(room);
260 261
}

262
IVector<ChatRoom^>^ Core::ChatRooms::get()
263 264
{
	API_LOCK;
265
	IVector<ChatRoom^>^ rooms = ref new Vector<ChatRoom^>();
Ghislain MARY's avatar
Ghislain MARY committed
266
	const MSList* roomList = linphone_core_get_chat_rooms(this->lc);
267
	RefToPtrProxy<IVector<ChatRoom^>^> *roomsPtr = new RefToPtrProxy<IVector<ChatRoom^>^>(rooms);
268 269
	ms_list_for_each2(roomList, AddChatRoomListToVector, roomsPtr);
	return rooms;
270 271
}

272
int Core::ConferenceSize::get()
273 274
{
	API_LOCK;
275
	return linphone_core_get_conference_size(this->lc);
276 277
}

278
BelledonneCommunications::Linphone::Native::LpConfig^ Core::Config::get()
279 280
{
	API_LOCK;
281
	::LpConfig *config = linphone_core_get_config(this->lc);
282
	return (LpConfig^)Utils::CreateLpConfig(config);
283 284
}

285
CoreListener^ Core::CoreListener::get()
286
{
287
	return this->listener;
288 289
}

290
void Core::CoreListener::set(BelledonneCommunications::Linphone::Native::CoreListener^ listener)
291 292
{
	API_LOCK;
293
	this->listener = listener;
294 295
}

296
Call^ Core::CurrentCall::get()
297 298
{
	API_LOCK;
299
	::LinphoneCall *lCall = linphone_core_get_current_call(this->lc);
300
	return (Call^)Utils::GetCall(lCall);
301 302
}

303
ProxyConfig^ Core::DefaultProxyConfig::get()
304 305
{
	API_LOCK;
306 307 308
	ProxyConfig^ defaultProxy = nullptr;
	::LinphoneProxyConfig *proxy = linphone_core_get_default_proxy_config(this->lc);
	if (proxy != nullptr) {
309
		defaultProxy = ref new ProxyConfig(proxy);
310
	}
311
	return defaultProxy;
312 313
}

314
void Core::DefaultProxyConfig::set(ProxyConfig^ proxyCfg)
315 316
{
	API_LOCK;
317
	linphone_core_set_default_proxy_config(this->lc, proxyCfg->proxyConfig);
318 319
}

320
int Core::DeviceRotation::get()
321 322
{
	API_LOCK;
323
	return linphone_core_get_device_rotation(this->lc);
324 325
}

326
void Core::DeviceRotation::set(int rotation)
327 328
{
	API_LOCK;
329
	linphone_core_set_device_rotation(this->lc, rotation);
330 331
}

332
int Core::DownloadBandwidth::get()
333 334
{
	API_LOCK;
335
	return linphone_core_get_download_bandwidth(this->lc);
336 337
}

338
void Core::DownloadBandwidth::set(int value)
339 340
{
	API_LOCK;
341
	linphone_core_set_download_bandwidth(this->lc, value);
342 343
}

344
int Core::DownloadPtime::get()
345 346
{
	API_LOCK;
347
	return linphone_core_get_download_ptime(this->lc);
348 349
}

350
void Core::DownloadPtime::set(int ptime)
351 352
{
	API_LOCK;
353
	linphone_core_set_download_ptime(this->lc, ptime);
354 355
}

356
FirewallPolicy Core::FirewallPolicy::get()
357 358
{
	API_LOCK;
359
	return (BelledonneCommunications::Linphone::Native::FirewallPolicy) linphone_core_get_firewall_policy(this->lc);
360 361
}

362
void Core::FirewallPolicy::set(BelledonneCommunications::Linphone::Native::FirewallPolicy policy)
363
{
364 365
	API_LOCK;
	linphone_core_set_firewall_policy(this->lc, (LinphoneFirewallPolicy)policy);
366 367
}

368
int Core::InCallTimeout::get()
369 370
{
	API_LOCK;
371
	return linphone_core_get_in_call_timeout(this->lc);
372 373
}

374
void Core::InCallTimeout::set(int timeout)
375 376
{
	API_LOCK;
377
	linphone_core_set_in_call_timeout(this->lc, timeout);
378 379
}

380
int Core::IncTimeout::get()
381 382
{
	API_LOCK;
383
	return linphone_core_get_inc_timeout(this->lc);
384 385
}

386
void Core::IncTimeout::set(int timeout)
387 388
{
	API_LOCK;
389
	linphone_core_set_inc_timeout(this->lc, timeout);
390 391
}

392
Platform::Boolean Core::IsEchoCancellationEnabled::get()
393 394
{
	API_LOCK;
395
	return (linphone_core_echo_cancellation_enabled(this->lc) == TRUE);
396 397
}

398
void Core::IsEchoCancellationEnabled::set(Platform::Boolean enable)
399 400
{
	API_LOCK;
401
	linphone_core_enable_echo_cancellation(this->lc, enable);
402 403
}

404
Platform::Boolean Core::IsEchoLimiterEnabled::get()
405 406
{
	API_LOCK;
407
	return (linphone_core_echo_limiter_enabled(this->lc) == TRUE);
408 409
}

410
void Core::IsEchoLimiterEnabled::set(Platform::Boolean enable)
411 412
{
	API_LOCK;
413
	linphone_core_enable_echo_limiter(this->lc, enable);
414 415
}

416
Platform::Boolean Core::IsInCall::get()
417 418
{
	API_LOCK;
419
	return (linphone_core_in_call(this->lc) == TRUE);
420 421
}

422
Platform::Boolean Core::IsIncomingInvitePending::get()
423 424
{
	API_LOCK;
425
	return (linphone_core_is_incoming_invite_pending(this->lc) == TRUE);
426 427
}

428
Platform::Boolean Core::IsInConference::get()
429 430
{
	API_LOCK;
431
	return (linphone_core_is_in_conference(this->lc) == TRUE);
432 433
}

434
Platform::Boolean Core::IsIpv6Enabled::get()
435 436
{
	API_LOCK;
437
	return (linphone_core_ipv6_enabled(this->lc) == TRUE);
438 439
}

440
void Core::IsIpv6Enabled::set(Platform::Boolean enable)
441 442
{
	API_LOCK;
443
	linphone_core_enable_ipv6(this->lc, enable);
444 445
}

446
Platform::Boolean Core::IsIterateEnabled::get()
447
{
448
	return isIterateEnabled;
449 450
}

451
void Core::IsIterateEnabled::set(Platform::Boolean value)
452 453
{
	API_LOCK;
454 455 456 457 458 459 460
	if (isIterateEnabled && !value && IterateWorkItem)
	{
		IterateWorkItem->Cancel();
		IterateWorkItem = nullptr;
	}
	else if (!isIterateEnabled && value)
	{
461
		IAsyncAction^ IterateWorkItem = Windows::System::Threading::ThreadPool::RunAsync(ref new Windows::System::Threading::WorkItemHandler([this](IAsyncAction^ action)
462 463 464 465 466 467 468
		{
			while (true) {
				GlobalApiLock::Instance()->Lock(__FUNCTION__);
				linphone_core_iterate(this->lc);
				GlobalApiLock::Instance()->Unlock(__FUNCTION__);
				ms_usleep(20000);
			}
469
		}), Windows::System::Threading::WorkItemPriority::Low);
470
	}
471
	isIterateEnabled = value;
472 473
}

474
Platform::Boolean Core::IsKeepAliveEnabled::get()
475 476
{
	API_LOCK;
477
	return (linphone_core_keep_alive_enabled(this->lc) == TRUE);
478 479
}

480
void Core::IsKeepAliveEnabled::set(Platform::Boolean enable)
481 482
{
	API_LOCK;
483
	linphone_core_enable_keep_alive(this->lc, enable);
484 485
}

486
Platform::Boolean Core::IsMediaEncryptionMandatory::get()
487 488
{
	API_LOCK;
489
	return (linphone_core_is_media_encryption_mandatory(this->lc) == TRUE);
490 491
}

492
void Core::IsMediaEncryptionMandatory::set(Platform::Boolean yesno)
493 494
{
	API_LOCK;
495
	linphone_core_set_media_encryption_mandatory(this->lc, yesno);
496 497
}

498
Platform::Boolean Core::IsMicEnabled::get()
499 500
{
	API_LOCK;
501
	return (linphone_core_mic_enabled(this->lc) == TRUE);
502 503
}

504
void Core::IsMicEnabled::set(Platform::Boolean isMuted)
505 506
{
	API_LOCK;
507
	linphone_core_enable_mic(this->lc, isMuted);
508 509
}

510
Platform::Boolean Core::IsNetworkReachable::get()
511 512
{
	API_LOCK;
513
	return (linphone_core_is_network_reachable(this->lc) == TRUE);
514 515
}

516
void Core::IsNetworkReachable::set(Platform::Boolean isReachable)
517 518
{
	API_LOCK;
519
	linphone_core_set_network_reachable(this->lc, isReachable);
520 521
}

522
Platform::Boolean Core::IsSelfViewEnabled::get()
523 524
{
	API_LOCK;
525
	return (linphone_core_self_view_enabled(this->lc) == TRUE);
526 527
}

528
void Core::IsSelfViewEnabled::set(Platform::Boolean enable)
529 530
{
	API_LOCK;
531
	linphone_core_enable_self_view(this->lc, enable);
532 533
}

534
Platform::Boolean Core::IsSoundResourcesLocked::get()
535 536
{
	API_LOCK;
537
	return (linphone_core_sound_resources_locked(this->lc) == TRUE);
538 539
}

540
Platform::Boolean Core::IsVideoCaptureEnabled::get()
541 542
{
	API_LOCK;
543
	return (linphone_core_video_capture_enabled(this->lc) == TRUE);
544 545
}

546
void Core::IsVideoCaptureEnabled::set(Platform::Boolean enable)
547 548
{
	API_LOCK;
549
	linphone_core_enable_video_capture(this->lc, enable);
550 551
}

552
Platform::Boolean Core::IsVideoDisplayEnabled::get()
553 554
{
	API_LOCK;
555
	return (linphone_core_video_display_enabled(this->lc) == TRUE);
556 557
}

558
void Core::IsVideoDisplayEnabled::set(Platform::Boolean enable)
559 560
{
	API_LOCK;
561
	linphone_core_enable_video_display(this->lc, enable);
562 563
}

564
Platform::Boolean Core::IsVideoSupported::get()
565 566
{
	API_LOCK;
567
	return (linphone_core_video_supported(this->lc) == TRUE);
568 569
}

570
Platform::String^ Core::LogCollectionUploadServerUrl::get()
571
{
572 573 574
	// TODO
	throw ref new NotImplementedException();
	return nullptr;
575 576
}

577
void Core::LogCollectionUploadServerUrl::set(Platform::String^ url)
578 579
{
	API_LOCK;
580
	const char *curl = Utils::pstoccs(url);
581 582
	linphone_core_set_log_collection_upload_server_url(this->lc, curl);
	delete(curl);
583 584
}

585
int Core::MaxCalls::get()
586 587
{
	API_LOCK;
588
	return linphone_core_get_max_calls(this->lc);
589 590
}

591
void Core::MaxCalls::set(int max)
592 593
{
	API_LOCK;
594
	linphone_core_set_max_calls(this->lc, max);
595 596
}

597
MediaEncryption Core::MediaEncryption::get()
598 599
{
	API_LOCK;
600
	return (BelledonneCommunications::Linphone::Native::MediaEncryption) linphone_core_get_media_encryption(this->lc);
601 602
}

603
void Core::MediaEncryption::set(BelledonneCommunications::Linphone::Native::MediaEncryption menc)
604 605
{
	API_LOCK;
606
	linphone_core_set_media_encryption(this->lc, (LinphoneMediaEncryption)menc);
607 608
}

609
float Core::MicGainDb::get()
610 611
{
	API_LOCK;
612
	return linphone_core_get_mic_gain_db(this->lc);
613 614
}

615
void Core::MicGainDb::set(float gain)
616 617
{
	API_LOCK;
618
	linphone_core_set_mic_gain_db(this->lc, gain);
619 620
}

621
int Core::MissedCallsCount::get()
622 623
{
	API_LOCK;
624
	return linphone_core_get_missed_calls_count(this->lc);
625 626
}

627
Platform::String^ Core::NativePreviewWindowId::get()
628 629 630 631
{
	API_LOCK;
	void *id = linphone_core_get_native_preview_window_id(this->lc);
	if (id == NULL) return nullptr;
632 633
	RefToPtrProxy<Platform::String^> *proxy = reinterpret_cast<RefToPtrProxy<Platform::String^>*>(id);
	Platform::String^ nativeWindowId = (proxy) ? proxy->Ref() : nullptr;
634 635 636
	return nativeWindowId;
}

637
void Core::NativePreviewWindowId::set(Platform::String^ value)
638 639
{
	API_LOCK;
640
	RefToPtrProxy<Platform::String^> *nativeWindowId = new RefToPtrProxy<Platform::String^>(value);
641
	linphone_core_set_native_preview_window_id(this->lc, nativeWindowId);
642
	linphone_core_use_preview_window(this->lc, TRUE);
643 644
}

645
Platform::String^ Core::NativeVideoWindowId::get()
646 647 648 649
{
	API_LOCK;
	void *id = linphone_core_get_native_video_window_id(this->lc);
	if (id == NULL) return nullptr;
650 651
	RefToPtrProxy<Platform::String^> *proxy = reinterpret_cast<RefToPtrProxy<Platform::String^>*>(id);
	Platform::String^ nativeWindowId = (proxy) ? proxy->Ref() : nullptr;
652 653 654
	return nativeWindowId;
}

655
void Core::NativeVideoWindowId::set(Platform::String^ value)
656 657
{
	API_LOCK;
658
	RefToPtrProxy<Platform::String^> *nativeWindowId = new RefToPtrProxy<Platform::String^>(value);
659 660 661
	linphone_core_set_native_video_window_id(this->lc, nativeWindowId);
}

662
float Core::PlaybackGainDb::get()
663 664
{
	API_LOCK;
665
	return linphone_core_get_playback_gain_db(this->lc);
666 667
}

668
void Core::PlaybackGainDb::set(float gain)
669 670
{
	API_LOCK;
671
	linphone_core_set_playback_gain_db(this->lc, gain);
672 673
}

674
Platform::String^ Core::PlayFile::get()
675 676
{
	API_LOCK;
677
	return Utils::cctops(linphone_core_get_play_file(this->lc));
678 679
}

680
void Core::PlayFile::set(Platform::String^ path)
681 682
{
	API_LOCK;
683
	const char* file = Utils::pstoccs(path);
684 685
	linphone_core_set_play_file(this->lc, file);
	delete(file);
686 687
}

688
int Core::PlayLevel::get()
689 690
{
	API_LOCK;
691
	return linphone_core_get_play_level(this->lc);
692 693
}

694
void Core::PlayLevel::set(int level)
695 696
{
	API_LOCK;
697
	linphone_core_set_play_level(this->lc, level);
698 699
}

700
VideoSize^ Core::PreferredVideoSize::get()
701 702
{
	API_LOCK;
703
	VideoSize^ size = nullptr;
704 705 706 707 708
	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) {
		if ((sizesList->vsize.width == vsize.width) && (sizesList->vsize.height == vsize.height)) {
			Platform::String^ sizeName = Utils::cctops(sizesList->name);
709
			size = ref new VideoSize(vsize.width, vsize.height, sizeName);
710 711 712 713 714
			break;
		}
		sizesList++;
	}
	if (size == nullptr) {
715
		size = ref new VideoSize(vsize.width, vsize.height);
716 717
	}
	return size;
718 719
}

720
void Core::PreferredVideoSize::set(VideoSize^ size)
721 722
{
	API_LOCK;
723 724 725 726 727 728 729 730 731 732 733
	if (size->Name != nullptr) {
		const char *ccname = Utils::pstoccs(size->Name);
		linphone_core_set_preferred_video_size_by_name(this->lc, ccname);
		delete ccname;
	}
	else {
		MSVideoSize vs = { 0 };
		vs.width = size->Width;
		vs.height = size->Height;
		linphone_core_set_preferred_video_size(this->lc, vs);
	}
734 735
}

736
Platform::String^ Core::PreferredVideoSizeName::get()
737 738
{
	API_LOCK;
739 740 741 742
	char *cSizeName = linphone_core_get_preferred_video_size_name(this->lc);
	Platform::String^ sizeName = Utils::cctops(cSizeName);
	ms_free(cSizeName);
	return sizeName;
743 744
}

745
static void AddProxyConfigToVector(void *vProxyConfig, void *vector)
746
{
747
	::LinphoneProxyConfig *lProxyConfig = (::LinphoneProxyConfig *)vProxyConfig;
748 749 750
	RefToPtrProxy<IVector<ProxyConfig^>^> *list = reinterpret_cast< RefToPtrProxy<IVector<ProxyConfig^>^> *>(vector);
	IVector<ProxyConfig^>^ proxyconfigs = (list) ? list->Ref() : nullptr;
	ProxyConfig^ proxyConfig = (ProxyConfig^)Utils::GetProxyConfig(lProxyConfig);
751
	proxyconfigs->Append(proxyConfig);
752 753
}

754
IVector<ProxyConfig^>^ Core::ProxyConfigList::get()
755 756
{
	API_LOCK;
757
	IVector<ProxyConfig^>^ proxyconfigs = ref new Vector<ProxyConfig^>();
758
	const MSList *configList = linphone_core_get_proxy_config_list(this->lc);
759
	RefToPtrProxy<IVector<ProxyConfig^>^> *proxyConfigPtr = new RefToPtrProxy<IVector<ProxyConfig^>^>(proxyconfigs);
760 761
	ms_list_for_each2(configList, AddProxyConfigToVector, proxyConfigPtr);
	return proxyconfigs;
762 763
}

764
Platform::String^ Core::RootCa::get()
765 766
{
	API_LOCK;
767
	return Utils::cctops(linphone_core_get_root_ca(this->lc));
768 769
}

770
void Core::RootCa::set(Platform::String^ path)
771 772
{
	API_LOCK;
773 774 775
	const char *ccPath = Utils::pstoccs(path);
	linphone_core_set_root_ca(this->lc, ccPath);
	delete ccPath;
776 777
}

778
Transports^ Core::SipTransports::get()
779 780
{
	API_LOCK;
781 782
	::LCSipTransports transports;
	linphone_core_get_sip_transports(this->lc, &transports);
783
	return ref new Transports(transports.udp_port, transports.tcp_port, transports.tls_port);
784 785
}

786
void Core::SipTransports::set(Transports^ t)
787 788
{
	API_LOCK;
789 790 791 792 793 794
	::LCSipTransports transports;
	memset(&transports, 0, sizeof(LCSipTransports));
	transports.udp_port = t->UDP;
	transports.tcp_port = t->TCP;
	transports.tls_port = t->TLS;
	linphone_core_set_sip_transports(this->lc, &transports);
795 796
}

797
Platform::String^ Core::StunServer::get()
798 799
{
	API_LOCK;
800
	return Utils::cctops(linphone_core_get_stun_server(this->lc));
801 802
}

803
void Core::StunServer::set(Platform::String^ stun)
804 805
{
	API_LOCK;
806
	const char* stunserver = Utils::pstoccs(stun);
807 808
	linphone_core_set_stun_server(this->lc, stunserver);
	delete(stunserver);
809 810
}

811
Windows::Foundation::Collections::IVector<VideoSize^>^ Core::SupportedVideoSizes::get()
812 813
{
	API_LOCK;
814
	Vector<VideoSize^>^ sizes = ref new Vector<VideoSize^>();
815 816 817
	const MSVideoSizeDef *sizesList = linphone_core_get_supported_video_sizes(this->lc);
	while (sizesList->name != NULL) {
		Platform::String^ sizeName = Utils::cctops(sizesList->name);
818
		VideoSize^ size = ref new VideoSize(sizesList->vsize.width, sizesList->vsize.height, sizeName);
819 820 821 822
		sizes->Append(size);
		sizesList++;
	}
	return sizes;
823 824
}

825
Tunnel^ Core::Tunnel::get()
826 827
{
	API_LOCK;
828
	BelledonneCommunications::Linphone::Native::Tunnel^ tunnel = nullptr;
829 830
	LinphoneTunnel *lt = linphone_core_get_tunnel(this->lc);
	if (lt != nullptr) {
831
		tunnel = ref new BelledonneCommunications::Linphone::Native::Tunnel(lt);
832 833
	}
	return tunnel;
834 835
}

836
int Core::UploadBandwidth::get()
837 838
{
	API_LOCK;
839
	return linphone_core_get_upload_bandwidth(this->lc);
840 841
}

842
void Core::UploadBandwidth::set(int value)
843 844
{
	API_LOCK;
845
	linphone_core_set_upload_bandwidth(this->lc, value);
846 847
}

848
int Core::UploadPtime::get()
849
{
850 851
	API_LOCK;
	return linphone_core_get_upload_ptime(this->lc);
852 853
}

854
void Core::UploadPtime::set(int ptime)
855 856
{
	API_LOCK;
857
	linphone_core_set_upload_ptime(this->lc, ptime);
858 859
}

860
Platform::Boolean Core::UseInfoForDtmf::get()
861 862
{
	API_LOCK;
863
	return (linphone_core_get_use_info_for_dtmf(this->lc) == TRUE);
864 865
}

866
void Core::UseInfoForDtmf::set(Platform::Boolean use)
867 868
{
	API_LOCK;
869
	linphone_core_set_use_info_for_dtmf(this->lc, use);
870 871
}

872
Platform::Boolean Core::UseRfc2833ForDtmf::get()
873 874
{
	API_LOCK;
875
	return (linphone_core_get_use_rfc2833_for_dtmf(this->lc) == TRUE);
876 877
}

878
void Core::UseRfc2833ForDtmf::set(Platform::Boolean use)
879 880
{
	API_LOCK;
881
	linphone_core_set_use_rfc2833_for_dtmf(this->lc, use);
882 883
}

884
IVector<BelledonneCommunications::Linphone::Native::PayloadType^>^ Core::VideoCodecs::get()
885 886
{
	API_LOCK;
887
	IVector<PayloadType^>^ codecs = ref new Vector<PayloadType^>();
888
	const MSList *codecslist = linphone_core_get_video_codecs(this->lc);
889
	RefToPtrProxy<IVector<PayloadType^>^> *codecsPtr = new RefToPtrProxy<IVector<PayloadType^>^>(codecs);
890 891
	ms_list_for_each2(codecslist, AddPayloadTypeToVector, codecsPtr);
	return codecs;
892 893
}

894
Platform::String^ Core::VideoDevice::get()
895 896
{
	API_LOCK;
897 898 899 900 901 902
	Platform::String^ device = nullptr;
	const char *ccname = linphone_core_get_video_device(this->lc);
	if (ccname != NULL) {
		device = Utils::cctops(ccname);
	}
	return device;
903 904
}

905
void Core::VideoDevice::set(Platform::String^ device)
906 907
{
	API_LOCK;
908 909 910
	const char *ccname = Utils::pstoccs(device);
	linphone_core_set_video_device(this->lc, ccname);
	delete ccname;
911 912
}

913
Windows::Foundation::Collections::IVector<Platform::String^>^ Core::VideoDevices::get()
914 915
{
	API_LOCK;
916 917 918 919 920 921 922 923
	Vector<Platform::String^>^ devices = ref new Vector<Platform::String^>();
	const char **lvds = linphone_core_get_video_devices(this->lc);
	while (*lvds != NULL) {
		Platform::String^ device = Utils::cctops(*lvds);
		devices->Append(device);
		lvds++;
	}
	return devices;
924 925
}

926
VideoPolicy^ Core::VideoPolicy::get()
927 928
{
	API_LOCK;
929
	const ::LinphoneVideoPolicy *lvp = linphone_core_get_video_policy(this->lc);
930
	return ref new BelledonneCommunications::Linphone::Native::VideoPolicy((lvp->automatically_initiate == TRUE), (lvp->automatically_accept == TRUE));
931 932
}

933
void Core::VideoPolicy::set(BelledonneCommunications::Linphone::Native::VideoPolicy^ policy)
934 935
{
	API_LOCK;
936 937 938 939
	::LinphoneVideoPolicy lvp;
	lvp.automatically_initiate = policy->AutomaticallyInitiate;
	lvp.automatically_accept = policy->AutomaticallyAccept;
	linphone_core_set_video_policy(this->lc, &lvp);
940 941
}

942 943 944 945 946 947
VoipCallController^ Core::VoipCallController::get()
{
	API_LOCK;
	return this->voipCallController;
}

948 949 950 951




952
void Core::AcceptCall(Call^ call)
953 954
{
	API_LOCK;
955
	linphone_core_accept_call(this->lc, call->call);
956 957
}

958
void Core::AcceptCallUpdate(Call^ call, CallParams^ params)
959 960
{
	API_LOCK;
961
	linphone_core_accept_call_update(this->lc, call->call, params->params);
962 963
}

964
void Core::AcceptCallWithParams(Call^ call, CallParams^ params)
965 966
{
	API_LOCK;
967
	linphone_core_accept_call_with_params(this->lc, call->call, params->params);
968 969
}

970
void Core::AddAllToConference()
971 972
{
	API_LOCK;
973
	linphone_core_add_all_to_conference(this->lc);
974 975
}

976
void Core::AddAuthInfo(AuthInfo^ info)
977 978
{
	API_LOCK;
979
	linphone_core_add_auth_info(this->lc, info->auth_info);
980 981
}

982
void Core::AddProxyConfig(ProxyConfig^ proxyCfg)
983 984
{
	API_LOCK;
985
	linphone_core_add_proxy_config(this->lc, proxyCfg->proxyConfig);
986 987
}

988
void Core::AddToConference(Call^ call)
989 990
{
	API_LOCK;
991
	linphone_core_add_to_conference(this->lc, call->call);
992 993
}

994
void Core::ClearAllAuthInfo()
995 996
{
	API_LOCK;
997
	linphone_core_clear_all_auth_info(this->lc);
998 999
}

1000
void Core::ClearCallLogs()
1001 1002
{
	API_LOCK;
1003
	linphone_core_clear_call_logs(this->lc);
Ghislain MARY's avatar