diff --git a/coreapi/chat.c b/coreapi/chat.c index ff427e12b..8d9489cd8 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -132,24 +132,9 @@ int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, localAddress = op->get_to(); } - // TODO: remove when using signals - LinphoneChatRoom *cr = L_GET_C_BACK_PTR( - L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom( - LinphonePrivate::ChatRoomId(LinphonePrivate::IdentityAddress(peerAddress), - LinphonePrivate::IdentityAddress(localAddress) - )) + shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom( + LinphonePrivate::ChatRoomId(LinphonePrivate::IdentityAddress(peerAddress), LinphonePrivate::IdentityAddress(localAddress)) ); - if (!cr) - return LinphoneReasonNone; - shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(cr); - - shared_ptr acr; - if (chatRoom->getCapabilities() & LinphonePrivate::ChatRoom::Capabilities::Proxy) - acr = static_pointer_cast(chatRoom)->getProxiedChatRoom(); - else - acr = chatRoom; - - L_SET_CPP_PTR_FROM_C_OBJECT(cr, acr); if (chatRoom) reason = L_GET_PRIVATE(chatRoom)->onSipMessageReceived(op, sal_msg); else { @@ -160,7 +145,6 @@ int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, reason = L_GET_PRIVATE_FROM_C_OBJECT(cr)->onSipMessageReceived(op, sal_msg); linphone_address_unref(addr); } - L_SET_CPP_PTR_FROM_C_OBJECT(cr, chatRoom); return reason; } diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 1b79ba040..92d4c9c87 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2136,14 +2136,10 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve const LinphoneAddress *resource = linphone_event_get_resource(lev); const LinphoneAddress *from = linphone_event_get_from(lev); - // TODO: remove when using signals - LinphoneChatRoom *cr = L_GET_C_BACK_PTR( - L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId( - IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)), - IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(from)) - )) - ); - shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(cr); + shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId( + IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)), + IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(from)) + )); if (chatRoom) { shared_ptr cgcr; @@ -2153,7 +2149,6 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve else cgcr = static_pointer_cast(chatRoom); - L_SET_CPP_PTR_FROM_C_OBJECT(cr, cgcr); if (linphone_content_is_multipart(body)) { // TODO : migrate to c++ 'Content'. int i = 0; @@ -2164,8 +2159,6 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve } } else L_GET_PRIVATE(cgcr)->notifyReceived(linphone_content_get_string_buffer(body)); - - L_SET_CPP_PTR_FROM_C_OBJECT(cr, chatRoom); } } } diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index b625af3a4..8b57705f5 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -858,20 +858,7 @@ void ChatMessage::send () { return; } - // TODO: remove when using signals - LinphoneChatRoom *cr = L_GET_C_BACK_PTR(getCore()->findChatRoom(getChatRoom()->getChatRoomId())); - - shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(cr); - - shared_ptr acr; - if (chatRoom->getCapabilities() & LinphonePrivate::ChatRoom::Capabilities::Proxy) - acr = static_pointer_cast(chatRoom)->getProxiedChatRoom(); - else - acr = chatRoom; - - L_SET_CPP_PTR_FROM_C_OBJECT(cr, acr); - acr->getPrivate()->sendChatMessage(getSharedFromThis()); - L_SET_CPP_PTR_FROM_C_OBJECT(cr, chatRoom); + getChatRoom()->getPrivate()->sendChatMessage(getSharedFromThis()); } void ChatMessage::sendDeliveryNotification (LinphoneReason reason) { diff --git a/src/chat/chat-room/basic-to-client-group-chat-room.cpp b/src/chat/chat-room/basic-to-client-group-chat-room.cpp index 4be674e01..ad4d14fc6 100644 --- a/src/chat/chat-room/basic-to-client-group-chat-room.cpp +++ b/src/chat/chat-room/basic-to-client-group-chat-room.cpp @@ -93,6 +93,7 @@ BasicToClientGroupChatRoom::BasicToClientGroupChatRoom (const shared_ptrchatRoom->getCapabilities(); + capabilities.set(Capabilities::Proxy); if (capabilities.isSet(Capabilities::Basic)) capabilities.set(Capabilities::Migratable); return capabilities; diff --git a/src/chat/chat-room/proxy-chat-room-p.h b/src/chat/chat-room/proxy-chat-room-p.h index 6fad6c69e..61d5273df 100644 --- a/src/chat/chat-room/proxy-chat-room-p.h +++ b/src/chat/chat-room/proxy-chat-room-p.h @@ -64,7 +64,11 @@ public: chatRoom->getPrivate()->onChatMessageReceived(chatMessage); } + void setupCallbacks (); + std::shared_ptr chatRoom; + + L_DECLARE_PUBLIC(ProxyChatRoom); }; LINPHONE_END_NAMESPACE diff --git a/src/chat/chat-room/proxy-chat-room.cpp b/src/chat/chat-room/proxy-chat-room.cpp index 73b05678e..d620236ff 100644 --- a/src/chat/chat-room/proxy-chat-room.cpp +++ b/src/chat/chat-room/proxy-chat-room.cpp @@ -20,6 +20,7 @@ #include "basic-to-client-group-chat-room.h" #include "chat-room.h" #include "proxy-chat-room-p.h" +#include "c-wrapper/c-wrapper.h" // ============================================================================= @@ -27,12 +28,103 @@ using namespace std; LINPHONE_BEGIN_NAMESPACE +#define PROXY_CALLBACK(callback, ...) \ + LinphoneChatRoomCbs *proxiedCbs = linphone_chat_room_get_callbacks(cr); \ + ProxyChatRoom *pcr = static_cast(linphone_chat_room_cbs_get_user_data(proxiedCbs)); \ + LinphoneChatRoom *lcr = L_GET_C_BACK_PTR(pcr->getSharedFromThis()); \ + LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(lcr); \ + if (linphone_chat_room_cbs_get_ ## callback(cbs)) \ + linphone_chat_room_cbs_get_ ## callback(cbs)(__VA_ARGS__) + +static void chatMessageReceived (LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + PROXY_CALLBACK(chat_message_received, cr, event_log); +} + +static void chatMessageSent (LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + PROXY_CALLBACK(chat_message_sent, cr, event_log); +} + +static void conferenceAddressGeneration (LinphoneChatRoom *cr) { + PROXY_CALLBACK(conference_address_generation, cr); +} + +static void isComposingReceived (LinphoneChatRoom *cr, const LinphoneAddress *remoteAddr, bool_t isComposing) { + PROXY_CALLBACK(is_composing_received, cr, remoteAddr, isComposing); +} + +static void messageReceived (LinphoneChatRoom *cr, LinphoneChatMessage *msg) { + PROXY_CALLBACK(message_received, cr, msg); +} + +static void participantAdded (LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + PROXY_CALLBACK(participant_added, cr, event_log); +} + +static void participantAdminStatusChanged (LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + PROXY_CALLBACK(participant_admin_status_changed, cr, event_log); +} + +static void participantDeviceAdded (LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + PROXY_CALLBACK(participant_device_added, cr, event_log); +} + +static void participantDeviceFetched (LinphoneChatRoom *cr, const LinphoneAddress *participantAddr) { + PROXY_CALLBACK(participant_device_fetched, cr, participantAddr); +} + +static void participantDeviceRemoved (LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + PROXY_CALLBACK(participant_device_removed, cr, event_log); +} + +static void participantRemoved (LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + PROXY_CALLBACK(participant_removed, cr, event_log); +} + +static void participantsCapabilitiesChecked (LinphoneChatRoom *cr, const LinphoneAddress *deviceAddr, const bctbx_list_t *participantsAddr) { + PROXY_CALLBACK(participants_capabilities_checked, cr, deviceAddr, participantsAddr); +} + +static void stateChanged (LinphoneChatRoom *cr, LinphoneChatRoomState newState) { + PROXY_CALLBACK(state_changed, cr, newState); +} + +static void subjectChanged (LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { + PROXY_CALLBACK(subject_changed, cr, event_log); +} + +static void undecryptableMessageReceived (LinphoneChatRoom *cr, LinphoneChatMessage *msg) { + PROXY_CALLBACK(undecryptable_message_received, cr, msg); +} + +void ProxyChatRoomPrivate::setupCallbacks () { + L_Q(); + LinphoneChatRoom *lcr = L_GET_C_BACK_PTR(chatRoom); + LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(lcr); + linphone_chat_room_cbs_set_user_data(cbs, q); + linphone_chat_room_cbs_set_chat_message_received(cbs, chatMessageReceived); + linphone_chat_room_cbs_set_chat_message_sent(cbs, chatMessageSent); + linphone_chat_room_cbs_set_conference_address_generation(cbs, conferenceAddressGeneration); + linphone_chat_room_cbs_set_is_composing_received(cbs, isComposingReceived); + linphone_chat_room_cbs_set_message_received(cbs, messageReceived); + linphone_chat_room_cbs_set_participant_added(cbs, participantAdded); + linphone_chat_room_cbs_set_participant_admin_status_changed(cbs, participantAdminStatusChanged); + linphone_chat_room_cbs_set_participant_device_added(cbs, participantDeviceAdded); + linphone_chat_room_cbs_set_participant_device_fetched(cbs, participantDeviceFetched); + linphone_chat_room_cbs_set_participant_device_removed(cbs, participantDeviceRemoved); + linphone_chat_room_cbs_set_participant_removed(cbs, participantRemoved); + linphone_chat_room_cbs_set_participants_capabilities_checked(cbs, participantsCapabilitiesChecked); + linphone_chat_room_cbs_set_state_changed(cbs, stateChanged); + linphone_chat_room_cbs_set_subject_changed(cbs, subjectChanged); + linphone_chat_room_cbs_set_undecryptable_message_received(cbs, undecryptableMessageReceived); +} + // ----------------------------------------------------------------------------- ProxyChatRoom::ProxyChatRoom (ProxyChatRoomPrivate &p, const shared_ptr &chatRoom) : AbstractChatRoom(p, chatRoom->getCore()) { L_D(); d->chatRoom = chatRoom; + d->setupCallbacks(); } // ----------------------------------------------------------------------------- diff --git a/tester/group_chat_tester.c b/tester/group_chat_tester.c index 285eddab9..e72d60fde 100644 --- a/tester/group_chat_tester.c +++ b/tester/group_chat_tester.c @@ -1655,7 +1655,7 @@ static void group_chat_room_migrate_from_basic_chat_room (void) { if (marieCr) { initialMarieStats = marie->stat; initialPaulineStats = pauline->stat; - BC_ASSERT_EQUAL(linphone_chat_room_get_capabilities(marieCr), LinphoneChatRoomCapabilitiesBasic | LinphoneChatRoomCapabilitiesProxy, int, "%d"); + BC_ASSERT_EQUAL(linphone_chat_room_get_capabilities(marieCr), LinphoneChatRoomCapabilitiesBasic | LinphoneChatRoomCapabilitiesProxy | LinphoneChatRoomCapabilitiesMigratable, int, "%d"); msg = linphone_chat_room_create_message(marieCr, "Did you migrate?"); linphone_chat_message_send(msg); BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_LinphoneChatRoomStateCreationPending, initialMarieStats.number_of_LinphoneChatRoomStateCreationPending + 1, 10000)); diff --git a/tester/rcfiles/marie_rc b/tester/rcfiles/marie_rc index f6f46ff8d..ac2b3e419 100644 --- a/tester/rcfiles/marie_rc +++ b/tester/rcfiles/marie_rc @@ -4,7 +4,6 @@ sip_tcp_port=-1 sip_tls_port=-1 default_proxy=0 ping_with_options=0 - composing_idle_timeout=1 store_ha1_passwd=0 #used for sipp @@ -29,7 +28,7 @@ pol=accept subscribe=0 [misc] -conference-factory-uri=sip:conference-factory@conf.example.org +conference_factory_uri=sip:conference-factory@conf.example.org [rtp] audio_rtp_port=18070-28000