From 28e67be84c418cb661e7c32f2326d0e665320a1e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 30 Jan 2018 16:39:05 +0100 Subject: One central place to generate uids --- common/CMakeLists.txt | 1 + common/domain/applicationdomaintype.cpp | 5 +++-- common/domain/applicationdomaintype.h | 1 - common/mail/threadindexer.cpp | 3 ++- common/pipeline.cpp | 1 - common/resourcecontrol.cpp | 6 +++--- common/storage_common.cpp | 4 ++-- common/store.cpp | 4 ++-- common/synchronizer.cpp | 3 ++- common/synchronizerstore.cpp | 1 - common/utils.cpp | 25 +++++++++++++++++++++++++ common/utils.h | 25 +++++++++++++++++++++++++ examples/dummyresource/resourcefactory.cpp | 1 - 13 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 common/utils.cpp create mode 100644 common/utils.h 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 commandprocessor.cpp inspector.cpp propertyparser.cpp + utils.cpp ${storage_SRCS}) add_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 @@ #include "definitions.h" #include "propertyregistry.h" #include "storage.h" //for generateUid() +#include "utils.h" //for generateUid() #include QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDomain::Mail::Contact &c) @@ -145,7 +146,7 @@ void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::Applicatio const auto value = buffer.getProperty(property); if (copyBlobs && value.canConvert()) { const auto oldPath = value.value().value; - const auto newPath = Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); + const auto newPath = Sink::temporaryFileLocation() + "/" + createUuid(); if (!QFile::copy(oldPath, newPath)) { SinkWarning() << "Failed to copy file from: " << oldPath << "to: " << newPath; } @@ -257,7 +258,7 @@ QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteArray &value) { - const auto path = Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); + const auto path = Sink::temporaryFileLocation() + "/" + createUuid(); QFile file(path); if (!file.open(QIODevice::WriteOnly)) { 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 @@ #include #include #include -#include #include "bufferadaptor.h" #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 @@ #include "typeindex.h" #include "log.h" +#include "utils.h" using namespace Sink; using namespace Sink::ApplicationDomain; @@ -76,7 +77,7 @@ void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const App SinkTrace() << "Found parent: " << thread; } if (thread.isEmpty()) { - thread << QUuid::createUuid().toByteArray(); + thread << Sink::createUuid(); SinkTrace() << "Created a new thread: " << thread; } 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 @@ #include #include -#include #include #include #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 @@ #include "resourcecontrol.h" #include -#include #include #include "resourceaccess.h" @@ -29,6 +28,7 @@ #include "commands.h" #include "log.h" #include "notifier.h" +#include "utils.h" namespace Sink { @@ -96,7 +96,7 @@ KAsync::Job ResourceControl::flush(Flush::FlushType type, const QByteArray { auto resourceAccess = ResourceAccessFactory::instance().getAccess(resourceIdentifier, ResourceConfig::getResourceType(resourceIdentifier)); auto notifier = QSharedPointer::create(resourceAccess); - auto id = QUuid::createUuid().toByteArray(); + auto id = createUuid(); return KAsync::start([=](KAsync::Future &future) { SinkTrace() << "Waiting for flush completion notification " << id; notifier->registerHandler([&future, id](const Notification ¬ification) { @@ -140,7 +140,7 @@ KAsync::Job ResourceControl::inspect(const Inspection &inspectionCommand) auto resourceIdentifier = inspectionCommand.resourceIdentifier; auto resourceAccess = ResourceAccessFactory::instance().getAccess(resourceIdentifier, ResourceConfig::getResourceType(resourceIdentifier)); auto notifier = QSharedPointer::create(resourceAccess); - auto id = QUuid::createUuid().toByteArray(); + auto id = createUuid(); return KAsync::start([=](KAsync::Future &future) { notifier->registerHandler([&future, id](const Notification ¬ification) { 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 @@ #include "storage.h" #include "log.h" -#include +#include "utils.h" QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error) { @@ -212,7 +212,7 @@ qint64 DataStore::revisionFromKey(const QByteArray &key) QByteArray DataStore::generateUid() { - return QUuid::createUuid().toByteArray(); + return createUuid(); } DataStore::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 @@ #include #include -#include #include #include @@ -35,6 +34,7 @@ #include "modelresult.h" #include "storage.h" #include "log.h" +#include "utils.h" #define ASSERT_ENUMS_MATCH(A, B) Q_STATIC_ASSERT_X(static_cast(A) == static_cast(B), "The enum values must match"); @@ -73,7 +73,7 @@ QString Store::storageLocation() QString Store::getTemporaryFilePath() { - return Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); + return Sink::temporaryFileLocation() + "/" + createUuid(); } 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 @@ #include "deleteentity_generated.h" #include "flush_generated.h" #include "notification_generated.h" +#include "utils.h" using namespace Sink; @@ -382,7 +383,7 @@ KAsync::Job Synchronizer::processRequest(const SyncRequest &request) modifiedRequest.options = SyncRequest::NoOptions; //Normally we won't have a requestId here if (modifiedRequest.requestId.isEmpty()) { - modifiedRequest.requestId = QUuid::createUuid().toByteArray(); + modifiedRequest.requestId = createUuid(); } SinkTraceCtx(mLogCtx) << "Enqueuing flush request " << modifiedRequest.requestId; 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 @@ */ #include "synchronizerstore.h" -#include #include "index.h" #include "log.h" 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 @@ +/* + Copyright (c) 2018 Christian Mollekopf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#include "utils.h" +#include + +QByteArray Sink::createUuid() +{ + return QUuid::createUuid().toByteArray(); +} 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 @@ +/* + Copyright (c) 2018 Christian Mollekopf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#pragma once + +#include + +namespace Sink { + QByteArray createUuid(); +} diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index f3c8be2..275371d 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -35,7 +35,6 @@ #include "mailpreprocessor.h" #include "specialpurposepreprocessor.h" #include -#include //This is the resources entity type, and not the domain type #define ENTITY_TYPE_EVENT "event" -- cgit v1.2.3