Commit b6a9bdee authored by Ghislain MARY's avatar Ghislain MARY

Use belle-sip reference counting for LinphoneProxyConfig and LinphoneCall objects.

parent f40c178d
......@@ -570,8 +570,6 @@ static void port_config_set(LinphoneCall *call, int stream_index, int min_port,
static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
int min_port, max_port;
ms_message("New LinphoneCall [%p] initialized (LinphoneCore version: %s)",call,linphone_core_get_version());
call->magic=linphone_call_magic;
call->refcnt=1;
call->state=LinphoneCallIdle;
call->transfer_state = LinphoneCallIdle;
call->media_start_time=0;
......@@ -647,8 +645,19 @@ static void linphone_call_outgoing_select_ip_version(LinphoneCall *call, Linphon
}else call->af=AF_INET;
}
static void linphone_call_destroy(LinphoneCall *obj);
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneCall);
BELLE_SIP_INSTANCIATE_VPTR(LinphoneCall, belle_sip_object_t,
(belle_sip_object_destroy_t)linphone_call_destroy,
NULL, // clone
NULL, // marshal
FALSE
);
LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, const LinphoneCallParams *params, LinphoneProxyConfig *cfg){
LinphoneCall *call=ms_new0(LinphoneCall,1);
LinphoneCall *call = belle_sip_object_new(LinphoneCall);
call->dir=LinphoneCallOutgoing;
call->core=lc;
......@@ -708,7 +717,7 @@ void linphone_call_set_compatible_incoming_call_parameters(LinphoneCall *call, c
}
LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){
LinphoneCall *call=ms_new0(LinphoneCall,1);
LinphoneCall *call = belle_sip_object_new(LinphoneCall);
const SalMediaDescription *md;
LinphoneFirewallPolicy fpol;
......@@ -999,7 +1008,6 @@ static void linphone_call_destroy(LinphoneCall *obj)
linphone_call_params_uninit(&obj->params);
linphone_call_params_uninit(&obj->current_params);
sal_error_info_reset(&obj->non_op_error);
ms_free(obj);
}
/**
......@@ -1007,27 +1015,13 @@ static void linphone_call_destroy(LinphoneCall *obj)
* @{
**/
/**
* Increments the call 's reference count.
* An application that wishes to retain a pointer to call object
* must use this function to unsure the pointer remains
* valid. Once the application no more needs this pointer,
* it must call linphone_call_unref().
**/
LinphoneCall * linphone_call_ref(LinphoneCall *obj){
obj->refcnt++;
belle_sip_object_ref(obj);
return obj;
}
/**
* Decrements the call object reference count.
* See linphone_call_ref().
**/
void linphone_call_unref(LinphoneCall *obj){
obj->refcnt--;
if (obj->refcnt==0){
linphone_call_destroy(obj);
}
belle_sip_object_unref(obj);
}
/**
......@@ -1154,7 +1148,7 @@ const LinphoneErrorInfo *linphone_call_get_error_info(const LinphoneCall *call){
*
* return user_pointer an opaque user pointer that can be retrieved at any time
**/
void *linphone_call_get_user_data(LinphoneCall *call)
void *linphone_call_get_user_data(const LinphoneCall *call)
{
return call->user_pointer;
}
......
......@@ -729,6 +729,41 @@ typedef enum _LinphoneCallState{
LINPHONE_PUBLIC const char *linphone_call_state_to_string(LinphoneCallState cs);
/**
* Acquire a reference to the call.
* An application that wishes to retain a pointer to call object
* must use this function to unsure the pointer remains
* valid. Once the application no more needs this pointer,
* it must call linphone_call_unref().
* @param[in] call The call.
* @return The same call.
* @ingroup call_control
**/
LINPHONE_PUBLIC LinphoneCall *linphone_call_ref(LinphoneCall *call);
/**
* Release reference to the call.
* @param[in] call The call.
* @ingroup call_control
**/
LINPHONE_PUBLIC void linphone_call_unref(LinphoneCall *call);
/**
* Retrieve the user pointer associated with the call.
* @param[in] call The call.
* @return The user pointer associated with the call.
* @ingroup call_control
**/
LINPHONE_PUBLIC void *linphone_call_get_user_data(const LinphoneCall *call);
/**
* Assign a user pointer to the call.
* @param[in] cfg The call.
* @param[in] ud The user pointer to associate with the call.
* @ingroup call_control
**/
LINPHONE_PUBLIC void linphone_call_set_user_data(LinphoneCall *call, void *ud);
LINPHONE_PUBLIC LinphoneCore *linphone_call_get_core(const LinphoneCall *call);
LINPHONE_PUBLIC LinphoneCallState linphone_call_get_state(const LinphoneCall *call);
LINPHONE_PUBLIC bool_t linphone_call_asked_to_autoanswer(LinphoneCall *call);
......@@ -736,8 +771,6 @@ LINPHONE_PUBLIC const LinphoneAddress * linphone_core_get_current_call_remote_ad
LINPHONE_PUBLIC const LinphoneAddress * linphone_call_get_remote_address(const LinphoneCall *call);
LINPHONE_PUBLIC char *linphone_call_get_remote_address_as_string(const LinphoneCall *call);
LINPHONE_PUBLIC LinphoneCallDir linphone_call_get_dir(const LinphoneCall *call);
LINPHONE_PUBLIC LinphoneCall * linphone_call_ref(LinphoneCall *call);
LINPHONE_PUBLIC void linphone_call_unref(LinphoneCall *call);
LINPHONE_PUBLIC LinphoneCallLog *linphone_call_get_call_log(const LinphoneCall *call);
LINPHONE_PUBLIC const char *linphone_call_get_refer_to(const LinphoneCall *call);
LINPHONE_PUBLIC bool_t linphone_call_has_transfer_pending(const LinphoneCall *call);
......@@ -765,10 +798,8 @@ LINPHONE_PUBLIC void linphone_call_set_authentication_token_verified(LinphoneCal
LINPHONE_PUBLIC void linphone_call_send_vfu_request(LinphoneCall *call);
/** @deprecated Use linphone_call_get_user_data() instead. */
#define linphone_call_get_user_pointer(call) linphone_call_get_user_data(call)
LINPHONE_PUBLIC void *linphone_call_get_user_data(LinphoneCall *call);
/** @deprecated Use linphone_call_set_user_data() instead. */
#define linphone_call_set_user_pointer(call, ud) linphone_call_set_user_data(call, ud)
LINPHONE_PUBLIC void linphone_call_set_user_data(LinphoneCall *call, void *user_data);
LINPHONE_PUBLIC void linphone_call_set_next_video_frame_decoded_callback(LinphoneCall *call, LinphoneCallCbFunc cb, void* user_data);
LINPHONE_PUBLIC LinphoneCallState linphone_call_get_transfer_state(LinphoneCall *call);
LINPHONE_PUBLIC void linphone_call_zoom_video(LinphoneCall* call, float zoom_factor, float* cx, float* cy);
......@@ -860,6 +891,34 @@ typedef enum _LinphoneRegistrationState{
*/
LINPHONE_PUBLIC const char *linphone_registration_state_to_string(LinphoneRegistrationState cs);
LINPHONE_PUBLIC LinphoneProxyConfig *linphone_proxy_config_new(void);
/**
* Acquire a reference to the proxy config.
* @param[in] cfg The proxy config.
* @return The same proxy config.
**/
LINPHONE_PUBLIC LinphoneProxyConfig *linphone_proxy_config_ref(LinphoneProxyConfig *cfg);
/**
* Release reference to the proxy config.
* @param[in] cfg The proxy config.
**/
LINPHONE_PUBLIC void linphone_proxy_config_unref(LinphoneProxyConfig *cfg);
/**
* Retrieve the user pointer associated with the proxy config.
* @param[in] cfg The proxy config.
* @return The user pointer associated with the proxy config.
**/
LINPHONE_PUBLIC void *linphone_proxy_config_get_user_data(const LinphoneProxyConfig *cfg);
/**
* Assign a user pointer to the proxy config.
* @param[in] cfg The proxy config.
* @param[in] ud The user pointer to associate with the proxy config.
**/
LINPHONE_PUBLIC void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cfg, void *ud);
LINPHONE_PUBLIC int linphone_proxy_config_set_server_addr(LinphoneProxyConfig *obj, const char *server_addr);
LINPHONE_PUBLIC int linphone_proxy_config_set_identity(LinphoneProxyConfig *obj, const char *identity);
LINPHONE_PUBLIC int linphone_proxy_config_set_route(LinphoneProxyConfig *obj, const char *route);
......@@ -1036,14 +1095,6 @@ LINPHONE_PUBLIC SipSetup *linphone_proxy_config_get_sip_setup(LinphoneProxyConfi
* normalize a human readable phone number into a basic string. 888-444-222 becomes 888444222
*/
LINPHONE_PUBLIC int linphone_proxy_config_normalize_number(LinphoneProxyConfig *proxy, const char *username, char *result, size_t result_len);
/*
* attached a user data to a proxy config
*/
LINPHONE_PUBLIC void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cr, void * ud);
/*
* get user data to a proxy config. return null if any
*/
LINPHONE_PUBLIC void * linphone_proxy_config_get_user_data(LinphoneProxyConfig *cr);
/**
* Set default privacy policy for all calls routed through this proxy.
......
......@@ -946,18 +946,6 @@ bool_t linphone_core_media_description_contains_video_stream(const SalMediaDescr
return FALSE;
}
LinphoneCall * is_a_linphone_call(void *user_pointer){
LinphoneCall *call=(LinphoneCall*)user_pointer;
if (call==NULL) return NULL;
return call->magic==linphone_call_magic ? call : NULL;
}
LinphoneProxyConfig * is_a_linphone_proxy_config(void *user_pointer){
LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)user_pointer;
if (cfg==NULL) return NULL;
return cfg->magic==linphone_proxy_config_magic ? cfg : NULL;
}
unsigned int linphone_core_get_audio_features(LinphoneCore *lc){
unsigned int ret=0;
const char *features=lp_config_get_string(lc->config,"sound","features",NULL);
......
......@@ -138,8 +138,6 @@ typedef struct _CallCallbackObj
void * _user_data;
}CallCallbackObj;
static const int linphone_call_magic=0x3343;
typedef enum _LinphoneChatMessageDir{
LinphoneChatMessageIncoming,
LinphoneChatMessageOutgoing
......@@ -183,7 +181,8 @@ typedef struct _PortConfig{
struct _LinphoneCall
{
int magic; /*used to distinguish from proxy config*/
belle_sip_object_t base;
void *user_data;
struct _LinphoneCore *core;
SalErrorInfo non_op_error;
int af; /*the address family to prefer for RTP path, guessed from signaling path*/
......@@ -202,7 +201,6 @@ struct _LinphoneCall
LinphoneCallState prevstate;
LinphoneCallState transfer_state; /*idle if no transfer*/
LinphoneProxyConfig *dest_proxy;
int refcnt;
void * user_pointer;
PortConfig media_ports[2];
MSMediaStreamSessions sessions[2]; /*the rtp, srtp, zrtp contexts for each stream*/
......@@ -252,6 +250,8 @@ struct _LinphoneCall
bool_t paused_by_app;
};
BELLE_SIP_DECLARE_VPTR(LinphoneCall);
LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, const LinphoneCallParams *params, LinphoneProxyConfig *cfg);
LinphoneCall * linphone_call_new_incoming(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op);
......@@ -402,12 +402,8 @@ extern SalCallbacks linphone_sal_callbacks;
bool_t linphone_core_rtcp_enabled(const LinphoneCore *lc);
bool_t linphone_core_symmetric_rtp_enabled(LinphoneCore*lc);
LinphoneCall * is_a_linphone_call(void *user_pointer);
LinphoneProxyConfig * is_a_linphone_proxy_config(void *user_pointer);
void linphone_core_queue_task(LinphoneCore *lc, belle_sip_source_func_t task_fun, void *data, const char *task_description);
static const int linphone_proxy_config_magic=0x7979;
LINPHONE_PUBLIC bool_t linphone_proxy_config_address_equal(const LinphoneAddress *a, const LinphoneAddress *b);
LINPHONE_PUBLIC bool_t linphone_proxy_config_is_server_config_changed(const LinphoneProxyConfig* obj);
void _linphone_proxy_config_unregister(LinphoneProxyConfig *obj);
......@@ -418,7 +414,8 @@ void linphone_chat_message_destroy(LinphoneChatMessage* msg);
struct _LinphoneProxyConfig
{
int magic;
belle_sip_object_t base;
void *user_data;
struct _LinphoneCore *lc;
char *reg_proxy;
char *reg_identity;
......@@ -447,7 +444,6 @@ struct _LinphoneProxyConfig
bool_t pad;
uint8_t avpf_rr_interval;
uint8_t quality_reporting_interval;
void* user_data;
time_t deletion_date;
LinphonePrivacyMask privacy;
/*use to check if server config has changed between edit() and done()*/
......@@ -457,6 +453,8 @@ struct _LinphoneProxyConfig
};
BELLE_SIP_DECLARE_VPTR(LinphoneProxyConfig);
struct _LinphoneAuthInfo
{
char *username;
......@@ -925,7 +923,9 @@ BELLE_SIP_TYPE_ID(LinphoneContactSearch),
BELLE_SIP_TYPE_ID(LinphoneContactProvider),
BELLE_SIP_TYPE_ID(LinphoneLDAPContactProvider),
BELLE_SIP_TYPE_ID(LinphoneLDAPContactSearch),
BELLE_SIP_TYPE_ID(LinphoneChatMessage)
BELLE_SIP_TYPE_ID(LinphoneChatMessage),
BELLE_SIP_TYPE_ID(LinphoneProxyConfig),
BELLE_SIP_TYPE_ID(LinphoneCall)
BELLE_SIP_DECLARE_TYPES_END
......
......@@ -99,8 +99,6 @@ static void linphone_proxy_config_init(LinphoneCore* lc, LinphoneProxyConfig *ob
const char *contact_params = lc ? lp_config_get_default_string(lc->config, "proxy", "contact_parameters", NULL) : NULL;
const char *contact_uri_params = lc ? lp_config_get_default_string(lc->config, "proxy", "contact_uri_parameters", NULL) : NULL;
memset(obj, 0, sizeof(LinphoneProxyConfig));
obj->magic = linphone_proxy_config_magic;
obj->expires = lc ? lp_config_get_default_int(lc->config, "proxy", "reg_expires", 3600) : 3600;
obj->reg_sendregister = lc ? lp_config_get_default_int(lc->config, "proxy", "reg_sendregister", 0) : 0;
obj->dial_prefix = dial_prefix ? ms_strdup(dial_prefix) : NULL;
......@@ -109,6 +107,7 @@ static void linphone_proxy_config_init(LinphoneCore* lc, LinphoneProxyConfig *ob
obj->reg_identity = identity ? ms_strdup(identity) : NULL;
obj->reg_proxy = proxy ? ms_strdup(proxy) : NULL;
obj->reg_route = route ? ms_strdup(route) : NULL;
obj->domain = NULL;
obj->realm = realm ? ms_strdup(realm) : NULL;
obj->quality_reporting_enabled = lc ? lp_config_get_default_int(lc->config, "proxy", "quality_reporting_enabled", 0) : 0;
obj->quality_reporting_collector = quality_reporting_collector ? ms_strdup(quality_reporting_collector) : NULL;
......@@ -133,20 +132,24 @@ LinphoneProxyConfig *linphone_proxy_config_new() {
return linphone_core_create_proxy_config(NULL);
}
static void _linphone_proxy_config_destroy(LinphoneProxyConfig *obj);
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneProxyConfig);
BELLE_SIP_INSTANCIATE_VPTR(LinphoneProxyConfig, belle_sip_object_t,
(belle_sip_object_destroy_t)_linphone_proxy_config_destroy,
NULL, // clone
NULL, // marshal
FALSE
);
LinphoneProxyConfig * linphone_core_create_proxy_config(LinphoneCore *lc) {
LinphoneProxyConfig *obj=NULL;
obj=ms_new(LinphoneProxyConfig,1);
LinphoneProxyConfig *obj = belle_sip_object_new(LinphoneProxyConfig);
linphone_proxy_config_init(lc,obj);
return obj;
}
/**
* Destroys a proxy config.
*
* @note: LinphoneProxyConfig that have been removed from LinphoneCore with
* linphone_core_remove_proxy_config() must not be freed.
**/
void linphone_proxy_config_destroy(LinphoneProxyConfig *obj){
void _linphone_proxy_config_destroy(LinphoneProxyConfig *obj){
if (obj->reg_proxy!=NULL) ms_free(obj->reg_proxy);
if (obj->reg_identity!=NULL) ms_free(obj->reg_identity);
if (obj->reg_route!=NULL) ms_free(obj->reg_route);
......@@ -162,7 +165,26 @@ void linphone_proxy_config_destroy(LinphoneProxyConfig *obj){
if (obj->contact_uri_params) ms_free(obj->contact_uri_params);
if (obj->saved_proxy!=NULL) linphone_address_destroy(obj->saved_proxy);
if (obj->saved_identity!=NULL) linphone_address_destroy(obj->saved_identity);
ms_free(obj);
}
/**
* Destroys a proxy config.
* @deprecated
*
* @note: LinphoneProxyConfig that have been removed from LinphoneCore with
* linphone_core_remove_proxy_config() must not be freed.
**/
void linphone_proxy_config_destroy(LinphoneProxyConfig *cfg) {
belle_sip_object_unref(cfg);
}
LinphoneProxyConfig *linphone_proxy_config_ref(LinphoneProxyConfig *cfg) {
belle_sip_object_ref(cfg);
return cfg;
}
void linphone_proxy_config_unref(LinphoneProxyConfig *cfg) {
belle_sip_object_unref(cfg);
}
/**
......@@ -1498,12 +1520,12 @@ void linphone_account_creator_destroy(LinphoneAccountCreator *obj){
}
}
void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cr, void * ud) {
cr->user_data=ud;
void linphone_proxy_config_set_user_data(LinphoneProxyConfig *cfg, void *ud) {
cfg->user_data = ud;
}
void * linphone_proxy_config_get_user_data(LinphoneProxyConfig *cr) {
return cr->user_data;
void * linphone_proxy_config_get_user_data(const LinphoneProxyConfig *cfg) {
return cfg->user_data;
}
void linphone_proxy_config_set_state(LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const char *message){
......
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