Commit 53b9758d authored by Ghislain MARY's avatar Ghislain MARY

Handle conference listener in client group chat room and wrap participant...

Handle conference listener in client group chat room and wrap participant manipulation callbacks in LinphoneChatRoomCbs.
parent ceec68bc
......@@ -48,6 +48,28 @@ typedef void (*LinphoneChatRoomCbsIsComposingReceivedCb) (LinphoneChatRoom *cr,
*/
typedef void (*LinphoneChatRoomCbsMessageReceivedCb) (LinphoneChatRoom *cr, LinphoneChatMessage *msg);
/**
* Callback used to notify a chat room that a participant has been added.
* @param[in] cr #LinphoneChatRoom object
* @param[in] participant The #LinphoneParticipant that has been added to the chat room
*/
typedef void (*LinphoneChatRoomCbsParticipantAddedCb) (LinphoneChatRoom *cr, LinphoneParticipant *participant);
/**
* Callback used to notify a chat room that a participant has been removed.
* @param[in] cr #LinphoneChatRoom object
* @param[in] participant The #LinphoneParticipant that has been removed from the chat room
*/
typedef void (*LinphoneChatRoomCbsParticipantRemovedCb) (LinphoneChatRoom *cr, LinphoneParticipant *participant);
/**
* Callback used to notify a chat room that the admin status of a participant has been changed.
* @param[in] cr #LinphoneChatRoom object
* @param[in] participant The #LinphoneParticipant for which the admin status has been changed
* @param[in] isAdmin The new admin status of the participant
*/
typedef void (*LinphoneChatRoomCbsParticipantAdminStatusChangedCb) (LinphoneChatRoom *cr, LinphoneParticipant *participant, bool_t isAdmin);
/**
* Callback used to notify a chat room state has changed.
* @param[in] cr #LinphoneChatRoom object
......
......@@ -88,6 +88,48 @@ LINPHONE_PUBLIC LinphoneChatRoomCbsMessageReceivedCb linphone_chat_room_cbs_get_
*/
LINPHONE_PUBLIC void linphone_chat_room_cbs_set_message_received (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsMessageReceivedCb cb);
/**
* Get the participant added callback.
* @param[in] cbs LinphoneChatRoomCbs object.
* @return The current participant added callback.
*/
LINPHONE_PUBLIC LinphoneChatRoomCbsParticipantAddedCb linphone_chat_room_cbs_get_participant_added (const LinphoneChatRoomCbs *cbs);
/**
* Set the participant added callback.
* @param[in] cbs LinphoneChatRoomCbs object.
* @param[in] cb The participant added callback to be used.
*/
LINPHONE_PUBLIC void linphone_chat_room_cbs_set_participant_added (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsParticipantAddedCb cb);
/**
* Get the participant removed callback.
* @param[in] cbs LinphoneChatRoomCbs object.
* @return The current participant removed callback.
*/
LINPHONE_PUBLIC LinphoneChatRoomCbsParticipantRemovedCb linphone_chat_room_cbs_get_participant_removed (const LinphoneChatRoomCbs *cbs);
/**
* Set the participant removed callback.
* @param[in] cbs LinphoneChatRoomCbs object.
* @param[in] cb The participant removed callback to be used.
*/
LINPHONE_PUBLIC void linphone_chat_room_cbs_set_participant_removed (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsParticipantRemovedCb cb);
/**
* Get the participant admin status changed callback.
* @param[in] cbs LinphoneChatRoomCbs object.
* @return The current participant admin status changed callback.
*/
LINPHONE_PUBLIC LinphoneChatRoomCbsParticipantAdminStatusChangedCb linphone_chat_room_cbs_get_participant_admin_status_changed (const LinphoneChatRoomCbs *cbs);
/**
* Set the participant admin status changed callback.
* @param[in] cbs LinphoneChatRoomCbs object.
* @param[in] cb The participant admin status changed callback to be used.
*/
LINPHONE_PUBLIC void linphone_chat_room_cbs_set_participant_admin_status_changed (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsParticipantAdminStatusChangedCb cb);
/**
* Get the state changed callback.
* @param[in] cbs LinphoneChatRoomCbs object.
......
......@@ -28,6 +28,9 @@ struct _LinphoneChatRoomCbs {
void *userData;
LinphoneChatRoomCbsIsComposingReceivedCb isComposingReceivedCb;
LinphoneChatRoomCbsMessageReceivedCb messageReceivedCb;
LinphoneChatRoomCbsParticipantAddedCb participantAddedCb;
LinphoneChatRoomCbsParticipantRemovedCb participantRemovedCb;
LinphoneChatRoomCbsParticipantAdminStatusChangedCb participantAdminStatusChangedCb;
LinphoneChatRoomCbsStateChangedCb stateChangedCb;
LinphoneChatRoomCbsUndecryptableMessageReceivedCb undecryptableMessageReceivedCb;
};
......@@ -82,6 +85,30 @@ void linphone_chat_room_cbs_set_message_received (LinphoneChatRoomCbs *cbs, Linp
cbs->messageReceivedCb = cb;
}
LinphoneChatRoomCbsParticipantAddedCb linphone_chat_room_cbs_get_participant_added (const LinphoneChatRoomCbs *cbs) {
return cbs->participantAddedCb;
}
void linphone_chat_room_cbs_set_participant_added (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsParticipantAddedCb cb) {
cbs->participantAddedCb = cb;
}
LinphoneChatRoomCbsParticipantRemovedCb linphone_chat_room_cbs_get_participant_removed (const LinphoneChatRoomCbs *cbs) {
return cbs->participantRemovedCb;
}
void linphone_chat_room_cbs_set_participant_removed (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsParticipantRemovedCb cb) {
cbs->participantRemovedCb = cb;
}
LinphoneChatRoomCbsParticipantAdminStatusChangedCb linphone_chat_room_cbs_get_participant_admin_status_changed (const LinphoneChatRoomCbs *cbs) {
return cbs->participantAdminStatusChangedCb;
}
void linphone_chat_room_cbs_set_participant_admin_status_changed (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsParticipantAdminStatusChangedCb cb) {
cbs->participantAdminStatusChangedCb = cb;
}
LinphoneChatRoomCbsStateChangedCb linphone_chat_room_cbs_get_state_changed (const LinphoneChatRoomCbs *cbs) {
return cbs->stateChangedCb;
}
......
......@@ -44,7 +44,7 @@ static void _linphone_chat_room_destructor (LinphoneChatRoom *cr);
L_DECLARE_C_STRUCT_IMPL_WITH_XTORS(ChatRoom, ChatRoom, chat_room,
_linphone_chat_room_constructor, _linphone_chat_room_destructor,
LinphoneChatRoomCbs * cbs;
LinphoneChatRoomCbs *cbs;
LinphoneAddress *peerAddressCache;
)
......
......@@ -17,11 +17,15 @@
*/
#include "client-group-chat-room-p.h"
#include "c-wrapper/c-tools.h"
#include "conference/participant-p.h"
#include "logger/logger.h"
// =============================================================================
extern LinphoneChatRoom * _linphone_chat_room_init();
extern LinphoneParticipant * _linphone_participant_init();
using namespace std;
LINPHONE_BEGIN_NAMESPACE
......@@ -79,4 +83,57 @@ void ClientGroupChatRoom::removeParticipants (const list<shared_ptr<Participant>
// TODO
}
// -----------------------------------------------------------------------------
void ClientGroupChatRoom::onConferenceCreated (const Address &addr) {
// TODO
}
void ClientGroupChatRoom::onConferenceTerminated (const Address &addr) {
// TODO
}
void ClientGroupChatRoom::onParticipantAdded (const Address &addr) {
shared_ptr<Participant> participant = findParticipant(addr);
if (participant) {
lWarning() << "Participant " << participant << " added but already in the list of participants!";
return;
}
participant = make_shared<Participant>(addr);
participants.push_back(participant);
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this->shared_from_this(), ChatRoom, chat_room);
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
LinphoneChatRoomCbsParticipantAddedCb cb = linphone_chat_room_cbs_get_participant_added(cbs);
if (cb)
cb(cr, L_GET_C_BACK_PTR(participant, Participant, participant));
}
void ClientGroupChatRoom::onParticipantRemoved (const Address &addr) {
shared_ptr<Participant> participant = findParticipant(addr);
if (!participant) {
lWarning() << "Participant " << participant << " removed but not in the list of participants!";
return;
}
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this->shared_from_this(), ChatRoom, chat_room);
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
LinphoneChatRoomCbsParticipantRemovedCb cb = linphone_chat_room_cbs_get_participant_removed(cbs);
if (cb)
cb(cr, L_GET_C_BACK_PTR(participant, Participant, participant));
participants.remove(participant);
}
void ClientGroupChatRoom::onParticipantSetAdmin (const Address &addr, bool isAdmin) {
shared_ptr<Participant> participant = findParticipant(addr);
if (!participant) {
lWarning() << "Participant " << participant << " admin status has been changed but is not in the list of participants!";
return;
}
participant->setAdmin(isAdmin);
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this->shared_from_this(), ChatRoom, chat_room);
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
LinphoneChatRoomCbsParticipantAdminStatusChangedCb cb = linphone_chat_room_cbs_get_participant_admin_status_changed(cbs);
if (cb)
cb(cr, L_GET_C_BACK_PTR(participant, Participant, participant), isAdmin);
}
LINPHONE_END_NAMESPACE
......@@ -49,6 +49,14 @@ public:
void removeParticipant (const std::shared_ptr<const Participant> &participant);
void removeParticipants (const std::list<std::shared_ptr<Participant>> &participants);
private:
/* ConferenceListener */
void onConferenceCreated (const Address &addr);
void onConferenceTerminated (const Address &addr);
void onParticipantAdded (const Address &addr);
void onParticipantRemoved (const Address &addr);
void onParticipantSetAdmin (const Address &addr, bool isAdmin);
private:
L_DECLARE_PRIVATE(ClientGroupChatRoom);
L_DISABLE_COPY(ClientGroupChatRoom);
......
......@@ -19,6 +19,7 @@
#include "participant-p.h"
#include "conference.h"
#include "logger/logger.h"
using namespace std;
......@@ -40,13 +41,13 @@ shared_ptr<Participant> Conference::getActiveParticipant () const {
// -----------------------------------------------------------------------------
shared_ptr<Participant> Conference::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) {
activeParticipant = make_shared<Participant>(addr);
activeParticipant->getPrivate()->createSession(*this, params, hasMedia, this);
return activeParticipant;
lError() << "Conference class does not handle addParticipant() generically";
return nullptr;
}
void Conference::addParticipants (const list<Address> &addresses, const CallSessionParams *params, bool hasMedia) {
// TODO
for (const auto &addr : addresses)
addParticipant(addr, params, hasMedia);
}
bool Conference::canHandleParticipants () const {
......@@ -58,8 +59,7 @@ const string& Conference::getId () const {
}
int Conference::getNbParticipants () const {
// TODO
return 1;
return participants.size();
}
list<shared_ptr<Participant>> Conference::getParticipants () const {
......@@ -67,11 +67,12 @@ list<shared_ptr<Participant>> Conference::getParticipants () const {
}
void Conference::removeParticipant (const shared_ptr<const Participant> &participant) {
// TODO
lError() << "Conference class does not handle removeParticipant() generically";
}
void Conference::removeParticipants (const list<shared_ptr<Participant>> &participants) {
// TODO
for (const auto &p : participants)
removeParticipant(p);
}
// -----------------------------------------------------------------------------
......
......@@ -24,9 +24,10 @@
#include "private.h"
// =============================================================================
using namespace std;
using namespace conference_info;
using namespace LinphonePrivate;
LINPHONE_BEGIN_NAMESPACE
......@@ -39,7 +40,7 @@ public:
LocalConference *conf = nullptr;
};
LINPHONE_END_NAMESPACE
// -----------------------------------------------------------------------------
void LocalConferenceEventHandlerPrivate::notifyFullState(string notify, LinphoneEvent *lev) {
LinphoneContent *content = linphone_core_create_content(lev->lc);
......@@ -64,7 +65,8 @@ void LocalConferenceEventHandlerPrivate::notifyAllExcept(string notify, const Ad
}
}
// -------- Conference::LocalConferenceEventHandler public methods ---------
// =============================================================================
LocalConferenceEventHandler::LocalConferenceEventHandler(LinphoneCore *core, LocalConference *localConf) : Object(*new LocalConferenceEventHandlerPrivate) {
L_D(LocalConferenceEventHandler);
xercesc::XMLPlatformUtils::Initialize();
......@@ -76,6 +78,8 @@ LocalConferenceEventHandler::~LocalConferenceEventHandler() {
xercesc::XMLPlatformUtils::Terminate();
}
// -----------------------------------------------------------------------------
string LocalConferenceEventHandler::subscribeReceived(LinphoneEvent *lev) {
L_D(LocalConferenceEventHandler);
string entity = d->conf->getMe()->getAddress().asStringUriOnly();
......@@ -163,3 +167,5 @@ string LocalConferenceEventHandler::notifyParticipantSetAdmin(const Address &add
//d->notifyAllExcept(notify.str(), addr);
return notify.str();
}
LINPHONE_END_NAMESPACE
......@@ -20,7 +20,8 @@
#include "participant-p.h"
using namespace std;
using namespace LinphonePrivate;
LINPHONE_BEGIN_NAMESPACE
// =============================================================================
......@@ -42,32 +43,11 @@ shared_ptr<Participant> LocalConference::addParticipant (const Address &addr, co
participant = make_shared<Participant>(addr);
participant->getPrivate()->createSession(*this, params, hasMedia, this);
participants.push_back(participant);
activeParticipant = participant;
if (!activeParticipant)
activeParticipant = participant;
return participant;
}
void LocalConference::addParticipants (const list<Address> &addresses, const CallSessionParams *params, bool hasMedia) {
for (const auto &addr : addresses)
addParticipant(addr, params, hasMedia);
}
bool LocalConference::canHandleParticipants () const {
return true;
}
const string& LocalConference::getId () const {
return id;
}
int LocalConference::getNbParticipants () const {
participants.size();
return 1;
}
list<shared_ptr<Participant>> LocalConference::getParticipants () const {
return participants;
}
void LocalConference::removeParticipant (const shared_ptr<const Participant> &participant) {
for (const auto &p : participants) {
if (participant->getAddress().equal(p->getAddress())) {
......@@ -77,7 +57,4 @@ void LocalConference::removeParticipant (const shared_ptr<const Participant> &pa
}
}
void LocalConference::removeParticipants (const list<shared_ptr<Participant>> &participants) {
for (const auto &p : participants)
removeParticipant(p);
}
LINPHONE_END_NAMESPACE
......@@ -36,13 +36,7 @@ public:
public:
/* ConferenceInterface */
virtual std::shared_ptr<Participant> addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia);
virtual void addParticipants (const std::list<Address> &addresses, const CallSessionParams *params, bool hasMedia);
virtual bool canHandleParticipants () const;
virtual const std::string& getId () const;
virtual int getNbParticipants () const;
virtual std::list<std::shared_ptr<Participant>> getParticipants () const;
virtual void removeParticipant (const std::shared_ptr<const Participant> &participant);
virtual void removeParticipants (const std::list<std::shared_ptr<Participant>> &participants);
private:
L_DISABLE_COPY(LocalConference);
......
......@@ -68,4 +68,10 @@ void Participant::setAdmin (bool isAdmin) {
d->isAdmin = isAdmin;
}
// =============================================================================
ostream & operator<< (ostream &strm, const shared_ptr<Participant> &participant) {
return strm << "'" << participant->getAddress().asString() << "'";
}
LINPHONE_END_NAMESPACE
......@@ -35,9 +35,9 @@ class Participant : public Object {
friend class Call;
friend class CallPrivate;
friend class ClientGroupChatRoom;
friend class Conference;
friend class LocalConference;
friend class MediaSessionPrivate;
friend class RemoteConference;
public:
Participant (const Address &addr);
......@@ -52,6 +52,8 @@ private:
L_DISABLE_COPY(Participant);
};
std::ostream & operator<< (std::ostream &strm, const std::shared_ptr<Participant> &participant);
LINPHONE_END_NAMESPACE
#endif // ifndef _PARTICIPANT_H_
......@@ -21,9 +21,10 @@
#include "private.h"
#include "object/object-p.h"
// =============================================================================
using namespace std;
using namespace conference_info;
using namespace LinphonePrivate;
LINPHONE_BEGIN_NAMESPACE
......@@ -36,15 +37,14 @@ public:
LinphoneEvent *lev = nullptr;
};
LINPHONE_END_NAMESPACE
// =============================================================================
// -------- RemoteConferenceEventHandler public methods ---------
RemoteConferenceEventHandler::RemoteConferenceEventHandler(LinphoneCore *core, ConferenceListener *listener, const Address &confAddr) : Object(*new RemoteConferenceEventHandlerPrivate) {
RemoteConferenceEventHandler::RemoteConferenceEventHandler(LinphoneCore *core, ConferenceListener *listener)
: Object(*new RemoteConferenceEventHandlerPrivate) {
L_D(RemoteConferenceEventHandler);
xercesc::XMLPlatformUtils::Initialize();
d->core = core;
d->listener = listener;
d->confAddr = confAddr;
}
RemoteConferenceEventHandler::~RemoteConferenceEventHandler() {
......@@ -54,6 +54,8 @@ RemoteConferenceEventHandler::~RemoteConferenceEventHandler() {
linphone_event_unref(d->lev);
}
// -----------------------------------------------------------------------------
void RemoteConferenceEventHandler::subscribe(string confId) {
L_D(RemoteConferenceEventHandler);
d->confId = confId;
......@@ -101,7 +103,16 @@ void RemoteConferenceEventHandler::notifyReceived(string xmlBody) {
}
}
// -----------------------------------------------------------------------------
string RemoteConferenceEventHandler::getConfId() {
L_D(RemoteConferenceEventHandler);
return d->confId;
}
void RemoteConferenceEventHandler::setConferenceAddress (const Address &addr) {
L_D(RemoteConferenceEventHandler);
d->confAddr = addr;
}
LINPHONE_END_NAMESPACE
......@@ -32,7 +32,7 @@ class RemoteConferenceEventHandlerPrivate;
class RemoteConferenceEventHandler : public Object {
public:
RemoteConferenceEventHandler(LinphoneCore *core, ConferenceListener *listener, const Address &confAddr);
RemoteConferenceEventHandler(LinphoneCore *core, ConferenceListener *listener);
~RemoteConferenceEventHandler();
void subscribe(std::string confId);
......@@ -40,6 +40,7 @@ class RemoteConferenceEventHandler : public Object {
void unsubscribe();
std::string getConfId();
void setConferenceAddress (const Address &addr);
private:
L_DECLARE_PRIVATE(RemoteConferenceEventHandler);
......
......@@ -17,12 +17,52 @@
*/
#include "remote-conference.h"
#include "participant-p.h"
using namespace std;
LINPHONE_BEGIN_NAMESPACE
// =============================================================================
RemoteConference::RemoteConference (LinphoneCore *core, const Address &myAddress, CallListener *listener)
: Conference(core, myAddress, listener) {}
: Conference(core, myAddress, listener) {
eventHandler = new RemoteConferenceEventHandler(core, this);
}
// -----------------------------------------------------------------------------
shared_ptr<Participant> RemoteConference::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) {
shared_ptr<Participant> participant = findParticipant(addr);
if (participant)
return participant;
participant = make_shared<Participant>(addr);
participant->getPrivate()->createSession(*this, params, hasMedia, this);
participants.push_back(participant);
if (!activeParticipant)
activeParticipant = participant;
return participant;
}
void RemoteConference::removeParticipant (const shared_ptr<const Participant> &participant) {
for (const auto &p : participants) {
if (participant->getAddress().equal(p->getAddress())) {
participants.remove(p);
return;
}
}
}
// -----------------------------------------------------------------------------
void RemoteConference::onConferenceCreated (const Address &addr) {}
void RemoteConference::onConferenceTerminated (const Address &addr) {}
void RemoteConference::onParticipantAdded (const Address &addr) {}
void RemoteConference::onParticipantRemoved (const Address &addr) {}
void RemoteConference::onParticipantSetAdmin (const Address &addr, bool isAdmin) {}
LINPHONE_END_NAMESPACE
......@@ -20,12 +20,13 @@
#define _REMOTE_CONFERENCE_H_
#include "conference.h"
#include "remote-conference-event-handler.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class RemoteConference : public Conference {
class RemoteConference : public Conference, public ConferenceListener {
public:
RemoteConference (LinphoneCore *core, const Address &myAddress, CallListener *listener = nullptr);
virtual ~RemoteConference() = default;
......@@ -33,8 +34,23 @@ public:
protected:
std::shared_ptr<Participant> focus = nullptr;
public:
/* ConferenceInterface */
virtual std::shared_ptr<Participant> addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia);
virtual void removeParticipant (const std::shared_ptr<const Participant> &participant);
protected:
/* ConferenceListener */
virtual void onConferenceCreated (const Address &addr);
virtual void onConferenceTerminated (const Address &addr);
virtual void onParticipantAdded (const Address &addr);
virtual void onParticipantRemoved (const Address &addr);
virtual void onParticipantSetAdmin (const Address &addr, bool isAdmin);
private:
L_DISABLE_COPY(RemoteConference);
RemoteConferenceEventHandler *eventHandler = nullptr;
};
LINPHONE_END_NAMESPACE
......
......@@ -437,7 +437,8 @@ public:
};
ConferenceEventTester::ConferenceEventTester (LinphoneCore *core, const Address &confAddr) {
handler = new RemoteConferenceEventHandler(core, this, confAddr);
handler = new RemoteConferenceEventHandler(core, this);
handler->setConferenceAddress(confAddr);
}
ConferenceEventTester::~ConferenceEventTester () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment