Commit 85b5ca09 authored by François Grisez's avatar François Grisez

Reworking of Liblinphone API

* Introduction of LinphoneFactory singleton class to create
  core-independent object like LinphoneAddress or LinphoneVcard.
* Make several C structures inherite from belle_sip_object_t class:
	* LinphoneCore
	* LinphoneVcard
	* LinphoneAuthInfo
* Creation of the LinphoneCoreCbs class that enable to store the
  callbacks used by LinphoneCore.
parent d6d0cbf5
......@@ -78,6 +78,7 @@ set(LINPHONE_SOURCE_FILES_C
enum.c
error_info.c
event.c
factory.c
friend.c
friendlist.c
im_notif_policy.c
......
......@@ -21,13 +21,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "linphone/lpconfig.h"
#include "private.h"
LinphoneAddress * linphone_address_new(const char *addr){
LinphoneAddress * _linphone_address_new(const char *addr){
SalAddress *saddr=sal_address_new(addr);
if (saddr==NULL)
ms_error("Cannot create LinphoneAddress, bad uri [%s]",addr);
return saddr;
}
LinphoneAddress * linphone_address_new(const char *addr) {
return _linphone_address_new(addr);
}
LinphoneAddress * linphone_address_clone(const LinphoneAddress *addr){
return sal_address_clone(addr);
}
......
......@@ -26,13 +26,22 @@
#include "private.h"
#include "linphone/lpconfig.h"
/**
* @addtogroup authentication
* @{
**/
static void _linphone_auth_info_uninit(LinphoneAuthInfo *obj);
static void _linphone_auth_info_copy(LinphoneAuthInfo *dst, const LinphoneAuthInfo *src);
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneAuthInfo);
BELLE_SIP_DECLARE_VPTR(LinphoneAuthInfo);
BELLE_SIP_INSTANCIATE_VPTR(
LinphoneAuthInfo,
belle_sip_object_t,
_linphone_auth_info_uninit, // destroy
_linphone_auth_info_copy, // clone
NULL, // marshal
FALSE
);
LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain){
LinphoneAuthInfo *obj=ms_new0(LinphoneAuthInfo,1);
LinphoneAuthInfo *obj=belle_sip_object_new(LinphoneAuthInfo);
if (username!=NULL && (strlen(username)>0) ) obj->username=ms_strdup(username);
if (userid!=NULL && (strlen(userid)>0)) obj->userid=ms_strdup(userid);
if (passwd!=NULL && (strlen(passwd)>0)) obj->passwd=ms_strdup(passwd);
......@@ -42,19 +51,29 @@ LinphoneAuthInfo *linphone_auth_info_new(const char *username, const char *useri
return obj;
}
static void _linphone_auth_info_copy(LinphoneAuthInfo *dst, const LinphoneAuthInfo *src) {
if (src->username) dst->username = ms_strdup(src->username);
if (src->userid) dst->userid = ms_strdup(src->userid);
if (src->passwd) dst->passwd = ms_strdup(src->passwd);
if (src->ha1) dst->ha1 = ms_strdup(src->ha1);
if (src->realm) dst->realm = ms_strdup(src->realm);
if (src->domain) dst->domain = ms_strdup(src->domain);
if (src->tls_cert) dst->tls_cert = ms_strdup(src->tls_cert);
if (src->tls_key) dst->tls_key = ms_strdup(src->tls_key);
if (src->tls_cert_path) dst->tls_cert_path = ms_strdup(src->tls_cert_path);
if (src->tls_key_path) dst->tls_key_path = ms_strdup(src->tls_key_path);
}
LinphoneAuthInfo *linphone_auth_info_clone(const LinphoneAuthInfo *ai){
LinphoneAuthInfo *obj=ms_new0(LinphoneAuthInfo,1);
if (ai->username) obj->username = ms_strdup(ai->username);
if (ai->userid) obj->userid = ms_strdup(ai->userid);
if (ai->passwd) obj->passwd = ms_strdup(ai->passwd);
if (ai->ha1) obj->ha1 = ms_strdup(ai->ha1);
if (ai->realm) obj->realm = ms_strdup(ai->realm);
if (ai->domain) obj->domain = ms_strdup(ai->domain);
if (ai->tls_cert) obj->tls_cert = ms_strdup(ai->tls_cert);
if (ai->tls_key) obj->tls_key = ms_strdup(ai->tls_key);
if (ai->tls_cert_path) obj->tls_cert_path = ms_strdup(ai->tls_cert_path);
if (ai->tls_key_path) obj->tls_key_path = ms_strdup(ai->tls_key_path);
return obj;
return LINPHONE_AUTH_INFO(belle_sip_object_clone(BELLE_SIP_OBJECT(ai)));
}
LinphoneAuthInfo *linphone_auth_info_ref(LinphoneAuthInfo *obj) {
return LINPHONE_AUTH_INFO(belle_sip_object_ref(obj));
}
void linphone_auth_info_unref(LinphoneAuthInfo *obj) {
belle_sip_object_unref(obj);
}
const char *linphone_auth_info_get_username(const LinphoneAuthInfo *i) {
......@@ -178,10 +197,7 @@ void linphone_auth_info_set_tls_key_path(LinphoneAuthInfo *info, const char *tls
if (tls_key_path && strlen(tls_key_path) > 0) info->tls_key_path = ms_strdup(tls_key_path);
}
/**
* Destroys a LinphoneAuthInfo object.
**/
void linphone_auth_info_destroy(LinphoneAuthInfo *obj){
static void _linphone_auth_info_uninit(LinphoneAuthInfo *obj) {
if (obj->username != NULL) ms_free(obj->username);
if (obj->userid != NULL) ms_free(obj->userid);
if (obj->passwd != NULL) ms_free(obj->passwd);
......@@ -192,7 +208,13 @@ void linphone_auth_info_destroy(LinphoneAuthInfo *obj){
if (obj->tls_key != NULL) ms_free(obj->tls_key);
if (obj->tls_cert_path != NULL) ms_free(obj->tls_cert_path);
if (obj->tls_key_path != NULL) ms_free(obj->tls_key_path);
ms_free(obj);
}
/**
* Destroys a LinphoneAuthInfo object.
**/
void linphone_auth_info_destroy(LinphoneAuthInfo *obj){
belle_sip_object_unref(obj);
}
void linphone_auth_info_write_config(LpConfig *config, LinphoneAuthInfo *obj, int pos) {
......@@ -457,11 +479,6 @@ void linphone_core_add_auth_info(LinphoneCore *lc, const LinphoneAuthInfo *info)
write_auth_infos(lc);
}
/**
* This method is used to abort a user authentication request initiated by LinphoneCore
* from the auth_info_requested callback of LinphoneCoreVTable.
**/
void linphone_core_abort_authentication(LinphoneCore *lc, LinphoneAuthInfo *info){
}
......@@ -479,9 +496,6 @@ const bctbx_list_t *linphone_core_get_auth_info_list(const LinphoneCore *lc){
return lc->auth_info;
}
/**
* Clear all authentication information.
**/
void linphone_core_clear_all_auth_info(LinphoneCore *lc){
bctbx_list_t *elem;
int i;
......@@ -493,7 +507,3 @@ void linphone_core_clear_all_auth_info(LinphoneCore *lc){
bctbx_list_free(lc->auth_info);
lc->auth_info=NULL;
}
/**
* @}
**/
......@@ -916,6 +916,11 @@ void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage
_linphone_chat_room_send_message(cr, msg);
}
void linphone_chat_room_send_message_3(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
linphone_chat_message_ref(msg);
_linphone_chat_room_send_message(cr, msg);
}
void linphone_chat_room_send_chat_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
_linphone_chat_room_send_message(cr, msg);
}
......
......@@ -208,7 +208,7 @@ private:
const char *m_focusAddr;
char *m_focusContact;
LinphoneCall *m_focusCall;
LinphoneCoreVTable *m_vtable;
LinphoneCoreCbs *m_coreCbs;
std::list<LinphoneCall *> m_pendingCalls;
std::list<LinphoneCall *> m_transferingCalls;
};
......@@ -625,19 +625,19 @@ RemoteConference::RemoteConference(LinphoneCore *core, const Conference::Params
m_focusAddr = NULL;
m_focusContact = NULL;
m_focusCall = NULL;
m_vtable = NULL;
m_coreCbs = NULL;
m_focusAddr = lp_config_get_string(m_core->config, "misc", "conference_focus_addr", "");
m_vtable = linphone_core_v_table_new();
m_vtable->call_state_changed = callStateChangedCb;
m_vtable->transfer_state_changed = transferStateChanged;
linphone_core_v_table_set_user_data(m_vtable, this);
_linphone_core_add_listener(m_core, m_vtable, FALSE, TRUE);
m_coreCbs = linphone_factory_create_core_cbs(linphone_factory_get());
linphone_core_cbs_set_call_state_changed(m_coreCbs, callStateChangedCb);
linphone_core_cbs_set_transfer_state_changed(m_coreCbs, transferStateChanged);
linphone_core_cbs_set_user_data(m_coreCbs, this);
_linphone_core_add_callbacks(m_core, m_coreCbs, TRUE);
}
RemoteConference::~RemoteConference() {
terminate();
linphone_core_remove_listener(m_core, m_vtable);
linphone_core_v_table_destroy(m_vtable);
linphone_core_remove_callbacks(m_core, m_coreCbs);
linphone_core_cbs_unref(m_coreCbs);
}
int RemoteConference::addParticipant(LinphoneCall *call) {
......
/*
linphone
Copyright (C) 2016 Belledonne Communications <info@belledonne-communications.com>
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.
*/
#include "private.h"
extern LinphoneCore *_linphone_core_new_with_config(LinphoneCoreCbs *cbs, struct _LpConfig *config, void *userdata);
extern LinphoneCoreCbs *_linphone_core_cbs_new(void);
extern LinphoneAddress *_linphone_address_new(const char *addr);
typedef belle_sip_object_t_vptr_t LinphoneFactory_vptr_t;
struct _LinphoneFactory {
belle_sip_object_t base;
};
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneFactory);
BELLE_SIP_INSTANCIATE_VPTR(LinphoneFactory, belle_sip_object_t,
NULL, // destroy
NULL, // clone
NULL, // Marshall
FALSE
);
static LinphoneFactory *_factory = NULL;
static void _linphone_factory_destroying_cb(void) {
if (_factory != NULL) {
belle_sip_object_unref(_factory);
_factory = NULL;
}
}
LinphoneFactory *linphone_factory_get(void) {
if (_factory == NULL) {
_factory = belle_sip_object_new(LinphoneFactory);
atexit(_linphone_factory_destroying_cb);
}
return _factory;
}
LinphoneCore *linphone_factory_create_core(const LinphoneFactory *factory, LinphoneCoreCbs *cbs,
const char *config_path, const char *factory_config_path) {
LpConfig *config = lp_config_new_with_factory(config_path, factory_config_path);
LinphoneCore *lc = _linphone_core_new_with_config(cbs, config, NULL);
lp_config_unref(config);
return lc;
}
LinphoneCore *linphone_factory_create_core_with_config(const LinphoneFactory *factory, LinphoneCoreCbs *cbs, LinphoneConfig *config) {
return _linphone_core_new_with_config(cbs, config, NULL);
}
LinphoneCoreCbs *linphone_factory_create_core_cbs(const LinphoneFactory *factory) {
return _linphone_core_cbs_new();
}
LinphoneAddress *linphone_factory_create_address(const LinphoneFactory *factory, const char *addr) {
return _linphone_address_new(addr);
}
LinphoneAuthInfo *linphone_factory_create_auth_info(const LinphoneFactory *factory, const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm, const char *domain) {
return linphone_auth_info_new(username, userid, passwd, ha1, realm, domain);
}
......@@ -1223,7 +1223,7 @@ void linphone_core_friends_storage_init(LinphoneCore *lc) {
int ret;
const char *errmsg;
sqlite3 *db;
const bctbx_list_t *friends_lists = NULL;
bctbx_list_t *friends_lists = NULL;
linphone_core_friends_storage_close(lc);
......@@ -1246,14 +1246,15 @@ void linphone_core_friends_storage_init(LinphoneCore *lc) {
friends_lists = linphone_core_fetch_friends_lists_from_db(lc);
if (friends_lists) {
const bctbx_list_t *it;
ms_warning("Replacing current default friend list by the one(s) from the database");
lc->friends_lists = bctbx_list_free_with_data(lc->friends_lists, (void (*)(void*))linphone_friend_list_unref);
while (friends_lists) {
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(friends_lists);
lc->friends_lists = bctbx_list_free_with_data(lc->friends_lists, (bctbx_list_free_func)linphone_friend_list_unref);
for (it=friends_lists;it!=NULL;it=bctbx_list_next(it)) {
LinphoneFriendList *list = (LinphoneFriendList *)bctbx_list_get_data(it);
linphone_core_add_friend_list(lc, list);
friends_lists = bctbx_list_next(friends_lists);
}
friends_lists = bctbx_list_free_with_data(friends_lists, (bctbx_list_free_func)linphone_friend_list_unref);
}
}
......
This diff is collapsed.
......@@ -677,6 +677,7 @@ BELLE_SIP_DECLARE_VPTR(LinphoneProxyConfig);
struct _LinphoneAuthInfo
{
belle_sip_object_t base;
char *username;
char *realm;
char *userid;
......@@ -950,8 +951,19 @@ void linphone_task_list_remove(LinphoneTaskList *t, LinphoneCoreIterateHook hook
void linphone_task_list_run(LinphoneTaskList *t);
void linphone_task_list_free(LinphoneTaskList *t);
struct _LinphoneCoreCbs {
belle_sip_object_t base;
LinphoneCoreVTable *vtable;
bool_t autorelease;
};
void _linphone_core_cbs_set_v_table(LinphoneCoreCbs *cbs, LinphoneCoreVTable *vtable, bool_t autorelease);
struct _LinphoneCore
{
belle_sip_object_t base;
MSFactory* factory;
MSList* vtable_refs;
int vtable_notify_recursion;
......@@ -1057,7 +1069,7 @@ struct _LinphoneCore
char *file_transfer_server;
const char **supported_formats;
LinphoneContent *log_collection_upload_information;
LinphoneCoreVTable *current_vtable; // the latest vtable to call a callback, see linphone_core_get_current_vtable
LinphoneCoreCbs *current_cbs; // the latest LinphoneCoreCbs object to call a callback, see linphone_core_get_current_cbs()
LinphoneRingtonePlayer *ringtoneplayer;
#ifdef ANDROID
jobject wifi_lock;
......@@ -1109,7 +1121,13 @@ void linphone_tunnel_destroy(LinphoneTunnel *tunnel);
void linphone_tunnel_configure(LinphoneTunnel *tunnel);
void linphone_tunnel_enable_logs_with_handler(LinphoneTunnel *tunnel, bool_t enabled, OrtpLogFunc logHandler);
/**
* Check if we do not have exceed the number of simultaneous call
*
* @ingroup call_control
**/
bool_t linphone_core_can_we_add_call(LinphoneCore *lc);
int linphone_core_add_call( LinphoneCore *lc, LinphoneCall *call);
int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call);
int linphone_core_get_calls_nb(const LinphoneCore *lc);
......@@ -1571,7 +1589,12 @@ BELLE_SIP_TYPE_ID(LinphoneXmlRpcSession),
BELLE_SIP_TYPE_ID(LinphoneTunnelConfig),
BELLE_SIP_TYPE_ID(LinphoneFriendListCbs),
BELLE_SIP_TYPE_ID(LinphoneEvent),
BELLE_SIP_TYPE_ID(LinphoneNatPolicy)
BELLE_SIP_TYPE_ID(LinphoneNatPolicy),
BELLE_SIP_TYPE_ID(LinphoneCore),
BELLE_SIP_TYPE_ID(LinphoneCoreCbs),
BELLE_SIP_TYPE_ID(LinphoneFactory),
BELLE_SIP_TYPE_ID(LinphoneAuthInfo),
BELLE_SIP_TYPE_ID(LinphoneVcard),
BELLE_SIP_DECLARE_TYPES_END
......@@ -1664,7 +1687,7 @@ void linphone_core_multicast_lock_release(LinphoneCore *lc);
#endif
struct _VTableReference{
LinphoneCoreVTable *vtable;
LinphoneCoreCbs *cbs;
bool_t valid;
bool_t autorelease;
bool_t internal;
......@@ -1674,7 +1697,7 @@ typedef struct _VTableReference VTableReference;
void v_table_reference_destroy(VTableReference *ref);
LINPHONE_PUBLIC void _linphone_core_add_listener(LinphoneCore *lc, LinphoneCoreVTable *vtable, bool_t autorelease, bool_t internal);
LINPHONE_PUBLIC void _linphone_core_add_callbacks(LinphoneCore *lc, LinphoneCoreCbs *vtable, bool_t internal);
#ifdef VIDEO_ENABLED
LINPHONE_PUBLIC MSWebCam *linphone_call_get_video_device(const LinphoneCall *call);
......
......@@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "sal/sal.h"
#include <bctoolbox/crypto.h>
#include "linphone/core.h"
#include "private.h"
#define VCARD_MD5_HASH_SIZE 16
......@@ -32,17 +33,7 @@ struct _LinphoneVcardContext {
void *user_data;
};
struct _LinphoneVcard {
shared_ptr<belcard::BelCard> belCard;
char *etag;
char *url;
unsigned char md5[VCARD_MD5_HASH_SIZE];
bctbx_list_t *sip_addresses_cache;
};
#ifdef __cplusplus
extern "C" {
#endif
LinphoneVcardContext* linphone_vcard_context_new(void) {
LinphoneVcardContext* context = ms_new0(LinphoneVcardContext, 1);
......@@ -67,25 +58,66 @@ void linphone_vcard_context_set_user_data(LinphoneVcardContext *context, void *d
if (context) context->user_data = data;
}
LinphoneVcard* linphone_vcard_new(void) {
LinphoneVcard* vCard = (LinphoneVcard*) ms_new0(LinphoneVcard, 1);
} // extern "C"
struct _LinphoneVcard {
belle_sip_object_t base;
shared_ptr<belcard::BelCard> belCard;
char *etag;
char *url;
unsigned char md5[VCARD_MD5_HASH_SIZE];
bctbx_list_t *sip_addresses_cache;
};
extern "C" {
static void _linphone_vcard_uninit(LinphoneVcard *vCard) {
if (vCard->etag) ms_free(vCard->etag);
if (vCard->url) ms_free(vCard->url);
linphone_vcard_clean_cache(vCard);
vCard->belCard.reset();
}
BELLE_SIP_DECLARE_VPTR(LinphoneVcard);
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneVcard);
BELLE_SIP_INSTANCIATE_VPTR(LinphoneVcard, belle_sip_object_t,
_linphone_vcard_uninit, // destroy
NULL, // clone
NULL, // Marshall
FALSE
);
static LinphoneVcard* _linphone_vcard_new(void) {
LinphoneVcard* vCard = belle_sip_object_new(LinphoneVcard);
vCard->belCard = belcard::BelCardGeneric::create<belcard::BelCard>();
return vCard;
}
LinphoneVcard *linphone_vcard_new(void) {
return _linphone_vcard_new();
}
LinphoneVcard *linphone_factory_create_vcard(LinphoneFactory *factory) {
return _linphone_vcard_new();
}
static LinphoneVcard* linphone_vcard_new_from_belcard(shared_ptr<belcard::BelCard> belcard) {
LinphoneVcard* vCard = (LinphoneVcard*) ms_new0(LinphoneVcard, 1);
LinphoneVcard* vCard = belle_sip_object_new(LinphoneVcard);
vCard->belCard = belcard;
return vCard;
}
void linphone_vcard_free(LinphoneVcard *vCard) {
if (!vCard) return;
if (vCard->etag) ms_free(vCard->etag);
if (vCard->url) ms_free(vCard->url);
linphone_vcard_clean_cache(vCard);
vCard->belCard.reset();
ms_free(vCard);
belle_sip_object_unref((belle_sip_object_t *)vCard);
}
LinphoneVcard *linphone_vcard_ref(LinphoneVcard *vCard) {
return (LinphoneVcard *)belle_sip_object_ref((belle_sip_object_t *)vCard);
}
void linphone_vcard_unref(LinphoneVcard *vCard) {
belle_sip_object_unref((belle_sip_object_t *)vCard);
}
bctbx_list_t* linphone_vcard_context_get_vcard_list_from_file(LinphoneVcardContext *context, const char *filename) {
......@@ -397,6 +429,4 @@ void linphone_vcard_clean_cache(LinphoneVcard *vCard) {
vCard->sip_addresses_cache = NULL;
}
#ifdef __cplusplus
}
#endif
} // extern "C"
......@@ -38,7 +38,8 @@ void linphone_core_v_table_destroy(LinphoneCoreVTable* table) {
}
LinphoneCoreVTable *linphone_core_get_current_vtable(LinphoneCore *lc) {
return lc->current_vtable;
if (lc->current_cbs != NULL) return lc->current_cbs->vtable;
else return NULL;
}
static void cleanup_dead_vtable_refs(LinphoneCore *lc){
......@@ -63,8 +64,8 @@ static void cleanup_dead_vtable_refs(LinphoneCore *lc){
bool_t has_cb = FALSE; \
lc->vtable_notify_recursion++;\
for (iterator=lc->vtable_refs; iterator!=NULL; iterator=iterator->next){\
if ((ref=(VTableReference*)iterator->data)->valid && (lc->current_vtable=ref->vtable)->function_name) {\
lc->current_vtable->function_name(__VA_ARGS__);\
if ((ref=(VTableReference*)iterator->data)->valid && (lc->current_cbs=ref->cbs)->vtable->function_name) {\
lc->current_cbs->vtable->function_name(__VA_ARGS__);\
has_cb = TRUE;\
}\
}\
......@@ -76,8 +77,8 @@ static void cleanup_dead_vtable_refs(LinphoneCore *lc){
VTableReference *ref; \
lc->vtable_notify_recursion++;\
for (iterator=lc->vtable_refs; iterator!=NULL; iterator=iterator->next){\
if ((ref=(VTableReference*)iterator->data)->valid && (lc->current_vtable=ref->vtable)->function_name && (ref->internal == internal_val)) {\
lc->current_vtable->function_name(__VA_ARGS__);\
if ((ref=(VTableReference*)iterator->data)->valid && (lc->current_cbs=ref->cbs)->vtable->function_name && (ref->internal == internal_val)) {\
lc->current_cbs->vtable->function_name(__VA_ARGS__);\
}\
}\
lc->vtable_notify_recursion--;
......@@ -229,7 +230,7 @@ bool_t linphone_core_dtmf_received_has_listener(const LinphoneCore* lc) {
bctbx_list_t* iterator;
for (iterator=lc->vtable_refs; iterator!=NULL; iterator=iterator->next){
VTableReference *ref=(VTableReference*)iterator->data;
if (ref->valid && ref->vtable->dtmf_received)
if (ref->valid && ref->cbs->vtable->dtmf_received)
return TRUE;
}
return FALSE;
......@@ -305,27 +306,33 @@ void linphone_core_notify_friend_list_removed(LinphoneCore *lc, LinphoneFriendLi
cleanup_dead_vtable_refs(lc);
}
static VTableReference * v_table_reference_new(LinphoneCoreVTable *vtable, bool_t autorelease, bool_t internal){
static VTableReference * v_table_reference_new(LinphoneCoreCbs *cbs, bool_t internal){
VTableReference *ref=ms_new0(VTableReference,1);
ref->valid=1;
ref->autorelease=autorelease;
ref->valid=TRUE;
ref->internal = internal;
ref->vtable=vtable;
ref->cbs=(LinphoneCoreCbs *)belle_sip_object_ref(cbs);
return ref;
}
void v_table_reference_destroy(VTableReference *ref){
if (ref->autorelease) linphone_core_v_table_destroy(ref->vtable);
belle_sip_object_unref(ref->cbs);
ms_free(ref);
}
void _linphone_core_add_listener(LinphoneCore *lc, LinphoneCoreVTable *vtable, bool_t autorelease, bool_t internal) {
ms_message("Vtable [%p] registered on core [%p]",vtable, lc);
lc->vtable_refs=bctbx_list_append(lc->vtable_refs,v_table_reference_new(vtable, autorelease, internal));
void _linphone_core_add_callbacks(LinphoneCore *lc, LinphoneCoreCbs *vtable, bool_t internal) {
ms_message("Core callbacks [%p] registered on core [%p]", vtable, lc);
lc->vtable_refs=bctbx_list_append(lc->vtable_refs,v_table_reference_new(vtable, internal));
}
void linphone_core_add_listener(LinphoneCore *lc, LinphoneCoreVTable *vtable){
_linphone_core_add_listener(lc, vtable, FALSE, FALSE);
LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(linphone_factory_get());
_linphone_core_cbs_set_v_table(cbs, vtable, FALSE);
_linphone_core_add_callbacks(lc, cbs, FALSE);
belle_sip_object_unref(cbs);
}
void linphone_core_add_callbacks(LinphoneCore *lc, LinphoneCoreCbs *cbs) {
_linphone_core_add_callbacks(lc, cbs, FALSE);
}
void linphone_core_remove_listener(LinphoneCore *lc, const LinphoneCoreVTable *vtable) {
......@@ -333,7 +340,19 @@ void linphone_core_remove_listener(LinphoneCore *lc, const LinphoneCoreVTable *v
ms_message("Vtable [%p] unregistered on core [%p]",vtable,lc);
for(it=lc->vtable_refs; it!=NULL; it=it->next){
VTableReference *ref=(VTableReference*)it->data;
if (ref->vtable==vtable)
ref->valid=0;
if (ref->cbs->vtable==vtable) {
ref->valid=FALSE;
}
}
}
void linphone_core_remove_callbacks(LinphoneCore *lc, const LinphoneCoreCbs *cbs) {
bctbx_list_t *it;
ms_message("Callbacks [%p] unregistered on core [%p]",cbs,lc);
for(it=lc->vtable_refs; it!=NULL; it=it->next){
VTableReference *ref=(VTableReference*)it->data;
if (ref->cbs==cbs) {
ref->valid=FALSE;
}
}
}
......@@ -38,6 +38,7 @@ set(HEADER_FILES
dictionary.h
error_info.h
event.h
factory.h
friend.h
friendlist.h
im_notif_policy.h
......
......@@ -122,7 +122,7 @@ LINPHONE_PUBLIC void linphone_address_clean(LinphoneAddress *uri);
* Returns true if address refers to a secure location (sips)
* @deprecated use linphone_address_get_secure()
**/
LINPHONE_PUBLIC bool_t linphone_address_is_secure(const LinphoneAddress *addr);
LINPHONE_DEPRECATED LINPHONE_PUBLIC bool_t linphone_address_is_secure(const LinphoneAddress *addr);
/**
* Returns true if address refers to a secure location (sips)
......@@ -231,7 +231,7 @@ LINPHONE_PUBLIC const char * linphone_address_get_uri_param(const LinphoneAddres
* Destroys a LinphoneAddress object (actually calls linphone_address_unref()).
* @deprecated Use linphone_address_unref() instead
**/
LINPHONE_PUBLIC void linphone_address_destroy(LinphoneAddress *u);
LINPHONE_DEPRECATED LINPHONE_PUBLIC void linphone_address_destroy(LinphoneAddress *u);
/**
* @}
......
This diff is collapsed.
......@@ -91,17 +91,29 @@ LINPHONE_PUBLIC const char *linphone_publish_state_to_string(LinphonePublishStat
/**
* Callback prototype for notifying the application about notification received from the network.
**/
typedef void (*LinphoneCoreNotifyReceivedCb)(LinphoneCore *lc, LinphoneEvent *lev, const char *notified_event, const LinphoneContent *body);
typedef void (*LinphoneCoreCbsNotifyReceivedCb)(LinphoneCore *lc, LinphoneEvent *lev, const char *notified_event, const LinphoneContent *body);
/**
* Old name of #LinphoneCoreCbsNotifyReceivedCb.
*/
typedef LinphoneCoreCbsNotifyReceivedCb LinphoneCoreNotifyReceivedCb;
/**
* Callback prototype for notifying the application about changes of subscription states, including arrival of new subscriptions.
**/
typedef void (*LinphoneCoreSubscriptionStateChangedCb)(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state);
typedef void (*LinphoneCoreCbsSubscriptionStateChangedCb)(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state);
/**
* Old name of #LinphoneCoreCbsSubscriptionStateChangedCb.
*/
typedef LinphoneCoreCbsSubscriptionStateChangedCb LinphoneCoreSubscriptionStateChangedCb;
/**
* Callback prototype for notifying the application about changes of publish states.
**/
typedef void (*LinphoneCorePublishStateChangedCb)(LinphoneCore *lc, LinphoneEvent *lev, LinphonePublishState state);
typedef void (*LinphoneCoreCbsPublishStateChangedCb)(LinphoneCore *lc, LinphoneEvent *lev, LinphonePublishState state);
/**
* Old name of LinphoneCoreCbsPublishStateChangedCb.
*/
typedef LinphoneCoreCbsPublishStateChangedCb LinphoneCorePublishStateChangedCb;
/**
* Create an outgoing subscription, specifying the destination resource, the event name, and an optional content body.
......
/*
linphone
Copyright (C) 2016 Belledonne Communications <info@belledonne-communications.com>
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.
*/
#ifndef LINPHONE_FACTORY_H
#define LINPHONE_FACTORY_H
#include "linphone/core.h"
#ifdef _cplusplus
extern "C" {
#endif
/**
* @addtogroup initializing
* @{
*/
/**
* #LinphoneFactory is a singleton object devoted to the creation of all the object
* of Liblinphone that cannot created by #LinphoneCore or #LinphoneCore itself.
*/
typedef struct _LinphoneFactory LinphoneFactory;
/**
* Create the #LinphoneFactory if that has not been done and return
* a pointer on it.
* @return A pointer on the #LinphoneFactory
*/
LINPHONE_PUBLIC LinphoneFactory *linphone_factory_get(void);
/**
* Instanciate a #LinphoneCore object.
*
* The LinphoneCore object is the primary handle for doing all phone actions.
* It should be unique within your application.
* @param factory The #LinphoneFactory singleton.
* @param cbs a #LinphoneCoreCbs object holding your application callbacks. A reference
* will be taken on it until the destruciton of the core or the unregistration
* with linphone_core_remove_cbs().
* @param 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, call logs, friends, proxies... so that all these settings
* become persistent over the life of the LinphoneCore object.
* It is allowed to set a NULL config file. In that case LinphoneCore will not store any settings.
* @param factory_config_path a path to a read-only config file that can be used to