diff --git a/src/db/main-db-p.h b/src/db/main-db-p.h index 882ac9dff..464cfa0c7 100644 --- a/src/db/main-db-p.h +++ b/src/db/main-db-p.h @@ -68,6 +68,7 @@ private: // --------------------------------------------------------------------------- long insertEvent (const EventLog &eventLog); + long insertCallEvent (const EventLog &eventLog); long insertMessageEvent (const EventLog &eventLog); long insertConferenceEvent (const EventLog &eventLog); long insertConferenceParticipantEvent (const EventLog &eventLog); diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index e639465f1..6ad867efe 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -244,6 +244,11 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} return insertEvent(eventLog.getType(), Utils::getLongAsTm(eventLog.getTime())); } + long MainDbPrivate::insertCallEvent (const EventLog &eventLog) { + // TODO. + return 0; + } + long MainDbPrivate::insertMessageEvent (const EventLog &eventLog) { // TODO. return 0; @@ -251,31 +256,49 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} long MainDbPrivate::insertConferenceEvent (const EventLog &eventLog) { long eventId = insertEvent(eventLog); + long chatRoomId = insertSipAddress( + static_cast(eventLog).getConferenceAddress().asString() + ); + soci::session *session = dbSession.getBackendSession(); *session << "INSERT INTO conference_event (event_id, chat_room_id)" - " VALUES (:eventId, (SELECT id FROM sip_address WHERE value = :conferenceAddress))", - soci::use(eventId), soci::use(static_cast(eventLog).getConferenceAddress().asString()); + " VALUES (:eventId, :chatRoomId)", soci::use(eventId), soci::use(chatRoomId); return eventId; } long MainDbPrivate::insertConferenceParticipantEvent (const EventLog &eventLog) { long eventId = insertConferenceEvent(eventLog); + long participantAddressId = insertSipAddress( + static_cast(eventLog).getParticipantAddress().asString() + ); + soci::session *session = dbSession.getBackendSession(); - *session << "INSERT INTO conference_participant_event (conference_event_id, chat_room_id)" - " VALUES (:eventId, (SELECT id FROM sip_address WHERE value = :participantAddress))", - soci::use(eventId), - soci::use(static_cast(eventLog).getParticipantAddress().asStringUriOnly()); + *session << "INSERT INTO conference_participant_event (conference_event_id, participant_address_id)" + " VALUES (:eventId, :participantAddressId)", soci::use(eventId), soci::use(participantAddressId); return eventId; } long MainDbPrivate::insertConferenceParticipantDeviceEvent (const EventLog &eventLog) { - // TODO. - return 0; + long eventId = insertConferenceParticipantEvent(eventLog); + long gruuAddressId = insertSipAddress( + static_cast(eventLog).getGruuAddress().asString() + ); + + soci::session *session = dbSession.getBackendSession(); + *session << "INSERT INTO conference_participant_device_event (conference_participant_event_id, gruu_address_id)" + " VALUES (:eventId, :gruuAddressId)", soci::use(eventId), soci::use(gruuAddressId); + return eventId; } long MainDbPrivate::insertConferenceSubjectEvent (const EventLog &eventLog) { - // TODO. - return 0; + long eventId = insertConferenceEvent(eventLog); + + soci::session *session = dbSession.getBackendSession(); + *session << "INSERT INTO conference_subject_event (conference_event_id, subject)" + " VALUES (:eventId, :subject)", soci::use(eventId), soci::use( + static_cast(eventLog).getSubject() + ); + return eventId; } // ----------------------------------------------------------------------------- @@ -533,7 +556,12 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} return false; } - // TODO. + bool soFarSoGood = false; + + L_BEGIN_LOG_EXCEPTION + + soci::transaction tr(*d->dbSession.getBackendSession()); + switch (eventLog.getType()) { case EventLog::Type::None: return false; @@ -544,7 +572,8 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} case EventLog::Type::CallStart: case EventLog::Type::CallEnd: - return false; // TODO. + d->insertCallEvent(eventLog); + break; case EventLog::Type::ConferenceCreated: case EventLog::Type::ConferenceDestroyed: @@ -568,7 +597,13 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} break; } - return true; + tr.commit(); + + soFarSoGood = true; + + L_END_LOG_EXCEPTION + + return soFarSoGood; } bool MainDb::deleteEvent (const EventLog &eventLog) { diff --git a/src/event-log/call-event.cpp b/src/event-log/call-event.cpp index b434bbff2..6f7a50173 100644 --- a/src/event-log/call-event.cpp +++ b/src/event-log/call-event.cpp @@ -33,7 +33,7 @@ public: // ----------------------------------------------------------------------------- -CallEvent::CallEvent (Type type, const time_t &time, const shared_ptr &call) : +CallEvent::CallEvent (Type type, time_t time, const shared_ptr &call) : EventLog(*new CallEventPrivate, type, time) { L_D(); L_ASSERT(call); diff --git a/src/event-log/call-event.h b/src/event-log/call-event.h index 5bc348f47..532da7805 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::time_t &time, const std::shared_ptr &message); + CallEvent (Type type, 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 e6a796d93..6c1e57419 100644 --- a/src/event-log/chat-message-event.cpp +++ b/src/event-log/chat-message-event.cpp @@ -34,7 +34,7 @@ public: // ----------------------------------------------------------------------------- ChatMessageEvent::ChatMessageEvent ( - const time_t &time, + time_t time, const shared_ptr &chatMessage ) : EventLog(*new ChatMessageEventPrivate, EventLog::Type::ChatMessage, time) { L_D(); diff --git a/src/event-log/chat-message-event.h b/src/event-log/chat-message-event.h index a9a3c7e76..bbe95baf8 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::time_t &time, const std::shared_ptr &chatMessage); + ChatMessageEvent (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 50311782b..c11c94428 100644 --- a/src/event-log/conference-event.cpp +++ b/src/event-log/conference-event.cpp @@ -26,7 +26,7 @@ using namespace std; LINPHONE_BEGIN_NAMESPACE -ConferenceEvent::ConferenceEvent (Type type, const time_t &time, const Address &conferenceAddress) : +ConferenceEvent::ConferenceEvent (Type type, time_t time, const Address &conferenceAddress) : EventLog(*new ConferenceEventPrivate, type, time) { L_D(); L_ASSERT(type == Type::ConferenceCreated || type == Type::ConferenceDestroyed); @@ -39,7 +39,7 @@ ConferenceEvent::ConferenceEvent (const ConferenceEvent &src) : ConferenceEvent::ConferenceEvent ( ConferenceEventPrivate &p, Type type, - const time_t &time, + time_t time, const Address &conferenceAddress ) : EventLog(p, type, time) { L_D(); diff --git a/src/event-log/conference-event.h b/src/event-log/conference-event.h index dbd2391ab..b2d791f2b 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 std::time_t &time, const Address &conferenceAddress); + ConferenceEvent (Type type, 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 std::time_t &time, const Address &conferenceAddress); + ConferenceEvent (ConferenceEventPrivate &p, Type type, 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 fa0334f89..fd090f1df 100644 --- a/src/event-log/conference-participant-device-event.cpp +++ b/src/event-log/conference-participant-device-event.cpp @@ -35,7 +35,7 @@ public: ConferenceParticipantDeviceEvent::ConferenceParticipantDeviceEvent ( Type type, - const time_t &time, + time_t time, const Address &conferenceAddress, const Address &participantAddress, const Address &gruuAddress diff --git a/src/event-log/conference-participant-device-event.h b/src/event-log/conference-participant-device-event.h index 4fcf4fa8d..d70d08549 100644 --- a/src/event-log/conference-participant-device-event.h +++ b/src/event-log/conference-participant-device-event.h @@ -32,7 +32,7 @@ class LINPHONE_PUBLIC ConferenceParticipantDeviceEvent : public ConferencePartic public: ConferenceParticipantDeviceEvent ( Type type, - const std::time_t &time, + 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 e58b668a2..3f6e560fd 100644 --- a/src/event-log/conference-participant-event.cpp +++ b/src/event-log/conference-participant-event.cpp @@ -29,7 +29,7 @@ LINPHONE_BEGIN_NAMESPACE ConferenceParticipantEvent::ConferenceParticipantEvent ( Type type, - const time_t &time, + time_t time, const Address &conferenceAddress, const Address &participantAddress ) : ConferenceEvent(*new ConferenceParticipantEventPrivate, type, time, conferenceAddress) { @@ -55,7 +55,7 @@ ConferenceParticipantEvent::ConferenceParticipantEvent ( ConferenceParticipantEvent::ConferenceParticipantEvent ( ConferenceParticipantEventPrivate &p, Type type, - const time_t &time, + time_t time, const Address &conferenceAddress, const Address &participantAddress ) : ConferenceEvent(p, type, time, conferenceAddress) { diff --git a/src/event-log/conference-participant-event.h b/src/event-log/conference-participant-event.h index 69b5416db..5b69d84cb 100644 --- a/src/event-log/conference-participant-event.h +++ b/src/event-log/conference-participant-event.h @@ -32,7 +32,7 @@ class LINPHONE_PUBLIC ConferenceParticipantEvent : public ConferenceEvent { public: ConferenceParticipantEvent ( Type type, - const std::time_t &time, + std::time_t time, const Address &conferenceAddress, const Address &participantAddress ); @@ -46,7 +46,7 @@ protected: ConferenceParticipantEvent ( ConferenceParticipantEventPrivate &p, Type type, - const std::time_t &time, + 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 492f6bcf4..dc1073506 100644 --- a/src/event-log/conference-subject-event.cpp +++ b/src/event-log/conference-subject-event.cpp @@ -34,7 +34,7 @@ public: // ----------------------------------------------------------------------------- ConferenceSubjectEvent::ConferenceSubjectEvent ( - const time_t &time, + time_t time, const Address &address, const string &subject ) : ConferenceEvent(*new ConferenceSubjectEventPrivate, Type::ConferenceSubjectChanged, time, address) { diff --git a/src/event-log/conference-subject-event.h b/src/event-log/conference-subject-event.h index a145b3fbd..144fb8e48 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 std::time_t &time, const Address &conferenceAddress, const std::string &subject); + ConferenceSubjectEvent (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.cpp b/src/event-log/event-log.cpp index 490334426..cdb2281bb 100644 --- a/src/event-log/event-log.cpp +++ b/src/event-log/event-log.cpp @@ -27,7 +27,7 @@ EventLog::EventLog () : ClonableObject(*new EventLogPrivate) {} EventLog::EventLog (const EventLog &) : ClonableObject(*new EventLogPrivate) {} -EventLog::EventLog (EventLogPrivate &p, Type type, const time_t &time) : ClonableObject(*new EventLogPrivate) { +EventLog::EventLog (EventLogPrivate &p, Type type, time_t time) : ClonableObject(*new EventLogPrivate) { L_D(); d->type = type; d->time = time; @@ -45,4 +45,9 @@ EventLog::Type EventLog::getType () const { return d->type; } +std::time_t EventLog::getTime () const { + L_D(); + return d->time; +} + LINPHONE_END_NAMESPACE diff --git a/src/event-log/event-log.h b/src/event-log/event-log.h index 4d3cba931..e5f0d682a 100644 --- a/src/event-log/event-log.h +++ b/src/event-log/event-log.h @@ -48,7 +48,7 @@ public: std::time_t getTime () const; protected: - EventLog (EventLogPrivate &p, Type type, const std::time_t &time); + EventLog (EventLogPrivate &p, Type type, std::time_t time); private: L_DECLARE_PRIVATE(EventLog);