From a947f8bd6c472a9f960cbde9e45ad7a603af3e67 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 23 Nov 2017 11:46:32 +0100 Subject: [PATCH] feat(c-chat-room): add a method to get local address --- include/linphone/api/c-chat-room.h | 8 ++++++++ src/c-wrapper/api/c-chat-room.cpp | 24 ++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/include/linphone/api/c-chat-room.h b/include/linphone/api/c-chat-room.h index 7d05bdcee..d4e0d65b9 100644 --- a/include/linphone/api/c-chat-room.h +++ b/include/linphone/api/c-chat-room.h @@ -99,6 +99,14 @@ LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_room_create_file_transfer_mes */ LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr); +/** + * get local address \link linphone_core_get_chat_room() associated to \endlink this #LinphoneChatRoom + * @param cr #LinphoneChatRoom object + * @return #LinphoneAddress local address + */ +LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_room_get_local_address(LinphoneChatRoom *cr); + + /** * Send a message to peer member of this chat room. * @deprecated Use linphone_chat_message_send() instead. diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index d8185943b..7f329f082 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -45,7 +45,8 @@ L_DECLARE_C_OBJECT_IMPL_WITH_XTORS( _linphone_chat_room_constructor, _linphone_chat_room_destructor, LinphoneChatRoomCbs *cbs; mutable LinphoneAddress *conferenceAddressCache; - LinphoneAddress *peerAddressCache; + mutable LinphoneAddress *peerAddressCache; + mutable LinphoneAddress *localAddressCache; ) static void _linphone_chat_room_constructor (LinphoneChatRoom *cr) { @@ -54,15 +55,12 @@ static void _linphone_chat_room_constructor (LinphoneChatRoom *cr) { static void _linphone_chat_room_destructor (LinphoneChatRoom *cr) { linphone_chat_room_cbs_unref(cr->cbs); - cr->cbs = nullptr; - if (cr->conferenceAddressCache) { + if (cr->conferenceAddressCache) linphone_address_unref(cr->conferenceAddressCache); - cr->conferenceAddressCache = nullptr; - } - if (cr->peerAddressCache) { + if (cr->peerAddressCache) linphone_address_unref(cr->peerAddressCache); - cr->peerAddressCache = nullptr; - } + if (cr->localAddressCache) + linphone_address_unref(cr->localAddressCache); } // ============================================================================= @@ -97,10 +95,20 @@ const LinphoneAddress *linphone_chat_room_get_peer_address (LinphoneChatRoom *cr if (cr->peerAddressCache) { linphone_address_unref(cr->peerAddressCache); } + cr->peerAddressCache = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getPeerAddress().asString().c_str()); return cr->peerAddressCache; } +const LinphoneAddress *linphone_chat_room_get_local_address (LinphoneChatRoom *cr) { + if (cr->localAddressCache) { + linphone_address_unref(cr->localAddressCache); + } + + cr->localAddressCache = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getLocalAddress().asString().c_str()); + return cr->localAddressCache; +} + LinphoneChatMessage *linphone_chat_room_create_message (LinphoneChatRoom *cr, const char *message) { shared_ptr cppPtr = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(L_C_TO_STRING(message)); LinphoneChatMessage *object = L_INIT(ChatMessage);