better use of memory

This commit is contained in:
Benjamin Reis 2017-08-07 11:22:56 +02:00
parent bbd08f3aaf
commit 23f4d851f1
3 changed files with 30 additions and 21 deletions

View file

@ -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);

View file

@ -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<Participant> getParticipants();
std::shared_ptr<LocalConferenceEventHandler> mHandler;
const LinphoneAddress *getAddress() const;
std::list<Participant> getParticipants() const;
const std::shared_ptr<LocalConferenceEventHandler> getHandler() const;
std::list<Participant> mParticipants;
private:
LinphoneAddress *mConfAddr;
std::shared_ptr<LocalConferenceEventHandler> 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::Participant> LinphonePrivate::Conference::LocalConference::getParticipants() {
const std::shared_ptr<LinphonePrivate::Conference::LocalConferenceEventHandler> LinphonePrivate::Conference::LocalConference::getHandler() const {
return mHandler;
}
std::list<LinphonePrivate::Conference::Participant> 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;
}

View file

@ -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");