Commit 1f3bcb46 authored by Ronan's avatar Ronan
Browse files

feat(event): provide a working message event

parent 6e7ae964
......@@ -37,6 +37,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
event/event.h
event/message-event.h
logger/logger.h
message/message.h
object/clonable-object-p.h
object/clonable-object.h
object/object-p.h
......@@ -59,6 +60,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
event/event.cpp
event/message-event.cpp
logger/logger.cpp
message/message.cpp
object/clonable-object.cpp
object/object.cpp
utils/utils.cpp
......
......@@ -19,7 +19,9 @@
#ifndef _ABSTRACT_DB_P_H_
#define _ABSTRACT_DB_P_H_
#include <soci/soci.h>
#ifdef SOCI_ENABLED
#include <soci/soci.h>
#endif // ifdef SOCI_ENABLED
#include "abstract-db.h"
#include "object/object-p.h"
......
......@@ -33,68 +33,68 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
void EventsDb::init () {
#ifdef SOCI_ENABLED
L_D(EventsDb);
d->session <<
"CREATE TABLE IF NOT EXISTS sip_address ("
" id" + primaryKeyAutoIncrementStr() + ","
" value VARCHAR(255) NOT NULL"
")";
d->session <<
"CREATE TABLE IF NOT EXISTS event ("
" id" + primaryKeyAutoIncrementStr() + ","
" timestamp TIMESTAMP NOT NULL"
")";
d->session <<
"CREATE TABLE IF NOT EXISTS message_status ("
" id" + primaryKeyAutoIncrementStr() + ","
" status VARCHAR(255) NOT NULL"
")";
d->session <<
"CREATE TABLE IF NOT EXISTS message_direction ("
" id" + primaryKeyAutoIncrementStr() + ","
" direction VARCHAR(255) NOT NULL"
")";
d->session <<
"CREATE TABLE IF NOT EXISTS dialog ("
" local_sip_address_id BIGINT UNSIGNED NOT NULL," // Sip address used to communicate.
" remote_sip_address_id BIGINT UNSIGNED NOT NULL," // Server (for conference) or user sip address.
" creation_timestamp TIMESTAMP NOT NULL," // Dialog creation date.
" last_update_timestamp TIMESTAMP NOT NULL," // Last event timestamp (call, message...).
" FOREIGN KEY (local_sip_address_id)"
" REFERENCES sip_address(id)"
" ON DELETE CASCADE,"
" FOREIGN KEY (remote_sip_address_id)"
" REFERENCES sip_address(id)"
" ON DELETE CASCADE"
")";
d->session <<
"CREATE TABLE IF NOT EXISTS message_event ("
" id" + primaryKeyAutoIncrementStr() + ","
" dialog_id BIGINT UNSIGNED NOT NULL,"
" status_id TINYINT UNSIGNED NOT NULL,"
" direction_id TINYINT UNSIGNED NOT NULL,"
" imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3
" content_type VARCHAR(255) NOT NULL,"
" is_secured BOOLEAN NOT NULL,"
" app_data VARCHAR(2048),"
" FOREIGN KEY (dialog_id)"
" REFERENCES dialog(id)"
" ON DELETE CASCADE,"
" FOREIGN KEY (status_id)"
" REFERENCES message_status(id)"
" ON DELETE CASCADE,"
" FOREIGN KEY (direction_id)"
" REFERENCES message_direction(id)"
" ON DELETE CASCADE"
")";
#endif // ifndef SOCI_ENABLED
L_D(EventsDb);
d->session <<
"CREATE TABLE IF NOT EXISTS sip_address ("
" id" + primaryKeyAutoIncrementStr() + ","
" value VARCHAR(255) NOT NULL"
")";
d->session <<
"CREATE TABLE IF NOT EXISTS event ("
" id" + primaryKeyAutoIncrementStr() + ","
" timestamp TIMESTAMP NOT NULL"
")";
d->session <<
"CREATE TABLE IF NOT EXISTS message_status ("
" id" + primaryKeyAutoIncrementStr() + ","
" status VARCHAR(255) NOT NULL"
")";
d->session <<
"CREATE TABLE IF NOT EXISTS message_direction ("
" id" + primaryKeyAutoIncrementStr() + ","
" direction VARCHAR(255) NOT NULL"
")";
d->session <<
"CREATE TABLE IF NOT EXISTS dialog ("
" local_sip_address_id BIGINT UNSIGNED NOT NULL," // Sip address used to communicate.
" remote_sip_address_id BIGINT UNSIGNED NOT NULL," // Server (for conference) or user sip address.
" creation_timestamp TIMESTAMP NOT NULL," // Dialog creation date.
" last_update_timestamp TIMESTAMP NOT NULL," // Last event timestamp (call, message...).
" FOREIGN KEY (local_sip_address_id)"
" REFERENCES sip_address(id)"
" ON DELETE CASCADE,"
" FOREIGN KEY (remote_sip_address_id)"
" REFERENCES sip_address(id)"
" ON DELETE CASCADE"
")";
d->session <<
"CREATE TABLE IF NOT EXISTS message_event ("
" id" + primaryKeyAutoIncrementStr() + ","
" dialog_id BIGINT UNSIGNED NOT NULL,"
" status_id TINYINT UNSIGNED NOT NULL,"
" direction_id TINYINT UNSIGNED NOT NULL,"
" imdn_message_id VARCHAR(255) NOT NULL," // See: https://tools.ietf.org/html/rfc5438#section-6.3
" content_type VARCHAR(255) NOT NULL,"
" is_secured BOOLEAN NOT NULL,"
" app_data VARCHAR(2048),"
" FOREIGN KEY (dialog_id)"
" REFERENCES dialog(id)"
" ON DELETE CASCADE,"
" FOREIGN KEY (status_id)"
" REFERENCES message_status(id)"
" ON DELETE CASCADE,"
" FOREIGN KEY (direction_id)"
" REFERENCES message_direction(id)"
" ON DELETE CASCADE"
")";
#endif // ifndef SOCI_ENABLED
}
LINPHONE_END_NAMESPACE
......@@ -30,7 +30,10 @@ Event::Event (const Event &) : ClonableObject(*new EventPrivate) {
// `src` parameter is useless.
}
Event::Event (EventPrivate &p) : ClonableObject(p) {}
Event::Event (EventPrivate &p, Type type) : ClonableObject(p) {
L_D(Event);
d->type = type;
}
Event::Type Event::getType () const {
L_D(const Event);
......
......@@ -32,8 +32,8 @@ public:
enum Type {
None,
MessageEvent,
FileMessageEvent,
CallEvent
CallStartEvent,
CallEndEvent
};
Event ();
......@@ -43,7 +43,7 @@ public:
Type getType () const;
protected:
Event (EventPrivate &p);
Event (EventPrivate &p, Type type);
private:
L_DECLARE_PRIVATE(Event);
......
......@@ -16,8 +16,34 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "event-p.h"
#include "message/message.h"
#include "message-event.h"
// =============================================================================
// TODO.
using namespace std;
LINPHONE_BEGIN_NAMESPACE
class MessageEventPrivate : public EventPrivate {
public:
shared_ptr<Message> message;
};
// -----------------------------------------------------------------------------
MessageEvent::MessageEvent (const shared_ptr<Message> &message) : Event(*new MessageEventPrivate, Event::MessageEvent) {
L_D(MessageEvent);
d->message = message;
}
MessageEvent::MessageEvent (const MessageEvent &src) : MessageEvent(src.getMessage()) {}
shared_ptr<Message> MessageEvent::getMessage () const {
L_D(const MessageEvent);
return d->message;
}
LINPHONE_END_NAMESPACE
......@@ -19,34 +19,23 @@
#ifndef _MESSAGE_EVENT_H_
#define _MESSAGE_EVENT_H_
#include <list>
#include <string>
#include <memory>
#include "enums.h"
#include "event.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class ErrorInfo;
class Message;
class MessageEventPrivate;
class LINPHONE_PUBLIC MessageEvent : public Event {
public:
typedef std::pair<std::string, std::string> CustomHeader;
MessageEvent (const Message &message);
MessageEvent (const std::shared_ptr<Message> &message);
MessageEvent (const MessageEvent &src);
std::string getText () const;
MessageState getState () const;
MessageDirection getDirection () const;
ErrorInfo getErrorInfo () const;
std::string getImdnMessageId () const;
std::list<CustomHeader> getCustomHeaders () const;
std::shared_ptr<Message> getMessage () const;
private:
L_DECLARE_PRIVATE(MessageEvent);
......
/*
* message.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/>.
*/
/*
* message.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 _MESSAGE_H_
#define _MESSAGE_H_
#include <list>
#include <memory>
#include <string>
#include "enums.h"
#include "object/object.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class Address;
class ChatRoom;
class ErrorInfo;
class MessagePrivate;
class LINPHONE_PUBLIC Message : public Object {
friend class ChatRoom;
public:
std::string getText () const;
/**
* @brief Set a chat message text to be sent by linphone_chat_room_send_message.
*/
int setText (const std::string &text);
/**
* @brief Get the state of the message.
*/
// ChatMessageState getState () const;
/**
* @brief Get if the message was encrypted when transfered.
*/
bool isSecured ();
/**
* @brief Get the time the message was sent.
*/
time_t getTime () const;
std::shared_ptr<ChatRoom> getChatRoom ();
std::string getMessageId () const;
std::string getAppdata () const;
void setAppdata (const std::string &data);
std::shared_ptr<const Address> getPeerAddress () const;
std::shared_ptr<const Address> getFromAddress () const;
void setFromAddress (const std::shared_ptr<const Address> &address);
std::shared_ptr<const Address> getToAddress () const;
void setToAddress (const std::shared_ptr<const Address> &addr);
std::shared_ptr<const Address> getLocalAddress () const;
std::string getCustomHeaderValue (const std::string &headerName);
void addCustomHeader (const std::string &headerName, const std::string &headerValue);
void removeCustomHeader (const std::string &headerName);
std::shared_ptr<const ErrorInfo> getErrorInfo () const;
protected:
Message ();
private:
L_DECLARE_PRIVATE(Message);
L_DISABLE_COPY(Message);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _MESSAGE_H_
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