From 62c03843ff5bf0146be44b8834edef38c7cf8450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Fri, 17 Mar 2017 10:33:03 +0100 Subject: [PATCH] Turn LinphoneTunnel into belle_sip_object_t --- coreapi/linphone_tunnel.cc | 29 +++++++++++++++++++++++------ coreapi/private.h | 4 ++-- include/linphone/tunnel.h | 25 ++++++++++++++++++++----- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/coreapi/linphone_tunnel.cc b/coreapi/linphone_tunnel.cc index 8bae4965b..5244e5133 100644 --- a/coreapi/linphone_tunnel.cc +++ b/coreapi/linphone_tunnel.cc @@ -34,16 +34,33 @@ LinphoneTunnel* linphone_core_get_tunnel(const LinphoneCore *lc){ } struct _LinphoneTunnel { + ::belle_sip_object_t *base; belledonnecomm::TunnelManager *manager; bctbx_list_t *config_list; }; +static void _linphone_tunnel_uninit(LinphoneTunnel *tunnel); + +BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneTunnel); +BELLE_SIP_DECLARE_VPTR(LinphoneTunnel); +BELLE_SIP_INSTANCIATE_VPTR(LinphoneTunnel, belle_sip_object_t, + _linphone_tunnel_uninit, // uninit + NULL, // clone + NULL, // marshal + FALSE // unowned +) + extern "C" LinphoneTunnel* linphone_core_tunnel_new(LinphoneCore *lc){ - LinphoneTunnel* tunnel = ms_new0(LinphoneTunnel, 1); + LinphoneTunnel* tunnel = belle_sip_object_new(LinphoneTunnel); tunnel->manager = new belledonnecomm::TunnelManager(lc); return tunnel; } +static void _linphone_tunnel_uninit(LinphoneTunnel *tunnel) { + delete tunnel->manager; + bctbx_list_free_with_data(tunnel->config_list, (bctbx_list_free_func)linphone_tunnel_config_unref); +} + belledonnecomm::TunnelManager *bcTunnel(const LinphoneTunnel *tunnel){ return tunnel->manager; } @@ -52,12 +69,12 @@ static inline _LpConfig *config(const LinphoneTunnel *tunnel){ return tunnel->manager->getLinphoneCore()->config; } -void linphone_tunnel_destroy(LinphoneTunnel *tunnel){ - delete tunnel->manager; +LinphoneTunnel *linphone_tunnel_ref(LinphoneTunnel *tunnel) { + return (LinphoneTunnel *)belle_sip_object_ref(tunnel); +} - bctbx_list_free_with_data(tunnel->config_list, (void (*)(void *))linphone_tunnel_config_destroy); - - ms_free(tunnel); +void linphone_tunnel_unref(LinphoneTunnel *tunnel) { + belle_sip_object_unref(tunnel); } static char *linphone_tunnel_config_to_string(const LinphoneTunnelConfig *tunnel_config) { diff --git a/coreapi/private.h b/coreapi/private.h index 5a90689eb..17ec6c769 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1119,7 +1119,6 @@ struct _LinphoneEvent{ BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneEvent); LinphoneTunnel *linphone_core_tunnel_new(LinphoneCore *lc); -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); @@ -1606,7 +1605,8 @@ BELLE_SIP_TYPE_ID(LinphonePresenceModel), BELLE_SIP_TYPE_ID(LinphonePresenceService), BELLE_SIP_TYPE_ID(LinphonePresencePerson), BELLE_SIP_TYPE_ID(LinphonePresenceActivity), -BELLE_SIP_TYPE_ID(LinphonePresenceNote) +BELLE_SIP_TYPE_ID(LinphonePresenceNote), +BELLE_SIP_TYPE_ID(LinphoneTunnel) BELLE_SIP_DECLARE_TYPES_END diff --git a/include/linphone/tunnel.h b/include/linphone/tunnel.h index 1847031a3..462a49fc3 100644 --- a/include/linphone/tunnel.h +++ b/include/linphone/tunnel.h @@ -81,6 +81,8 @@ \endcode **/ +#define LINPHONE_TUNNEL(obj) BELLE_SIP_CAST(obj, LinphoneTunnel) + #ifdef __cplusplus extern "C" { @@ -91,6 +93,19 @@ extern "C" */ LINPHONE_PUBLIC LinphoneTunnelConfig *linphone_tunnel_config_new(void); +/** + * Take a reference on a #LinphoneTunnel. + * @param[in] tunnel The #LinphoneTunnel whose the ref counter will be increased. + * @return Pointer on the freshly refed #LinphoneTunnel. + */ +LINPHONE_PUBLIC LinphoneTunnel *linphone_tunnel_ref(LinphoneTunnel *tunnel); + +/** + * Release a reference on a #LinphoneTunnel. + * @param[in] tunnel The #LinphoneTunnel whose the ref counter will be decreased. + */ +LINPHONE_PUBLIC void linphone_tunnel_unref(LinphoneTunnel *tunnel); + /** * Set the IP address or hostname of the tunnel server. * @param tunnel LinphoneTunnelConfig object @@ -194,7 +209,7 @@ LINPHONE_PUBLIC void linphone_tunnel_config_unref(LinphoneTunnelConfig *cfg); * @param tunnel LinphoneTunnelConfig object * @deprecated use linphone_tunnel_config_unref(). */ -LINPHONE_PUBLIC void linphone_tunnel_config_destroy(LinphoneTunnelConfig *tunnel); +LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_tunnel_config_destroy(LinphoneTunnelConfig *tunnel); /** * Store a user data in the tunnel config object @@ -345,7 +360,7 @@ LINPHONE_PUBLIC void linphone_tunnel_set_http_proxy_auth_info(LinphoneTunnel*tun * The TunnelManager takes care of refreshing SIP registration when switching on or off the tunneled mode. * @deprecated Replaced by linphone_tunnel_set_mode() **/ -LINPHONE_PUBLIC void linphone_tunnel_enable(LinphoneTunnel *tunnel, bool_t enabled); +LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_tunnel_enable(LinphoneTunnel *tunnel, bool_t enabled); /** * Check whether tunnel is enabled @@ -353,7 +368,7 @@ LINPHONE_PUBLIC void linphone_tunnel_enable(LinphoneTunnel *tunnel, bool_t enabl * @return Returns a boolean indicating whether tunneled operation is enabled. * @deprecated Replaced by linphone_tunnel_get_mode() **/ -LINPHONE_PUBLIC bool_t linphone_tunnel_enabled(const LinphoneTunnel *tunnel); +LINPHONE_PUBLIC LINPHONE_DEPRECATED bool_t linphone_tunnel_enabled(const LinphoneTunnel *tunnel); /** * Start tunnel need detection. @@ -363,7 +378,7 @@ LINPHONE_PUBLIC bool_t linphone_tunnel_enabled(const LinphoneTunnel *tunnel); *
Call this method each time to run the auto detection algorithm * @deprecated Replaced by linphone_tunnel_set_mode(LinphoneTunnelModeAuto) */ -LINPHONE_PUBLIC void linphone_tunnel_auto_detect(LinphoneTunnel *tunnel); +LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_tunnel_auto_detect(LinphoneTunnel *tunnel); /** * Tell whether tunnel auto detection is enabled. @@ -371,7 +386,7 @@ LINPHONE_PUBLIC void linphone_tunnel_auto_detect(LinphoneTunnel *tunnel); * @return TRUE if auto detection is enabled, FALSE otherwise. * @deprecated Replaced by linphone_tunnel_get_mode() */ -LINPHONE_PUBLIC bool_t linphone_tunnel_auto_detect_enabled(LinphoneTunnel *tunnel); +LINPHONE_PUBLIC LINPHONE_DEPRECATED bool_t linphone_tunnel_auto_detect_enabled(LinphoneTunnel *tunnel); LINPHONE_PUBLIC void linphone_tunnel_simulate_udp_loss(LinphoneTunnel *tunnel, bool_t enabled);