Commit 71f0c480 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Started init/start/uninit process refactor to add a stop() method to be able...

Started init/start/uninit process refactor to add a stop() method to be able to destroy a Core in a more deterministic way than in the destructor
parent a3bc9e44
......@@ -870,6 +870,7 @@ void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf) {
if (!friendList) {
friendList = linphone_core_create_friend_list(lc);
linphone_core_add_friend_list(lc, friendList);
linphone_friend_list_unref(friendList);
}
if (linphone_friend_list_add_friend(friendList, lf) != LinphoneFriendListOK) return;
if (bctbx_list_find(lc->subscribers, lf)) {
......
This diff is collapsed.
......@@ -841,7 +841,7 @@ namespace LinphonePrivate {
bctbx_list_t *chat_rooms; \
bctbx_list_t *callsCache; \
bool_t dns_set_by_app; \
int auto_download_incoming_files_max_size; \
int auto_download_incoming_files_max_size;
#define LINPHONE_CORE_STRUCT_FIELDS \
LINPHONE_CORE_STRUCT_BASE_FIELDS \
......@@ -849,6 +849,7 @@ namespace LinphonePrivate {
bctbx_mutex_t zrtp_cache_db_mutex; \
sqlite3 *logs_db; \
sqlite3 *friends_db; \
bool_t debug_storage;
bool_t debug_storage; \
void *system_context;
#endif /* _PRIVATE_STRUCTS_H_ */
......@@ -1004,12 +1004,23 @@ LINPHONE_DEPRECATED LINPHONE_PUBLIC LinphoneCore *linphone_core_new(const Linpho
LINPHONE_DEPRECATED LINPHONE_PUBLIC LinphoneCore *linphone_core_new_with_config(const LinphoneCoreVTable *vtable, LpConfig *config, void *userdata);
/**
* Start a #LinphoneCore object after it has been instantiated.
* Start a #LinphoneCore object after it has been instantiated and not automatically started.
* Also re-initialize a #LinphoneCore object that has been stopped using linphone_core_stop().
* Must be called only if #LinphoneGlobalState is either Ready of Off. State will changed to Startup, Configuring and then On.
* @ingroup initializing
* @param[in] core The #LinphoneCore object to be started
*/
LINPHONE_PUBLIC void linphone_core_start (LinphoneCore *core);
/**
* Stop a #LinphoneCore object after it has been instantiated and started.
* If stopped, it can be started again using linphone_core_start().
* Must be called only if #LinphoneGlobalState is either On. State will changed to Shutdown and then Off.
* @ingroup initializing
* @param[in] core The #LinphoneCore object to be stopped
*/
LINPHONE_PUBLIC void linphone_core_stop (LinphoneCore *core);
/**
* Increment the reference counter of a #LinphoneCore object.
* @param lc The #LinphoneCore which the ref counter is to be incremented.
......
......@@ -109,6 +109,8 @@ LINPHONE_DEPRECATED LINPHONE_PUBLIC LinphoneCore *linphone_factory_create_core_2
* The #LinphoneCore object is the primary handle for doing all phone actions. It should be unique within your
* application.
* The #LinphoneCore object is not started automatically, you need to call linphone_core_start() to that effect.
* The returned #LinphoneCore will be in #LinphoneGlobalState Ready.
* Core ressources can be released using linphone_core_stop() which is strongly encouraged on garbage collected languages.
* @param[in] factory The #LinphoneFactory singleton.
* @param[in] config_path A path to a config file. If it does not exists it will be created. The config file is used to
* store all settings, proxies... so that all these settings become persistent over the life of the #LinphoneCore object.
......@@ -175,6 +177,8 @@ LINPHONE_DEPRECATED LINPHONE_PUBLIC LinphoneCore *linphone_factory_create_core_w
* The #LinphoneCore object is the primary handle for doing all phone actions. It should be unique within your
* application.
* The #LinphoneCore object is not started automatically, you need to call linphone_core_start() to that effect.
* The returned #LinphoneCore will be in #LinphoneGlobalState Ready.
* Core ressources can be released using linphone_core_stop() which is strongly encouraged on garbage collected languages.
* @param[in] factory The #LinphoneFactory singleton.
* @param[in] config A #LinphoneConfig object holding the configuration for the #LinphoneCore to be instantiated.
* @param[in] system_context A pointer to a system object required by the core to operate. Currently it is required to
......
......@@ -505,11 +505,18 @@ typedef enum _LinphoneFriendListSyncStatus {
* @ingroup initializing
**/
typedef enum _LinphoneGlobalState {
/** State in which we're in after linphone_core_stop(). Do not call any method while in this state except for linphone_core_start() */
LinphoneGlobalOff,
/** Transient state for when we call linphone_core_start() */
LinphoneGlobalStartup,
/** Indicates #LinphoneCore has been started and is up and running */
LinphoneGlobalOn,
/** Transient state for when we call linphone_core_stop() */
LinphoneGlobalShutdown,
LinphoneGlobalConfiguring
/** Transient state between Startup and On if there is a remote provisionning URI configured */
LinphoneGlobalConfiguring,
/** #LinphoneCore state after being created by linphone_factory_create_core(), generally followed by a call to linphone_core_start() */
LinphoneGlobalReady
} LinphoneGlobalState;
/**
......
......@@ -42,6 +42,7 @@ L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(
)
static void _linphone_core_constructor (LinphoneCore *lc) {
lc->state = LinphoneGlobalOff;
}
static void _linphone_core_destructor (LinphoneCore *lc) {
......
......@@ -98,6 +98,10 @@ void CorePrivate::uninit () {
chatRooms.clear();
chatRoomsById.clear();
noCreatedClientGroupChatRooms.clear();
listeners.clear();
if (q->limeX3dhEnabled()) {
q->enableLimeX3dh(false);
}
remoteListEventHandler = nullptr;
localListEventHandler = nullptr;
......
......@@ -85,6 +85,51 @@ static void core_init_test(void) {
/* until we have good certificates on our test server... */
linphone_core_verify_server_certificates(lc,FALSE);
if (BC_ASSERT_PTR_NOT_NULL(lc)) {
BC_ASSERT_EQUAL(linphone_core_get_global_state(lc), LinphoneGlobalOn, int, "%i");
linphone_core_unref(lc);
}
}
static void core_init_stop_test(void) {
LinphoneCore* lc;
lc = linphone_factory_create_core_2(linphone_factory_get(),NULL,NULL,liblinphone_tester_get_empty_rc(), NULL, system_context);
/* until we have good certificates on our test server... */
linphone_core_verify_server_certificates(lc,FALSE);
if (BC_ASSERT_PTR_NOT_NULL(lc)) {
BC_ASSERT_EQUAL(linphone_core_get_global_state(lc), LinphoneGlobalOn, int, "%i");
linphone_core_stop(lc);
BC_ASSERT_EQUAL(linphone_core_get_global_state(lc), LinphoneGlobalOff, int, "%i");
}
if (BC_ASSERT_PTR_NOT_NULL(lc)) {
linphone_core_unref(lc);
}
}
static void core_init_stop_start_test(void) {
LinphoneCore* lc;
lc = linphone_factory_create_core_2(linphone_factory_get(),NULL,NULL,liblinphone_tester_get_empty_rc(), NULL, system_context);
/* until we have good certificates on our test server... */
linphone_core_verify_server_certificates(lc, FALSE);
const char *uuid = lp_config_get_string(linphone_core_get_config(lc), "misc", "uuid", NULL);
BC_ASSERT_STRING_NOT_EQUAL(uuid, "");
if (BC_ASSERT_PTR_NOT_NULL(lc)) {
BC_ASSERT_EQUAL(linphone_core_get_global_state(lc), LinphoneGlobalOn, int, "%i");
linphone_core_stop(lc);
BC_ASSERT_EQUAL(linphone_core_get_global_state(lc), LinphoneGlobalOff, int, "%i");
}
if (BC_ASSERT_PTR_NOT_NULL(lc)) {
linphone_core_start(lc);
BC_ASSERT_EQUAL(linphone_core_get_global_state(lc), LinphoneGlobalOn, int, "%i");
}
const char *uuid2 = lp_config_get_string(linphone_core_get_config(lc), "misc", "uuid", NULL);
BC_ASSERT_STRING_NOT_EQUAL(uuid2, "");
BC_ASSERT_STRING_EQUAL(uuid, uuid2);
if (BC_ASSERT_PTR_NOT_NULL(lc)) {
linphone_core_unref(lc);
}
......@@ -1486,6 +1531,8 @@ test_t setup_tests[] = {
TEST_NO_TAG("Linphone proxy config address equal (internal api)", linphone_proxy_config_address_equal_test),
TEST_NO_TAG("Linphone proxy config server address change (internal api)", linphone_proxy_config_is_server_config_changed_test),
TEST_NO_TAG("Linphone core init/uninit", core_init_test),
TEST_NO_TAG("Linphone core init/stop/uninit", core_init_stop_test),
TEST_NO_TAG("Linphone core init/stop/start/uninit", core_init_stop_start_test),
TEST_NO_TAG("Linphone random transport port",core_sip_transport_test),
TEST_NO_TAG("Linphone interpret url", linphone_interpret_url_test),
TEST_NO_TAG("LPConfig from buffer", linphone_lpconfig_from_buffer),
......
......@@ -522,6 +522,7 @@ void linphone_core_manager_stop(LinphoneCoreManager *mgr){
unlink(record_file);
}
}
linphone_core_stop(mgr->lc);
linphone_core_unref(mgr->lc);
mgr->lc = NULL;
}
......@@ -543,7 +544,13 @@ void linphone_core_manager_reinit(LinphoneCoreManager *mgr) {
}
void linphone_core_manager_restart(LinphoneCoreManager *mgr, bool_t check_for_proxies) {
linphone_core_manager_reinit(mgr);
//linphone_core_manager_reinit(mgr);
if (mgr->lc) {
linphone_core_stop(mgr->lc);
} else {
linphone_core_manager_configure(mgr);
}
reset_counters(&mgr->stat);
linphone_core_manager_start(mgr, check_for_proxies);
}
......
......@@ -520,7 +520,7 @@ public class AndroidPlatformHelper {
mContext.unregisterReceiver(mNetworkReceiver);
}
} else {
if (mConnectivityManager != null) {
if (mNetworkManagerAbove21 != null && mConnectivityManager != null) {
Log.i("[Platform Helper] Unregistering network callbacks");
mNetworkManagerAbove21.unregisterNetworkCallbacks(mConnectivityManager);
}
......
......@@ -251,6 +251,12 @@ class JavaTranslator(object):
methodDict['classImplName'] = className + 'Impl'
methodDict['isLinphoneFactory'] = (className == 'Factory')
methodDict['jniPath'] = self.jni_path
methodDict['isLinphoneCore'] = (className == 'Core')
methodDict['isNotLinphoneCoreStart'] = (_method.name.to_c() != 'linphone_core_start')
hasCoreAccessor = class_.name.to_camel_case() in CORE_ACCESSOR_LIST
methodDict['hasCoreAccessor'] = hasCoreAccessor
if hasCoreAccessor:
methodDict['c_core_accessor'] = 'linphone_' + class_.name.to_snake_case() + '_get_core'
methodDict['return'] = _method.returnType.translate(self.langTranslator, jni=True, isReturn=True, namespace=namespace)
methodDict['hasListReturn'] = methodDict['return'] == 'jobjectArray'
......
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