local-conference.cpp 2.69 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 "handlers/local-conference-event-handler.h"
21
#include "local-conference-p.h"
22
#include "participant-p.h"
23
#include "xml/resource-lists.h"
24

25 26
// =============================================================================

27
using namespace std;
28 29

LINPHONE_BEGIN_NAMESPACE
30

31
LocalConference::LocalConference (const shared_ptr<Core> &core, const IdentityAddress &myAddress, CallSessionListener *listener)
32
	: Conference(*new LocalConferencePrivate, core, myAddress, listener) {
33
	L_D();
34
	d->eventHandler.reset(new LocalConferenceEventHandler(this));
35 36
}

Ghislain MARY's avatar
Ghislain MARY committed
37 38 39 40 41
LocalConference::~LocalConference () {
	L_D();
	d->eventHandler.reset();
}

42 43
// -----------------------------------------------------------------------------

44
void LocalConference::addParticipant (const IdentityAddress &addr, const CallSessionParams *params, bool hasMedia) {
45
	L_D();
46 47
	shared_ptr<Participant> participant = findParticipant(addr);
	if (participant)
48
		return;
Ronan's avatar
Ronan committed
49
	participant = make_shared<Participant>(addr);
50
	participant->getPrivate()->createSession(*this, params, hasMedia, d->listener);
51 52 53
	d->participants.push_back(participant);
	if (!d->activeParticipant)
		d->activeParticipant = participant;
54 55
}

56
void LocalConference::removeParticipant (const shared_ptr<const Participant> &participant) {
57 58
	L_D();
	for (const auto &p : d->participants) {
59
		if (participant->getAddress() == p->getAddress()) {
60
			d->participants.remove(p);
61 62 63 64 65
			return;
		}
	}
}

66
list<IdentityAddress> LocalConference::parseResourceLists (const string &xmlBody) {
67
	istringstream data(xmlBody);
68 69 70 71
	unique_ptr<Xsd::ResourceLists::ResourceLists> rl = LinphonePrivate::Xsd::ResourceLists::parseResourceLists(
		data,
		Xsd::XmlSchema::Flags::dont_validate
	);
72
	list<IdentityAddress> addresses = list<IdentityAddress>();
73 74
	for (const auto &l : rl->getList()) {
		for (const auto &entry : l.getEntry()) {
75
			IdentityAddress addr(entry.getUri());
76 77 78 79 80 81
			addresses.push_back(addr);
		}
	}
	return addresses;
}

82
LINPHONE_END_NAMESPACE