Commit be1d6f99 authored by Ronan's avatar Ronan

feat(Event): events are now shared

parent 4bfbe3d9
......@@ -18,7 +18,6 @@
*/
#include "linphone/api/c-dial-plan.h"
#include "linphone/wrapper_utils.h"
#include "c-wrapper/c-wrapper.h"
#include "dial-plan/dial-plan.h"
......@@ -29,61 +28,61 @@ using namespace std;
L_DECLARE_C_OBJECT_IMPL(DialPlan);
LinphoneDialPlan *linphone_dial_plan_ref(LinphoneDialPlan *dp) {
return (LinphoneDialPlan *)belle_sip_object_ref(dp);
LinphoneDialPlan *linphone_dial_plan_ref (LinphoneDialPlan *dp) {
return reinterpret_cast<LinphoneDialPlan *>(belle_sip_object_ref(dp));
}
void linphone_dial_plan_unref(LinphoneDialPlan *dp) {
void linphone_dial_plan_unref (LinphoneDialPlan *dp) {
belle_sip_object_unref(dp);
}
const char * linphone_dial_plan_get_country(const LinphoneDialPlan *dp) {
const char *linphone_dial_plan_get_country (const LinphoneDialPlan *dp) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getCountry());
}
const char * linphone_dial_plan_get_iso_country_code(const LinphoneDialPlan *dp) {
const char *linphone_dial_plan_get_iso_country_code (const LinphoneDialPlan *dp) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getIsoCountryCode());
}
const char * linphone_dial_plan_get_country_calling_code(const LinphoneDialPlan *dp) {
const char *linphone_dial_plan_get_country_calling_code (const LinphoneDialPlan *dp) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getCountryCallingCode());
}
int linphone_dial_plan_get_national_number_length(const LinphoneDialPlan *dp) {
int linphone_dial_plan_get_national_number_length (const LinphoneDialPlan *dp) {
return L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getNationalNumberLength();
}
const char * linphone_dial_plan_get_international_call_prefix(const LinphoneDialPlan *dp) {
const char *linphone_dial_plan_get_international_call_prefix (const LinphoneDialPlan *dp) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getInternationalCallPrefix());
}
int linphone_dial_plan_lookup_ccc_from_e164(const char* e164) {
return LinphonePrivate::DialPlan::lookupCccFromE164(L_C_TO_STRING(e164));
int linphone_dial_plan_lookup_ccc_from_e164 (const char *e164) {
return LinphonePrivate::DialPlan::lookupCccFromE164(L_C_TO_STRING(e164));
}
int linphone_dial_plan_lookup_ccc_from_iso(const char* iso) {
int linphone_dial_plan_lookup_ccc_from_iso (const char *iso) {
return LinphonePrivate::DialPlan::lookupCccFromIso(L_C_TO_STRING(iso));
}
const LinphoneDialPlan* linphone_dial_plan_by_ccc_as_int(int ccc) {
const LinphonePrivate::DialPlan& dp = LinphonePrivate::DialPlan::findByCccAsInt(ccc);
const LinphoneDialPlan *linphone_dial_plan_by_ccc_as_int (int ccc) {
const LinphonePrivate::DialPlan &dp = LinphonePrivate::DialPlan::findByCccAsInt(ccc);
return L_GET_C_BACK_PTR(&dp);
}
const LinphoneDialPlan* linphone_dial_plan_by_ccc(const char *ccc) {
const LinphonePrivate::DialPlan& dp = LinphonePrivate::DialPlan::findByCcc(L_C_TO_STRING(ccc));
const LinphoneDialPlan *linphone_dial_plan_by_ccc (const char *ccc) {
const LinphonePrivate::DialPlan &dp = LinphonePrivate::DialPlan::findByCcc(L_C_TO_STRING(ccc));
return L_GET_C_BACK_PTR(&dp);
}
const LinphoneDialPlan* linphone_dial_plan_get_all() {
return NULL;
const LinphoneDialPlan *linphone_dial_plan_get_all () {
return nullptr;
}
const bctbx_list_t * linphone_dial_plan_get_all_list() {
const list<LinphonePrivate::DialPlan>& dps = LinphonePrivate::DialPlan::getAllDialPlans();
const bctbx_list_t *linphone_dial_plan_get_all_list () {
const list<LinphonePrivate::DialPlan> &dps = LinphonePrivate::DialPlan::getAllDialPlans();
return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(dps);
}
bool_t linphone_dial_plan_is_generic(const LinphoneDialPlan *ccc) {
bool_t linphone_dial_plan_is_generic (const LinphoneDialPlan *ccc) {
return L_GET_CPP_PTR_FROM_C_OBJECT(ccc)->isGeneric();
}
......@@ -27,13 +27,13 @@
// =============================================================================
L_DECLARE_C_BASE_OBJECT_IMPL(CallEvent);
L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceChatMessageEvent);
L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceEvent);
L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceParticipantDeviceEvent);
L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceParticipantEvent);
L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceSubjectEvent);
L_DECLARE_C_BASE_OBJECT_IMPL(EventLog);
L_DECLARE_C_OBJECT_IMPL(CallEvent);
L_DECLARE_C_OBJECT_IMPL(ConferenceChatMessageEvent);
L_DECLARE_C_OBJECT_IMPL(ConferenceEvent);
L_DECLARE_C_OBJECT_IMPL(ConferenceParticipantDeviceEvent);
L_DECLARE_C_OBJECT_IMPL(ConferenceParticipantEvent);
L_DECLARE_C_OBJECT_IMPL(ConferenceSubjectEvent);
L_DECLARE_C_OBJECT_IMPL(EventLog);
using namespace std;
......@@ -43,7 +43,7 @@ using namespace std;
LinphoneEventLog *linphone_event_log_new () {
LinphoneEventLog *event_log = _linphone_EventLog_init();
L_SET_CPP_PTR_FROM_C_OBJECT(event_log, new LinphonePrivate::EventLog());
L_SET_CPP_PTR_FROM_C_OBJECT(event_log, make_shared<LinphonePrivate::EventLog>());
return event_log;
}
......@@ -66,7 +66,7 @@ LinphoneCallEvent *linphone_call_event_new (LinphoneEventLogType type, time_t ti
LinphoneCallEvent *call_event = _linphone_CallEvent_init();
L_SET_CPP_PTR_FROM_C_OBJECT(
call_event,
new LinphonePrivate::CallEvent(
make_shared<LinphonePrivate::CallEvent>(
static_cast<LinphonePrivate::EventLog::Type>(type),
time,
L_GET_CPP_PTR_FROM_C_OBJECT(call)
......@@ -128,7 +128,7 @@ LinphoneConferenceChatMessageEvent *linphone_chat_message_event_new (LinphoneCha
LinphoneConferenceChatMessageEvent *chat_message_event = _linphone_ConferenceChatMessageEvent_init();
L_SET_CPP_PTR_FROM_C_OBJECT(
chat_message_event,
new LinphonePrivate::ConferenceChatMessageEvent(
make_shared<LinphonePrivate::ConferenceChatMessageEvent>(
time,
L_GET_CPP_PTR_FROM_C_OBJECT(chat_message)
)
......
This diff is collapsed.
......@@ -276,7 +276,7 @@ void ClientGroupChatRoom::onParticipantAdded (time_t tm, const Address &addr) {
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
LinphoneChatRoomCbsParticipantAddedCb cb = linphone_chat_room_cbs_get_participant_added(cbs);
const ConferenceParticipantEvent event(
shared_ptr<ConferenceParticipantEvent> event = make_shared<ConferenceParticipantEvent>(
EventLog::Type::ConferenceParticipantAdded,
tm,
dConference->conferenceAddress,
......@@ -286,7 +286,7 @@ void ClientGroupChatRoom::onParticipantAdded (time_t tm, const Address &addr) {
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(&event));
cb(cr, L_GET_C_BACK_PTR(event));
}
void ClientGroupChatRoom::onParticipantRemoved (time_t tm, const Address &addr) {
......@@ -301,7 +301,7 @@ void ClientGroupChatRoom::onParticipantRemoved (time_t tm, const Address &addr)
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
LinphoneChatRoomCbsParticipantRemovedCb cb = linphone_chat_room_cbs_get_participant_removed(cbs);
const ConferenceParticipantEvent event(
shared_ptr<ConferenceParticipantEvent> event = make_shared<ConferenceParticipantEvent>(
EventLog::Type::ConferenceParticipantRemoved,
tm,
dConference->conferenceAddress,
......@@ -311,7 +311,7 @@ void ClientGroupChatRoom::onParticipantRemoved (time_t tm, const Address &addr)
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(&event));
cb(cr, L_GET_C_BACK_PTR(event));
dConference->participants.remove(participant);
}
......@@ -332,7 +332,7 @@ void ClientGroupChatRoom::onParticipantSetAdmin (time_t tm, const Address &addr,
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
LinphoneChatRoomCbsParticipantAdminStatusChangedCb cb = linphone_chat_room_cbs_get_participant_admin_status_changed(cbs);
const ConferenceParticipantEvent event(
shared_ptr<ConferenceParticipantEvent> event = make_shared<ConferenceParticipantEvent>(
isAdmin ? EventLog::Type::ConferenceParticipantSetAdmin : EventLog::Type::ConferenceParticipantUnsetAdmin,
tm,
dConference->conferenceAddress,
......@@ -342,7 +342,7 @@ void ClientGroupChatRoom::onParticipantSetAdmin (time_t tm, const Address &addr,
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(&event));
cb(cr, L_GET_C_BACK_PTR(event));
}
void ClientGroupChatRoom::onSubjectChanged (time_t tm, const std::string &subject) {
......@@ -351,7 +351,7 @@ void ClientGroupChatRoom::onSubjectChanged (time_t tm, const std::string &subjec
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
LinphoneChatRoomCbsSubjectChangedCb cb = linphone_chat_room_cbs_get_subject_changed(cbs);
const ConferenceSubjectEvent event(
shared_ptr<ConferenceSubjectEvent> event = make_shared<ConferenceSubjectEvent>(
tm,
dConference->conferenceAddress,
dConference->eventHandler->getLastNotify(),
......@@ -360,7 +360,7 @@ void ClientGroupChatRoom::onSubjectChanged (time_t tm, const std::string &subjec
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(&event));
cb(cr, L_GET_C_BACK_PTR(event));
}
void ClientGroupChatRoom::onParticipantDeviceAdded (time_t tm, const Address &addr, const Address &gruu) {
......@@ -378,7 +378,7 @@ void ClientGroupChatRoom::onParticipantDeviceAdded (time_t tm, const Address &ad
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
LinphoneChatRoomCbsParticipantDeviceAddedCb cb = linphone_chat_room_cbs_get_participant_device_added(cbs);
const ConferenceParticipantDeviceEvent event(
shared_ptr<ConferenceParticipantDeviceEvent> event = make_shared<ConferenceParticipantDeviceEvent>(
EventLog::Type::ConferenceParticipantDeviceAdded,
tm,
dConference->conferenceAddress,
......@@ -389,7 +389,7 @@ void ClientGroupChatRoom::onParticipantDeviceAdded (time_t tm, const Address &ad
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(&event));
cb(cr, L_GET_C_BACK_PTR(event));
}
void ClientGroupChatRoom::onParticipantDeviceRemoved (time_t tm, const Address &addr, const Address &gruu) {
......@@ -407,7 +407,7 @@ void ClientGroupChatRoom::onParticipantDeviceRemoved (time_t tm, const Address &
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this);
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
LinphoneChatRoomCbsParticipantDeviceRemovedCb cb = linphone_chat_room_cbs_get_participant_device_removed(cbs);
const ConferenceParticipantDeviceEvent event(
shared_ptr<ConferenceParticipantDeviceEvent> event = make_shared<ConferenceParticipantDeviceEvent>(
EventLog::Type::ConferenceParticipantDeviceRemoved,
tm,
dConference->conferenceAddress,
......@@ -418,7 +418,7 @@ void ClientGroupChatRoom::onParticipantDeviceRemoved (time_t tm, const Address &
Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event);
if (cb)
cb(cr, L_GET_C_BACK_PTR(&event));
cb(cr, L_GET_C_BACK_PTR(event));
}
// -----------------------------------------------------------------------------
......
......@@ -99,14 +99,14 @@ private:
const std::string &peerAddress
) const;
long long insertEvent (const EventLog &eventLog);
long long insertConferenceEvent (const EventLog &eventLog, long long *chatRoomId = nullptr);
long long insertConferenceCallEvent (const EventLog &eventLog);
long long insertConferenceChatMessageEvent (const EventLog &eventLog);
long long insertConferenceNotifiedEvent (const EventLog &eventLog);
long long insertConferenceParticipantEvent (const EventLog &eventLog);
long long insertConferenceParticipantDeviceEvent (const EventLog &eventLog);
long long insertConferenceSubjectEvent (const EventLog &eventLog);
long long insertEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceEvent (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr);
long long insertConferenceCallEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceChatMessageEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceNotifiedEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceParticipantEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceParticipantDeviceEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceSubjectEvent (const std::shared_ptr<EventLog> &eventLog);
L_DECLARE_PUBLIC(MainDb);
};
......
......@@ -366,19 +366,19 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
// -----------------------------------------------------------------------------
long long MainDbPrivate::insertEvent (const EventLog &eventLog) {
long long MainDbPrivate::insertEvent (const shared_ptr<EventLog> &eventLog) {
L_Q();
soci::session *session = dbSession.getBackendSession<soci::session>();
*session << "INSERT INTO event (type, date) VALUES (:type, :date)",
soci::use(static_cast<int>(eventLog.getType())), soci::use(Utils::getLongAsTm(eventLog.getTime()));
soci::use(static_cast<int>(eventLog->getType())), soci::use(Utils::getLongAsTm(eventLog->getTime()));
return q->getLastInsertId();
}
long long MainDbPrivate::insertConferenceEvent (const EventLog &eventLog, long long *chatRoomId) {
long long MainDbPrivate::insertConferenceEvent (const shared_ptr<EventLog> &eventLog, long long *chatRoomId) {
long long eventId = insertEvent(eventLog);
long long curChatRoomId = insertSipAddress(
static_cast<const ConferenceEvent &>(eventLog).getConferenceAddress().asString()
static_pointer_cast<ConferenceEvent>(eventLog)->getConferenceAddress().asString()
);
soci::session *session = dbSession.getBackendSession<soci::session>();
......@@ -391,20 +391,20 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
return eventId;
}
long long MainDbPrivate::insertConferenceCallEvent (const EventLog &eventLog) {
long long MainDbPrivate::insertConferenceCallEvent (const shared_ptr<EventLog> &eventLog) {
// TODO.
return 0;
}
long long MainDbPrivate::insertConferenceChatMessageEvent (const EventLog &eventLog) {
shared_ptr<ChatMessage> chatMessage = static_cast<const ConferenceChatMessageEvent &>(eventLog).getChatMessage();
long long MainDbPrivate::insertConferenceChatMessageEvent (const shared_ptr<EventLog> &eventLog) {
shared_ptr<ChatMessage> chatMessage = static_pointer_cast<ConferenceChatMessageEvent>(eventLog)->getChatMessage();
shared_ptr<ChatRoom> chatRoom = chatMessage->getChatRoom();
if (!chatRoom) {
lError() << "Unable to get a valid chat room. It was removed from database.";
return -1;
}
tm eventTime = Utils::getLongAsTm(static_cast<long>(eventLog.getTime()));
tm eventTime = Utils::getLongAsTm(static_cast<long>(eventLog->getTime()));
long long localSipAddressId = insertSipAddress(chatMessage->getLocalAddress().asString());
long long remoteSipAddressId = insertSipAddress(chatMessage->getRemoteAddress().asString());
......@@ -429,10 +429,10 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
return eventId;
}
long long MainDbPrivate::insertConferenceNotifiedEvent (const EventLog &eventLog) {
long long MainDbPrivate::insertConferenceNotifiedEvent (const shared_ptr<EventLog> &eventLog) {
long long chatRoomId;
long long eventId = insertConferenceEvent(eventLog, &chatRoomId);
unsigned int lastNotifyId = static_cast<const ConferenceNotifiedEvent &>(eventLog).getNotifyId();
unsigned int lastNotifyId = static_pointer_cast<ConferenceNotifiedEvent>(eventLog)->getNotifyId();
soci::session *session = dbSession.getBackendSession<soci::session>();
*session << "INSERT INTO conference_notified_event (event_id, notify_id)"
......@@ -443,10 +443,10 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
return eventId;
}
long long MainDbPrivate::insertConferenceParticipantEvent (const EventLog &eventLog) {
long long MainDbPrivate::insertConferenceParticipantEvent (const shared_ptr<EventLog> &eventLog) {
long long eventId = insertConferenceNotifiedEvent(eventLog);
long long participantAddressId = insertSipAddress(
static_cast<const ConferenceParticipantEvent &>(eventLog).getParticipantAddress().asString()
static_pointer_cast<ConferenceParticipantEvent>(eventLog)->getParticipantAddress().asString()
);
soci::session *session = dbSession.getBackendSession<soci::session>();
......@@ -456,10 +456,10 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
return eventId;
}
long long MainDbPrivate::insertConferenceParticipantDeviceEvent (const EventLog &eventLog) {
long long MainDbPrivate::insertConferenceParticipantDeviceEvent (const shared_ptr<EventLog> &eventLog) {
long long eventId = insertConferenceParticipantEvent(eventLog);
long long gruuAddressId = insertSipAddress(
static_cast<const ConferenceParticipantDeviceEvent &>(eventLog).getGruuAddress().asString()
static_pointer_cast<ConferenceParticipantDeviceEvent>(eventLog)->getGruuAddress().asString()
);
soci::session *session = dbSession.getBackendSession<soci::session>();
......@@ -469,13 +469,13 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
return eventId;
}
long long MainDbPrivate::insertConferenceSubjectEvent (const EventLog &eventLog) {
long long MainDbPrivate::insertConferenceSubjectEvent (const shared_ptr<EventLog> &eventLog) {
long long eventId = insertConferenceNotifiedEvent(eventLog);
soci::session *session = dbSession.getBackendSession<soci::session>();
*session << "INSERT INTO conference_subject_event (event_id, subject)"
" VALUES (:eventId, :subject)", soci::use(eventId), soci::use(
static_cast<const ConferenceSubjectEvent &>(eventLog).getSubject()
static_pointer_cast<ConferenceSubjectEvent>(eventLog)->getSubject()
);
return eventId;
......@@ -716,7 +716,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
*session << participantMessageDeleter;
}
bool MainDb::addEvent (const EventLog &eventLog) {
bool MainDb::addEvent (const shared_ptr<EventLog> &eventLog) {
L_D();
if (!isConnected()) {
......@@ -730,7 +730,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
soci::transaction tr(*d->dbSession.getBackendSession<soci::session>());
switch (eventLog.getType()) {
switch (eventLog->getType()) {
case EventLog::Type::None:
return false;
......@@ -774,7 +774,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
return soFarSoGood;
}
bool MainDb::deleteEvent (const EventLog &eventLog) {
bool MainDb::deleteEvent (const shared_ptr<EventLog> &eventLog) {
L_D();
if (!isConnected()) {
......@@ -782,7 +782,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
return false;
}
long long &storageId = const_cast<EventLog &>(eventLog).getPrivate()->storageId;
long long &storageId = eventLog->getPrivate()->storageId;
if (storageId < 0)
return false;
......
......@@ -48,8 +48,8 @@ public:
MainDb ();
// Generic.
bool addEvent (const EventLog &eventLog);
bool deleteEvent (const EventLog &eventLog);
bool addEvent (const std::shared_ptr<EventLog> &eventLog);
bool deleteEvent (const std::shared_ptr<EventLog> &eventLog);
void cleanEvents (FilterMask mask = NoFilter);
int getEventsCount (FilterMask mask = NoFilter) const;
......
......@@ -21,6 +21,7 @@
#define _EVENT_LOG_H_
#include <ctime>
#include <memory>
#include "linphone/enums/event-log-enums.h"
#include "linphone/utils/enum-generator.h"
......
......@@ -31,7 +31,7 @@ LINPHONE_BEGIN_NAMESPACE
class BaseObjectPrivate;
/*
* Base Object of Linphone. Cannot be cloned. Cannot be Shared.
* Base Object of Linphone. Cannot be cloned. Can be Shared.
* It's the base class of Object. It's useful for lightweight entities
* like Events.
*/
......
......@@ -31,6 +31,7 @@ LINPHONE_BEGIN_NAMESPACE
/*
* Main Object of Linphone. Can be shared but is not Clonable.
* Supports properties and shared from this.
* Must be built with ObjectFactory.
*/
class LINPHONE_PUBLIC Object : public BaseObject, public PropertyContainer {
......
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