Commit fc029784 authored by Benjamin REIS's avatar Benjamin REIS
Browse files

create the conf event notify + tests

parent d77af885
......@@ -39,7 +39,8 @@ set(LINPHONE_PRIVATE_HEADER_FILES
../src/object/singleton.h
../src/utils/general.h
../src/conference/conference-listener.h
../src/conference/conference-event-package.h
../src/conference/remote-conference-event-handler.h
../src/conference/local-conference-event-handler.h
../src/conference/conference-info.hxx
bellesip_sal/sal_impl.h
carddav.h
......@@ -127,7 +128,8 @@ set(LINPHONE_SOURCE_FILES_C
)
set(LINPHONE_SOURCE_FILES_CXX
conference.cc
../src/conference/conference-event-package.cpp
../src/conference/remote-conference-event-handler.cpp
../src/conference/local-conference-event-handler.cpp
../src/conference/conference-info.cxx
)
set(LINPHONE_INCLUDE_DIRS ${LINPHONE_INCLUDE_DIRS} /Users/reisbenjamin/xsd-4.0.0-i686-macosx/libxsd /usr/local/Cellar/xerces-c/3.1.4/include)
......
......@@ -45,7 +45,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "mediastreamer2/msjpegwriter.h"
#include "mediastreamer2/msogl.h"
#include "mediastreamer2/msvolume.h"
#include "conference/conference-event-package.h"
#include "conference/remote-conference-event-handler.h"
#ifdef INET6
#ifndef _WIN32
......@@ -2117,10 +2117,10 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve
friendLists = friendLists->next;
}
} else if (strcmp(notified_event, "Conference") == 0) {
LinphonePrivate::Conference::ConferenceEventPackage *cep = reinterpret_cast<LinphonePrivate::Conference::ConferenceEventPackage *>(linphone_event_get_user_data(lev));
if(cep) {
ms_message("notify event for conference %s", cep->getConfId().c_str());
cep->notifyReceived((char *) linphone_content_get_buffer(body));
LinphonePrivate::Conference::RemoteConferenceEventHandler *handler = reinterpret_cast<LinphonePrivate::Conference::RemoteConferenceEventHandler *>(linphone_event_get_user_data(lev));
if(handler) {
ms_message("notify event for conference %s", handler->getConfId().c_str());
handler->notifyReceived((char *) linphone_content_get_buffer(body));
}
}
}
......@@ -2129,10 +2129,7 @@ static void linphone_core_internal_subscription_state_changed(LinphoneCore *lc,
if (strcasecmp(linphone_event_get_name(lev), "Presence") == 0) {
linphone_friend_list_subscription_state_changed(lc, lev, state);
} else if (strcmp(linphone_event_get_name(lev), "Conference") == 0) {
LinphonePrivate::Conference::ConferenceEventPackage *cep = reinterpret_cast<LinphonePrivate::Conference::ConferenceEventPackage *>(linphone_event_get_user_data(lev));
if(cep) {
}
}
}
......
/*
* local-conference-event-handler.cpp
* Copyright (C) 2017 Belledonne Communications SARL
*
* 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 3 of the License, or
* (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "local-conference-event-handler.h"
#include "conference-info.hxx"
#include "private.h"
using namespace std;
using namespace conference_info;
using namespace LinphonePrivate;
class Conference::LocalConferenceEventHandlerPrivate : public ObjectPrivate {
public:
void notifyFullState(string notify, LinphoneEvent *lev);
void notifyAllExcept(string notify, LinphoneAddress *addr);
LocalConference *conf;
LinphoneCore *lc;
};
void Conference::LocalConferenceEventHandlerPrivate::notifyFullState(string notify, LinphoneEvent *lev) {
LinphoneContent* content = linphone_core_create_content(lev->lc);
linphone_content_set_buffer(content,notify.c_str(),strlen(notify.c_str()));
linphone_event_notify(lev, content);
linphone_content_unref(content);
// linphone_event_unref(lev); ??
}
void Conference::LocalConferenceEventHandlerPrivate::notifyAllExcept(string notify, LinphoneAddress *addr) {
for(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);
linphone_content_set_buffer(content,notify.c_str(),strlen(notify.c_str()));
linphone_event_notify(lev, content);
linphone_content_unref(content);
linphone_event_unref(lev);
}
}
}
// -------- Conference::LocalConferenceEventHandler public methods ---------
Conference::LocalConferenceEventHandler::LocalConferenceEventHandler(LinphoneCore *core, LocalConference *localConf) : Object(new LocalConferenceEventHandlerPrivate) {
L_D(LocalConferenceEventHandler);
xercesc::XMLPlatformUtils::Initialize();
d->conf = localConf;
d->lc = core; // conf->getCore() ?
}
Conference::LocalConferenceEventHandler::~LocalConferenceEventHandler() {
xercesc::XMLPlatformUtils::Terminate();
}
string Conference::LocalConferenceEventHandler::subscribeReceived(LinphoneEvent *lev) {
L_D(LocalConferenceEventHandler);
char *entity = linphone_address_as_string_uri_only(d->conf->getAddress());
Conference_type confInfo = Conference_type(entity);
Users_type users;
confInfo.setUsers(users);
stringstream notify;
xml_schema::NamespaceInfomap map;
map[""].name = "urn:ietf:params:xml:ns:conference-info";
for(auto participant : d->conf->getParticipants()) {
User_type user = User_type();
User_roles_type roles;
user.setRoles(roles);
user.setEntity(linphone_address_as_string_uri_only(participant.getAddress()));
user.getRoles()->getEntry().push_back(participant.isAdmin() ? "admin" : "participant");
user.setState("full");
confInfo.getUsers()->getUser().push_back(user);
}
serializeConference_info(notify, confInfo, map);
//d->notifyFullState(notify.str(), lev);
return notify.str();
}
string Conference::LocalConferenceEventHandler::notifyParticipantAdded(LinphoneAddress *addr) {
L_D(LocalConferenceEventHandler);
char *entity = linphone_address_as_string_uri_only(d->conf->getAddress());
Conference_type confInfo = Conference_type(entity);
Users_type users;
confInfo.setUsers(users);
stringstream notify;
xml_schema::NamespaceInfomap map;
User_type user = User_type();
User_roles_type roles;
user.setRoles(roles);
user.setEntity(linphone_address_as_string_uri_only(addr));
user.getRoles()->getEntry().push_back("participant");
user.setState("full");
confInfo.getUsers()->getUser().push_back(user);
serializeConference_info(notify, confInfo, map);
//d->notifyAllExcept(notify.str(), addr);
return notify.str();
}
string Conference::LocalConferenceEventHandler::notifyParticipantRemoved(LinphoneAddress *addr) {
L_D(LocalConferenceEventHandler);
char *entity = linphone_address_as_string_uri_only(d->conf->getAddress());
Conference_type confInfo = Conference_type(entity);
Users_type users;
confInfo.setUsers(users);
stringstream notify;
xml_schema::NamespaceInfomap map;
User_type user = User_type();
user.setEntity(linphone_address_as_string_uri_only(addr));
user.setState("deleted");
confInfo.getUsers()->getUser().push_back(user);
serializeConference_info(notify, confInfo, map);
//d->notifyAllExcept(notify.str(), addr);
return notify.str();
}
string Conference::LocalConferenceEventHandler::notifyParticipantSetAdmin(LinphoneAddress *addr, bool isAdmin) {
L_D(LocalConferenceEventHandler);
char *entity = linphone_address_as_string_uri_only(d->conf->getAddress());
Conference_type confInfo = Conference_type(entity);
Users_type users;
confInfo.setUsers(users);
stringstream notify;
xml_schema::NamespaceInfomap map;
User_type user = User_type();
User_roles_type roles;
user.setRoles(roles);
user.setEntity(linphone_address_as_string_uri_only(addr));
user.getRoles()->getEntry().push_back(isAdmin ? "admin" : "participant");
user.setState("partial");
confInfo.getUsers()->getUser().push_back(user);
serializeConference_info(notify, confInfo, map);
//d->notifyAllExcept(notify.str(), addr);
return notify.str();
}
/*
* local-conference-event-handler.h
* Copyright (C) 2017 Belledonne Communications SARL
*
* 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 3 of the License, or
* (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _LOCAL_CONFERENCE_EVENT_HANDLER_H_
#define _LOCAL_CONFERENCE_EVENT_HANDLER_H_
#include <map>
#include <list>
#include <string>
#include "object/object.h"
#include "linphone/core.h"
#include "linphone/event.h"
namespace LinphonePrivate {
namespace Conference {
// -------------------------------------------------------------------------
// LocalConferenceEventHandler.
// -------------------------------------------------------------------------
class LocalConference;
class LocalConferenceEventHandlerPrivate;
class LocalConferenceEventHandler : public Object {
public:
LocalConferenceEventHandler(LinphoneCore *core, LocalConference* localConf);
~LocalConferenceEventHandler();
std::string subscribeReceived(LinphoneEvent *lev);
std::string notifyParticipantAdded(LinphoneAddress *addr);
std::string notifyParticipantRemoved(LinphoneAddress *addr);
std::string notifyParticipantSetAdmin(LinphoneAddress *addr, bool isAdmin);
private:
L_DECLARE_PRIVATE(LocalConferenceEventHandler);
L_DISABLE_COPY(LocalConferenceEventHandler);
};
class Participant {
public:
Participant(LinphoneAddress *addr, bool admin);
~Participant();
bool isAdmin();
LinphoneAddress *getAddress();
LinphoneAddress *mAddr;
bool mAdmin;
};
class LocalConference {
public:
LocalConference(LinphoneCore *lc, LinphoneAddress *confAddr);
~LocalConference();
LinphoneAddress *getAddress();
std::list<Participant> getParticipants();
std::shared_ptr<LocalConferenceEventHandler> mHandler;
std::list<Participant> mParticipants;
LinphoneAddress *mConfAddr;
};
}
}
// -------- Conference::LocalConference public methods ---------
LinphonePrivate::Conference::LocalConference::LocalConference(LinphoneCore *core, LinphoneAddress *confAddr) {
mConfAddr = confAddr;
mHandler = std::make_shared<LinphonePrivate::Conference::LocalConferenceEventHandler>(core, this);
}
LinphonePrivate::Conference::LocalConference::~LocalConference() {
//linphone_address_unref(mConfAddr);
}
LinphoneAddress* LinphonePrivate::Conference::LocalConference::getAddress() {
return mConfAddr;
}
std::list<LinphonePrivate::Conference::Participant> LinphonePrivate::Conference::LocalConference::getParticipants() {
return mParticipants;
}
LinphonePrivate::Conference::Participant::Participant(LinphoneAddress *addr, bool admin) {
mAddr = addr;
mAdmin = admin;
}
LinphonePrivate::Conference::Participant::~Participant() {
//linphone_address_unref(mAddr);
}
bool LinphonePrivate::Conference::Participant::isAdmin() {
return mAdmin;
}
LinphoneAddress* LinphonePrivate::Conference::Participant::getAddress() {
return mAddr;
}
#endif // ifndef _LOCAL_CONFERENCE_EVENT_HANDLER_H_
\ No newline at end of file
/*
* conference-event-package.cpp
* remote-conference-event-handler.cpp
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
......@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "conference-event-package.h"
#include "remote-conference-event-handler.h"
#include "conference-info.hxx"
#include "private.h"
......@@ -24,7 +24,7 @@ using namespace std;
using namespace conference_info;
using namespace LinphonePrivate;
class LinphonePrivate::Conference::ConferenceEventPackagePrivate : public ObjectPrivate {
class Conference::RemoteConferenceEventHandlerPrivate : public ObjectPrivate {
public:
LinphoneCore *lc;
ConferenceListener *listener;
......@@ -33,8 +33,9 @@ public:
LinphoneEvent *lev;
};
Conference::ConferenceEventPackage::ConferenceEventPackage(LinphoneCore *lc, ConferenceListener *listener, LinphoneAddress *confAddr) : Object(new Conference::ConferenceEventPackagePrivate) {
L_D(ConferenceEventPackage);
// -------- Conference::RemoteConferenceEventHandler public methods ---------
Conference::RemoteConferenceEventHandler::RemoteConferenceEventHandler(LinphoneCore *lc, ConferenceListener *listener, LinphoneAddress *confAddr) : Object(new RemoteConferenceEventHandlerPrivate) {
L_D(RemoteConferenceEventHandler);
xercesc::XMLPlatformUtils::Initialize();
d->lc = lc;
d->listener = listener;
......@@ -43,15 +44,15 @@ Conference::ConferenceEventPackage::ConferenceEventPackage(LinphoneCore *lc, Con
d->lev = NULL;
}
Conference::ConferenceEventPackage::~ConferenceEventPackage() {
L_D(ConferenceEventPackage);
Conference::RemoteConferenceEventHandler::~RemoteConferenceEventHandler() {
L_D(RemoteConferenceEventHandler);
xercesc::XMLPlatformUtils::Terminate();
linphone_address_unref(d->confAddr);
if(d->lev) linphone_event_unref(d->lev);
}
void Conference::ConferenceEventPackage::subscribe(string confId) {
L_D(ConferenceEventPackage);
void Conference::RemoteConferenceEventHandler::subscribe(string confId) {
L_D(RemoteConferenceEventHandler);
d->confId = confId;
d->lev = linphone_core_create_subscribe(d->lc, d->confAddr, "Conference", 600);
linphone_event_ref(d->lev);
......@@ -61,13 +62,13 @@ void Conference::ConferenceEventPackage::subscribe(string confId) {
linphone_event_send_subscribe(d->lev, NULL);
}
void Conference::ConferenceEventPackage::unsubscribe() {
L_D(ConferenceEventPackage);
void Conference::RemoteConferenceEventHandler::unsubscribe() {
L_D(RemoteConferenceEventHandler);
linphone_event_terminate(d->lev);
}
void Conference::ConferenceEventPackage::notifyReceived(const char *xmlBody) {
L_D(ConferenceEventPackage);
void Conference::RemoteConferenceEventHandler::notifyReceived(const char *xmlBody) {
L_D(RemoteConferenceEventHandler);
istringstream data(xmlBody);
unique_ptr<Conference_type> confInfo = parseConference_info(data, xml_schema::Flags::dont_validate);
if(strcmp(confInfo->getEntity().c_str(), linphone_address_as_string(d->confAddr)) == 0) {
......@@ -95,7 +96,7 @@ void Conference::ConferenceEventPackage::notifyReceived(const char *xmlBody) {
}
}
string Conference::ConferenceEventPackage::getConfId() {
L_D(ConferenceEventPackage);
string Conference::RemoteConferenceEventHandler::getConfId() {
L_D(RemoteConferenceEventHandler);
return d->confId;
}
/*
* conference-event-package.h
* remote-conference-event-handler.h
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
......@@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CONFERENCE_EVENT_PACKAGE_H_
#define _CONFERENCE_EVENT_PACKAGE_H_
#ifndef _REMOTE_CONFERENCE_EVENT_HANDLER_H_
#define _REMOTE_CONFERENCE_EVENT_HANDLER_H_
#include <string>
......@@ -27,25 +27,24 @@
namespace LinphonePrivate {
namespace Conference {
class ConferenceEventPackagePrivate;
// -------------------------------------------------------------------------
// ConferenceEventPackage.
// RemoteConferenceEventHandler.
// -------------------------------------------------------------------------
class ConferenceEventPackage : public Object {
class RemoteConferenceEventHandlerPrivate;
class RemoteConferenceEventHandler : public Object {
public:
ConferenceEventPackage(LinphoneCore *lc, ConferenceListener *listener, LinphoneAddress *confAddr);
~ConferenceEventPackage();
RemoteConferenceEventHandler(LinphoneCore *lc, ConferenceListener *listener, LinphoneAddress *confAddr);
~RemoteConferenceEventHandler();
void subscribe(std::string confId);
void notifyReceived(const char *xmlBody);
void unsubscribe();
std::string getConfId();
private:
L_DECLARE_PRIVATE(ConferenceEventPackage);
L_DISABLE_COPY(ConferenceEventPackage);
L_DECLARE_PRIVATE(RemoteConferenceEventHandler);
L_DISABLE_COPY(RemoteConferenceEventHandler);
};
}
}
#endif // ifndef _CONFERENCE_EVENT_PACKAGE_H_
#endif // ifndef _REMOTE_CONFERENCE_EVENT_HANDLER_H_
This diff is collapsed.
......@@ -83,7 +83,7 @@ void linphone_subscription_state_change(LinphoneCore *lc, LinphoneEvent *lev, Li
if (linphone_event_get_subscription_dir(lev)==LinphoneSubscriptionIncoming){
mgr->lev=lev;
if(strcmp(linphone_event_get_name(lev), "Conference") == 0) {
linphone_conf_event_notify(lev);
// TODO : Get LocalConfEventHandler and call handler->subscribeReceived(lev)
} else {
linphone_event_notify(lev,content);
}
......
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