local-conference.cpp 2.54 KB
Newer Older
1 2
/*
 * local-conference.cpp
Ghislain MARY's avatar
Ghislain MARY committed
3
 * Copyright (C) 2010-2017 Belledonne Communications SARL
4
 *
Ghislain MARY's avatar
Ghislain MARY committed
5 6 7 8
 * 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.
9 10 11 12 13 14 15
 *
 * 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
Ghislain MARY's avatar
Ghislain MARY committed
16 17
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 19 20
 */

#include "local-conference.h"
21
#include "participant-p.h"
22
#include "xml/resource-lists.h"
23

24
using namespace std;
25
using namespace LinphonePrivate::Xsd::ResourceLists;
26 27

LINPHONE_BEGIN_NAMESPACE
28 29 30

// =============================================================================

31
LocalConference::LocalConference (LinphoneCore *core, const Address &myAddress, CallListener *listener)
32 33 34
	: Conference(core, myAddress, listener) {
	eventHandler = new LocalConferenceEventHandler(core, this);
}
35

36 37 38 39 40 41
LocalConference::~LocalConference () {
	delete eventHandler;
}

// -----------------------------------------------------------------------------

42
void LocalConference::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) {
43 44
	shared_ptr<Participant> participant = findParticipant(addr);
	if (participant)
45
		return;
46
	participant = ObjectFactory::create<Participant>(addr);
47
	participants.push_back(participant);
48 49
	if (!activeParticipant)
		activeParticipant = participant;
50 51
}

52
void LocalConference::removeParticipant (const shared_ptr<const Participant> &participant) {
53
	for (const auto &p : participants) {
54
		if (participant->getAddress() == p->getAddress()) {
55 56 57 58 59 60
			participants.remove(p);
			return;
		}
	}
}

61
list<Address> LocalConference::parseResourceLists (string xmlBody) {
62 63
	istringstream data(xmlBody);
	unique_ptr<ResourceLists> rl = LinphonePrivate::Xsd::ResourceLists::parseResourceLists(data, Xsd::XmlSchema::Flags::dont_validate);
64 65 66 67 68 69
	list<Address> addresses = list<Address>();
	for (const auto &l : rl->getList()) {
		for (const auto &entry : l.getEntry()) {
			Address addr(entry.getUri());
			if (entry.getDisplayName().present())
				addr.setDisplayName(entry.getDisplayName().get());
70 71 72 73 74 75
			addresses.push_back(addr);
		}
	}
	return addresses;
}

76
LINPHONE_END_NAMESPACE