summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-30 16:39:05 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-01-30 16:39:05 +0100
commit28e67be84c418cb661e7c32f2326d0e665320a1e (patch)
treed2a39540fd4d8aebaec9489ce1e3ebc1c70c7ecc /common
parent74d357f533b49b0d1eeb72606303cfd8a16fb20e (diff)
downloadsink-28e67be84c418cb661e7c32f2326d0e665320a1e.tar.gz
sink-28e67be84c418cb661e7c32f2326d0e665320a1e.zip
One central place to generate uids
Diffstat (limited to 'common')
-rw-r--r--common/CMakeLists.txt1
-rw-r--r--common/domain/applicationdomaintype.cpp5
-rw-r--r--common/domain/applicationdomaintype.h1
-rw-r--r--common/mail/threadindexer.cpp3
-rw-r--r--common/pipeline.cpp1
-rw-r--r--common/resourcecontrol.cpp6
-rw-r--r--common/storage_common.cpp4
-rw-r--r--common/store.cpp4
-rw-r--r--common/synchronizer.cpp3
-rw-r--r--common/synchronizerstore.cpp1
-rw-r--r--common/utils.cpp25
-rw-r--r--common/utils.h25
12 files changed, 65 insertions, 14 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index b90ab6a..ec83f6f 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -79,6 +79,7 @@ set(command_SRCS
79 commandprocessor.cpp 79 commandprocessor.cpp
80 inspector.cpp 80 inspector.cpp
81 propertyparser.cpp 81 propertyparser.cpp
82 utils.cpp
82 ${storage_SRCS}) 83 ${storage_SRCS})
83 84
84add_library(${PROJECT_NAME} SHARED ${command_SRCS}) 85add_library(${PROJECT_NAME} SHARED ${command_SRCS})
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp
index 5cc89b3..c1ac7e8 100644
--- a/common/domain/applicationdomaintype.cpp
+++ b/common/domain/applicationdomaintype.cpp
@@ -23,6 +23,7 @@
23#include "definitions.h" 23#include "definitions.h"
24#include "propertyregistry.h" 24#include "propertyregistry.h"
25#include "storage.h" //for generateUid() 25#include "storage.h" //for generateUid()
26#include "utils.h" //for generateUid()
26#include <QFile> 27#include <QFile>
27 28
28QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDomain::Mail::Contact &c) 29QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDomain::Mail::Contact &c)
@@ -145,7 +146,7 @@ void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::Applicatio
145 const auto value = buffer.getProperty(property); 146 const auto value = buffer.getProperty(property);
146 if (copyBlobs && value.canConvert<BLOB>()) { 147 if (copyBlobs && value.canConvert<BLOB>()) {
147 const auto oldPath = value.value<BLOB>().value; 148 const auto oldPath = value.value<BLOB>().value;
148 const auto newPath = Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); 149 const auto newPath = Sink::temporaryFileLocation() + "/" + createUuid();
149 if (!QFile::copy(oldPath, newPath)) { 150 if (!QFile::copy(oldPath, newPath)) {
150 SinkWarning() << "Failed to copy file from: " << oldPath << "to: " << newPath; 151 SinkWarning() << "Failed to copy file from: " << oldPath << "to: " << newPath;
151 } 152 }
@@ -257,7 +258,7 @@ QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const
257 258
258void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteArray &value) 259void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteArray &value)
259{ 260{
260 const auto path = Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); 261 const auto path = Sink::temporaryFileLocation() + "/" + createUuid();
261 QFile file(path); 262 QFile file(path);
262 if (!file.open(QIODevice::WriteOnly)) { 263 if (!file.open(QIODevice::WriteOnly)) {
263 SinkError() << "Failed to open the file for writing: " << file.errorString() << path << " For property " << key; 264 SinkError() << "Failed to open the file for writing: " << file.errorString() << path << " For property " << key;
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index dc4cbe1..77754c1 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -25,7 +25,6 @@
25#include <QByteArray> 25#include <QByteArray>
26#include <QDateTime> 26#include <QDateTime>
27#include <QDebug> 27#include <QDebug>
28#include <QUuid>
29#include "bufferadaptor.h" 28#include "bufferadaptor.h"
30 29
31#define SINK_ENTITY(TYPE, LOWERCASENAME) \ 30#define SINK_ENTITY(TYPE, LOWERCASENAME) \
diff --git a/common/mail/threadindexer.cpp b/common/mail/threadindexer.cpp
index 68f7af7..2e6a6e7 100644
--- a/common/mail/threadindexer.cpp
+++ b/common/mail/threadindexer.cpp
@@ -20,6 +20,7 @@
20 20
21#include "typeindex.h" 21#include "typeindex.h"
22#include "log.h" 22#include "log.h"
23#include "utils.h"
23 24
24using namespace Sink; 25using namespace Sink;
25using namespace Sink::ApplicationDomain; 26using namespace Sink::ApplicationDomain;
@@ -76,7 +77,7 @@ void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const App
76 SinkTrace() << "Found parent: " << thread; 77 SinkTrace() << "Found parent: " << thread;
77 } 78 }
78 if (thread.isEmpty()) { 79 if (thread.isEmpty()) {
79 thread << QUuid::createUuid().toByteArray(); 80 thread << Sink::createUuid();
80 SinkTrace() << "Created a new thread: " << thread; 81 SinkTrace() << "Created a new thread: " << thread;
81 } 82 }
82 83
diff --git a/common/pipeline.cpp b/common/pipeline.cpp
index efe358b..4e55e76 100644
--- a/common/pipeline.cpp
+++ b/common/pipeline.cpp
@@ -23,7 +23,6 @@
23 23
24#include <QByteArray> 24#include <QByteArray>
25#include <QVector> 25#include <QVector>
26#include <QUuid>
27#include <QDebug> 26#include <QDebug>
28#include <QTime> 27#include <QTime>
29#include "entity_generated.h" 28#include "entity_generated.h"
diff --git a/common/resourcecontrol.cpp b/common/resourcecontrol.cpp
index a69b7fa..678e6c0 100644
--- a/common/resourcecontrol.cpp
+++ b/common/resourcecontrol.cpp
@@ -21,7 +21,6 @@
21#include "resourcecontrol.h" 21#include "resourcecontrol.h"
22 22
23#include <QTime> 23#include <QTime>
24#include <QUuid>
25#include <functional> 24#include <functional>
26 25
27#include "resourceaccess.h" 26#include "resourceaccess.h"
@@ -29,6 +28,7 @@
29#include "commands.h" 28#include "commands.h"
30#include "log.h" 29#include "log.h"
31#include "notifier.h" 30#include "notifier.h"
31#include "utils.h"
32 32
33namespace Sink { 33namespace Sink {
34 34
@@ -96,7 +96,7 @@ KAsync::Job<void> ResourceControl::flush(Flush::FlushType type, const QByteArray
96{ 96{
97 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resourceIdentifier, ResourceConfig::getResourceType(resourceIdentifier)); 97 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resourceIdentifier, ResourceConfig::getResourceType(resourceIdentifier));
98 auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess); 98 auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess);
99 auto id = QUuid::createUuid().toByteArray(); 99 auto id = createUuid();
100 return KAsync::start<void>([=](KAsync::Future<void> &future) { 100 return KAsync::start<void>([=](KAsync::Future<void> &future) {
101 SinkTrace() << "Waiting for flush completion notification " << id; 101 SinkTrace() << "Waiting for flush completion notification " << id;
102 notifier->registerHandler([&future, id](const Notification &notification) { 102 notifier->registerHandler([&future, id](const Notification &notification) {
@@ -140,7 +140,7 @@ KAsync::Job<void> ResourceControl::inspect(const Inspection &inspectionCommand)
140 auto resourceIdentifier = inspectionCommand.resourceIdentifier; 140 auto resourceIdentifier = inspectionCommand.resourceIdentifier;
141 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resourceIdentifier, ResourceConfig::getResourceType(resourceIdentifier)); 141 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resourceIdentifier, ResourceConfig::getResourceType(resourceIdentifier));
142 auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess); 142 auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess);
143 auto id = QUuid::createUuid().toByteArray(); 143 auto id = createUuid();
144 return KAsync::start<void>([=](KAsync::Future<void> &future) { 144 return KAsync::start<void>([=](KAsync::Future<void> &future) {
145 notifier->registerHandler([&future, id](const Notification &notification) { 145 notifier->registerHandler([&future, id](const Notification &notification) {
146 if (notification.id == id) { 146 if (notification.id == id) {
diff --git a/common/storage_common.cpp b/common/storage_common.cpp
index 830eff2..78d4c84 100644
--- a/common/storage_common.cpp
+++ b/common/storage_common.cpp
@@ -22,7 +22,7 @@
22#include "storage.h" 22#include "storage.h"
23 23
24#include "log.h" 24#include "log.h"
25#include <QUuid> 25#include "utils.h"
26 26
27QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error) 27QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error)
28{ 28{
@@ -212,7 +212,7 @@ qint64 DataStore::revisionFromKey(const QByteArray &key)
212 212
213QByteArray DataStore::generateUid() 213QByteArray DataStore::generateUid()
214{ 214{
215 return QUuid::createUuid().toByteArray(); 215 return createUuid();
216} 216}
217 217
218DataStore::NamedDatabase DataStore::mainDatabase(const DataStore::Transaction &t, const QByteArray &type) 218DataStore::NamedDatabase DataStore::mainDatabase(const DataStore::Transaction &t, const QByteArray &type)
diff --git a/common/store.cpp b/common/store.cpp
index 2fa62d6..a2204fc 100644
--- a/common/store.cpp
+++ b/common/store.cpp
@@ -22,7 +22,6 @@
22 22
23#include <QTime> 23#include <QTime>
24#include <QAbstractItemModel> 24#include <QAbstractItemModel>
25#include <QUuid>
26#include <functional> 25#include <functional>
27#include <memory> 26#include <memory>
28 27
@@ -35,6 +34,7 @@
35#include "modelresult.h" 34#include "modelresult.h"
36#include "storage.h" 35#include "storage.h"
37#include "log.h" 36#include "log.h"
37#include "utils.h"
38 38
39#define ASSERT_ENUMS_MATCH(A, B) Q_STATIC_ASSERT_X(static_cast<int>(A) == static_cast<int>(B), "The enum values must match"); 39#define ASSERT_ENUMS_MATCH(A, B) Q_STATIC_ASSERT_X(static_cast<int>(A) == static_cast<int>(B), "The enum values must match");
40 40
@@ -73,7 +73,7 @@ QString Store::storageLocation()
73 73
74QString Store::getTemporaryFilePath() 74QString Store::getTemporaryFilePath()
75{ 75{
76 return Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); 76 return Sink::temporaryFileLocation() + "/" + createUuid();
77} 77}
78 78
79 79
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp
index 4a0ac46..b8de1ed 100644
--- a/common/synchronizer.cpp
+++ b/common/synchronizer.cpp
@@ -29,6 +29,7 @@
29#include "deleteentity_generated.h" 29#include "deleteentity_generated.h"
30#include "flush_generated.h" 30#include "flush_generated.h"
31#include "notification_generated.h" 31#include "notification_generated.h"
32#include "utils.h"
32 33
33using namespace Sink; 34using namespace Sink;
34 35
@@ -382,7 +383,7 @@ KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request)
382 modifiedRequest.options = SyncRequest::NoOptions; 383 modifiedRequest.options = SyncRequest::NoOptions;
383 //Normally we won't have a requestId here 384 //Normally we won't have a requestId here
384 if (modifiedRequest.requestId.isEmpty()) { 385 if (modifiedRequest.requestId.isEmpty()) {
385 modifiedRequest.requestId = QUuid::createUuid().toByteArray(); 386 modifiedRequest.requestId = createUuid();
386 } 387 }
387 SinkTraceCtx(mLogCtx) << "Enqueuing flush request " << modifiedRequest.requestId; 388 SinkTraceCtx(mLogCtx) << "Enqueuing flush request " << modifiedRequest.requestId;
388 389
diff --git a/common/synchronizerstore.cpp b/common/synchronizerstore.cpp
index ee33018..0dd2846 100644
--- a/common/synchronizerstore.cpp
+++ b/common/synchronizerstore.cpp
@@ -19,7 +19,6 @@
19 */ 19 */
20#include "synchronizerstore.h" 20#include "synchronizerstore.h"
21 21
22#include <QUuid>
23#include "index.h" 22#include "index.h"
24#include "log.h" 23#include "log.h"
25 24
diff --git a/common/utils.cpp b/common/utils.cpp
new file mode 100644
index 0000000..3c54db4
--- /dev/null
+++ b/common/utils.cpp
@@ -0,0 +1,25 @@
1/*
2 Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#include "utils.h"
20#include <QUuid>
21
22QByteArray Sink::createUuid()
23{
24 return QUuid::createUuid().toByteArray();
25}
diff --git a/common/utils.h b/common/utils.h
new file mode 100644
index 0000000..253de61
--- /dev/null
+++ b/common/utils.h
@@ -0,0 +1,25 @@
1/*
2 Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#pragma once
20
21#include <QByteArray>
22
23namespace Sink {
24 QByteArray createUuid();
25}