From 26cc84140d86273f48c5a49ea5c7ac05844b496a Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Wed, 11 Oct 2017 10:18:57 +0200 Subject: [PATCH] added participant's device added/removed listener --- src/CMakeLists.txt | 2 ++ src/chat/client-group-chat-room.cpp | 28 +++++++++++++++- src/chat/client-group-chat-room.h | 2 ++ src/conference/conference-listener.h | 2 ++ src/conference/participant-device.cpp | 36 ++++++++++++++++++++ src/conference/participant-device.h | 48 +++++++++++++++++++++++++++ src/conference/participant-p.h | 17 ++++++---- src/conference/participant.cpp | 25 ++++++++++++++ src/conference/participant.h | 4 ++- src/conference/remote-conference.cpp | 4 +++ src/conference/remote-conference.h | 2 ++ tester/conference-event-tester.cpp | 20 ++++++++++- 12 files changed, 181 insertions(+), 9 deletions(-) create mode 100644 src/conference/participant-device.cpp create mode 100644 src/conference/participant-device.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8bf3bbf28..701a1339c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -62,6 +62,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES conference/params/call-session-params.h conference/params/media-session-params-p.h conference/params/media-session-params.h + conference/participant-device.h conference/participant-p.h conference/participant.h conference/remote-conference-event-handler-p.h @@ -144,6 +145,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES conference/local-conference.cpp conference/params/call-session-params.cpp conference/params/media-session-params.cpp + conference/participant-device.cpp conference/participant.cpp conference/remote-conference-event-handler.cpp conference/remote-conference.cpp diff --git a/src/chat/client-group-chat-room.cpp b/src/chat/client-group-chat-room.cpp index 7abc13ad1..907c93d74 100644 --- a/src/chat/client-group-chat-room.cpp +++ b/src/chat/client-group-chat-room.cpp @@ -231,7 +231,7 @@ void ClientGroupChatRoom::onParticipantAdded (const Address &addr) { void ClientGroupChatRoom::onParticipantRemoved (const Address &addr) { shared_ptr participant = findParticipant(addr); if (!participant) { - lWarning() << "Participant " << participant << " removed but not in the list of participants!"; + lWarning() << "Participant " << participant << " removed but is not in the list of participants!"; return; } LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); @@ -269,6 +269,32 @@ void ClientGroupChatRoom::onSubjectChanged (const std::string &subject) { cb(cr, subject.c_str()); } +void ClientGroupChatRoom::onParticipantDeviceAdded (const Address &addr, const Address &gruu) { + shared_ptr participant = nullptr; + if (isMe(addr)) + participant = me; + else + participant = findParticipant(addr); + if (!participant) { + lWarning() << "Participant " << participant << " added a device but is not in the list of participants!"; + return; + } + participant->getPrivate()->addDevice(gruu); +} + +void ClientGroupChatRoom::onParticipantDeviceRemoved (const Address &addr, const Address &gruu) { + shared_ptr participant = nullptr; + if (isMe(addr)) + participant = me; + else + participant = findParticipant(addr); + if (!participant) { + lWarning() << "Participant " << participant << " removed a device but is not in the list of participants!"; + return; + } + participant->getPrivate()->removeDevice(gruu); +} + // ----------------------------------------------------------------------------- void ClientGroupChatRoom::onCallSessionSetReleased (const std::shared_ptr &session) { diff --git a/src/chat/client-group-chat-room.h b/src/chat/client-group-chat-room.h index 2d8692646..200effef1 100644 --- a/src/chat/client-group-chat-room.h +++ b/src/chat/client-group-chat-room.h @@ -65,6 +65,8 @@ private: void onParticipantRemoved (const Address &addr) override; void onParticipantSetAdmin (const Address &addr, bool isAdmin) override; void onSubjectChanged (const std::string &subject) override; + void onParticipantDeviceAdded (const Address &addr, const Address &gruu) override; + void onParticipantDeviceRemoved (const Address &addr, const Address &gruu) override; private: /* CallSessionListener */ diff --git a/src/conference/conference-listener.h b/src/conference/conference-listener.h index aabe88a0c..34665bfbd 100644 --- a/src/conference/conference-listener.h +++ b/src/conference/conference-listener.h @@ -34,6 +34,8 @@ public: virtual void onParticipantRemoved (const Address &addr) = 0; virtual void onParticipantSetAdmin (const Address &addr, bool isAdmin) = 0; virtual void onSubjectChanged (const std::string &subject) = 0; + virtual void onParticipantDeviceAdded (const Address &addr, const Address &gruu) = 0; + virtual void onParticipantDeviceRemoved (const Address &addr, const Address &gruu) = 0; }; LINPHONE_END_NAMESPACE diff --git a/src/conference/participant-device.cpp b/src/conference/participant-device.cpp new file mode 100644 index 000000000..524ae7e2d --- /dev/null +++ b/src/conference/participant-device.cpp @@ -0,0 +1,36 @@ +/* + * participant-device.cpp + * 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. + */ + +#include "participant-device.h" + +using namespace std; + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +ParticipantDevice::ParticipantDevice (const Address &gruu) { + mGruu = gruu; +} + +bool ParticipantDevice::operator== (const ParticipantDevice &device) const { + return (mGruu == device.getGruu()); +} + +LINPHONE_END_NAMESPACE \ No newline at end of file diff --git a/src/conference/participant-device.h b/src/conference/participant-device.h new file mode 100644 index 000000000..38f495b21 --- /dev/null +++ b/src/conference/participant-device.h @@ -0,0 +1,48 @@ +/* + * participant-device.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 _PARTICIPANT_DEVICE_H_ +#define _PARTICIPANT_DEVICE_H_ + +#include + +#include "address/address.h" +#include "linphone/utils/general.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class ParticipantDevice { +public: + explicit ParticipantDevice (const Address &gruu); + + bool operator== (const ParticipantDevice &device) const; + + inline const Address &getGruu () const { + return mGruu; + }; + +private: + Address mGruu; +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _PARTICIPANT_DEVICE_H_ \ No newline at end of file diff --git a/src/conference/participant-p.h b/src/conference/participant-p.h index fabce499c..258c65d7b 100644 --- a/src/conference/participant-p.h +++ b/src/conference/participant-p.h @@ -40,18 +40,23 @@ public: virtual ~ParticipantPrivate () = default; std::shared_ptr createSession (const Conference &conference, const CallSessionParams *params, bool hasMedia, CallSessionListener *listener); - std::shared_ptr getSession () const { return session; } - bool isSubscribedToConferenceEventPackage () const { return _isSubscribedToConferenceEventPackage; } - void subscribeToConferenceEventPackage (bool value) { _isSubscribedToConferenceEventPackage = value; } - void removeSession () { session = nullptr; } - void setAddress (const Address &newAddr) { addr = newAddr; } - void setAdmin (bool isAdmin) { this->isAdmin = isAdmin; } + inline std::shared_ptr getSession () const { return session; } + inline bool isSubscribedToConferenceEventPackage () const { return _isSubscribedToConferenceEventPackage; } + inline void subscribeToConferenceEventPackage (bool value) { _isSubscribedToConferenceEventPackage = value; } + inline void removeSession () { session.reset(); } + inline void setAddress (const Address &newAddr) { addr = newAddr; } + inline void setAdmin (bool isAdmin) { this->isAdmin = isAdmin; } + const std::list::const_iterator findDevice (const Address &gruu) const; + const std::list &getDevices () const; + void addDevice (const Address &gruu); + void removeDevice (const Address &gruu); private: Address addr; bool isAdmin = false; bool _isSubscribedToConferenceEventPackage = false; std::shared_ptr session; + std::list devices; L_DECLARE_PUBLIC(Participant); }; diff --git a/src/conference/participant.cpp b/src/conference/participant.cpp index 0c9fc5003..f4ef38269 100644 --- a/src/conference/participant.cpp +++ b/src/conference/participant.cpp @@ -17,6 +17,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include + #include "object/object-p.h" #include "participant-p.h" @@ -41,6 +43,29 @@ shared_ptr ParticipantPrivate::createSession ( return session; } +// ----------------------------------------------------------------------------- + +const list::const_iterator ParticipantPrivate::findDevice (const Address &gruu) const { + ParticipantDevice device(gruu); + return find(devices.cbegin(), devices.cend(), device); +} + +const list &ParticipantPrivate::getDevices () const { + return devices; +} + +void ParticipantPrivate::addDevice (const Address &gruu) { + ParticipantDevice device(gruu); + if(findDevice(gruu) == devices.cend()) + devices.push_back(device); +} + +void ParticipantPrivate::removeDevice (const Address &gruu) { + ParticipantDevice device(gruu); + if(findDevice(gruu) != devices.cend()) + devices.remove(device); +} + // ============================================================================= Participant::Participant (const Address &address) : Object(*new ParticipantPrivate) { diff --git a/src/conference/participant.h b/src/conference/participant.h index 707227425..a1b2904c3 100644 --- a/src/conference/participant.h +++ b/src/conference/participant.h @@ -20,10 +20,12 @@ #ifndef _PARTICIPANT_H_ #define _PARTICIPANT_H_ -#include "address/address.h" +#include +#include "address/address.h" #include "object/object.h" #include "conference/params/call-session-params.h" +#include "conference/participant-device.h" // ============================================================================= diff --git a/src/conference/remote-conference.cpp b/src/conference/remote-conference.cpp index 171908333..aca20de9f 100644 --- a/src/conference/remote-conference.cpp +++ b/src/conference/remote-conference.cpp @@ -94,4 +94,8 @@ void RemoteConference::onParticipantSetAdmin (const Address &addr, bool isAdmin) void RemoteConference::onSubjectChanged (const std::string &subject) {} +void RemoteConference::onParticipantDeviceAdded (const Address &addr, const Address &gruu) {} + +void RemoteConference::onParticipantDeviceRemoved (const Address &addr, const Address &gruu) {} + LINPHONE_END_NAMESPACE diff --git a/src/conference/remote-conference.h b/src/conference/remote-conference.h index d9f93bc59..ea97a397f 100644 --- a/src/conference/remote-conference.h +++ b/src/conference/remote-conference.h @@ -50,6 +50,8 @@ protected: void onParticipantRemoved (const Address &addr) override; void onParticipantSetAdmin (const Address &addr, bool isAdmin) override; void onSubjectChanged (const std::string &subject) override; + void onParticipantDeviceAdded (const Address &addr, const Address &gruu) override; + void onParticipantDeviceRemoved (const Address &addr, const Address &gruu) override; protected: RemoteConferenceEventHandler *eventHandler = nullptr; diff --git a/tester/conference-event-tester.cpp b/tester/conference-event-tester.cpp index 96db4c8cb..f3d30e5b6 100644 --- a/tester/conference-event-tester.cpp +++ b/tester/conference-event-tester.cpp @@ -434,9 +434,12 @@ private: void onParticipantRemoved (const Address &addr) override; void onParticipantSetAdmin (const Address &addr, bool isAdmin) override; void onSubjectChanged(const string &subject) override; + void onParticipantDeviceAdded(const Address &addr, const Address &gruu) override; + void onParticipantDeviceRemoved(const Address &addr, const Address &gruu) override; public: RemoteConferenceEventHandler *handler; map participants; + map participantDevices; string confSubject; }; @@ -453,10 +456,12 @@ void ConferenceEventTester::onConferenceCreated (const Address &addr) {} void ConferenceEventTester::onConferenceTerminated (const Address &addr) {} void ConferenceEventTester::onParticipantAdded (const Address &addr) { - participants.insert(pair(addr.asString(), false)); + participants.insert(pair(addr.asString(), FALSE)); + participantDevices.insert(pair(addr.asString(), 0)); } void ConferenceEventTester::onParticipantRemoved (const Address &addr) { participants.erase(addr.asString()); + participantDevices.erase(addr.asString()); } void ConferenceEventTester::onParticipantSetAdmin (const Address &addr, bool isAdmin) { @@ -469,6 +474,19 @@ void ConferenceEventTester::onSubjectChanged(const string &subject) { confSubject = subject; } +void ConferenceEventTester::onParticipantDeviceAdded (const Address &addr, const Address &gruu) { + auto it = participantDevices.find(addr.asString()); + if (it != participantDevices.end()) + it->second++; + +} + +void ConferenceEventTester::onParticipantDeviceRemoved (const Address &addr, const Address &gruu) { + auto it = participantDevices.find(addr.asString()); + if (it != participantDevices.end() && it->second > 0) + it->second--; +} + void first_notify_parsing() { LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc"); LinphoneAddress *confAddress = linphone_core_interpret_url(marie->lc, confUri);