From 1caa2d8de3b8064e530734f30a4205d26b654c2e Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 29 Aug 2014 15:07:13 +0200 Subject: [PATCH] Add reference count handling to LinphoneCallLog objects. --- coreapi/call_log.c | 36 ++++++++++++++++++++++++++++-------- coreapi/call_log.h | 20 ++++++++++++++++++++ coreapi/private.h | 18 ++++++++++-------- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/coreapi/call_log.c b/coreapi/call_log.c index a1bd835ce..480f14ce6 100644 --- a/coreapi/call_log.c +++ b/coreapi/call_log.c @@ -235,32 +235,38 @@ bool_t linphone_call_log_video_enabled(LinphoneCallLog *cl) { * Reference and user data handling functions * ******************************************************************************/ -void *linphone_call_log_get_user_data(const LinphoneCallLog *cl){ - return cl->user_pointer; +void *linphone_call_log_get_user_data(const LinphoneCallLog *cl) { + return cl->user_data; } -void linphone_call_log_set_user_data(LinphoneCallLog *cl, void *ud){ - cl->user_pointer=ud; +void linphone_call_log_set_user_data(LinphoneCallLog *cl, void *ud) { + cl->user_data = ud; } +LinphoneCallLog * linphone_call_log_ref(LinphoneCallLog *cl) { + belle_sip_object_ref(cl); + return cl; +} + +void linphone_call_log_unref(LinphoneCallLog *cl) { + belle_sip_object_unref(cl); +} /******************************************************************************* * Constructor and destructor functions * ******************************************************************************/ -void linphone_call_log_destroy(LinphoneCallLog *cl){ +static void _linphone_call_log_destroy(LinphoneCallLog *cl){ if (cl->from!=NULL) linphone_address_destroy(cl->from); if (cl->to!=NULL) linphone_address_destroy(cl->to); if (cl->refkey!=NULL) ms_free(cl->refkey); if (cl->call_id) ms_free(cl->call_id); if (cl->reporting.reports[LINPHONE_CALL_STATS_AUDIO]!=NULL) linphone_reporting_destroy(cl->reporting.reports[LINPHONE_CALL_STATS_AUDIO]); if (cl->reporting.reports[LINPHONE_CALL_STATS_VIDEO]!=NULL) linphone_reporting_destroy(cl->reporting.reports[LINPHONE_CALL_STATS_VIDEO]); - - ms_free(cl); } LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){ - LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1); + LinphoneCallLog *cl=belle_sip_object_new(LinphoneCallLog); cl->dir=call->dir; cl->start_date_time=time(NULL); set_call_log_date(cl,cl->start_date_time); @@ -273,3 +279,17 @@ LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *fro cl->reporting.reports[LINPHONE_CALL_STATS_VIDEO]=linphone_reporting_new(); return cl; } + +/* DEPRECATED */ +void linphone_call_log_destroy(LinphoneCallLog *cl) { + belle_sip_object_unref(cl); +} + +BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneCallLog); + +BELLE_SIP_INSTANCIATE_VPTR(LinphoneCallLog, belle_sip_object_t, + (belle_sip_object_destroy_t)linphone_call_log_destroy, + NULL, // clone + NULL, // marshal + FALSE +); diff --git a/coreapi/call_log.h b/coreapi/call_log.h index e69f17098..d274037d2 100644 --- a/coreapi/call_log.h +++ b/coreapi/call_log.h @@ -198,6 +198,19 @@ LINPHONE_PUBLIC void *linphone_call_log_get_user_data(const LinphoneCallLog *cl) **/ LINPHONE_PUBLIC void linphone_call_log_set_user_data(LinphoneCallLog *cl, void *ud); +/** + * Acquire a reference to the call log. + * @param[in] cl LinphoneCallLog object + * @return The same LinphoneCallLog object +**/ +LINPHONE_PUBLIC LinphoneCallLog * linphone_call_log_ref(LinphoneCallLog *cl); + +/** + * Release a reference to the call log. + * @param[in] cl LinphoneCallLog object +**/ +LINPHONE_PUBLIC void linphone_call_log_unref(LinphoneCallLog *cl); + /******************************************************************************* * DEPRECATED * @@ -215,6 +228,13 @@ LINPHONE_PUBLIC void linphone_call_log_set_user_data(LinphoneCallLog *cl, void * /** @deprecated Use linphone_call_log_get_user_data() instead. */ #define linphone_call_log_get_user_pointer(cl) linphone_call_log_get_user_data(cl) +/** + * Destroy a LinphoneCallLog. + * @param cl LinphoneCallLog object + * @deprecated Use linphone_call_log_unref() instead. + */ +LINPHONE_PUBLIC void linphone_call_log_destroy(LinphoneCallLog *cl); + /** * @} diff --git a/coreapi/private.h b/coreapi/private.h index 6ea57830e..78e990b61 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -111,6 +111,8 @@ struct _LinphoneQualityReporting{ }; struct _LinphoneCallLog{ + belle_sip_object_t base; + void *user_data; struct _LinphoneCore *lc; LinphoneCallDir dir; /**< The direction of the call*/ LinphoneCallStatus status; /**< The status of the call*/ @@ -119,18 +121,17 @@ struct _LinphoneCallLog{ char start_date[128]; /**