main-db-p.h 6.12 KB
Newer Older
Ronan's avatar
Ronan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * main-db-p.h
 * Copyright (C) 2010-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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef _MAIN_DB_P_H_
#define _MAIN_DB_P_H_

#include "abstract/abstract-db-p.h"
#include "event-log/event-log.h"
#include "main-db.h"

// =============================================================================

29 30 31 32
namespace soci {
	class row;
}

Ronan's avatar
Ronan committed
33 34 35 36 37
LINPHONE_BEGIN_NAMESPACE

class Content;

class MainDbPrivate : public AbstractDbPrivate {
38
public:
Ronan's avatar
Ronan committed
39
	mutable std::unordered_map<long long, std::weak_ptr<EventLog>> storageIdToEvent;
40
	mutable std::unordered_map<long long, std::weak_ptr<ChatMessage>> storageIdToChatMessage;
41

Ronan's avatar
Ronan committed
42
private:
43 44 45 46 47 48
	// ---------------------------------------------------------------------------
	// SOCI helpers.
	// ---------------------------------------------------------------------------

	long long resolveId (const soci::row &row, int col) const;

49 50 51 52
	// ---------------------------------------------------------------------------
	// Low level API.
	// ---------------------------------------------------------------------------

53 54 55
	long long insertSipAddress (const std::string &sipAddress);
	void insertContent (long long messageEventId, const Content &content);
	long long insertContentType (const std::string &contentType);
56
	long long insertOrUpdateImportedBasicChatRoom (
57 58
		long long peerSipAddressId,
		long long localSipAddressId,
59
		const tm &creationTime
60
	);
61
	long long insertChatRoom (const std::shared_ptr<AbstractChatRoom> &chatRoom);
62 63
	long long insertChatRoomParticipant (long long chatRoomId, long long participantSipAddressId, bool isAdmin);
	void insertChatRoomParticipantDevice (long long participantId, long long participantDeviceSipAddressId);
64
	void insertChatMessageParticipant (long long messageEventId, long long sipAddressId, int state);
Ronan's avatar
Ronan committed
65

66 67 68
	long long selectSipAddressId (const std::string &sipAddress) const;
	long long selectChatRoomId (long long peerSipAddressId, long long localSipAddressId) const;
	long long selectChatRoomId (const ChatRoomId &chatRoomId) const;
69
	long long selectChatRoomParticipantId (long long chatRoomId, long long participantSipAddressId) const;
70

71
	void deleteContents (long long messageEventId);
72
	void deleteChatRoomParticipant (long long chatRoomId, long long participantSipAddressId);
73
	void deleteChatRoomParticipantDevice (long long participantId, long long participantDeviceSipAddressId);
74

75 76 77
	// ---------------------------------------------------------------------------
	// Events API.
	// ---------------------------------------------------------------------------
78

79
	std::shared_ptr<EventLog> selectGenericConferenceEvent (
80
		long long eventId,
81
		EventLog::Type type,
82
		time_t creationTime,
83
		const ChatRoomId &chatRoomId
84 85 86
	) const;

	std::shared_ptr<EventLog> selectConferenceEvent (
87
		long long eventId,
88
		EventLog::Type type,
89
		time_t creationTime,
90
		const ChatRoomId &chatRoomId
91 92 93
	) const;

	std::shared_ptr<EventLog> selectConferenceCallEvent (
94
		long long eventId,
95
		EventLog::Type type,
96
		time_t creationTime,
97
		const ChatRoomId &chatRoomId
98 99 100
	) const;

	std::shared_ptr<EventLog> selectConferenceChatMessageEvent (
101
		long long eventId,
102
		EventLog::Type type,
103
		time_t creationTime,
104
		const ChatRoomId &chatRoomId
105 106 107
	) const;

	std::shared_ptr<EventLog> selectConferenceParticipantEvent (
108
		long long eventId,
109
		EventLog::Type type,
110
		time_t creationTime,
111
		const ChatRoomId &chatRoomId
112 113 114
	) const;

	std::shared_ptr<EventLog> selectConferenceParticipantDeviceEvent (
115
		long long eventId,
116
		EventLog::Type type,
117
		time_t creationTime,
118
		const ChatRoomId &chatRoomId
119 120 121
	) const;

	std::shared_ptr<EventLog> selectConferenceSubjectEvent (
122
		long long eventId,
123
		EventLog::Type type,
124
		time_t creationTime,
125
		const ChatRoomId &chatRoomId
126
	) const;
Ronan's avatar
Ronan committed
127

Ronan's avatar
Ronan committed
128 129 130 131
	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);
132
	void updateConferenceChatMessageEvent(const std::shared_ptr<EventLog> &eventLog);
133
	long long insertConferenceNotifiedEvent (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr);
134
	long long insertConferenceParticipantEvent (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr);
Ronan's avatar
Ronan committed
135 136
	long long insertConferenceParticipantDeviceEvent (const std::shared_ptr<EventLog> &eventLog);
	long long insertConferenceSubjectEvent (const std::shared_ptr<EventLog> &eventLog);
Ronan's avatar
Ronan committed
137

138 139 140 141
	// ---------------------------------------------------------------------------
	// Cache API.
	// ---------------------------------------------------------------------------

142 143 144 145 146 147
	void cache (const std::shared_ptr<EventLog> &eventLog, long long storageId) const;
	void cache (const std::shared_ptr<ChatMessage> &chatMessage, long long storageId) const;

	std::shared_ptr<EventLog> getEventFromCache (long long storageId) const;
	std::shared_ptr<ChatMessage> getChatMessageFromCache (long long storageId) const;

148
	void invalidConferenceEventsFromQuery (const std::string &query, long long chatRoomId);
149

150 151 152 153 154 155 156
	// ---------------------------------------------------------------------------
	// Versions.
	// ---------------------------------------------------------------------------

	unsigned int getModuleVersion (const std::string &name);
	void updateModuleVersion (const std::string &name, unsigned int version);

Ronan's avatar
Ronan committed
157 158 159 160 161 162
	L_DECLARE_PUBLIC(MainDb);
};

LINPHONE_END_NAMESPACE

#endif // ifndef _MAIN_DB_P_H_