From 47b12a26b2b6a8a3949f43556cb06d4b2f8bf443 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Tue, 26 Jun 2018 11:00:28 +0200 Subject: [PATCH] Allow access to Core from Participant and ParticipantDevice. --- src/chat/chat-room/basic-chat-room.cpp | 4 ++-- src/chat/chat-room/client-group-chat-room.cpp | 10 +++++----- src/conference/conference.cpp | 2 +- src/conference/local-conference.cpp | 2 +- src/conference/participant-device.cpp | 5 +++++ src/conference/participant-device.h | 3 +++ src/conference/participant-p.h | 5 +++++ src/conference/participant.cpp | 3 ++- src/conference/participant.h | 4 +++- src/conference/remote-conference.cpp | 2 +- src/db/main-db.cpp | 13 ++++++++++--- 11 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/chat/chat-room/basic-chat-room.cpp b/src/chat/chat-room/basic-chat-room.cpp index 16d6185ce..63b4372ed 100644 --- a/src/chat/chat-room/basic-chat-room.cpp +++ b/src/chat/chat-room/basic-chat-room.cpp @@ -40,8 +40,8 @@ BasicChatRoom::BasicChatRoom ( const ChatRoomId &chatRoomId ) : ChatRoom(p, core, chatRoomId) { L_D(); - d->me = make_shared(getLocalAddress()); - d->participants.push_back(make_shared(getPeerAddress())); + d->me = make_shared(nullptr, getLocalAddress()); + d->participants.push_back(make_shared(nullptr, getPeerAddress())); } void BasicChatRoom::allowCpim (bool value) { diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index 3e576d155..6d4f8817b 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -130,7 +130,7 @@ void ClientGroupChatRoomPrivate::confirmJoining (SalCallOp *op) { for (const auto &addr : identAddresses) { auto participant = q->findParticipant(addr); if (!participant) { - participant = make_shared(addr); + participant = make_shared(q, addr); qConference->getPrivate()->participants.push_back(participant); } } @@ -249,12 +249,12 @@ RemoteConference(core, me, nullptr) { L_D_T(RemoteConference, dConference); IdentityAddress focusAddr(uri); - dConference->focus = make_shared(focusAddr); + dConference->focus = make_shared(this, focusAddr); dConference->focus->getPrivate()->addDevice(focusAddr); RemoteConference::setSubject(subject); list identAddresses = Conference::parseResourceLists(content); for (const auto &addr : identAddresses) - dConference->participants.push_back(make_shared(addr)); + dConference->participants.push_back(make_shared(this, addr)); } ClientGroupChatRoom::ClientGroupChatRoom ( @@ -273,7 +273,7 @@ RemoteConference(core, me->getAddress(), nullptr) { d->capabilities |= capabilities & ClientGroupChatRoom::Capabilities::OneToOne; const IdentityAddress &peerAddress = chatRoomId.getPeerAddress(); - dConference->focus = make_shared(peerAddress); + dConference->focus = make_shared(this, peerAddress); dConference->focus->getPrivate()->addDevice(peerAddress); dConference->conferenceAddress = peerAddress; dConference->subject = subject; @@ -628,7 +628,7 @@ void ClientGroupChatRoom::onParticipantAdded (const shared_ptr(addr); + participant = make_shared(this, addr); dConference->participants.push_back(participant); if (isFullState) diff --git a/src/conference/conference.cpp b/src/conference/conference.cpp index 7dc5ed023..672695eb0 100644 --- a/src/conference/conference.cpp +++ b/src/conference/conference.cpp @@ -41,7 +41,7 @@ Conference::Conference ( ) : CoreAccessor(core), mPrivate(&p) { L_D(); d->mPublic = this; - d->me = make_shared(myAddress); + d->me = make_shared(this, myAddress); d->listener = listener; } diff --git a/src/conference/local-conference.cpp b/src/conference/local-conference.cpp index def610da1..ea6e9caa4 100644 --- a/src/conference/local-conference.cpp +++ b/src/conference/local-conference.cpp @@ -48,7 +48,7 @@ void LocalConference::addParticipant (const IdentityAddress &addr, const CallSes lInfo() << "Not adding participant '" << addr.asString() << "' because it is already a participant of the LocalConference"; return; } - participant = make_shared(addr); + participant = make_shared(this, addr); participant->getPrivate()->createSession(*this, params, hasMedia, d->listener); d->participants.push_back(participant); if (!d->activeParticipant) diff --git a/src/conference/participant-device.cpp b/src/conference/participant-device.cpp index c6cbcc197..18bb24dd2 100644 --- a/src/conference/participant-device.cpp +++ b/src/conference/participant-device.cpp @@ -18,6 +18,7 @@ */ #include "participant-device.h" +#include "participant-p.h" #include "linphone/event.h" @@ -41,6 +42,10 @@ bool ParticipantDevice::operator== (const ParticipantDevice &device) const { return (mGruu == device.getAddress()); } +shared_ptr ParticipantDevice::getCore () const { + return mParticipant ? mParticipant->getPrivate()->getCore() : nullptr; +} + void ParticipantDevice::setConferenceSubscribeEvent (LinphoneEvent *ev) { if (mConferenceSubscribeEvent) linphone_event_unref(mConferenceSubscribeEvent); diff --git a/src/conference/participant-device.h b/src/conference/participant-device.h index 284c83917..a2a46109c 100644 --- a/src/conference/participant-device.h +++ b/src/conference/participant-device.h @@ -32,6 +32,7 @@ LINPHONE_BEGIN_NAMESPACE class CallSession; +class Core; class Participant; class ParticipantDevice { @@ -49,6 +50,8 @@ public: bool operator== (const ParticipantDevice &device) const; + std::shared_ptr getCore () const; + inline const IdentityAddress &getAddress () const { return mGruu; } Participant *getParticipant () const { return mParticipant; } inline std::shared_ptr getSession () const { return mSession; } diff --git a/src/conference/participant-p.h b/src/conference/participant-p.h index 84febee7e..cdff47ac5 100644 --- a/src/conference/participant-p.h +++ b/src/conference/participant-p.h @@ -33,6 +33,10 @@ LINPHONE_BEGIN_NAMESPACE class ParticipantPrivate : public ObjectPrivate { public: + std::shared_ptr getCore () const { return mConference ? mConference->getCore() : nullptr; } + Conference *getConference () const { return mConference; } + void setConference (Conference *conference) { mConference = conference; } + std::shared_ptr createSession (const Conference &conference, const CallSessionParams *params, bool hasMedia, CallSessionListener *listener); inline std::shared_ptr getSession () const { return session; } inline void removeSession () { session.reset(); } @@ -47,6 +51,7 @@ public: void removeDevice (const IdentityAddress &gruu); private: + Conference *mConference = nullptr; IdentityAddress addr; bool isAdmin = false; std::shared_ptr session; diff --git a/src/conference/participant.cpp b/src/conference/participant.cpp index 3d3c4e472..564118f40 100644 --- a/src/conference/participant.cpp +++ b/src/conference/participant.cpp @@ -92,8 +92,9 @@ void ParticipantPrivate::removeDevice (const IdentityAddress &gruu) { // ============================================================================= -Participant::Participant (const IdentityAddress &address) : Object(*new ParticipantPrivate) { +Participant::Participant (Conference *conference, const IdentityAddress &address) : Object(*new ParticipantPrivate) { L_D(); + d->mConference = conference; d->addr = address.getAddressWithoutGruu(); } diff --git a/src/conference/participant.h b/src/conference/participant.h index 5d59188f4..1a248a022 100644 --- a/src/conference/participant.h +++ b/src/conference/participant.h @@ -31,6 +31,7 @@ LINPHONE_BEGIN_NAMESPACE class ClientGroupChatRoom; +class Conference; class ParticipantPrivate; class Participant : public Object { @@ -49,6 +50,7 @@ class Participant : public Object { friend class MainDb; friend class MainDbPrivate; friend class MediaSessionPrivate; + friend class ParticipantDevice; friend class RemoteConference; friend class RemoteConferenceCall; friend class RemoteConferenceCallPrivate; @@ -58,7 +60,7 @@ class Participant : public Object { public: L_OVERRIDE_SHARED_FROM_THIS(Participant); - explicit Participant (const IdentityAddress &address); + explicit Participant (Conference *conference, const IdentityAddress &address); const IdentityAddress &getAddress () const; bool isAdmin () const; diff --git a/src/conference/remote-conference.cpp b/src/conference/remote-conference.cpp index 537832189..ea50c58b5 100644 --- a/src/conference/remote-conference.cpp +++ b/src/conference/remote-conference.cpp @@ -51,7 +51,7 @@ void RemoteConference::addParticipant (const IdentityAddress &addr, const CallSe lInfo() << "Not adding participant '" << addr.asString() << "' because it is already a participant of the RemoteConference"; return; } - participant = make_shared(addr); + participant = make_shared(this, addr); participant->getPrivate()->createSession(*this, params, hasMedia, d->listener); d->participants.push_back(participant); if (!d->activeParticipant) diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 19405c72e..6b958df20 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -2402,7 +2402,7 @@ list> MainDb::getChatRooms () const { soci::rowset rows = (session->prepare << query, soci::use(dbChatRoomId)); shared_ptr me; for (const auto &row : rows) { - shared_ptr participant = make_shared(IdentityAddress(row.get(1))); + shared_ptr participant = make_shared(nullptr, IdentityAddress(row.get(1))); ParticipantPrivate *dParticipant = participant->getPrivate(); dParticipant->setAdmin(!!row.get(2)); @@ -2426,6 +2426,7 @@ list> MainDb::getChatRooms () const { participants.push_back(participant); } + Conference *conference = nullptr; if (!linphone_core_conference_server_enabled(core->getCCore())) { bool hasBeenLeft = !!row.get(8, 0); if (!me) { @@ -2433,7 +2434,7 @@ list> MainDb::getChatRooms () const { ", local=" + chatRoomId.getLocalAddress().asString() + ")."; continue; } - chatRoom = make_shared( + auto clientGroupChatRoom = make_shared( core, chatRoomId, me, @@ -2443,6 +2444,8 @@ list> MainDb::getChatRooms () const { lastNotifyId, hasBeenLeft ); + chatRoom = clientGroupChatRoom; + conference = clientGroupChatRoom.get(); AbstractChatRoomPrivate *dChatRoom = chatRoom->getPrivate(); dChatRoom->setState(ChatRoom::State::Instantiated); dChatRoom->setState(hasBeenLeft @@ -2450,7 +2453,7 @@ list> MainDb::getChatRooms () const { : ChatRoom::State::Created ); } else { - chatRoom = make_shared( + auto serverGroupChatRoom = make_shared( core, chatRoomId.getPeerAddress(), capabilities, @@ -2458,10 +2461,14 @@ list> MainDb::getChatRooms () const { move(participants), lastNotifyId ); + chatRoom = serverGroupChatRoom; + conference = serverGroupChatRoom.get(); AbstractChatRoomPrivate *dChatRoom = chatRoom->getPrivate(); dChatRoom->setState(ChatRoom::State::Instantiated); dChatRoom->setState(ChatRoom::State::Created); } + for (auto participant : chatRoom->getParticipants()) + participant->getPrivate()->setConference(conference); } if (!chatRoom)