feat(MainDb): supports conference events insertion

This commit is contained in:
Ronan Abhamon 2017-10-17 14:13:34 +02:00
parent 0369182673
commit e4e40d183f
16 changed files with 72 additions and 31 deletions

View file

@ -68,6 +68,7 @@ private:
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
long insertEvent (const EventLog &eventLog); long insertEvent (const EventLog &eventLog);
long insertCallEvent (const EventLog &eventLog);
long insertMessageEvent (const EventLog &eventLog); long insertMessageEvent (const EventLog &eventLog);
long insertConferenceEvent (const EventLog &eventLog); long insertConferenceEvent (const EventLog &eventLog);
long insertConferenceParticipantEvent (const EventLog &eventLog); long insertConferenceParticipantEvent (const EventLog &eventLog);

View file

@ -244,6 +244,11 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
return insertEvent(eventLog.getType(), Utils::getLongAsTm(eventLog.getTime())); return insertEvent(eventLog.getType(), Utils::getLongAsTm(eventLog.getTime()));
} }
long MainDbPrivate::insertCallEvent (const EventLog &eventLog) {
// TODO.
return 0;
}
long MainDbPrivate::insertMessageEvent (const EventLog &eventLog) { long MainDbPrivate::insertMessageEvent (const EventLog &eventLog) {
// TODO. // TODO.
return 0; return 0;
@ -251,31 +256,49 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
long MainDbPrivate::insertConferenceEvent (const EventLog &eventLog) { long MainDbPrivate::insertConferenceEvent (const EventLog &eventLog) {
long eventId = insertEvent(eventLog); long eventId = insertEvent(eventLog);
long chatRoomId = insertSipAddress(
static_cast<const ConferenceEvent &>(eventLog).getConferenceAddress().asString()
);
soci::session *session = dbSession.getBackendSession<soci::session>(); soci::session *session = dbSession.getBackendSession<soci::session>();
*session << "INSERT INTO conference_event (event_id, chat_room_id)" *session << "INSERT INTO conference_event (event_id, chat_room_id)"
" VALUES (:eventId, (SELECT id FROM sip_address WHERE value = :conferenceAddress))", " VALUES (:eventId, :chatRoomId)", soci::use(eventId), soci::use(chatRoomId);
soci::use(eventId), soci::use(static_cast<const ConferenceEvent &>(eventLog).getConferenceAddress().asString());
return eventId; return eventId;
} }
long MainDbPrivate::insertConferenceParticipantEvent (const EventLog &eventLog) { long MainDbPrivate::insertConferenceParticipantEvent (const EventLog &eventLog) {
long eventId = insertConferenceEvent(eventLog); long eventId = insertConferenceEvent(eventLog);
long participantAddressId = insertSipAddress(
static_cast<const ConferenceParticipantEvent &>(eventLog).getParticipantAddress().asString()
);
soci::session *session = dbSession.getBackendSession<soci::session>(); soci::session *session = dbSession.getBackendSession<soci::session>();
*session << "INSERT INTO conference_participant_event (conference_event_id, chat_room_id)" *session << "INSERT INTO conference_participant_event (conference_event_id, participant_address_id)"
" VALUES (:eventId, (SELECT id FROM sip_address WHERE value = :participantAddress))", " VALUES (:eventId, :participantAddressId)", soci::use(eventId), soci::use(participantAddressId);
soci::use(eventId),
soci::use(static_cast<const ConferenceParticipantEvent &>(eventLog).getParticipantAddress().asStringUriOnly());
return eventId; return eventId;
} }
long MainDbPrivate::insertConferenceParticipantDeviceEvent (const EventLog &eventLog) { long MainDbPrivate::insertConferenceParticipantDeviceEvent (const EventLog &eventLog) {
// TODO. long eventId = insertConferenceParticipantEvent(eventLog);
return 0; long gruuAddressId = insertSipAddress(
static_cast<const ConferenceParticipantDeviceEvent &>(eventLog).getGruuAddress().asString()
);
soci::session *session = dbSession.getBackendSession<soci::session>();
*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) { long MainDbPrivate::insertConferenceSubjectEvent (const EventLog &eventLog) {
// TODO. long eventId = insertConferenceEvent(eventLog);
return 0;
soci::session *session = dbSession.getBackendSession<soci::session>();
*session << "INSERT INTO conference_subject_event (conference_event_id, subject)"
" VALUES (:eventId, :subject)", soci::use(eventId), soci::use(
static_cast<const ConferenceSubjectEvent &>(eventLog).getSubject()
);
return eventId;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -533,7 +556,12 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
return false; return false;
} }
// TODO. bool soFarSoGood = false;
L_BEGIN_LOG_EXCEPTION
soci::transaction tr(*d->dbSession.getBackendSession<soci::session>());
switch (eventLog.getType()) { switch (eventLog.getType()) {
case EventLog::Type::None: case EventLog::Type::None:
return false; return false;
@ -544,7 +572,8 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
case EventLog::Type::CallStart: case EventLog::Type::CallStart:
case EventLog::Type::CallEnd: case EventLog::Type::CallEnd:
return false; // TODO. d->insertCallEvent(eventLog);
break;
case EventLog::Type::ConferenceCreated: case EventLog::Type::ConferenceCreated:
case EventLog::Type::ConferenceDestroyed: case EventLog::Type::ConferenceDestroyed:
@ -568,7 +597,13 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
break; break;
} }
return true; tr.commit();
soFarSoGood = true;
L_END_LOG_EXCEPTION
return soFarSoGood;
} }
bool MainDb::deleteEvent (const EventLog &eventLog) { bool MainDb::deleteEvent (const EventLog &eventLog) {

View file

@ -33,7 +33,7 @@ public:
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
CallEvent::CallEvent (Type type, const time_t &time, const shared_ptr<Call> &call) : CallEvent::CallEvent (Type type, time_t time, const shared_ptr<Call> &call) :
EventLog(*new CallEventPrivate, type, time) { EventLog(*new CallEventPrivate, type, time) {
L_D(); L_D();
L_ASSERT(call); L_ASSERT(call);

View file

@ -33,7 +33,7 @@ class CallEventPrivate;
class LINPHONE_PUBLIC CallEvent : public EventLog { class LINPHONE_PUBLIC CallEvent : public EventLog {
public: public:
CallEvent (Type type, const std::time_t &time, const std::shared_ptr<Call> &message); CallEvent (Type type, std::time_t time, const std::shared_ptr<Call> &message);
CallEvent (const CallEvent &src); CallEvent (const CallEvent &src);
CallEvent &operator= (const CallEvent &src); CallEvent &operator= (const CallEvent &src);

View file

@ -34,7 +34,7 @@ public:
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
ChatMessageEvent::ChatMessageEvent ( ChatMessageEvent::ChatMessageEvent (
const time_t &time, time_t time,
const shared_ptr<ChatMessage> &chatMessage const shared_ptr<ChatMessage> &chatMessage
) : EventLog(*new ChatMessageEventPrivate, EventLog::Type::ChatMessage, time) { ) : EventLog(*new ChatMessageEventPrivate, EventLog::Type::ChatMessage, time) {
L_D(); L_D();

View file

@ -33,7 +33,7 @@ class ChatMessageEventPrivate;
class LINPHONE_PUBLIC ChatMessageEvent : public EventLog { class LINPHONE_PUBLIC ChatMessageEvent : public EventLog {
public: public:
ChatMessageEvent (const std::time_t &time, const std::shared_ptr<ChatMessage> &chatMessage); ChatMessageEvent (std::time_t time, const std::shared_ptr<ChatMessage> &chatMessage);
ChatMessageEvent (const ChatMessageEvent &src); ChatMessageEvent (const ChatMessageEvent &src);
ChatMessageEvent &operator= (const ChatMessageEvent &src); ChatMessageEvent &operator= (const ChatMessageEvent &src);

View file

@ -26,7 +26,7 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE 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) { EventLog(*new ConferenceEventPrivate, type, time) {
L_D(); L_D();
L_ASSERT(type == Type::ConferenceCreated || type == Type::ConferenceDestroyed); L_ASSERT(type == Type::ConferenceCreated || type == Type::ConferenceDestroyed);
@ -39,7 +39,7 @@ ConferenceEvent::ConferenceEvent (const ConferenceEvent &src) :
ConferenceEvent::ConferenceEvent ( ConferenceEvent::ConferenceEvent (
ConferenceEventPrivate &p, ConferenceEventPrivate &p,
Type type, Type type,
const time_t &time, time_t time,
const Address &conferenceAddress const Address &conferenceAddress
) : EventLog(p, type, time) { ) : EventLog(p, type, time) {
L_D(); L_D();

View file

@ -31,7 +31,7 @@ class ConferenceEventPrivate;
class LINPHONE_PUBLIC ConferenceEvent : public EventLog { class LINPHONE_PUBLIC ConferenceEvent : public EventLog {
public: 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 (const ConferenceEvent &src);
ConferenceEvent &operator= (const ConferenceEvent &src); ConferenceEvent &operator= (const ConferenceEvent &src);
@ -39,7 +39,7 @@ public:
const Address &getConferenceAddress () const; const Address &getConferenceAddress () const;
protected: 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: private:
L_DECLARE_PRIVATE(ConferenceEvent); L_DECLARE_PRIVATE(ConferenceEvent);

View file

@ -35,7 +35,7 @@ public:
ConferenceParticipantDeviceEvent::ConferenceParticipantDeviceEvent ( ConferenceParticipantDeviceEvent::ConferenceParticipantDeviceEvent (
Type type, Type type,
const time_t &time, time_t time,
const Address &conferenceAddress, const Address &conferenceAddress,
const Address &participantAddress, const Address &participantAddress,
const Address &gruuAddress const Address &gruuAddress

View file

@ -32,7 +32,7 @@ class LINPHONE_PUBLIC ConferenceParticipantDeviceEvent : public ConferencePartic
public: public:
ConferenceParticipantDeviceEvent ( ConferenceParticipantDeviceEvent (
Type type, Type type,
const std::time_t &time, std::time_t time,
const Address &conferenceAddress, const Address &conferenceAddress,
const Address &participantAddress, const Address &participantAddress,
const Address &gruuAddress const Address &gruuAddress

View file

@ -29,7 +29,7 @@ LINPHONE_BEGIN_NAMESPACE
ConferenceParticipantEvent::ConferenceParticipantEvent ( ConferenceParticipantEvent::ConferenceParticipantEvent (
Type type, Type type,
const time_t &time, time_t time,
const Address &conferenceAddress, const Address &conferenceAddress,
const Address &participantAddress const Address &participantAddress
) : ConferenceEvent(*new ConferenceParticipantEventPrivate, type, time, conferenceAddress) { ) : ConferenceEvent(*new ConferenceParticipantEventPrivate, type, time, conferenceAddress) {
@ -55,7 +55,7 @@ ConferenceParticipantEvent::ConferenceParticipantEvent (
ConferenceParticipantEvent::ConferenceParticipantEvent ( ConferenceParticipantEvent::ConferenceParticipantEvent (
ConferenceParticipantEventPrivate &p, ConferenceParticipantEventPrivate &p,
Type type, Type type,
const time_t &time, time_t time,
const Address &conferenceAddress, const Address &conferenceAddress,
const Address &participantAddress const Address &participantAddress
) : ConferenceEvent(p, type, time, conferenceAddress) { ) : ConferenceEvent(p, type, time, conferenceAddress) {

View file

@ -32,7 +32,7 @@ class LINPHONE_PUBLIC ConferenceParticipantEvent : public ConferenceEvent {
public: public:
ConferenceParticipantEvent ( ConferenceParticipantEvent (
Type type, Type type,
const std::time_t &time, std::time_t time,
const Address &conferenceAddress, const Address &conferenceAddress,
const Address &participantAddress const Address &participantAddress
); );
@ -46,7 +46,7 @@ protected:
ConferenceParticipantEvent ( ConferenceParticipantEvent (
ConferenceParticipantEventPrivate &p, ConferenceParticipantEventPrivate &p,
Type type, Type type,
const std::time_t &time, std::time_t time,
const Address &conferenceAddress, const Address &conferenceAddress,
const Address &participantAddress const Address &participantAddress
); );

View file

@ -34,7 +34,7 @@ public:
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
ConferenceSubjectEvent::ConferenceSubjectEvent ( ConferenceSubjectEvent::ConferenceSubjectEvent (
const time_t &time, time_t time,
const Address &address, const Address &address,
const string &subject const string &subject
) : ConferenceEvent(*new ConferenceSubjectEventPrivate, Type::ConferenceSubjectChanged, time, address) { ) : ConferenceEvent(*new ConferenceSubjectEventPrivate, Type::ConferenceSubjectChanged, time, address) {

View file

@ -30,7 +30,7 @@ class ConferenceSubjectEventPrivate;
class LINPHONE_PUBLIC ConferenceSubjectEvent : public ConferenceEvent { class LINPHONE_PUBLIC ConferenceSubjectEvent : public ConferenceEvent {
public: 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 (const ConferenceSubjectEvent &src);
ConferenceSubjectEvent &operator= (const ConferenceSubjectEvent &src); ConferenceSubjectEvent &operator= (const ConferenceSubjectEvent &src);

View file

@ -27,7 +27,7 @@ EventLog::EventLog () : ClonableObject(*new EventLogPrivate) {}
EventLog::EventLog (const 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(); L_D();
d->type = type; d->type = type;
d->time = time; d->time = time;
@ -45,4 +45,9 @@ EventLog::Type EventLog::getType () const {
return d->type; return d->type;
} }
std::time_t EventLog::getTime () const {
L_D();
return d->time;
}
LINPHONE_END_NAMESPACE LINPHONE_END_NAMESPACE

View file

@ -48,7 +48,7 @@ public:
std::time_t getTime () const; std::time_t getTime () const;
protected: protected:
EventLog (EventLogPrivate &p, Type type, const std::time_t &time); EventLog (EventLogPrivate &p, Type type, std::time_t time);
private: private:
L_DECLARE_PRIVATE(EventLog); L_DECLARE_PRIVATE(EventLog);