From 006ecf4d76ee5e3e3fc820c7fa9f06e37dc42744 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 12 Oct 2017 16:54:47 +0200 Subject: [PATCH] feat(Conference): hide private attributes of Conference classes (feat Benjamin Reis aka Ben Rei Jeb) --- coreapi/callbacks.c | 5 +- include/linphone/utils/general.h | 7 + include/linphone/utils/utils.h | 10 ++ src/CMakeLists.txt | 3 + src/c-wrapper/api/c-chat-room.cpp | 10 +- src/call/call-p.h | 2 + src/chat/chat-room/basic-chat-room.cpp | 7 +- src/chat/chat-room/basic-chat-room.h | 2 +- src/chat/chat-room/client-group-chat-room.cpp | 108 +++++++----- src/chat/chat-room/client-group-chat-room.h | 4 +- .../chat-room/real-time-text-chat-room.cpp | 5 +- src/chat/chat-room/real-time-text-chat-room.h | 2 +- src/conference/conference-interface.h | 10 +- src/conference/conference-listener.h | 7 +- src/conference/conference-p.h | 59 +++++++ src/conference/conference.cpp | 162 +++++++++++------- src/conference/conference.h | 35 ++-- .../local-conference-event-handler.cpp | 16 +- src/conference/local-conference-p.h | 41 +++++ src/conference/local-conference.cpp | 34 ++-- src/conference/local-conference.h | 11 +- .../remote-conference-event-handler-p.h | 9 +- src/conference/remote-conference-p.h | 43 +++++ src/conference/remote-conference.cpp | 45 ++--- src/conference/remote-conference.h | 14 +- tester/conference-event-tester.cpp | 109 ++++++------ tester/tools/tester.h | 6 +- 27 files changed, 508 insertions(+), 258 deletions(-) create mode 100644 src/conference/conference-p.h create mode 100644 src/conference/local-conference-p.h create mode 100644 src/conference/remote-conference-p.h diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index e21544b49..b1dd16297 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -40,10 +40,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "c-wrapper/c-wrapper.h" #include "call/call-p.h" #include "chat/chat-room/chat-room.h" -#include "conference/session/call-session.h" +#include "conference/participant.h" #include "conference/session/call-session-p.h" -#include "conference/session/media-session.h" +#include "conference/session/call-session.h" #include "conference/session/media-session-p.h" +#include "conference/session/media-session.h" using namespace LinphonePrivate; diff --git a/include/linphone/utils/general.h b/include/linphone/utils/general.h index 495d72ee1..8e9e5d146 100644 --- a/include/linphone/utils/general.h +++ b/include/linphone/utils/general.h @@ -117,6 +117,13 @@ class ObjectPrivate; friend class Tester; #endif +// Generic public helper. (Neither ClonableObject nor Object.) +// `void *` is used to avoid downcasting. +template +constexpr T *getPublicHelper (void *object, const void *) { + return static_cast(object); +} + template inline T *getPublicHelper (const U *map, const ClonableObjectPrivate *context) { auto it = map->find(context); diff --git a/include/linphone/utils/utils.h b/include/linphone/utils/utils.h index c2f5d19df..6f5569192 100644 --- a/include/linphone/utils/utils.h +++ b/include/linphone/utils/utils.h @@ -42,6 +42,16 @@ namespace Utils { return object.get(); } + template + LINPHONE_PUBLIC constexpr T *getPtr (std::unique_ptr &object) { + return object.get(); + } + + template + LINPHONE_PUBLIC constexpr T *getPtr (const std::unique_ptr &object) { + return object.get(); + } + template LINPHONE_PUBLIC constexpr T *getPtr (T *object) { return object; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a596c879..692371a06 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,9 +54,11 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES chat/modifier/encryption-chat-message-modifier.h chat/modifier/multipart-chat-message-modifier.h conference/conference-listener.h + conference/conference-p.h conference/conference.h conference/local-conference-event-handler-p.h conference/local-conference-event-handler.h + conference/local-conference-p.h conference/local-conference.h conference/params/call-session-params-p.h conference/params/call-session-params.h @@ -67,6 +69,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES conference/participant.h conference/remote-conference-event-handler-p.h conference/remote-conference-event-handler.h + conference/remote-conference-p.h conference/remote-conference.h conference/session/call-session-listener.h conference/session/call-session-p.h diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index 89e668ee5..f92827208 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -230,12 +230,12 @@ LinphoneParticipant *linphone_chat_room_find_participant (const LinphoneChatRoom } const LinphoneAddress *linphone_chat_room_get_conference_address (const LinphoneChatRoom *cr) { - if (cr->conferenceAddressCache) { + if (cr->conferenceAddressCache) linphone_address_unref(cr->conferenceAddressCache); - } - auto addr = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getConferenceAddress(); - if (addr) - cr->conferenceAddressCache = linphone_address_new(addr->asString().c_str()); + + const LinphonePrivate::Address &address = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getConferenceAddress(); + if (address.isValid()) + cr->conferenceAddressCache = linphone_address_new(address.asString().c_str()); else cr->conferenceAddressCache = nullptr; return cr->conferenceAddressCache; diff --git a/src/call/call-p.h b/src/call/call-p.h index 1bc0c420c..5c75fa610 100644 --- a/src/call/call-p.h +++ b/src/call/call-p.h @@ -20,10 +20,12 @@ #ifndef _CALL_P_H_ #define _CALL_P_H_ +#include "call-listener.h" #include "call.h" #include "conference/conference.h" #include "object/object-p.h" +// TODO: Remove me later. #include "private.h" // ============================================================================= diff --git a/src/chat/chat-room/basic-chat-room.cpp b/src/chat/chat-room/basic-chat-room.cpp index 2814a253d..c439570fe 100644 --- a/src/chat/chat-room/basic-chat-room.cpp +++ b/src/chat/chat-room/basic-chat-room.cpp @@ -17,7 +17,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "linphone/utils/utils.h" + #include "basic-chat-room-p.h" +#include "conference/participant.h" #include "logger/logger.h" // ============================================================================= @@ -57,9 +60,9 @@ shared_ptr BasicChatRoom::findParticipant (const Address &addr) con return nullptr; } -const Address *BasicChatRoom::getConferenceAddress () const { +const Address &BasicChatRoom::getConferenceAddress () const { lError() << "a BasicChatRoom does not have a conference address"; - return nullptr; + return Utils::getEmptyConstRefObject
(); } int BasicChatRoom::getNbParticipants () const { diff --git a/src/chat/chat-room/basic-chat-room.h b/src/chat/chat-room/basic-chat-room.h index d6b64d9a6..9e8bf1f72 100644 --- a/src/chat/chat-room/basic-chat-room.h +++ b/src/chat/chat-room/basic-chat-room.h @@ -40,7 +40,7 @@ public: void addParticipants (const std::list
&addresses, const CallSessionParams *params, bool hasMedia) override; bool canHandleParticipants () const override; std::shared_ptr findParticipant (const Address &addr) const override; - const Address *getConferenceAddress () const override; + const Address &getConferenceAddress () const override; int getNbParticipants () const override; std::list> getParticipants () const override; const std::string &getSubject () const override; diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index a1de405f0..22ed84b38 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -20,10 +20,12 @@ #include "linphone/utils/utils.h" #include "address/address-p.h" -#include "client-group-chat-room-p.h" #include "c-wrapper/c-wrapper.h" -#include "conference/session/call-session-p.h" +#include "client-group-chat-room-p.h" #include "conference/participant-p.h" +#include "conference/remote-conference-event-handler.h" +#include "conference/remote-conference-p.h" +#include "conference/session/call-session-p.h" #include "logger/logger.h" #include "sal/refer-op.h" @@ -39,12 +41,17 @@ ClientGroupChatRoomPrivate::ClientGroupChatRoomPrivate (LinphoneCore *core) : Ch shared_ptr ClientGroupChatRoomPrivate::createSession () { L_Q(); + CallSessionParams csp; csp.addCustomHeader("Require", "recipient-list-invite"); - shared_ptr session = q->focus->getPrivate()->createSession(*q, &csp, false, q); - session->configure(LinphoneCallOutgoing, nullptr, nullptr, q->me->getAddress(), q->focus->getAddress()); + + shared_ptr focus = static_cast(q)->getPrivate()->focus; + shared_ptr session = focus->getPrivate()->createSession(*q, &csp, false, q); + const Address &myAddress = q->getMe()->getAddress(); + session->configure(LinphoneCallOutgoing, nullptr, nullptr, myAddress, focus->getAddress()); session->initiateOutgoing(); - Address addr = q->me->getAddress(); + + Address addr = myAddress; addr.setParam("text"); session->getPrivate()->getOp()->set_contact_address(addr.getPrivate()->getInternalAddress()); return session; @@ -52,15 +59,16 @@ shared_ptr ClientGroupChatRoomPrivate::createSession () { void ClientGroupChatRoomPrivate::notifyReceived (string body) { L_Q(); - q->eventHandler->notifyReceived(body); + static_cast(q)->getPrivate()->eventHandler->notifyReceived(body); } // ============================================================================= ClientGroupChatRoom::ClientGroupChatRoom (LinphoneCore *core, const Address &me, const string &uri, const string &subject) : ChatRoom(*new ClientGroupChatRoomPrivate(core)), RemoteConference(core, me, nullptr) { - focus = ObjectFactory::create(Address(uri)); - this->subject = subject; + static_cast(Conference::mPrivate)->focus = + ObjectFactory::create(Address(uri)); + setSubject(subject); } int ClientGroupChatRoom::getCapabilities () const { @@ -75,28 +83,33 @@ void ClientGroupChatRoom::addParticipant (const Address &addr, const CallSession void ClientGroupChatRoom::addParticipants (const list
&addresses, const CallSessionParams *params, bool hasMedia) { L_D(); + if (addresses.empty()) return; + if ((d->state != ChatRoom::State::Instantiated) && (d->state != ChatRoom::State::Created)) { lError() << "Cannot add participants to the ClientGroupChatRoom in a state other than Instantiated or Created"; return; } + list
sortedAddresses(addresses); sortedAddresses.sort(); sortedAddresses.unique(); + Content content; content.setBody(getResourceLists(sortedAddresses)); content.setContentType("application/resource-lists+xml"); content.setContentDisposition("recipient-list"); - shared_ptr session = focus->getPrivate()->getSession(); + + shared_ptr session = + static_cast(Conference::mPrivate)->focus->getPrivate()->getSession(); if (session) - session->update(nullptr, subject, &content); + session->update(nullptr, getSubject(), &content); else { session = d->createSession(); - session->startInvite(nullptr, subject, &content); - if (d->state == ChatRoom::State::Instantiated) { + session->startInvite(nullptr, getSubject(), &content); + if (d->state == ChatRoom::State::Instantiated) d->setState(ChatRoom::State::CreationPending); - } } } @@ -108,7 +121,7 @@ shared_ptr ClientGroupChatRoom::findParticipant (const Address &add return RemoteConference::findParticipant(addr); } -const Address *ClientGroupChatRoom::getConferenceAddress () const { +const Address &ClientGroupChatRoom::getConferenceAddress () const { return RemoteConference::getConferenceAddress(); } @@ -126,7 +139,8 @@ const string &ClientGroupChatRoom::getSubject () const { void ClientGroupChatRoom::join () { L_D(); - shared_ptr session = focus->getPrivate()->getSession(); + shared_ptr session = + static_cast(Conference::mPrivate)->focus->getPrivate()->getSession(); if (!session && (d->state == ChatRoom::State::Instantiated)) { session = d->createSession(); session->startInvite(nullptr, "", nullptr); @@ -136,21 +150,26 @@ void ClientGroupChatRoom::join () { void ClientGroupChatRoom::leave () { L_D(); - eventHandler->unsubscribe(); - shared_ptr session = focus->getPrivate()->getSession(); + + RemoteConferencePrivate *conferencePrivate = + static_cast(Conference::mPrivate); + conferencePrivate->eventHandler->unsubscribe(); + + shared_ptr session = conferencePrivate->focus->getPrivate()->getSession(); if (session) session->terminate(); else { session = d->createSession(); session->startInvite(nullptr, "", nullptr); } + d->setState(ChatRoom::State::TerminationPending); } void ClientGroupChatRoom::removeParticipant (const shared_ptr &participant) { L_D(); SalReferOp *referOp = new SalReferOp(d->core->sal); - LinphoneAddress *lAddr = linphone_address_new(conferenceAddress.asString().c_str()); + LinphoneAddress *lAddr = linphone_address_new(getConferenceAddress().asString().c_str()); linphone_configure_op(d->core, referOp, lAddr, nullptr, false); linphone_address_unref(lAddr); Address referToAddr = participant->getAddress(); @@ -168,14 +187,17 @@ void ClientGroupChatRoom::removeParticipants (const list void ClientGroupChatRoom::setParticipantAdminStatus (shared_ptr &participant, bool isAdmin) { L_D(); + if (isAdmin == participant->isAdmin()) return; - if (!me->isAdmin()) { + + if (!getMe()->isAdmin()) { lError() << "Cannot change the participant admin status because I am not admin"; return; } + SalReferOp *referOp = new SalReferOp(d->core->sal); - LinphoneAddress *lAddr = linphone_address_new(conferenceAddress.asString().c_str()); + LinphoneAddress *lAddr = linphone_address_new(getConferenceAddress().asString().c_str()); linphone_configure_op(d->core, referOp, lAddr, nullptr, false); linphone_address_unref(lAddr); Address referToAddr = participant->getAddress(); @@ -189,15 +211,19 @@ void ClientGroupChatRoom::setParticipantAdminStatus (shared_ptr &pa void ClientGroupChatRoom::setSubject (const string &subject) { L_D(); + if (d->state != ChatRoom::State::Created) { lError() << "Cannot change the ClientGroupChatRoom subject in a state other than Created"; return; } - if (!me->isAdmin()) { + + if (!getMe()->isAdmin()) { lError() << "Cannot change the ClientGroupChatRoom subject because I am not admin"; return; } - shared_ptr session = focus->getPrivate()->getSession(); + + shared_ptr session = + static_cast(Conference::mPrivate)->focus->getPrivate()->getSession(); if (session) session->update(nullptr, subject); else { @@ -210,7 +236,7 @@ void ClientGroupChatRoom::setSubject (const string &subject) { void ClientGroupChatRoom::onConferenceCreated (const Address &addr) { L_D(); - conferenceAddress = addr; + static_cast(Conference::mPrivate)->conferenceAddress = addr; d->setState(ChatRoom::State::Created); _linphone_core_add_group_chat_room(d->core, addr, L_GET_C_BACK_PTR(this)); } @@ -223,13 +249,15 @@ void ClientGroupChatRoom::onConferenceTerminated (const Address &addr) { void ClientGroupChatRoom::onParticipantAdded (const Address &addr) { if (isMe(addr)) return; + shared_ptr participant = findParticipant(addr); if (participant) { lWarning() << "Participant " << participant << " added but already in the list of participants!"; return; } + participant = ObjectFactory::create(addr); - participants.push_back(participant); + RemoteConference::mPrivate->participants.push_back(participant); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); LinphoneChatRoomCbsParticipantAddedCb cb = linphone_chat_room_cbs_get_participant_added(cbs); @@ -248,13 +276,13 @@ void ClientGroupChatRoom::onParticipantRemoved (const Address &addr) { LinphoneChatRoomCbsParticipantRemovedCb cb = linphone_chat_room_cbs_get_participant_removed(cbs); if (cb) cb(cr, L_GET_C_BACK_PTR(participant)); - participants.remove(participant); + RemoteConference::mPrivate->participants.remove(participant); } void ClientGroupChatRoom::onParticipantSetAdmin (const Address &addr, bool isAdmin) { shared_ptr participant; if (isMe(addr)) - participant = me; + participant = getMe(); else participant = findParticipant(addr); if (!participant) { @@ -270,7 +298,7 @@ void ClientGroupChatRoom::onParticipantSetAdmin (const Address &addr, bool isAdm } void ClientGroupChatRoom::onSubjectChanged (const std::string &subject) { - this->subject = subject; + setSubject(subject); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); LinphoneChatRoomCbsSubjectChangedCb cb = linphone_chat_room_cbs_get_subject_changed(cbs); @@ -281,7 +309,7 @@ void ClientGroupChatRoom::onSubjectChanged (const std::string &subject) { void ClientGroupChatRoom::onParticipantDeviceAdded (const Address &addr, const Address &gruu) { shared_ptr participant; if (isMe(addr)) - participant = me; + participant = getMe(); else participant = findParticipant(addr); if (!participant) { @@ -294,7 +322,7 @@ void ClientGroupChatRoom::onParticipantDeviceAdded (const Address &addr, const A void ClientGroupChatRoom::onParticipantDeviceRemoved (const Address &addr, const Address &gruu) { shared_ptr participant; if (isMe(addr)) - participant = me; + participant = getMe(); else participant = findParticipant(addr); if (!participant) { @@ -307,8 +335,11 @@ void ClientGroupChatRoom::onParticipantDeviceRemoved (const Address &addr, const // ----------------------------------------------------------------------------- void ClientGroupChatRoom::onCallSessionSetReleased (const std::shared_ptr &session) { - if (session == focus->getPrivate()->getSession()) - focus->getPrivate()->removeSession(); + ParticipantPrivate *participantPrivate = + static_cast(Conference::mPrivate)->focus->getPrivate(); + + if (session == participantPrivate->getSession()) + participantPrivate->removeSession(); } void ClientGroupChatRoom::onCallSessionStateChanged (const std::shared_ptr &session, LinphoneCallState state, const string &message) { @@ -319,14 +350,13 @@ void ClientGroupChatRoom::onCallSessionStateChanged (const std::shared_ptrgetRemoteContactAddress()->hasParam("isfocus")) - eventHandler->subscribe(conferenceAddress); - } else if (d->state == ChatRoom::State::TerminationPending) { - focus->getPrivate()->getSession()->terminate(); - } - } else { - if ((state == LinphoneCallReleased) && (d->state == ChatRoom::State::TerminationPending)) - onConferenceTerminated(conferenceAddress); - } + static_cast(Conference::mPrivate)->eventHandler->subscribe( + getConferenceAddress() + ); + } else if (d->state == ChatRoom::State::TerminationPending) + static_cast(Conference::mPrivate)->focus->getPrivate()->getSession()->terminate(); + } else if ((state == LinphoneCallReleased) && (d->state == ChatRoom::State::TerminationPending)) + onConferenceTerminated(getConferenceAddress()); } LINPHONE_END_NAMESPACE diff --git a/src/chat/chat-room/client-group-chat-room.h b/src/chat/chat-room/client-group-chat-room.h index b97156cd2..0d9432ccb 100644 --- a/src/chat/chat-room/client-group-chat-room.h +++ b/src/chat/chat-room/client-group-chat-room.h @@ -41,7 +41,7 @@ public: void addParticipants (const std::list
&addresses, const CallSessionParams *params, bool hasMedia) override; bool canHandleParticipants () const override; std::shared_ptr findParticipant (const Address &addr) const override; - const Address *getConferenceAddress () const override; + const Address &getConferenceAddress () const override; int getNbParticipants () const override; std::list> getParticipants () const override; const std::string &getSubject () const override; @@ -69,7 +69,7 @@ private: void onCallSessionStateChanged (const std::shared_ptr &session, LinphoneCallState state, const std::string &message) override; private: - L_DECLARE_PRIVATE(ClientGroupChatRoom); + L_DECLARE_PRIVATE_T(ClientGroupChatRoom, ChatRoom); L_DISABLE_COPY(ClientGroupChatRoom); }; diff --git a/src/chat/chat-room/real-time-text-chat-room.cpp b/src/chat/chat-room/real-time-text-chat-room.cpp index 1aa4a4693..705fc0172 100644 --- a/src/chat/chat-room/real-time-text-chat-room.cpp +++ b/src/chat/chat-room/real-time-text-chat-room.cpp @@ -19,6 +19,7 @@ #include "c-wrapper/c-wrapper.h" #include "chat/chat-message/chat-message-p.h" +#include "conference/participant.h" #include "logger/logger.h" #include "real-time-text-chat-room-p.h" @@ -150,9 +151,9 @@ shared_ptr RealTimeTextChatRoom::findParticipant (const Address &ad return nullptr; } -const Address *RealTimeTextChatRoom::getConferenceAddress () const { +const Address &RealTimeTextChatRoom::getConferenceAddress () const { lError() << "a RealTimeTextChatRoom does not have a conference address"; - return nullptr; + return Utils::getEmptyConstRefObject
(); } int RealTimeTextChatRoom::getNbParticipants () const { diff --git a/src/chat/chat-room/real-time-text-chat-room.h b/src/chat/chat-room/real-time-text-chat-room.h index e8d7c919f..01a84035d 100644 --- a/src/chat/chat-room/real-time-text-chat-room.h +++ b/src/chat/chat-room/real-time-text-chat-room.h @@ -43,7 +43,7 @@ public: void addParticipants (const std::list
&addresses, const CallSessionParams *params, bool hasMedia) override; bool canHandleParticipants () const override; std::shared_ptr findParticipant (const Address &addr) const override; - const Address *getConferenceAddress () const override; + const Address &getConferenceAddress () const override; int getNbParticipants () const override; std::list> getParticipants () const override; const std::string &getSubject () const override; diff --git a/src/conference/conference-interface.h b/src/conference/conference-interface.h index 443181f26..42bdca4e2 100644 --- a/src/conference/conference-interface.h +++ b/src/conference/conference-interface.h @@ -23,14 +23,16 @@ #include #include -#include "address/address.h" -#include "conference/participant.h" -#include "conference/params/call-session-params.h" +#include "linphone/utils/general.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE +class Address; +class CallSessionParams; +class Participant; + class LINPHONE_PUBLIC ConferenceInterface { public: virtual ~ConferenceInterface() = default; @@ -39,7 +41,7 @@ public: virtual void addParticipants (const std::list
&addresses, const CallSessionParams *params, bool hasMedia) = 0; virtual bool canHandleParticipants () const = 0; virtual std::shared_ptr findParticipant (const Address &addr) const = 0; - virtual const Address *getConferenceAddress () const = 0; + virtual const Address &getConferenceAddress () const = 0; virtual int getNbParticipants () const = 0; virtual std::list> getParticipants () const = 0; virtual const std::string &getSubject () const = 0; diff --git a/src/conference/conference-listener.h b/src/conference/conference-listener.h index 34665bfbd..96c30528e 100644 --- a/src/conference/conference-listener.h +++ b/src/conference/conference-listener.h @@ -20,12 +20,16 @@ #ifndef _CONFERENCE_LISTENER_H_ #define _CONFERENCE_LISTENER_H_ -#include "address/address.h" +#include + +#include "linphone/utils/general.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE +class Address; + class ConferenceListener { public: virtual void onConferenceCreated (const Address &addr) = 0; @@ -41,4 +45,3 @@ public: LINPHONE_END_NAMESPACE #endif // ifndef _CONFERENCE_LISTENER_H_ - diff --git a/src/conference/conference-p.h b/src/conference/conference-p.h new file mode 100644 index 000000000..1b0421da4 --- /dev/null +++ b/src/conference/conference-p.h @@ -0,0 +1,59 @@ +/* + * conference-p.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _CONFERENCE_P_H_ +#define _CONFERENCE_P_H_ + +#include +#include + +#include "linphone/types.h" + +#include "address/address.h" +#include "conference.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class CallListener; +class Participant; + +class ConferencePrivate { +public: + Address conferenceAddress; + std::list> participants; + +protected: + LinphoneCore *core = nullptr; + CallListener *callListener = nullptr; + + std::shared_ptr activeParticipant; + std::shared_ptr me; + std::string subject; + + Conference *mPublic = nullptr; + +private: + L_DECLARE_PUBLIC(Conference); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _CONFERENCE_P_H_ diff --git a/src/conference/conference.cpp b/src/conference/conference.cpp index 3ba9cf826..0d97d880f 100644 --- a/src/conference/conference.cpp +++ b/src/conference/conference.cpp @@ -17,27 +17,45 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "participant-p.h" - -#include "conference.h" +#include "call/call-listener.h" +#include "conference-p.h" #include "conference/session/call-session-p.h" #include "logger/logger.h" +#include "participant-p.h" + +// ============================================================================= using namespace std; LINPHONE_BEGIN_NAMESPACE -// ============================================================================= +Conference::Conference (ConferencePrivate &p, LinphoneCore *core, const Address &myAddress, CallListener *listener) : mPrivate(&p) { + L_D(); + d->mPublic = this; + d->core = core; + d->callListener = listener; + d->me = ObjectFactory::create(myAddress); +} -Conference::Conference (LinphoneCore *core, const Address &myAddress, CallListener *listener) - : core(core), callListener(listener) { - me = ObjectFactory::create(myAddress); +Conference::~Conference () { + delete mPrivate; } // ----------------------------------------------------------------------------- shared_ptr Conference::getActiveParticipant () const { - return activeParticipant; + L_D(); + return d->activeParticipant; +} + +shared_ptr Conference::getMe () const { + L_D(); + return d->me; +} + +LinphoneCore *Conference::getCore () const { + L_D(); + return d->core; } // ----------------------------------------------------------------------------- @@ -61,20 +79,24 @@ bool Conference::canHandleParticipants () const { return true; } -const Address *Conference::getConferenceAddress () const { - return &conferenceAddress; +const Address &Conference::getConferenceAddress () const { + L_D(); + return d->conferenceAddress; } int Conference::getNbParticipants () const { - return static_cast(participants.size()); + L_D(); + return static_cast(d->participants.size()); } list> Conference::getParticipants () const { - return participants; + L_D(); + return d->participants; } const string &Conference::getSubject () const { - return subject; + L_D(); + return d->subject; } void Conference::join () {} @@ -90,110 +112,132 @@ void Conference::removeParticipants (const list> &partic removeParticipant(p); } -void Conference::setParticipantAdminStatus (std::shared_ptr &participant, bool isAdmin) { +void Conference::setParticipantAdminStatus (shared_ptr &participant, bool isAdmin) { lError() << "Conference class does not handle setParticipantAdminStatus() generically"; } void Conference::setSubject (const string &subject) { - this->subject = subject; + L_D(); + d->subject = subject; } // ----------------------------------------------------------------------------- -void Conference::onAckBeingSent (const std::shared_ptr &session, LinphoneHeaders *headers) { - if (callListener) - callListener->onAckBeingSent(headers); +void Conference::onAckBeingSent (const shared_ptr &session, LinphoneHeaders *headers) { + L_D(); + if (d->callListener) + d->callListener->onAckBeingSent(headers); } -void Conference::onAckReceived (const std::shared_ptr &session, LinphoneHeaders *headers) { - if (callListener) - callListener->onAckReceived(headers); +void Conference::onAckReceived (const shared_ptr &session, LinphoneHeaders *headers) { + L_D(); + if (d->callListener) + d->callListener->onAckReceived(headers); } -void Conference::onCallSessionAccepted (const std::shared_ptr &session) { - if (callListener) - callListener->onIncomingCallToBeAdded(); +void Conference::onCallSessionAccepted (const shared_ptr &session) { + L_D(); + if (d->callListener) + d->callListener->onIncomingCallToBeAdded(); } -void Conference::onCallSessionSetReleased (const std::shared_ptr &session) { - if (callListener) - callListener->onCallSetReleased(); +void Conference::onCallSessionSetReleased (const shared_ptr &session) { + L_D(); + if (d->callListener) + d->callListener->onCallSetReleased(); } -void Conference::onCallSessionSetTerminated (const std::shared_ptr &session) { - if (callListener) - callListener->onCallSetTerminated(); +void Conference::onCallSessionSetTerminated (const shared_ptr &session) { + L_D(); + if (d->callListener) + d->callListener->onCallSetTerminated(); } -void Conference::onCallSessionStateChanged (const std::shared_ptr &session, LinphoneCallState state, const string &message) { - if (callListener) - callListener->onCallStateChanged(state, message); +void Conference::onCallSessionStateChanged (const shared_ptr &session, LinphoneCallState state, const string &message) { + L_D(); + if (d->callListener) + d->callListener->onCallStateChanged(state, message); } -void Conference::onCheckForAcceptation (const std::shared_ptr &session) { - if (callListener) - callListener->onCheckForAcceptation(); +void Conference::onCheckForAcceptation (const shared_ptr &session) { + L_D(); + if (d->callListener) + d->callListener->onCheckForAcceptation(); } -void Conference::onIncomingCallSessionStarted (const std::shared_ptr &session) { - if (callListener) - callListener->onIncomingCallStarted(); +void Conference::onIncomingCallSessionStarted (const shared_ptr &session) { + L_D(); + if (d->callListener) + d->callListener->onIncomingCallStarted(); } -void Conference::onEncryptionChanged (const std::shared_ptr &session, bool activated, const string &authToken) { - if (callListener) - callListener->onEncryptionChanged(activated, authToken); +void Conference::onEncryptionChanged (const shared_ptr &session, bool activated, const string &authToken) { + L_D(); + if (d->callListener) + d->callListener->onEncryptionChanged(activated, authToken); } void Conference::onStatsUpdated (const LinphoneCallStats *stats) { - if (callListener) - callListener->onStatsUpdated(stats); + L_D(); + if (d->callListener) + d->callListener->onStatsUpdated(stats); } -void Conference::onResetCurrentSession (const std::shared_ptr &session) { - if (callListener) - callListener->onResetCurrentCall(); +void Conference::onResetCurrentSession (const shared_ptr &session) { + L_D(); + if (d->callListener) + d->callListener->onResetCurrentCall(); } -void Conference::onSetCurrentSession (const std::shared_ptr &session) { - if (callListener) - callListener->onSetCurrentCall(); +void Conference::onSetCurrentSession (const shared_ptr &session) { + L_D(); + if (d->callListener) + d->callListener->onSetCurrentCall(); } -void Conference::onFirstVideoFrameDecoded (const std::shared_ptr &session) { - if (callListener) - callListener->onFirstVideoFrameDecoded(); +void Conference::onFirstVideoFrameDecoded (const shared_ptr &session) { + L_D(); + if (d->callListener) + d->callListener->onFirstVideoFrameDecoded(); } -void Conference::onResetFirstVideoFrameDecoded (const std::shared_ptr &session) { - if (callListener) - callListener->onResetFirstVideoFrameDecoded(); +void Conference::onResetFirstVideoFrameDecoded (const shared_ptr &session) { + L_D(); + if (d->callListener) + d->callListener->onResetFirstVideoFrameDecoded(); } // ----------------------------------------------------------------------------- shared_ptr Conference::findParticipant (const Address &addr) const { + L_D(); + Address testedAddr = addr; testedAddr.setPort(0); - for (const auto &participant : participants) { + for (const auto &participant : d->participants) { Address participantAddr = participant->getAddress(); participantAddr.setPort(0); if (testedAddr.weakEqual(participantAddr)) return participant; } + return nullptr; } shared_ptr Conference::findParticipant (const shared_ptr &session) const { - for (const auto &participant : participants) { + L_D(); + + for (const auto &participant : d->participants) { if (participant->getPrivate()->getSession() == session) return participant; } + return nullptr; } bool Conference::isMe (const Address &addr) const { - Address cleanedMe = me->getAddress(); + L_D(); + Address cleanedMe = d->me->getAddress(); cleanedMe.setPort(0); Address cleanedAddr = addr; cleanedAddr.setPort(0); diff --git a/src/conference/conference.h b/src/conference/conference.h index cee450b11..b89117c25 100644 --- a/src/conference/conference.h +++ b/src/conference/conference.h @@ -22,39 +22,36 @@ #include "linphone/types.h" -#include "address/address.h" -#include "call/call-listener.h" #include "conference/conference-interface.h" -#include "conference/params/call-session-params.h" -#include "conference/participant.h" #include "conference/session/call-session-listener.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE +class CallListener; class CallSessionPrivate; +class ConferencePrivate; class LINPHONE_PUBLIC Conference : public ConferenceInterface, public CallSessionListener { friend class CallSessionPrivate; public: - virtual ~Conference() = default; + virtual ~Conference(); std::shared_ptr getActiveParticipant () const; - std::shared_ptr getMe () const { return me; } + std::shared_ptr getMe () const; - LinphoneCore * getCore () const { return core; } + LinphoneCore * getCore () const; std::shared_ptr findParticipant (const std::shared_ptr &session) const; -public: /* ConferenceInterface */ void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override; void addParticipants (const std::list
&addresses, const CallSessionParams *params, bool hasMedia) override; bool canHandleParticipants () const override; std::shared_ptr findParticipant (const Address &addr) const override; - const Address *getConferenceAddress () const override; + const Address &getConferenceAddress () const override; int getNbParticipants () const override; std::list> getParticipants () const override; const std::string &getSubject () const override; @@ -83,21 +80,19 @@ private: void onResetFirstVideoFrameDecoded (const std::shared_ptr &session) override; protected: - explicit Conference (LinphoneCore *core, const Address &myAddress, CallListener *listener = nullptr); + explicit Conference ( + ConferencePrivate &p, + LinphoneCore *core, + const Address &myAddress, + CallListener *listener = nullptr + ); - bool isMe (const Address &addr) const ; + bool isMe (const Address &addr) const; -protected: - LinphoneCore *core = nullptr; - CallListener *callListener = nullptr; - - std::shared_ptr activeParticipant; - std::shared_ptr me; - std::list> participants; - Address conferenceAddress; - std::string subject; + ConferencePrivate *mPrivate = nullptr; private: + L_DECLARE_PRIVATE(Conference); L_DISABLE_COPY(Conference); }; diff --git a/src/conference/local-conference-event-handler.cpp b/src/conference/local-conference-event-handler.cpp index 59b67edaa..ff9b33167 100644 --- a/src/conference/local-conference-event-handler.cpp +++ b/src/conference/local-conference-event-handler.cpp @@ -78,7 +78,7 @@ string LocalConferenceEventHandlerPrivate::createNotify (ConferenceType confInfo } string LocalConferenceEventHandlerPrivate::createNotifyFullState () { - string entity = conf->getConferenceAddress()->asStringUriOnly(); + string entity = conf->getConferenceAddress().asStringUriOnly(); string subject = conf->getSubject(); ConferenceType confInfo = ConferenceType(entity); UsersType users; @@ -112,7 +112,7 @@ string LocalConferenceEventHandlerPrivate::createNotifyFullState () { } string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdded (const Address &addr) { - string entity = conf->getConferenceAddress()->asStringUriOnly(); + string entity = conf->getConferenceAddress().asStringUriOnly(); ConferenceType confInfo = ConferenceType(entity); UsersType users; confInfo.setUsers(users); @@ -142,7 +142,7 @@ string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdded (const A } string LocalConferenceEventHandlerPrivate::createNotifyParticipantRemoved (const Address &addr) { - string entity = conf->getConferenceAddress()->asStringUriOnly(); + string entity = conf->getConferenceAddress().asStringUriOnly(); ConferenceType confInfo = ConferenceType(entity); UsersType users; confInfo.setUsers(users); @@ -156,7 +156,7 @@ string LocalConferenceEventHandlerPrivate::createNotifyParticipantRemoved (const } string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdmined (const Address &addr, bool isAdmin) { - string entity = conf->getConferenceAddress()->asStringUriOnly(); + string entity = conf->getConferenceAddress().asStringUriOnly(); ConferenceType confInfo = ConferenceType(entity); UsersType users; confInfo.setUsers(users); @@ -173,7 +173,7 @@ string LocalConferenceEventHandlerPrivate::createNotifyParticipantAdmined (const } string LocalConferenceEventHandlerPrivate::createNotifySubjectChanged () { - string entity = conf->getConferenceAddress()->asStringUriOnly(); + string entity = conf->getConferenceAddress().asStringUriOnly(); string subject = conf->getSubject(); ConferenceType confInfo = ConferenceType(entity); ConferenceDescriptionType confDescr = ConferenceDescriptionType(); @@ -184,7 +184,7 @@ string LocalConferenceEventHandlerPrivate::createNotifySubjectChanged () { } string LocalConferenceEventHandlerPrivate::createNotifyParticipantDeviceAdded (const Address &addr, const Address &gruu) { - string entity = conf->getConferenceAddress()->asStringUriOnly(); + string entity = conf->getConferenceAddress().asStringUriOnly(); string subject = conf->getSubject(); ConferenceType confInfo = ConferenceType(entity); UsersType users; @@ -209,7 +209,7 @@ string LocalConferenceEventHandlerPrivate::createNotifyParticipantDeviceAdded (c } string LocalConferenceEventHandlerPrivate::createNotifyParticipantDeviceRemoved (const Address &addr, const Address &gruu) { - string entity = conf->getConferenceAddress()->asStringUriOnly(); + string entity = conf->getConferenceAddress().asStringUriOnly(); string subject = conf->getSubject(); ConferenceType confInfo = ConferenceType(entity); UsersType users; @@ -237,7 +237,7 @@ void LocalConferenceEventHandlerPrivate::sendNotify (const string ¬ify, const LinphoneAddress *cAddr = linphone_address_new(addr.asString().c_str()); LinphoneEvent *lev = linphone_core_create_notify(core, cAddr, "conference"); // Fix the From header to put the chat room URI - lev->op->set_from(conf->getConferenceAddress()->asString().c_str()); + lev->op->set_from(conf->getConferenceAddress().asString().c_str()); linphone_address_unref(cAddr); doNotify(notify, lev); } diff --git a/src/conference/local-conference-p.h b/src/conference/local-conference-p.h new file mode 100644 index 000000000..def1a9111 --- /dev/null +++ b/src/conference/local-conference-p.h @@ -0,0 +1,41 @@ +/* + * local-conference-p.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _LOCAL_CONFERENCE_P_H_ +#define _LOCAL_CONFERENCE_P_H_ + +#include "conference-p.h" +#include "local-conference.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class LocalConferenceEventHandler; + +class LocalConferencePrivate : public ConferencePrivate { +private: + std::unique_ptr eventHandler; + + L_DECLARE_PUBLIC(LocalConference); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _LOCAL_CONFERENCE_P_H_ diff --git a/src/conference/local-conference.cpp b/src/conference/local-conference.cpp index a26a63832..872e6da9e 100644 --- a/src/conference/local-conference.cpp +++ b/src/conference/local-conference.cpp @@ -17,42 +17,41 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "local-conference.h" +#include "local-conference-event-handler.h" +#include "local-conference-p.h" #include "participant-p.h" #include "xml/resource-lists.h" +// ============================================================================= + using namespace std; -using namespace LinphonePrivate::Xsd::ResourceLists; LINPHONE_BEGIN_NAMESPACE -// ============================================================================= - LocalConference::LocalConference (LinphoneCore *core, const Address &myAddress, CallListener *listener) - : Conference(core, myAddress, listener) { - eventHandler = new LocalConferenceEventHandler(core, this); -} - -LocalConference::~LocalConference () { - delete eventHandler; + : Conference(*new LocalConferencePrivate, core, myAddress, listener) { + L_D(); + d->eventHandler.reset(new LocalConferenceEventHandler(core, this)); } // ----------------------------------------------------------------------------- void LocalConference::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) { + L_D(); shared_ptr participant = findParticipant(addr); if (participant) return; participant = ObjectFactory::create(addr); - participants.push_back(participant); - if (!activeParticipant) - activeParticipant = participant; + d->participants.push_back(participant); + if (!d->activeParticipant) + d->activeParticipant = participant; } void LocalConference::removeParticipant (const shared_ptr &participant) { - for (const auto &p : participants) { + L_D(); + for (const auto &p : d->participants) { if (participant->getAddress() == p->getAddress()) { - participants.remove(p); + d->participants.remove(p); return; } } @@ -60,7 +59,10 @@ void LocalConference::removeParticipant (const shared_ptr &pa list
LocalConference::parseResourceLists (string xmlBody) { istringstream data(xmlBody); - unique_ptr rl = LinphonePrivate::Xsd::ResourceLists::parseResourceLists(data, Xsd::XmlSchema::Flags::dont_validate); + unique_ptr rl = LinphonePrivate::Xsd::ResourceLists::parseResourceLists( + data, + Xsd::XmlSchema::Flags::dont_validate + ); list
addresses = list
(); for (const auto &l : rl->getList()) { for (const auto &entry : l.getEntry()) { diff --git a/src/conference/local-conference.h b/src/conference/local-conference.h index 5fe1eabc7..0c425447a 100644 --- a/src/conference/local-conference.h +++ b/src/conference/local-conference.h @@ -21,30 +21,25 @@ #define _LOCAL_CONFERENCE_H_ #include "conference.h" -#include "local-conference-event-handler.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE +class LocalConferencePrivate; + class LocalConference : public Conference { public: LocalConference (LinphoneCore *core, const Address &myAddress, CallListener *listener = nullptr); - virtual ~LocalConference(); - LocalConferenceEventHandler * getEventHandler() const { return eventHandler; } - -public: /* ConferenceInterface */ void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override; void removeParticipant (const std::shared_ptr &participant) override; std::list
parseResourceLists (std::string xmlBody); -protected: - LocalConferenceEventHandler *eventHandler = nullptr; - private: + L_DECLARE_PRIVATE(LocalConference); L_DISABLE_COPY(LocalConference); }; diff --git a/src/conference/remote-conference-event-handler-p.h b/src/conference/remote-conference-event-handler-p.h index e89c454c1..776435e08 100644 --- a/src/conference/remote-conference-event-handler-p.h +++ b/src/conference/remote-conference-event-handler-p.h @@ -20,14 +20,19 @@ #ifndef _REMOTE_CONFERENCE_EVENT_HANDLER_P_H_ #define _REMOTE_CONFERENCE_EVENT_HANDLER_P_H_ +#include "address/address.h" #include "object/object-p.h" #include "remote-conference-event-handler.h" +// ============================================================================= + LINPHONE_BEGIN_NAMESPACE class RemoteConferenceEventHandlerPrivate : public ObjectPrivate { public: - inline unsigned int getLastNotify () const { return lastNotify; }; + inline unsigned int getLastNotify () const { + return lastNotify; + }; private: LinphoneCore *core = nullptr; @@ -41,4 +46,4 @@ private: LINPHONE_END_NAMESPACE -#endif // ifndef _REMOTE_CONFERENCE_EVENT_HANDLER_P_H_ \ No newline at end of file +#endif // ifndef _REMOTE_CONFERENCE_EVENT_HANDLER_P_H_ diff --git a/src/conference/remote-conference-p.h b/src/conference/remote-conference-p.h new file mode 100644 index 000000000..54c3a1ad5 --- /dev/null +++ b/src/conference/remote-conference-p.h @@ -0,0 +1,43 @@ +/* + * remote-conference-p.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _REMOTE_CONFERENCE_P_H_ +#define _REMOTE_CONFERENCE_P_H_ + +#include "conference-p.h" +#include "remote-conference.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class RemoteConferenceEventHandler; + +class RemoteConferencePrivate : public ConferencePrivate { +public: + std::shared_ptr focus; + std::unique_ptr eventHandler; + +private: + L_DECLARE_PUBLIC(RemoteConference); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _REMOTE_CONFERENCE_P_H_ diff --git a/src/conference/remote-conference.cpp b/src/conference/remote-conference.cpp index ef6e4dd0f..9fa0df9d0 100644 --- a/src/conference/remote-conference.cpp +++ b/src/conference/remote-conference.cpp @@ -17,57 +17,59 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "remote-conference.h" #include "participant-p.h" +#include "remote-conference-event-handler.h" +#include "remote-conference-p.h" #include "xml/resource-lists.h" -using namespace std; -using namespace LinphonePrivate::Xsd::ResourceLists; - -LINPHONE_BEGIN_NAMESPACE - // ============================================================================= +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + RemoteConference::RemoteConference (LinphoneCore *core, const Address &myAddress, CallListener *listener) - : Conference(core, myAddress, listener) { - eventHandler = new RemoteConferenceEventHandler(core, this); + : Conference(*new RemoteConferencePrivate, core, myAddress, listener) { + L_D(); + d->eventHandler.reset(new RemoteConferenceEventHandler(core, this)); } RemoteConference::~RemoteConference () { - eventHandler->unsubscribe(); - delete eventHandler; + L_D(); + d->eventHandler->unsubscribe(); } // ----------------------------------------------------------------------------- void RemoteConference::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) { + L_D(); shared_ptr participant = findParticipant(addr); if (participant) return; participant = ObjectFactory::create(addr); participant->getPrivate()->createSession(*this, params, hasMedia, this); - participants.push_back(participant); - if (!activeParticipant) - activeParticipant = participant; + d->participants.push_back(participant); + if (!d->activeParticipant) + d->activeParticipant = participant; } void RemoteConference::removeParticipant (const shared_ptr &participant) { - for (const auto &p : participants) { + L_D(); + for (const auto &p : d->participants) { if (participant->getAddress() == p->getAddress()) { - participants.remove(p); + d->participants.remove(p); return; } } } - string RemoteConference::getResourceLists (const list
&addresses) const { - ResourceLists rl = ResourceLists(); - ListType l = ListType(); + Xsd::ResourceLists::ResourceLists rl = Xsd::ResourceLists::ResourceLists(); + Xsd::ResourceLists::ListType l = Xsd::ResourceLists::ListType(); for (const auto &addr : addresses) { - EntryType entry = EntryType(addr.asStringUriOnly()); + Xsd::ResourceLists::EntryType entry = Xsd::ResourceLists::EntryType(addr.asStringUriOnly()); if (!addr.getDisplayName().empty()) - entry.setDisplayName(DisplayName(addr.getDisplayName())); + entry.setDisplayName(Xsd::ResourceLists::DisplayName(addr.getDisplayName())); l.getEntry().push_back(entry); } rl.getList().push_back(l); @@ -83,7 +85,8 @@ string RemoteConference::getResourceLists (const list
&addresses) const void RemoteConference::onConferenceCreated (const Address &addr) {} void RemoteConference::onConferenceTerminated (const Address &addr) { - eventHandler->unsubscribe(); + L_D(); + d->eventHandler->unsubscribe(); } void RemoteConference::onParticipantAdded (const Address &addr) {} diff --git a/src/conference/remote-conference.h b/src/conference/remote-conference.h index 572873136..fb8b80ee8 100644 --- a/src/conference/remote-conference.h +++ b/src/conference/remote-conference.h @@ -20,22 +20,22 @@ #ifndef _REMOTE_CONFERENCE_H_ #define _REMOTE_CONFERENCE_H_ +#include "conference-listener.h" #include "conference.h" -#include "remote-conference-event-handler.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE +class RemoteConferencePrivate; + class LINPHONE_PUBLIC RemoteConference : public Conference, public ConferenceListener { + friend class ClientGroupChatRoomPrivate; + public: RemoteConference (LinphoneCore *core, const Address &myAddress, CallListener *listener = nullptr); virtual ~RemoteConference(); -protected: - std::shared_ptr focus; - -public: /* ConferenceInterface */ void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override; void removeParticipant (const std::shared_ptr &participant) override; @@ -53,10 +53,8 @@ protected: void onParticipantDeviceAdded (const Address &addr, const Address &gruu) override; void onParticipantDeviceRemoved (const Address &addr, const Address &gruu) override; -protected: - RemoteConferenceEventHandler *eventHandler = nullptr; - private: + L_DECLARE_PRIVATE(RemoteConference); L_DISABLE_COPY(RemoteConference); }; diff --git a/tester/conference-event-tester.cpp b/tester/conference-event-tester.cpp index f4554e5a6..3c4876e6c 100644 --- a/tester/conference-event-tester.cpp +++ b/tester/conference-event-tester.cpp @@ -19,14 +19,15 @@ #include #include -#include "linphone/core.h" -#include "private.h" -#include "liblinphone_tester.h" #include "conference/conference-listener.h" -#include "conference/local-conference.h" #include "conference/local-conference-event-handler-p.h" +#include "conference/local-conference-p.h" +#include "conference/local-conference.h" #include "conference/participant-p.h" #include "conference/remote-conference-event-handler-p.h" +#include "liblinphone_tester.h" +#include "linphone/core.h" +#include "private.h" #include "tools/private-access.h" #include "tools/tester.h" @@ -431,14 +432,12 @@ static const char *participant_unadmined_notify = \ " "\ " "; - static const char *bobUri = "sip:bob@example.com"; static const char *aliceUri = "sip:alice@example.com"; static const char *frankUri = "sip:frank@example.com"; static const char *confUri = "sips:conf233@example.com"; -L_ENABLE_ATTR_ACCESS(RemoteConferenceEventHandlerPrivate, Address, confAddress); -L_ENABLE_ATTR_ACCESS(Conference, Address, conferenceAddress); +L_ENABLE_ATTR_ACCESS(LocalConferencePrivate, unique_ptr, eventHandler); class ConferenceEventTester : public ConferenceListener { public: @@ -518,8 +517,8 @@ void first_notify_parsing() { size_t size = strlen(first_notify) + strlen(confUri); char *notify = new char[size]; - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; + snprintf(notify, size, first_notify, confUri); tester.handler->notifyReceived(notify); @@ -555,8 +554,7 @@ void first_notify_parsing_wrong_conf() { size_t size = strlen(first_notify) + strlen(confUri); char *notify = new char[size]; - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; snprintf(notify, size, first_notify, confUri); tester.handler->notifyReceived(notify); @@ -587,8 +585,7 @@ void participant_added_parsing() { size_t size2 = strlen(participant_added_notify) + strlen(confUri); char *notify_added = new char[size2]; - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; snprintf(notify, size, first_notify, confUri); tester.handler->notifyReceived(notify); @@ -633,8 +630,7 @@ void participant_not_added_parsing() { size_t size2 = strlen(participant_not_added_notify) + strlen(confUri); char *notify_not_added = new char[size2]; - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; snprintf(notify, size, first_notify, confUri); tester.handler->notifyReceived(notify); @@ -676,8 +672,7 @@ void participant_deleted_parsing() { size_t size2 = strlen(participant_deleted_notify) + strlen(confUri); char *notify_deleted = new char[size2]; - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; snprintf(notify, size, first_notify, confUri); tester.handler->notifyReceived(notify); @@ -719,8 +714,7 @@ void participant_admined_parsing() { size_t size2 = strlen(participant_admined_notify) + strlen(confUri); char *notify_admined = new char[size2]; - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; snprintf(notify, size, first_notify, confUri); tester.handler->notifyReceived(notify); @@ -761,8 +755,7 @@ void participant_unadmined_parsing() { size_t size2 = strlen(participant_unadmined_notify) + strlen(confUri); char *notify_unadmined = new char[size2]; - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; snprintf(notify, size, first_notify, confUri); tester.handler->notifyReceived(notify); @@ -813,12 +806,13 @@ void send_first_notify() { localConf.setSubject("A random test subject"); shared_ptr alice = localConf.findParticipant(aliceAddr); L_GET_PRIVATE(alice)->setAdmin(true); - LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE(localConf.getEventHandler()); - L_ATTR_GET(static_cast(localConf), conferenceAddress) = addr; + LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE( + L_ATTR_GET(L_GET_PRIVATE(localConf), eventHandler) + ); + const_cast
(localConf.getConferenceAddress()) = addr; string notify = localHandlerPrivate->createNotifyFullState(); - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; tester.handler->notifyReceived(notify); BC_ASSERT_STRING_EQUAL(tester.confSubject.c_str(), "A random test subject"); @@ -861,12 +855,13 @@ void send_added_notify() { localConf.addParticipant(aliceAddr, ¶ms, false); shared_ptr alice = localConf.findParticipant(aliceAddr); L_GET_PRIVATE(alice)->setAdmin(true); - LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE(localConf.getEventHandler()); - L_ATTR_GET(static_cast(localConf), conferenceAddress) = addr; + LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE( + L_ATTR_GET(L_GET_PRIVATE(localConf), eventHandler) + ); + const_cast
(localConf.getConferenceAddress()) = addr; string notify = localHandlerPrivate->createNotifyFullState(); - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; tester.handler->notifyReceived(notify); BC_ASSERT_EQUAL(tester.participants.size(), 2, int, "%d"); @@ -916,12 +911,13 @@ void send_removed_notify() { localConf.addParticipant(aliceAddr, ¶ms, false); shared_ptr alice = localConf.findParticipant(aliceAddr); L_GET_PRIVATE(alice)->setAdmin(true); - LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE(localConf.getEventHandler()); - L_ATTR_GET(static_cast(localConf), conferenceAddress) = addr; + LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE( + L_ATTR_GET(L_GET_PRIVATE(localConf), eventHandler) + ); + const_cast
(localConf.getConferenceAddress()) = addr; string notify = localHandlerPrivate->createNotifyFullState(); - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; tester.handler->notifyReceived(notify); BC_ASSERT_EQUAL(tester.participants.size(), 2, int, "%d"); @@ -968,11 +964,13 @@ void send_admined_notify() { localConf.addParticipant(aliceAddr, ¶ms, false); shared_ptr alice = localConf.findParticipant(aliceAddr); L_GET_PRIVATE(alice)->setAdmin(true); - LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE(localConf.getEventHandler()); - L_ATTR_GET(static_cast(localConf), conferenceAddress) = addr; + LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE( + L_ATTR_GET(L_GET_PRIVATE(localConf), eventHandler) + ); + const_cast
(localConf.getConferenceAddress()) = addr; string notify = localHandlerPrivate->createNotifyFullState(); - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + + const_cast
(tester.handler->getConfAddress()) = addr; tester.handler->notifyReceived(notify); BC_ASSERT_EQUAL(tester.participants.size(), 2, int, "%d"); @@ -1018,11 +1016,13 @@ void send_unadmined_notify() { localConf.addParticipant(aliceAddr, ¶ms, false); shared_ptr alice = localConf.findParticipant(aliceAddr); L_GET_PRIVATE(alice)->setAdmin(true); - LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE(localConf.getEventHandler()); - L_ATTR_GET(static_cast(localConf), conferenceAddress) = addr; + LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE( + L_ATTR_GET(L_GET_PRIVATE(localConf), eventHandler) + ); + const_cast
(localConf.getConferenceAddress()) = addr; string notify = localHandlerPrivate->createNotifyFullState(); - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + + const_cast
(tester.handler->getConfAddress()) = addr; tester.handler->notifyReceived(notify); @@ -1070,12 +1070,13 @@ void send_subject_changed_notify () { localConf.setSubject("A random test subject"); shared_ptr alice = localConf.findParticipant(aliceAddr); L_GET_PRIVATE(alice)->setAdmin(true); - LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE(localConf.getEventHandler()); - L_ATTR_GET(static_cast(localConf), conferenceAddress) = addr; + LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE( + L_ATTR_GET(L_GET_PRIVATE(localConf), eventHandler) + ); + const_cast
(localConf.getConferenceAddress()) = addr; string notify = localHandlerPrivate->createNotifyFullState(); - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; tester.handler->notifyReceived(notify); BC_ASSERT_STRING_EQUAL(tester.confSubject.c_str(), "A random test subject"); @@ -1124,12 +1125,13 @@ void send_device_added_notify() { localConf.addParticipant(aliceAddr, ¶ms, false); shared_ptr alice = localConf.findParticipant(aliceAddr); L_GET_PRIVATE(alice)->setAdmin(true); - LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE(localConf.getEventHandler()); - L_ATTR_GET(static_cast(localConf), conferenceAddress) = addr; + LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE( + L_ATTR_GET(L_GET_PRIVATE(localConf), eventHandler) + ); + const_cast
(localConf.getConferenceAddress()) = addr; string notify = localHandlerPrivate->createNotifyFullState(); - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; tester.handler->notifyReceived(notify); BC_ASSERT_EQUAL(tester.participantDevices.size(), 2, int, "%d"); @@ -1176,12 +1178,13 @@ void send_device_removed_notify() { localConf.setSubject("A random test subject"); shared_ptr alice = localConf.findParticipant(aliceAddr); L_GET_PRIVATE(alice)->setAdmin(true); - LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE(localConf.getEventHandler()); - L_ATTR_GET(static_cast(localConf), conferenceAddress) = addr; + LocalConferenceEventHandlerPrivate *localHandlerPrivate = L_GET_PRIVATE( + L_ATTR_GET(L_GET_PRIVATE(localConf), eventHandler) + ); + const_cast
(localConf.getConferenceAddress()) = addr; string notify = localHandlerPrivate->createNotifyFullState(); - RemoteConferenceEventHandlerPrivate *remoteHandlerPrivate = L_GET_PRIVATE(tester.handler); - L_ATTR_GET(remoteHandlerPrivate, confAddress) = addr; + const_cast
(tester.handler->getConfAddress()) = addr; tester.handler->notifyReceived(notify); BC_ASSERT_EQUAL(tester.participantDevices.size(), 2, int, "%d"); diff --git a/tester/tools/tester.h b/tester/tools/tester.h index 650fefcd5..19e0c22ab 100644 --- a/tester/tools/tester.h +++ b/tester/tools/tester.h @@ -36,9 +36,9 @@ class Tester { public: Tester () = delete; - template - static constexpr decltype(std::declval().getPrivate()) getPrivate (Object *cppObject) { - return cppObject->getPrivate(); + template + static constexpr decltype(std::declval().getPrivate()) getPrivate (T *object) { + return object->getPrivate(); } private: