From 23f4d851f193b1e8998b9f2aacdae3c315ce8c2c Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Mon, 7 Aug 2017 11:22:56 +0200 Subject: [PATCH] better use of memory --- .../local-conference-event-handler.cpp | 4 +-- .../local-conference-event-handler.h | 29 ++++++++++++------- tester/confeventpackage_tester.cpp | 18 ++++++------ 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/conference/local-conference-event-handler.cpp b/src/conference/local-conference-event-handler.cpp index ff0e6a3b5..3bde61970 100644 --- a/src/conference/local-conference-event-handler.cpp +++ b/src/conference/local-conference-event-handler.cpp @@ -42,7 +42,7 @@ void Conference::LocalConferenceEventHandlerPrivate::notifyFullState(string noti } void Conference::LocalConferenceEventHandlerPrivate::notifyAllExcept(string notify, LinphoneAddress *addr) { - for(auto participant : conf->getParticipants()) { + for(const auto &participant : conf->getParticipants()) { if(!linphone_address_equal(participant.getAddress(), addr)) { LinphoneEvent *lev = linphone_core_create_notify(lc, participant.getAddress(), "Conference"); LinphoneContent* content = linphone_core_create_content(lev->lc); @@ -76,7 +76,7 @@ string Conference::LocalConferenceEventHandler::subscribeReceived(LinphoneEvent xml_schema::NamespaceInfomap map; map[""].name = "urn:ietf:params:xml:ns:conference-info"; - for(auto participant : d->conf->getParticipants()) { + for(const auto &participant : d->conf->getParticipants()) { User_type user = User_type(); User_roles_type roles; user.setRoles(roles); diff --git a/src/conference/local-conference-event-handler.h b/src/conference/local-conference-event-handler.h index 001a2a492..0b2768685 100644 --- a/src/conference/local-conference-event-handler.h +++ b/src/conference/local-conference-event-handler.h @@ -52,9 +52,10 @@ namespace LinphonePrivate { public: Participant(LinphoneAddress *addr, bool admin); ~Participant(); - bool isAdmin(); - LinphoneAddress *getAddress(); + bool isAdmin() const; + const LinphoneAddress *getAddress() const; + private: LinphoneAddress *mAddr; bool mAdmin; }; @@ -63,12 +64,15 @@ namespace LinphonePrivate { public: LocalConference(LinphoneCore *lc, LinphoneAddress *confAddr); ~LocalConference(); - LinphoneAddress *getAddress(); - std::list getParticipants(); - - std::shared_ptr mHandler; + const LinphoneAddress *getAddress() const; + std::list getParticipants() const; + const std::shared_ptr getHandler() const; + std::list mParticipants; + + private: LinphoneAddress *mConfAddr; + std::shared_ptr mHandler; }; } } @@ -84,11 +88,16 @@ LinphonePrivate::Conference::LocalConference::~LocalConference() { //linphone_address_unref(mConfAddr); } -LinphoneAddress* LinphonePrivate::Conference::LocalConference::getAddress() { +const LinphoneAddress* LinphonePrivate::Conference::LocalConference::getAddress() const { return mConfAddr; } -std::list LinphonePrivate::Conference::LocalConference::getParticipants() { + +const std::shared_ptr LinphonePrivate::Conference::LocalConference::getHandler() const { + return mHandler; +} + +std::list LinphonePrivate::Conference::LocalConference::getParticipants() const { return mParticipants; } @@ -101,11 +110,11 @@ LinphonePrivate::Conference::Participant::~Participant() { //linphone_address_unref(mAddr); } -bool LinphonePrivate::Conference::Participant::isAdmin() { +bool LinphonePrivate::Conference::Participant::isAdmin() const { return mAdmin; } -LinphoneAddress* LinphonePrivate::Conference::Participant::getAddress() { +const LinphoneAddress* LinphonePrivate::Conference::Participant::getAddress() const { return mAddr; } diff --git a/tester/confeventpackage_tester.cpp b/tester/confeventpackage_tester.cpp index e737ec654..64d43468e 100644 --- a/tester/confeventpackage_tester.cpp +++ b/tester/confeventpackage_tester.cpp @@ -665,7 +665,7 @@ void send_first_notify(void) { localConf.mParticipants.push_back(p1); localConf.mParticipants.push_back(p2); - notify = localConf.mHandler->subscribeReceived(lev); + notify = localConf.getHandler()->subscribeReceived(lev); tester.mHandler->notifyReceived(notify.c_str()); BC_ASSERT_EQUAL(tester.mParticipants.size(), 2, int, "%d"); @@ -697,7 +697,7 @@ void send_added_notify(void) { localConf.mParticipants.push_back(p1); localConf.mParticipants.push_back(p2); - notify = localConf.mHandler->subscribeReceived(lev); + notify = localConf.getHandler()->subscribeReceived(lev); tester.mHandler->notifyReceived(notify.c_str()); BC_ASSERT_EQUAL(tester.mParticipants.size(), 2, int, "%d"); @@ -706,7 +706,7 @@ void send_added_notify(void) { BC_ASSERT_TRUE(tester.mParticipants.find(linphone_address_as_string(bobAddr))->second == 0); BC_ASSERT_TRUE(tester.mParticipants.find(linphone_address_as_string(aliceAddr))->second == 1); - notify = localConf.mHandler->notifyParticipantAdded(frankAddr); + notify = localConf.getHandler()->notifyParticipantAdded(frankAddr); tester.mHandler->notifyReceived(notify.c_str()); BC_ASSERT_EQUAL(tester.mParticipants.size(), 3, int, "%d"); @@ -739,7 +739,7 @@ void send_removed_notify(void) { localConf.mParticipants.push_back(p1); localConf.mParticipants.push_back(p2); - notify = localConf.mHandler->subscribeReceived(lev); + notify = localConf.getHandler()->subscribeReceived(lev); tester.mHandler->notifyReceived(notify.c_str()); BC_ASSERT_EQUAL(tester.mParticipants.size(), 2, int, "%d"); @@ -748,7 +748,7 @@ void send_removed_notify(void) { BC_ASSERT_TRUE(tester.mParticipants.find(linphone_address_as_string(bobAddr))->second == 0); BC_ASSERT_TRUE(tester.mParticipants.find(linphone_address_as_string(aliceAddr))->second == 1); - notify = localConf.mHandler->notifyParticipantRemoved(bobAddr); + notify = localConf.getHandler()->notifyParticipantRemoved(bobAddr); tester.mHandler->notifyReceived(notify.c_str()); BC_ASSERT_EQUAL(tester.mParticipants.size(), 1, int, "%d"); @@ -778,7 +778,7 @@ void send_admined_notify(void) { localConf.mParticipants.push_back(p1); localConf.mParticipants.push_back(p2); - notify = localConf.mHandler->subscribeReceived(lev); + notify = localConf.getHandler()->subscribeReceived(lev); tester.mHandler->notifyReceived(notify.c_str()); BC_ASSERT_EQUAL(tester.mParticipants.size(), 2, int, "%d"); @@ -787,7 +787,7 @@ void send_admined_notify(void) { BC_ASSERT_TRUE(tester.mParticipants.find(linphone_address_as_string(bobAddr))->second == 0); BC_ASSERT_TRUE(tester.mParticipants.find(linphone_address_as_string(aliceAddr))->second == 1); - notify = localConf.mHandler->notifyParticipantSetAdmin(bobAddr, true); + notify = localConf.getHandler()->notifyParticipantSetAdmin(bobAddr, true); tester.mHandler->notifyReceived(notify.c_str()); BC_ASSERT_EQUAL(tester.mParticipants.size(), 2, int, "%d"); @@ -818,7 +818,7 @@ void send_unadmined_notify(void) { localConf.mParticipants.push_back(p1); localConf.mParticipants.push_back(p2); - notify = localConf.mHandler->subscribeReceived(lev); + notify = localConf.getHandler()->subscribeReceived(lev); tester.mHandler->notifyReceived(notify.c_str()); BC_ASSERT_EQUAL(tester.mParticipants.size(), 2, int, "%d"); @@ -827,7 +827,7 @@ void send_unadmined_notify(void) { BC_ASSERT_TRUE(tester.mParticipants.find(linphone_address_as_string(bobAddr))->second == 0); BC_ASSERT_TRUE(tester.mParticipants.find(linphone_address_as_string(aliceAddr))->second == 1); - notify = localConf.mHandler->notifyParticipantSetAdmin(aliceAddr, false); + notify = localConf.getHandler()->notifyParticipantSetAdmin(aliceAddr, false); tester.mHandler->notifyReceived(notify.c_str()); BC_ASSERT_EQUAL(tester.mParticipants.size(), 2, int, "%d");