Commit 06f9d69a authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Added vtable callbacks for friend list created / removed + tests

parent 5fe2c68b
......@@ -918,6 +918,7 @@ int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char *
#ifndef VCARD_ENABLED
ms_error("vCard support wasn't enabled at compilation time");
return -1;
#endif
if (!vcards) {
ms_error("Failed to parse the file %s", vcard_file);
......@@ -948,6 +949,7 @@ int linphone_core_import_friends_from_vcard4_buffer(LinphoneCore *lc, const char
#ifndef VCARD_ENABLED
ms_error("vCard support wasn't enabled at compilation time");
return -1;
#endif
if (!vcards) {
ms_error("Failed to parse the buffer");
......
......@@ -1937,12 +1937,13 @@ LinphoneFriendList* linphone_core_get_default_friend_list(const LinphoneCore *lc
void linphone_core_remove_friend_list(LinphoneCore *lc, LinphoneFriendList *list) {
MSList *elem = ms_list_find(lc->friends_lists, list);
if (elem == NULL) return;
list->lc = NULL;
linphone_friend_list_unref(list);
lc->friends_lists = ms_list_remove_link(lc->friends_lists, elem);
#ifdef FRIENDS_SQL_STORAGE_ENABLED
linphone_core_remove_friends_list_from_db(lc, list);
#endif
linphone_core_notify_friend_list_removed(lc, list);
list->lc = NULL;
linphone_friend_list_unref(list);
lc->friends_lists = ms_list_remove_link(lc->friends_lists, elem);
}
void linphone_core_add_friend_list(LinphoneCore *lc, LinphoneFriendList *list) {
......@@ -1954,6 +1955,7 @@ void linphone_core_add_friend_list(LinphoneCore *lc, LinphoneFriendList *list) {
#ifdef FRIENDS_SQL_STORAGE_ENABLED
linphone_core_store_friends_list_in_db(lc, list);
#endif
linphone_core_notify_friend_list_created(lc, list);
} else {
const char *rls_uri = lp_config_get_string(lc->config, "sip", "rls_uri", NULL);
list = linphone_core_create_friend_list(lc);
......
......@@ -2068,6 +2068,20 @@ typedef void (*LinphoneCoreLogCollectionUploadStateChangedCb)(LinphoneCore *lc,
*/
typedef void (*LinphoneCoreLogCollectionUploadProgressIndicationCb)(LinphoneCore *lc, size_t offset, size_t total);
/**
* Callback prototype for reporting when a friend list has been added to the core friends list.
* @param[in] lc LinphoneCore object
* @param[in] list LinphoneFriendList object
*/
typedef void (*LinphoneCoreFriendListCreatedCb) (LinphoneCore *lc, LinphoneFriendList *list);
/**
* Callback prototype for reporting when a friend list has been removed from the core friends list.
* @param[in] lc LinphoneCore object
* @param[in] list LinphoneFriendList object
*/
typedef void (*LinphoneCoreFriendListRemovedCb) (LinphoneCore *lc, LinphoneFriendList *list);
/**
* This structure holds all callbacks that the application should implement.
* None is mandatory.
......@@ -2105,6 +2119,8 @@ typedef struct _LinphoneCoreVTable{
LinphoneCoreNetworkReachableCb network_reachable; /**< Callback to report IP network status (I.E up/down )*/
LinphoneCoreLogCollectionUploadStateChangedCb log_collection_upload_state_changed; /**< Callback to upload collected logs */
LinphoneCoreLogCollectionUploadProgressIndicationCb log_collection_upload_progress_indication; /**< Callback to indicate log collection upload progress */
LinphoneCoreFriendListCreatedCb friend_list_created;
LinphoneCoreFriendListRemovedCb friend_list_removed;
void *user_data; /**<User data associated with the above callbacks */
} LinphoneCoreVTable;
......
......@@ -1433,6 +1433,8 @@ void linphone_core_notify_subscription_state_changed(LinphoneCore *lc, LinphoneE
void linphone_core_notify_publish_state_changed(LinphoneCore *lc, LinphoneEvent *lev, LinphonePublishState state);
void linphone_core_notify_log_collection_upload_state_changed(LinphoneCore *lc, LinphoneCoreLogCollectionUploadState state, const char *info);
void linphone_core_notify_log_collection_upload_progress_indication(LinphoneCore *lc, size_t offset, size_t total);
void linphone_core_notify_friend_list_created(LinphoneCore *lc, LinphoneFriendList *list);
void linphone_core_notify_friend_list_removed(LinphoneCore *lc, LinphoneFriendList *list);
void set_mic_gain_db(AudioStream *st, float gain);
void set_playback_gain_db(AudioStream *st, float gain);
......
......@@ -264,6 +264,16 @@ void linphone_core_notify_log_collection_upload_progress_indication(LinphoneCore
cleanup_dead_vtable_refs(lc);
}
void linphone_core_notify_friend_list_created(LinphoneCore *lc, LinphoneFriendList *list) {
NOTIFY_IF_EXIST(friend_list_created, lc, list);
cleanup_dead_vtable_refs(lc);
}
void linphone_core_notify_friend_list_removed(LinphoneCore *lc, LinphoneFriendList *list) {
NOTIFY_IF_EXIST(friend_list_removed, lc, list);
cleanup_dead_vtable_refs(lc);
}
static VTableReference * v_table_reference_new(LinphoneCoreVTable *vtable, bool_t autorelease, bool_t internal){
VTableReference *ref=ms_new0(VTableReference,1);
ref->valid=1;
......
......@@ -133,22 +133,46 @@ end:
linphone_core_manager_destroy(manager);
}
typedef struct _LinphoneFriendListStats {
int new_list_count;
int removed_list_count;
} LinphoneFriendListStats;
static void friend_list_created_cb(LinphoneCore *lc, LinphoneFriendList *list) {
LinphoneFriendListStats *stats = (LinphoneFriendListStats *)linphone_friend_list_get_user_data(list);
stats->new_list_count++;
}
static void friend_list_removed_cb(LinphoneCore *lc, LinphoneFriendList *list) {
LinphoneFriendListStats *stats = (LinphoneFriendListStats *)linphone_friend_list_get_user_data(list);
stats->removed_list_count++;
}
static void friends_sqlite_storage(void) {
LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
LinphoneVCard *lvc = linphone_vcard_new();
LinphoneCoreVTable *v_table = linphone_core_v_table_new();
LinphoneCore* lc = NULL;
LinphoneFriendList *lfl = NULL;
LinphoneFriend *lf = NULL;
LinphoneFriend *lf2 = NULL;
LinphoneVCard *lvc = linphone_vcard_new();
LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org");
const MSList *friends = linphone_core_get_friend_list(manager->lc);
const MSList *friends = NULL;
MSList *friends_from_db = NULL;
MSList *friends_lists_from_db = NULL;
char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db");
LinphoneFriendListStats *stats = (LinphoneFriendListStats *)ms_new0(LinphoneFriendListStats, 1);
v_table->friend_list_created = friend_list_created_cb;
v_table->friend_list_removed = friend_list_removed_cb;
lc = linphone_core_new(v_table, NULL, NULL, NULL);
friends = linphone_core_get_friend_list(lc);
lfl = linphone_core_create_friend_list(lc);
linphone_friend_list_set_user_data(lfl, stats);
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
unlink(friends_db);
linphone_core_set_friends_database_path(manager->lc, friends_db);
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, linphone_core_get_default_friend_list(manager->lc));
linphone_core_set_friends_database_path(lc, friends_db);
friends_from_db = linphone_core_fetch_friends_from_db(lc, linphone_core_get_default_friend_list(lc));
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d");
linphone_vcard_set_etag(lvc, "\"123-456789\"");
......@@ -157,7 +181,9 @@ static void friends_sqlite_storage(void) {
linphone_friend_set_address(lf, addr);
linphone_friend_set_name(lf, "Sylvain");
linphone_core_add_friend_list(manager->lc, lfl);
linphone_core_add_friend_list(lc, lfl);
wait_for_until(lc, NULL, &stats->new_list_count, 1, 1000);
BC_ASSERT_EQUAL(stats->new_list_count, 1, int, "%i");
linphone_friend_list_unref(lfl);
linphone_friend_list_set_display_name(lfl, "Test");
BC_ASSERT_EQUAL_FATAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%i");
......@@ -165,10 +191,10 @@ static void friends_sqlite_storage(void) {
BC_ASSERT_EQUAL(lfl->storage_id, 1, int, "%d");
BC_ASSERT_EQUAL(lf->storage_id, 1, int, "%d");
friends = linphone_core_get_friend_list(manager->lc);
friends = linphone_core_get_friend_list(lc);
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(manager->lc);
friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(lc);
BC_ASSERT_EQUAL(ms_list_size(friends_lists_from_db), 1, int, "%d");
friends_from_db = ((LinphoneFriendList *)friends_lists_from_db->data)->friends;
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d");
......@@ -177,7 +203,7 @@ static void friends_sqlite_storage(void) {
BC_ASSERT_PTR_NOT_NULL(lf2->friend_list);
friends_lists_from_db = ms_list_free_with_data(friends_lists_from_db, (void (*)(void *))linphone_friend_list_unref);
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl);
friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl);
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d");
if (ms_list_size(friends_from_db) < 1) {
goto end;
......@@ -193,7 +219,7 @@ static void friends_sqlite_storage(void) {
linphone_friend_set_name(lf, "Margaux");
linphone_friend_done(lf);
friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl);
friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl);
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d");
if (ms_list_size(friends_from_db) < 1) {
goto end;
......@@ -202,17 +228,21 @@ static void friends_sqlite_storage(void) {
BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), "Margaux");
friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
linphone_core_remove_friend(manager->lc, lf);
friends = linphone_core_get_friend_list(manager->lc);
linphone_core_remove_friend(lc, lf);
friends = linphone_core_get_friend_list(lc);
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl);
friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl);
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d");
linphone_core_remove_friend_list(lc, lfl);
wait_for_until(lc, NULL, &stats->removed_list_count, 1, 1000);
BC_ASSERT_EQUAL(stats->removed_list_count, 1, int, "%i");
end:
unlink(friends_db);
ms_free(friends_db);
linphone_address_unref(addr);
linphone_core_manager_destroy(manager);
linphone_core_destroy(lc);
}
#endif
......
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