Commit 7d9458ee authored by DanmeiChen's avatar DanmeiChen
Browse files

enable auto iterate for ios

parent 017d34d0
......@@ -22,8 +22,11 @@
@interface IosAppDelegate : NSObject {
std::shared_ptr<LinphonePrivate::Core> pcore;
NSTimer* mIterateTimer;
}
- (void)setCore:(std::shared_ptr<LinphonePrivate::Core>)core;
- (void)onLinphoneCoreStart;
- (void)onLinphoneCoreStop;
@end
......@@ -56,4 +56,36 @@
pcore->enterForeground();
}
- (void)iterate {
linphone_core_iterate(pcore->getCCore());
}
- (void)onLinphoneCoreStart {
if (linphone_core_is_auto_iterate_enabled(pcore->getCCore())) {
if (mIterateTimer.valid) {
ms_message("[Ios App] core.iterate() is already scheduled");
return;
}
mIterateTimer = [NSTimer timerWithTimeInterval:0.02 target:self selector:@selector(iterate) userInfo:nil repeats:YES];
// NSTimer runs only in the main thread correctly. Since there may not be a current thread loop.
[[NSRunLoop mainRunLoop] addTimer:mIterateTimer forMode:NSDefaultRunLoopMode];
ms_message("[Ios App] Call to core.iterate() scheduled every 20ms");
} else {
ms_warning("[Ios App] Auto core.iterate() isn't enabled, ensure you do it in your application!");
}
}
- (void)onLinphoneCoreStop {
if (linphone_core_is_auto_iterate_enabled(pcore->getCCore())) {
if (mIterateTimer) {
[mIterateTimer invalidate];
mIterateTimer = nil;
}
ms_message("[Ios App] Auto core.iterate() stopped");
}
}
@end
/*
linphone
Copyright (C) 2017 Belledonne Communications SARL
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* Copyright (c) 2010-2019 Belledonne Communications SARL.
*
* This file is part of Liblinphone.
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifdef __APPLE__
......@@ -262,12 +262,14 @@ void IosPlatformHelpers::onLinphoneCoreStart(bool monitoringEnabled) {
mNetworkMonitoringEnabled = monitoringEnabled;
if (monitoringEnabled) {
startNetworkMonitoring();
[mAppDelegate onLinphoneCoreStart];
}
}
void IosPlatformHelpers::onLinphoneCoreStop() {
if (mNetworkMonitoringEnabled) {
stopNetworkMonitoring();
[mAppDelegate onLinphoneCoreStop];
}
getSharedCoreHelpers()->onLinphoneCoreStop();
......
......@@ -53,7 +53,9 @@ static void shared_main_core_prevent_executor_core_start(void) {
LinphoneCoreManager *main_mgr;
LinphoneCoreManager *executor_mgr;
main_mgr = linphone_core_manager_create_shared("marie_rc", TEST_GROUP_ID, TRUE, NULL);
linphone_core_set_auto_iterate_enabled(main_mgr->lc, FALSE);
executor_mgr = linphone_core_manager_create_shared("", TEST_GROUP_ID, FALSE, main_mgr);
linphone_core_set_auto_iterate_enabled(executor_mgr->lc, FALSE);
linphone_core_manager_start(main_mgr, TRUE);
BC_ASSERT_TRUE(wait_for_until(main_mgr->lc, NULL, &main_mgr->stat.number_of_LinphoneGlobalOn, 1, 2000));
......@@ -68,6 +70,7 @@ void *thread_shared_main_core_stops_executor_core(void *arguments) {
#if TARGET_OS_IPHONE
LinphoneCoreManager *executor_mgr = (LinphoneCoreManager *)arguments;
LinphoneCoreManager *main_mgr = linphone_core_manager_create_shared("", TEST_GROUP_ID, TRUE, executor_mgr);
linphone_core_set_auto_iterate_enabled(main_mgr->lc, FALSE);
ms_sleep(5); // for synchro with main thread
linphone_core_manager_start(main_mgr, TRUE);
BC_ASSERT_TRUE(wait_for_until(main_mgr->lc, NULL, &main_mgr->stat.number_of_LinphoneGlobalOn, 1, 2000));
......@@ -82,6 +85,7 @@ static void shared_main_core_stops_executor_core(void) {
#if TARGET_OS_IPHONE
LinphoneCoreManager *executor_mgr;
executor_mgr = linphone_core_manager_create_shared("marie_rc", TEST_GROUP_ID, FALSE, NULL);
linphone_core_set_auto_iterate_enabled(executor_mgr->lc, FALSE);
linphone_core_manager_start(executor_mgr, TRUE);
BC_ASSERT_TRUE(wait_for_until(executor_mgr->lc, NULL, &executor_mgr->stat.number_of_LinphoneGlobalOn, 1, 2000));
......@@ -209,11 +213,21 @@ void *thread_shared_core_get_message_from_user_defaults(void *arguments) {
return NULL;
}
// This test suite does not work yet, so do not test "automatic iterator".
// In addition, "automatic iterator" must be disabled for extensions.
LinphoneCoreManager *linphone_core_manager_new_without_auto_iterate(const char *rc_file) {
LinphoneCoreManager *manager = linphone_core_manager_create2(rc_file, NULL);
linphone_core_set_auto_iterate_enabled(manager->lc, FALSE);
linphone_core_manager_start(manager, TRUE);
return manager;
}
static void shared_executor_core_get_message_by_starting_a_core(void) {
#if TARGET_OS_IPHONE
const char *text = "Bli bli bli \n blu";
LinphoneCoreManager *sender_mgr = linphone_core_manager_new("marie_rc");
LinphoneCoreManager *sender_mgr = linphone_core_manager_new_without_auto_iterate("marie_rc");
LinphoneCoreManager *receiver_mgr = linphone_core_manager_create_shared("pauline_rc", TEST_GROUP_ID, FALSE, NULL);
linphone_core_set_auto_iterate_enabled(receiver_mgr->lc, FALSE);
linphone_core_manager_start(receiver_mgr, TRUE);
const char *call_id = shared_core_send_msg_and_get_call_id(sender_mgr, receiver_mgr, text);
......@@ -231,8 +245,9 @@ static void shared_executor_core_get_message_with_user_defaults_mono_thread(void
#if TARGET_OS_IPHONE
/* mono thread means that the msg in already in the user defaults when the executor core start */
const char *text = "Bli bli bli \n blu";
LinphoneCoreManager *sender_mgr = linphone_core_manager_new("marie_rc");
LinphoneCoreManager *sender_mgr = linphone_core_manager_new_without_auto_iterate("marie_rc");
LinphoneCoreManager *main_mgr = linphone_core_manager_create_shared("pauline_rc", TEST_GROUP_ID, TRUE, NULL);
linphone_core_set_auto_iterate_enabled(main_mgr->lc, FALSE);
linphone_core_manager_start(main_mgr, TRUE);
const char *call_id = shared_core_send_msg_and_get_call_id(sender_mgr, main_mgr, text);
......@@ -254,8 +269,9 @@ static void shared_executor_core_get_message_with_user_defaults_multi_thread(voi
#if TARGET_OS_IPHONE
/* multi thread means that the executor core waits for the msg to be written by the main core into the user defaults */
const char *text = "Bli bli bli \n blu";
LinphoneCoreManager *sender_mgr = linphone_core_manager_new("marie_rc");
LinphoneCoreManager *sender_mgr = linphone_core_manager_new_without_auto_iterate("marie_rc");
LinphoneCoreManager *main_mgr = linphone_core_manager_create_shared("pauline_rc", TEST_GROUP_ID, TRUE, NULL);
linphone_core_set_auto_iterate_enabled(main_mgr->lc, FALSE);
linphone_core_manager_start(main_mgr, TRUE);
pthread_t executor;
......@@ -286,8 +302,9 @@ static void shared_executor_core_get_message_with_user_defaults_multi_thread(voi
static void two_shared_executor_cores_get_messages(void) {
#if TARGET_OS_IPHONE
LinphoneCoreManager *sender_mgr = linphone_core_manager_new("marie_rc");
LinphoneCoreManager *sender_mgr = linphone_core_manager_new_without_auto_iterate("marie_rc");
LinphoneCoreManager *receiver_mgr = linphone_core_manager_create_shared("pauline_rc", TEST_GROUP_ID, FALSE, NULL);
linphone_core_set_auto_iterate_enabled(receiver_mgr->lc, FALSE);
linphone_core_manager_start(receiver_mgr, TRUE);
const char *call_id1 = shared_core_send_msg_and_get_call_id(sender_mgr, receiver_mgr, "message1");
......
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