From ebe1a5f12fe8569ca4df9db3395ce45f664e31aa Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Tue, 17 Oct 2017 14:51:45 +0200 Subject: [PATCH] add time managment to confernce event notification --- src/chat/chat-room/client-group-chat-room.cpp | 12 ++++----- src/chat/chat-room/client-group-chat-room.h | 12 ++++----- src/conference/conference-listener.h | 13 +++++----- .../local-conference-event-handler.cpp | 9 +++++++ .../remote-conference-event-handler.cpp | 16 +++++++----- src/conference/remote-conference.cpp | 12 ++++----- src/conference/remote-conference.h | 12 ++++----- tester/conference-event-tester.cpp | 25 ++++++++++--------- 8 files changed, 63 insertions(+), 48 deletions(-) diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index 15d7d0251..af63cc759 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -257,7 +257,7 @@ void ClientGroupChatRoom::onConferenceTerminated (const Address &addr) { d->setState(ChatRoom::State::Terminated); } -void ClientGroupChatRoom::onParticipantAdded (const Address &addr) { +void ClientGroupChatRoom::onParticipantAdded (time_t tm, const Address &addr) { L_D_T(RemoteConference, dConference); if (isMe(addr)) @@ -278,7 +278,7 @@ void ClientGroupChatRoom::onParticipantAdded (const Address &addr) { cb(cr, L_GET_C_BACK_PTR(participant)); } -void ClientGroupChatRoom::onParticipantRemoved (const Address &addr) { +void ClientGroupChatRoom::onParticipantRemoved (time_t tm, const Address &addr) { L_D_T(RemoteConference, dConference); shared_ptr participant = findParticipant(addr); @@ -297,7 +297,7 @@ void ClientGroupChatRoom::onParticipantRemoved (const Address &addr) { dConference->participants.remove(participant); } -void ClientGroupChatRoom::onParticipantSetAdmin (const Address &addr, bool isAdmin) { +void ClientGroupChatRoom::onParticipantSetAdmin (time_t tm, const Address &addr, bool isAdmin) { shared_ptr participant; if (isMe(addr)) participant = getMe(); @@ -317,7 +317,7 @@ void ClientGroupChatRoom::onParticipantSetAdmin (const Address &addr, bool isAdm cb(cr, L_GET_C_BACK_PTR(participant), isAdmin); } -void ClientGroupChatRoom::onSubjectChanged (const std::string &subject) { +void ClientGroupChatRoom::onSubjectChanged (time_t tm, const std::string &subject) { RemoteConference::setSubject(subject); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); @@ -327,7 +327,7 @@ void ClientGroupChatRoom::onSubjectChanged (const std::string &subject) { cb(cr, subject.c_str()); } -void ClientGroupChatRoom::onParticipantDeviceAdded (const Address &addr, const Address &gruu) { +void ClientGroupChatRoom::onParticipantDeviceAdded (time_t tm, const Address &addr, const Address &gruu) { shared_ptr participant; if (isMe(addr)) participant = getMe(); @@ -340,7 +340,7 @@ void ClientGroupChatRoom::onParticipantDeviceAdded (const Address &addr, const A participant->getPrivate()->addDevice(gruu); } -void ClientGroupChatRoom::onParticipantDeviceRemoved (const Address &addr, const Address &gruu) { +void ClientGroupChatRoom::onParticipantDeviceRemoved (time_t tm, const Address &addr, const Address &gruu) { shared_ptr participant; if (isMe(addr)) participant = getMe(); diff --git a/src/chat/chat-room/client-group-chat-room.h b/src/chat/chat-room/client-group-chat-room.h index 0d9432ccb..52f176d00 100644 --- a/src/chat/chat-room/client-group-chat-room.h +++ b/src/chat/chat-room/client-group-chat-room.h @@ -56,12 +56,12 @@ private: /* ConferenceListener */ void onConferenceCreated (const Address &addr) override; void onConferenceTerminated (const Address &addr) override; - void onParticipantAdded (const Address &addr) override; - 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; + void onParticipantAdded (time_t tm, const Address &addr) override; + void onParticipantRemoved (time_t tm, const Address &addr) override; + void onParticipantSetAdmin (time_t tm, const Address &addr, bool isAdmin) override; + void onSubjectChanged (time_t tm, const std::string &subject) override; + void onParticipantDeviceAdded (time_t tm, const Address &addr, const Address &gruu) override; + void onParticipantDeviceRemoved (time_t tm, const Address &addr, const Address &gruu) override; private: /* CallSessionListener */ diff --git a/src/conference/conference-listener.h b/src/conference/conference-listener.h index 96c30528e..248052fb6 100644 --- a/src/conference/conference-listener.h +++ b/src/conference/conference-listener.h @@ -20,6 +20,7 @@ #ifndef _CONFERENCE_LISTENER_H_ #define _CONFERENCE_LISTENER_H_ +#include #include #include "linphone/utils/general.h" @@ -34,12 +35,12 @@ class ConferenceListener { public: virtual void onConferenceCreated (const Address &addr) = 0; virtual void onConferenceTerminated (const Address &addr) = 0; - virtual void onParticipantAdded (const Address &addr) = 0; - 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; + virtual void onParticipantAdded (time_t tm, const Address &addr) = 0; + virtual void onParticipantRemoved (time_t tm, const Address &addr) = 0; + virtual void onParticipantSetAdmin (time_t tm, const Address &addr, bool isAdmin) = 0; + virtual void onSubjectChanged (time_t tm, const std::string &subject) = 0; + virtual void onParticipantDeviceAdded (time_t tm, const Address &addr, const Address &gruu) = 0; + virtual void onParticipantDeviceRemoved (time_t tm, const Address &addr, const Address &gruu) = 0; }; LINPHONE_END_NAMESPACE diff --git a/src/conference/local-conference-event-handler.cpp b/src/conference/local-conference-event-handler.cpp index ec6a0cd0c..92c6149e2 100644 --- a/src/conference/local-conference-event-handler.cpp +++ b/src/conference/local-conference-event-handler.cpp @@ -17,6 +17,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include + #include "conference/local-conference.h" #include "conference/participant-p.h" #include "linphone/utils/utils.h" @@ -68,6 +70,13 @@ void LocalConferenceEventHandlerPrivate::notifyAll (const string ¬ify) { string LocalConferenceEventHandlerPrivate::createNotify (ConferenceType confInfo) { lastNotify = lastNotify + 1; confInfo.setVersion(lastNotify); + if (!confInfo.getConferenceDescription()) { + ConferenceDescriptionType description = ConferenceDescriptionType(); + confInfo.setConferenceDescription(description); + } + + time_t result = time(nullptr); + confInfo.getConferenceDescription()->setFreeText(Utils::toString(static_cast(result))); stringstream notify; Xsd::XmlSchema::NamespaceInfomap map; diff --git a/src/conference/remote-conference-event-handler.cpp b/src/conference/remote-conference-event-handler.cpp index 53eeaf20a..685f2ef7d 100644 --- a/src/conference/remote-conference-event-handler.cpp +++ b/src/conference/remote-conference-event-handler.cpp @@ -73,11 +73,15 @@ void RemoteConferenceEventHandler::notifyReceived (string xmlBody) { lInfo() << "NOTIFY received for conference " << d->confAddress.asString(); istringstream data(xmlBody); unique_ptr confInfo = parseConferenceInfo(data, Xsd::XmlSchema::Flags::dont_validate); + time_t tm = time(nullptr); + if (confInfo->getConferenceDescription()->getFreeText().present()) + tm = static_cast(Utils::stoll(confInfo->getConferenceDescription()->getFreeText().get())); + Address cleanedConfAddress = d->confAddress; cleanedConfAddress.setPort(0); if (confInfo->getEntity() == cleanedConfAddress.asString()) { if (confInfo->getConferenceDescription().present() && confInfo->getConferenceDescription().get().getSubject().present()) - d->listener->onSubjectChanged(confInfo->getConferenceDescription().get().getSubject().get()); + d->listener->onSubjectChanged(tm, confInfo->getConferenceDescription().get().getSubject().get()); if (confInfo->getVersion().present()) d->lastNotify = confInfo->getVersion().get(); @@ -91,7 +95,7 @@ void RemoteConferenceEventHandler::notifyReceived (string xmlBody) { Address addr(cAddrStr); bctbx_free(cAddrStr); if (user.getState() == "deleted") - d->listener->onParticipantRemoved(addr); + d->listener->onParticipantRemoved(tm, addr); else { bool isAdmin = false; if (user.getRoles()) { @@ -103,17 +107,17 @@ void RemoteConferenceEventHandler::notifyReceived (string xmlBody) { } } if (user.getState() == "full") - d->listener->onParticipantAdded(addr); - d->listener->onParticipantSetAdmin(addr, isAdmin); + d->listener->onParticipantAdded(tm, addr); + d->listener->onParticipantSetAdmin(tm, addr, isAdmin); for (const auto &endpoint : user.getEndpoint()) { if (!endpoint.getEntity().present()) break; Address gruu(endpoint.getEntity().get()); if (endpoint.getState() == "deleted") - d->listener->onParticipantDeviceRemoved(addr, gruu); + d->listener->onParticipantDeviceRemoved(tm, addr, gruu); else if (endpoint.getState() == "full") - d->listener->onParticipantDeviceAdded(addr, gruu); + d->listener->onParticipantDeviceAdded(tm, addr, gruu); } } diff --git a/src/conference/remote-conference.cpp b/src/conference/remote-conference.cpp index 9fa0df9d0..3b317a10e 100644 --- a/src/conference/remote-conference.cpp +++ b/src/conference/remote-conference.cpp @@ -89,16 +89,16 @@ void RemoteConference::onConferenceTerminated (const Address &addr) { d->eventHandler->unsubscribe(); } -void RemoteConference::onParticipantAdded (const Address &addr) {} +void RemoteConference::onParticipantAdded (time_t tm, const Address &addr) {} -void RemoteConference::onParticipantRemoved (const Address &addr) {} +void RemoteConference::onParticipantRemoved (time_t tm, const Address &addr) {} -void RemoteConference::onParticipantSetAdmin (const Address &addr, bool isAdmin) {} +void RemoteConference::onParticipantSetAdmin (time_t tm, const Address &addr, bool isAdmin) {} -void RemoteConference::onSubjectChanged (const std::string &subject) {} +void RemoteConference::onSubjectChanged (time_t tm, const std::string &subject) {} -void RemoteConference::onParticipantDeviceAdded (const Address &addr, const Address &gruu) {} +void RemoteConference::onParticipantDeviceAdded (time_t tm, const Address &addr, const Address &gruu) {} -void RemoteConference::onParticipantDeviceRemoved (const Address &addr, const Address &gruu) {} +void RemoteConference::onParticipantDeviceRemoved (time_t tm, const Address &addr, const Address &gruu) {} LINPHONE_END_NAMESPACE diff --git a/src/conference/remote-conference.h b/src/conference/remote-conference.h index fb8b80ee8..f1898f10c 100644 --- a/src/conference/remote-conference.h +++ b/src/conference/remote-conference.h @@ -46,12 +46,12 @@ protected: /* ConferenceListener */ void onConferenceCreated (const Address &addr) override; void onConferenceTerminated (const Address &addr) override; - void onParticipantAdded (const Address &addr) override; - 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; + void onParticipantAdded (time_t tm, const Address &addr) override; + void onParticipantRemoved (time_t tm, const Address &addr) override; + void onParticipantSetAdmin (time_t tm, const Address &addr, bool isAdmin) override; + void onSubjectChanged (time_t tm, const std::string &subject) override; + void onParticipantDeviceAdded (time_t tm, const Address &addr, const Address &gruu) override; + void onParticipantDeviceRemoved (time_t tm, const Address &addr, const Address &gruu) override; private: L_DECLARE_PRIVATE(RemoteConference); diff --git a/tester/conference-event-tester.cpp b/tester/conference-event-tester.cpp index 72b78453b..c12317ac7 100644 --- a/tester/conference-event-tester.cpp +++ b/tester/conference-event-tester.cpp @@ -447,12 +447,13 @@ public: private: void onConferenceCreated (const Address &addr) override; void onConferenceTerminated (const Address &addr) override; - void onParticipantAdded (const Address &addr) override; - 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; + void onParticipantAdded (time_t tm, const Address &addr) override; + void onParticipantRemoved (time_t tm, const Address &addr) override; + void onParticipantSetAdmin (time_t tm, const Address &addr, bool isAdmin) override; + void onSubjectChanged (time_t tm, const string &subject) override; + void onParticipantDeviceAdded (time_t tm, const Address &addr, const Address &gruu) override; + void onParticipantDeviceRemoved (time_t tm, const Address &addr, const Address &gruu) override; + public: RemoteConferenceEventHandler *handler; map participants; @@ -472,33 +473,33 @@ void ConferenceEventTester::onConferenceCreated (const Address &addr) {} void ConferenceEventTester::onConferenceTerminated (const Address &addr) {} -void ConferenceEventTester::onParticipantAdded (const Address &addr) { +void ConferenceEventTester::onParticipantAdded (time_t tm, const Address &addr) { participants.insert(pair(addr.asString(), FALSE)); participantDevices.insert(pair(addr.asString(), 0)); } -void ConferenceEventTester::onParticipantRemoved (const Address &addr) { +void ConferenceEventTester::onParticipantRemoved (time_t tm, const Address &addr) { participants.erase(addr.asString()); participantDevices.erase(addr.asString()); } -void ConferenceEventTester::onParticipantSetAdmin (const Address &addr, bool isAdmin) { +void ConferenceEventTester::onParticipantSetAdmin (time_t tm, const Address &addr, bool isAdmin) { auto it = participants.find(addr.asString()); if (it != participants.end()) it->second = isAdmin; } -void ConferenceEventTester::onSubjectChanged(const string &subject) { +void ConferenceEventTester::onSubjectChanged(time_t tm, const string &subject) { confSubject = subject; } -void ConferenceEventTester::onParticipantDeviceAdded (const Address &addr, const Address &gruu) { +void ConferenceEventTester::onParticipantDeviceAdded (time_t tm, 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) { +void ConferenceEventTester::onParticipantDeviceRemoved (time_t tm, const Address &addr, const Address &gruu) { auto it = participantDevices.find(addr.asString()); if (it != participantDevices.end() && it->second > 0) it->second--;