From d64b2adf77a03450004adb491fc4c9fc47e19afc Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 17 Oct 2017 10:07:29 +0200 Subject: [PATCH] feat(EventLog): supports time --- include/linphone/api/c-event-log.h | 13 ++++++++++-- src/c-wrapper/api/c-event-log.cpp | 8 ++++++-- src/db/main-db.cpp | 10 +++++----- src/event-log/call-event.cpp | 5 +++-- src/event-log/call-event.h | 2 +- src/event-log/chat-message-event.cpp | 10 +++++++--- src/event-log/chat-message-event.h | 2 +- src/event-log/conference-event.cpp | 20 +++++++++++-------- src/event-log/conference-event.h | 4 ++-- .../conference-participant-device-event.cpp | 3 +++ .../conference-participant-device-event.h | 1 + .../conference-participant-event.cpp | 16 +++++++++++---- src/event-log/conference-participant-event.h | 2 ++ src/event-log/conference-subject-event.cpp | 9 ++++++--- src/event-log/conference-subject-event.h | 2 +- src/event-log/event-log-p.h | 3 ++- src/event-log/event-log.cpp | 3 ++- src/event-log/event-log.h | 5 ++++- 18 files changed, 81 insertions(+), 37 deletions(-) diff --git a/include/linphone/api/c-event-log.h b/include/linphone/api/c-event-log.h index f800373c5..9d71a30e5 100644 --- a/include/linphone/api/c-event-log.h +++ b/include/linphone/api/c-event-log.h @@ -33,12 +33,17 @@ LINPHONE_PUBLIC LinphoneEventLog *linphone_event_log_clone (const LinphoneEventL LINPHONE_PUBLIC LinphoneEventLog *linphone_event_log_ref (LinphoneEventLog *event_log); LINPHONE_PUBLIC LinphoneEventLogType linphone_event_log_get_type (const LinphoneEventLog *event_log); -LINPHONE_PUBLIC LinphoneCallEvent *linphone_call_event_new (LinphoneEventLogType type, LinphoneCall *call); +LINPHONE_PUBLIC LinphoneCallEvent *linphone_call_event_new ( + LinphoneEventLogType type, + time_t time, + LinphoneCall *call +); LINPHONE_PUBLIC LinphoneCallEvent *linphone_call_event_clone (const LinphoneCallEvent *call_event); LINPHONE_PUBLIC LinphoneCall *linphone_call_event_get_call (const LinphoneCallEvent *call_event); LINPHONE_PUBLIC LinphoneConferenceEvent *linphone_conference_event_new ( LinphoneEventLogType type, + time_t time, const LinphoneAddress *address ); LINPHONE_PUBLIC LinphoneConferenceEvent *linphone_conference_event_clone (const LinphoneConferenceEvent *conference_event); @@ -46,6 +51,7 @@ LINPHONE_PUBLIC const LinphoneAddress *linphone_conference_event_get_address (co LINPHONE_PUBLIC LinphoneConferenceParticipantEvent *linphone_conference_participant_event_new ( LinphoneEventLogType type, + time_t time, const LinphoneAddress *conferenceAddress, const LinphoneAddress *participantAddress ); @@ -56,7 +62,10 @@ LINPHONE_PUBLIC const LinphoneAddress *linphone_conference_participant_event_get const LinphoneConferenceParticipantEvent *conference_participant_event ); -LINPHONE_PUBLIC LinphoneChatMessageEvent *linphone_chat_message_event_new (LinphoneChatMessage *chat_message); +LINPHONE_PUBLIC LinphoneChatMessageEvent *linphone_chat_message_event_new ( + LinphoneChatMessage *chat_message, + time_t time +); LINPHONE_PUBLIC LinphoneChatMessageEvent *linphone_chat_message_event_clone ( const LinphoneChatMessageEvent *chat_message_event ); diff --git a/src/c-wrapper/api/c-event-log.cpp b/src/c-wrapper/api/c-event-log.cpp index 4737af3f5..77dd75244 100644 --- a/src/c-wrapper/api/c-event-log.cpp +++ b/src/c-wrapper/api/c-event-log.cpp @@ -62,12 +62,13 @@ LinphoneEventLogType linphone_event_log_get_type (const LinphoneEventLog *event_ // Call event. // ----------------------------------------------------------------------------- -LinphoneCallEvent *linphone_call_event_new (LinphoneEventLogType type, LinphoneCall *call) { +LinphoneCallEvent *linphone_call_event_new (LinphoneEventLogType type, time_t time, LinphoneCall *call) { LinphoneCallEvent *call_event = _linphone_CallEvent_init(); L_SET_CPP_PTR_FROM_C_OBJECT( call_event, new LinphonePrivate::CallEvent( static_cast(type), + time, L_GET_CPP_PTR_FROM_C_OBJECT(call) ) ); @@ -86,6 +87,7 @@ LinphoneCall *linphone_call_event_get_call (const LinphoneCallEvent *call_event) LinphoneConferenceEvent *linphone_conference_event_new ( LinphoneEventLogType type, + time_t time, const LinphoneAddress *address ) { // TODO. @@ -103,6 +105,7 @@ const LinphoneAddress *linphone_conference_event_get_address (const LinphoneConf LinphoneConferenceParticipantEvent *linphone_conference_participant_event_new ( LinphoneEventLogType type, + time_t time, const LinphoneAddress *conferenceAddress, const LinphoneAddress *participantAddress ) { @@ -121,11 +124,12 @@ const LinphoneAddress *linphone_conference_participant_event_get_participant_add // Message event. // ----------------------------------------------------------------------------- -LinphoneChatMessageEvent *linphone_chat_message_event_new (LinphoneChatMessage *chat_message) { +LinphoneChatMessageEvent *linphone_chat_message_event_new (LinphoneChatMessage *chat_message, time_t time) { LinphoneChatMessageEvent *chat_message_event = _linphone_ChatMessageEvent_init(); L_SET_CPP_PTR_FROM_C_OBJECT( chat_message_event, new LinphonePrivate::ChatMessageEvent( + time, L_GET_CPP_PTR_FROM_C_OBJECT(chat_message) ) ); diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 5aa1bd04e..db0d2360c 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -519,19 +519,19 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} return false; } - long &id = const_cast(eventLog).getPrivate()->id; - if (id < 0) + long &storageId = const_cast(eventLog).getPrivate()->storageId; + if (storageId < 0) return false; L_BEGIN_LOG_EXCEPTION soci::session *session = d->dbSession.getBackendSession(); - *session << "DELETE FROM event WHERE id = :id", soci::use(id); - id = -1; + *session << "DELETE FROM event WHERE id = :id", soci::use(storageId); + storageId = -1; L_END_LOG_EXCEPTION - return id == -1; + return storageId == -1; } void MainDb::cleanEvents (FilterMask mask) { diff --git a/src/event-log/call-event.cpp b/src/event-log/call-event.cpp index f98d7fad1..b434bbff2 100644 --- a/src/event-log/call-event.cpp +++ b/src/event-log/call-event.cpp @@ -33,14 +33,15 @@ public: // ----------------------------------------------------------------------------- -CallEvent::CallEvent (Type type, const shared_ptr &call) : EventLog(*new CallEventPrivate, type) { +CallEvent::CallEvent (Type type, const time_t &time, const shared_ptr &call) : + EventLog(*new CallEventPrivate, type, time) { L_D(); L_ASSERT(call); L_ASSERT(type == Type::CallStart || type == Type::CallEnd); d->call = call; } -CallEvent::CallEvent (const CallEvent &src) : CallEvent(src.getType(), src.getCall()) {} +CallEvent::CallEvent (const CallEvent &src) : CallEvent(src.getType(), src.getTime(), src.getCall()) {} CallEvent &CallEvent::operator= (const CallEvent &src) { L_D(); diff --git a/src/event-log/call-event.h b/src/event-log/call-event.h index 512d891c2..5bc348f47 100644 --- a/src/event-log/call-event.h +++ b/src/event-log/call-event.h @@ -33,7 +33,7 @@ class CallEventPrivate; class LINPHONE_PUBLIC CallEvent : public EventLog { public: - CallEvent (Type type, const std::shared_ptr &message); + CallEvent (Type type, const std::time_t &time, const std::shared_ptr &message); CallEvent (const CallEvent &src); CallEvent &operator= (const CallEvent &src); diff --git a/src/event-log/chat-message-event.cpp b/src/event-log/chat-message-event.cpp index 6305413ea..e6a796d93 100644 --- a/src/event-log/chat-message-event.cpp +++ b/src/event-log/chat-message-event.cpp @@ -33,14 +33,18 @@ public: // ----------------------------------------------------------------------------- -ChatMessageEvent::ChatMessageEvent (const shared_ptr &chatMessage) : - EventLog(*new ChatMessageEventPrivate, EventLog::Type::ChatMessage) { +ChatMessageEvent::ChatMessageEvent ( + const time_t &time, + const shared_ptr &chatMessage +) : EventLog(*new ChatMessageEventPrivate, EventLog::Type::ChatMessage, time) { L_D(); L_ASSERT(chatMessage); d->chatMessage = chatMessage; } -ChatMessageEvent::ChatMessageEvent (const ChatMessageEvent &src) : ChatMessageEvent(src.getChatMessage()) {} +ChatMessageEvent::ChatMessageEvent ( + const ChatMessageEvent &src +) : ChatMessageEvent(src.getTime(), src.getChatMessage()) {} ChatMessageEvent &ChatMessageEvent::operator= (const ChatMessageEvent &src) { L_D(); diff --git a/src/event-log/chat-message-event.h b/src/event-log/chat-message-event.h index 91764665c..a9a3c7e76 100644 --- a/src/event-log/chat-message-event.h +++ b/src/event-log/chat-message-event.h @@ -33,7 +33,7 @@ class ChatMessageEventPrivate; class LINPHONE_PUBLIC ChatMessageEvent : public EventLog { public: - ChatMessageEvent (const std::shared_ptr &chatMessage); + ChatMessageEvent (const std::time_t &time, const std::shared_ptr &chatMessage); ChatMessageEvent (const ChatMessageEvent &src); ChatMessageEvent &operator= (const ChatMessageEvent &src); diff --git a/src/event-log/conference-event.cpp b/src/event-log/conference-event.cpp index b6f4e67e3..50311782b 100644 --- a/src/event-log/conference-event.cpp +++ b/src/event-log/conference-event.cpp @@ -26,21 +26,25 @@ using namespace std; LINPHONE_BEGIN_NAMESPACE -ConferenceEvent::ConferenceEvent (Type type, const Address &conferenceAddress) : - EventLog(*new ConferenceEventPrivate, type) { +ConferenceEvent::ConferenceEvent (Type type, const time_t &time, const Address &conferenceAddress) : + EventLog(*new ConferenceEventPrivate, type, time) { L_D(); L_ASSERT(type == Type::ConferenceCreated || type == Type::ConferenceDestroyed); d->conferenceAddress = conferenceAddress; } ConferenceEvent::ConferenceEvent (const ConferenceEvent &src) : - ConferenceEvent(src.getType(), src.getConferenceAddress()) {} + ConferenceEvent(src.getType(), src.getTime(), src.getConferenceAddress()) {} -ConferenceEvent::ConferenceEvent (ConferenceEventPrivate &p, Type type, const Address &conferenceAddress) : - EventLog(p, type) { - L_D(); - d->conferenceAddress = conferenceAddress; - } +ConferenceEvent::ConferenceEvent ( + ConferenceEventPrivate &p, + Type type, + const time_t &time, + const Address &conferenceAddress +) : EventLog(p, type, time) { + L_D(); + d->conferenceAddress = conferenceAddress; +} ConferenceEvent &ConferenceEvent::operator= (const ConferenceEvent &src) { L_D(); diff --git a/src/event-log/conference-event.h b/src/event-log/conference-event.h index ff1e93439..dbd2391ab 100644 --- a/src/event-log/conference-event.h +++ b/src/event-log/conference-event.h @@ -31,7 +31,7 @@ class ConferenceEventPrivate; class LINPHONE_PUBLIC ConferenceEvent : public EventLog { public: - ConferenceEvent (Type type, const Address &conferenceAddress); + ConferenceEvent (Type type, const std::time_t &time, const Address &conferenceAddress); ConferenceEvent (const ConferenceEvent &src); ConferenceEvent &operator= (const ConferenceEvent &src); @@ -39,7 +39,7 @@ public: const Address &getConferenceAddress () const; protected: - ConferenceEvent (ConferenceEventPrivate &p, Type type, const Address &conferenceAddress); + ConferenceEvent (ConferenceEventPrivate &p, Type type, const std::time_t &time, const Address &conferenceAddress); private: L_DECLARE_PRIVATE(ConferenceEvent); diff --git a/src/event-log/conference-participant-device-event.cpp b/src/event-log/conference-participant-device-event.cpp index ce1ffbe9a..fa0334f89 100644 --- a/src/event-log/conference-participant-device-event.cpp +++ b/src/event-log/conference-participant-device-event.cpp @@ -35,12 +35,14 @@ public: ConferenceParticipantDeviceEvent::ConferenceParticipantDeviceEvent ( Type type, + const time_t &time, const Address &conferenceAddress, const Address &participantAddress, const Address &gruuAddress ) : ConferenceParticipantEvent( *new ConferenceParticipantDeviceEventPrivate, type, + time, conferenceAddress, participantAddress ) { @@ -55,6 +57,7 @@ ConferenceParticipantDeviceEvent::ConferenceParticipantDeviceEvent ( ConferenceParticipantDeviceEvent::ConferenceParticipantDeviceEvent (const ConferenceParticipantDeviceEvent &src) : ConferenceParticipantDeviceEvent( src.getType(), + src.getTime(), src.getConferenceAddress(), src.getParticipantAddress(), src.getGruuAddress() diff --git a/src/event-log/conference-participant-device-event.h b/src/event-log/conference-participant-device-event.h index b30f86903..4fcf4fa8d 100644 --- a/src/event-log/conference-participant-device-event.h +++ b/src/event-log/conference-participant-device-event.h @@ -32,6 +32,7 @@ class LINPHONE_PUBLIC ConferenceParticipantDeviceEvent : public ConferencePartic public: ConferenceParticipantDeviceEvent ( Type type, + const std::time_t &time, const Address &conferenceAddress, const Address &participantAddress, const Address &gruuAddress diff --git a/src/event-log/conference-participant-event.cpp b/src/event-log/conference-participant-event.cpp index 00f591b4e..e58b668a2 100644 --- a/src/event-log/conference-participant-event.cpp +++ b/src/event-log/conference-participant-event.cpp @@ -29,9 +29,10 @@ LINPHONE_BEGIN_NAMESPACE ConferenceParticipantEvent::ConferenceParticipantEvent ( Type type, + const time_t &time, const Address &conferenceAddress, const Address &participantAddress -) : ConferenceEvent(*new ConferenceParticipantEventPrivate, type, conferenceAddress) { +) : ConferenceEvent(*new ConferenceParticipantEventPrivate, type, time, conferenceAddress) { L_D(); L_ASSERT( type == Type::ConferenceParticipantAdded || @@ -42,15 +43,22 @@ ConferenceParticipantEvent::ConferenceParticipantEvent ( d->participantAddress = participantAddress; } -ConferenceParticipantEvent::ConferenceParticipantEvent (const ConferenceParticipantEvent &src) : - ConferenceParticipantEvent(src.getType(), src.getConferenceAddress(), src.getParticipantAddress()) {} +ConferenceParticipantEvent::ConferenceParticipantEvent ( + const ConferenceParticipantEvent &src +) : ConferenceParticipantEvent( + src.getType(), + src.getTime(), + src.getConferenceAddress(), + src.getParticipantAddress() +) {} ConferenceParticipantEvent::ConferenceParticipantEvent ( ConferenceParticipantEventPrivate &p, Type type, + const time_t &time, const Address &conferenceAddress, const Address &participantAddress -) : ConferenceEvent(p, type, conferenceAddress) { +) : ConferenceEvent(p, type, time, conferenceAddress) { L_D(); d->participantAddress = participantAddress; } diff --git a/src/event-log/conference-participant-event.h b/src/event-log/conference-participant-event.h index 97f7e2eb0..69b5416db 100644 --- a/src/event-log/conference-participant-event.h +++ b/src/event-log/conference-participant-event.h @@ -32,6 +32,7 @@ class LINPHONE_PUBLIC ConferenceParticipantEvent : public ConferenceEvent { public: ConferenceParticipantEvent ( Type type, + const std::time_t &time, const Address &conferenceAddress, const Address &participantAddress ); @@ -45,6 +46,7 @@ protected: ConferenceParticipantEvent ( ConferenceParticipantEventPrivate &p, Type type, + const std::time_t &time, const Address &conferenceAddress, const Address &participantAddress ); diff --git a/src/event-log/conference-subject-event.cpp b/src/event-log/conference-subject-event.cpp index 2cb6c9889..492f6bcf4 100644 --- a/src/event-log/conference-subject-event.cpp +++ b/src/event-log/conference-subject-event.cpp @@ -33,14 +33,17 @@ public: // ----------------------------------------------------------------------------- -ConferenceSubjectEvent::ConferenceSubjectEvent (const Address &address, const string &subject) : - ConferenceEvent(*new ConferenceSubjectEventPrivate, Type::ConferenceSubjectChanged, address) { +ConferenceSubjectEvent::ConferenceSubjectEvent ( + const time_t &time, + const Address &address, + const string &subject +) : ConferenceEvent(*new ConferenceSubjectEventPrivate, Type::ConferenceSubjectChanged, time, address) { L_D(); d->subject = subject; } ConferenceSubjectEvent::ConferenceSubjectEvent (const ConferenceSubjectEvent &src) : - ConferenceSubjectEvent(src.getConferenceAddress(), src.getSubject()) {} + ConferenceSubjectEvent(src.getTime(), src.getConferenceAddress(), src.getSubject()) {} ConferenceSubjectEvent &ConferenceSubjectEvent::operator= (const ConferenceSubjectEvent &src) { L_D(); diff --git a/src/event-log/conference-subject-event.h b/src/event-log/conference-subject-event.h index efb4e49f4..a145b3fbd 100644 --- a/src/event-log/conference-subject-event.h +++ b/src/event-log/conference-subject-event.h @@ -30,7 +30,7 @@ class ConferenceSubjectEventPrivate; class LINPHONE_PUBLIC ConferenceSubjectEvent : public ConferenceEvent { public: - ConferenceSubjectEvent (const Address &conferenceAddress, const std::string &subject); + ConferenceSubjectEvent (const std::time_t &time, const Address &conferenceAddress, const std::string &subject); ConferenceSubjectEvent (const ConferenceSubjectEvent &src); ConferenceSubjectEvent &operator= (const ConferenceSubjectEvent &src); diff --git a/src/event-log/event-log-p.h b/src/event-log/event-log-p.h index 7e7a7788b..5732a56cc 100644 --- a/src/event-log/event-log-p.h +++ b/src/event-log/event-log-p.h @@ -29,10 +29,11 @@ LINPHONE_BEGIN_NAMESPACE class EventLogPrivate : public ClonableObjectPrivate { public: - long id = -1; + long storageId = -1; private: EventLog::Type type = EventLog::Type::None; + std::time_t time = -1; L_DECLARE_PUBLIC(EventLog); }; diff --git a/src/event-log/event-log.cpp b/src/event-log/event-log.cpp index 25b73953c..490334426 100644 --- a/src/event-log/event-log.cpp +++ b/src/event-log/event-log.cpp @@ -27,9 +27,10 @@ EventLog::EventLog () : ClonableObject(*new EventLogPrivate) {} EventLog::EventLog (const EventLog &) : ClonableObject(*new EventLogPrivate) {} -EventLog::EventLog (EventLogPrivate &p, Type type) : ClonableObject(*new EventLogPrivate) { +EventLog::EventLog (EventLogPrivate &p, Type type, const time_t &time) : ClonableObject(*new EventLogPrivate) { L_D(); d->type = type; + d->time = time; } EventLog &EventLog::operator= (const EventLog &src) { diff --git a/src/event-log/event-log.h b/src/event-log/event-log.h index 057c141e6..4d3cba931 100644 --- a/src/event-log/event-log.h +++ b/src/event-log/event-log.h @@ -20,6 +20,8 @@ #ifndef _EVENT_LOG_H_ #define _EVENT_LOG_H_ +#include + #include "linphone/enums/event-log-enums.h" #include "linphone/utils/enum-generator.h" @@ -43,9 +45,10 @@ public: EventLog &operator= (const EventLog &src); Type getType () const; + std::time_t getTime () const; protected: - EventLog (EventLogPrivate &p, Type type); + EventLog (EventLogPrivate &p, Type type, const std::time_t &time); private: L_DECLARE_PRIVATE(EventLog);