summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/changereplay.cpp27
-rw-r--r--common/configstore.cpp8
-rw-r--r--common/domain/applicationdomaintype.cpp8
-rw-r--r--common/domain/folder.cpp4
-rw-r--r--common/domain/mail.cpp4
-rw-r--r--common/domainadaptor.h15
-rw-r--r--common/entityreader.cpp50
-rw-r--r--common/facade.cpp9
-rw-r--r--common/facade.h3
-rw-r--r--common/genericresource.cpp44
-rw-r--r--common/genericresource.h3
-rw-r--r--common/index.cpp9
-rw-r--r--common/index.h2
-rw-r--r--common/listener.cpp65
-rw-r--r--common/listener.h2
-rw-r--r--common/log.cpp45
-rw-r--r--common/log.h25
-rw-r--r--common/mailpreprocessor.cpp18
-rw-r--r--common/messagequeue.cpp6
-rw-r--r--common/modelresult.cpp19
-rw-r--r--common/pipeline.cpp71
-rw-r--r--common/queryrunner.cpp41
-rw-r--r--common/queryrunner.h4
-rw-r--r--common/remoteidmap.cpp4
-rw-r--r--common/resourceaccess.cpp94
-rw-r--r--common/resourceaccess.h4
-rw-r--r--common/resourcecontrol.cpp21
-rw-r--r--common/resourcefacade.cpp18
-rw-r--r--common/sourcewriteback.cpp24
-rw-r--r--common/specialpurposepreprocessor.cpp4
-rw-r--r--common/storage_common.cpp12
-rw-r--r--common/storage_lmdb.cpp28
-rw-r--r--common/store.cpp55
-rw-r--r--common/synchronizer.cpp38
-rw-r--r--common/test.cpp10
-rw-r--r--common/typeindex.cpp21
-rw-r--r--examples/dummyresource/resourcefactory.cpp12
-rw-r--r--examples/imapresource/imapresource.cpp99
-rw-r--r--examples/imapresource/imapserverproxy.cpp40
-rw-r--r--examples/imapresource/tests/imapserverproxytest.cpp10
-rw-r--r--examples/maildirresource/facade.cpp4
-rw-r--r--examples/maildirresource/maildirresource.cpp57
-rw-r--r--examples/mailtransportresource/mailtransportresource.cpp18
-rw-r--r--synchronizer/main.cpp13
-rw-r--r--tests/clientapitest.cpp10
-rw-r--r--tests/mailsynctest.cpp4
-rw-r--r--tests/mailtest.cpp6
-rw-r--r--tests/messagequeuetest.cpp4
48 files changed, 565 insertions, 527 deletions
diff --git a/common/changereplay.cpp b/common/changereplay.cpp
index 78c0ff5..99bbaab 100644
--- a/common/changereplay.cpp
+++ b/common/changereplay.cpp
@@ -26,13 +26,12 @@
26 26
27using namespace Sink; 27using namespace Sink;
28 28
29#undef DEBUG_AREA 29SINK_DEBUG_AREA("changereplay");
30#define DEBUG_AREA "resource.changereplay"
31 30
32ChangeReplay::ChangeReplay(const QByteArray &resourceName) 31ChangeReplay::ChangeReplay(const QByteArray &resourceName)
33 : mStorage(storageLocation(), resourceName, Storage::ReadOnly), mChangeReplayStore(storageLocation(), resourceName + ".changereplay", Storage::ReadWrite), mReplayInProgress(false) 32 : mStorage(storageLocation(), resourceName, Storage::ReadOnly), mChangeReplayStore(storageLocation(), resourceName + ".changereplay", Storage::ReadWrite), mReplayInProgress(false)
34{ 33{
35 Trace() << "Created change replay: " << resourceName; 34 SinkTrace() << "Created change replay: " << resourceName;
36} 35}
37 36
38qint64 ChangeReplay::getLastReplayedRevision() 37qint64 ChangeReplay::getLastReplayedRevision()
@@ -51,10 +50,10 @@ qint64 ChangeReplay::getLastReplayedRevision()
51bool ChangeReplay::allChangesReplayed() 50bool ChangeReplay::allChangesReplayed()
52{ 51{
53 const qint64 topRevision = Storage::maxRevision(mStorage.createTransaction(Storage::ReadOnly, [](const Sink::Storage::Error &error) { 52 const qint64 topRevision = Storage::maxRevision(mStorage.createTransaction(Storage::ReadOnly, [](const Sink::Storage::Error &error) {
54 Warning() << error.message; 53 SinkWarning() << error.message;
55 })); 54 }));
56 const qint64 lastReplayedRevision = getLastReplayedRevision(); 55 const qint64 lastReplayedRevision = getLastReplayedRevision();
57 Trace() << "All changes replayed " << topRevision << lastReplayedRevision; 56 SinkTrace() << "All changes replayed " << topRevision << lastReplayedRevision;
58 return (lastReplayedRevision >= topRevision); 57 return (lastReplayedRevision >= topRevision);
59} 58}
60 59
@@ -62,10 +61,10 @@ KAsync::Job<void> ChangeReplay::replayNextRevision()
62{ 61{
63 mReplayInProgress = true; 62 mReplayInProgress = true;
64 auto mainStoreTransaction = mStorage.createTransaction(Storage::ReadOnly, [](const Sink::Storage::Error &error) { 63 auto mainStoreTransaction = mStorage.createTransaction(Storage::ReadOnly, [](const Sink::Storage::Error &error) {
65 Warning() << error.message; 64 SinkWarning() << error.message;
66 }); 65 });
67 auto replayStoreTransaction = mChangeReplayStore.createTransaction(Storage::ReadOnly, [](const Sink::Storage::Error &error) { 66 auto replayStoreTransaction = mChangeReplayStore.createTransaction(Storage::ReadOnly, [](const Sink::Storage::Error &error) {
68 Warning() << error.message; 67 SinkWarning() << error.message;
69 }); 68 });
70 qint64 lastReplayedRevision = 0; 69 qint64 lastReplayedRevision = 0;
71 replayStoreTransaction.openDatabase().scan("lastReplayedRevision", 70 replayStoreTransaction.openDatabase().scan("lastReplayedRevision",
@@ -78,14 +77,14 @@ KAsync::Job<void> ChangeReplay::replayNextRevision()
78 77
79 auto recordReplayedRevision = [this](qint64 revision) { 78 auto recordReplayedRevision = [this](qint64 revision) {
80 auto replayStoreTransaction = mChangeReplayStore.createTransaction(Storage::ReadWrite, [](const Sink::Storage::Error &error) { 79 auto replayStoreTransaction = mChangeReplayStore.createTransaction(Storage::ReadWrite, [](const Sink::Storage::Error &error) {
81 Warning() << error.message; 80 SinkWarning() << error.message;
82 }); 81 });
83 replayStoreTransaction.openDatabase().write("lastReplayedRevision", QByteArray::number(revision)); 82 replayStoreTransaction.openDatabase().write("lastReplayedRevision", QByteArray::number(revision));
84 replayStoreTransaction.commit(); 83 replayStoreTransaction.commit();
85 }; 84 };
86 85
87 if (lastReplayedRevision < topRevision) { 86 if (lastReplayedRevision < topRevision) {
88 Trace() << "Changereplay from " << lastReplayedRevision << " to " << topRevision; 87 SinkTrace() << "Changereplay from " << lastReplayedRevision << " to " << topRevision;
89 emit replayingChanges(); 88 emit replayingChanges();
90 qint64 revision = lastReplayedRevision + 1; 89 qint64 revision = lastReplayedRevision + 1;
91 const auto uid = Storage::getUidFromRevision(mainStoreTransaction, revision); 90 const auto uid = Storage::getUidFromRevision(mainStoreTransaction, revision);
@@ -95,25 +94,25 @@ KAsync::Job<void> ChangeReplay::replayNextRevision()
95 Storage::mainDatabase(mainStoreTransaction, type) 94 Storage::mainDatabase(mainStoreTransaction, type)
96 .scan(key, 95 .scan(key,
97 [&lastReplayedRevision, type, this, &replayJob](const QByteArray &key, const QByteArray &value) -> bool { 96 [&lastReplayedRevision, type, this, &replayJob](const QByteArray &key, const QByteArray &value) -> bool {
98 Trace() << "Replaying " << key; 97 SinkTrace() << "Replaying " << key;
99 replayJob = replay(type, key, value); 98 replayJob = replay(type, key, value);
100 return false; 99 return false;
101 }, 100 },
102 [key](const Storage::Error &) { ErrorMsg() << "Failed to replay change " << key; }); 101 [key](const Storage::Error &) { SinkError() << "Failed to replay change " << key; });
103 return replayJob.then<void>([this, revision, recordReplayedRevision]() { 102 return replayJob.then<void>([this, revision, recordReplayedRevision]() {
104 Trace() << "Replayed until " << revision; 103 SinkTrace() << "Replayed until " << revision;
105 recordReplayedRevision(revision); 104 recordReplayedRevision(revision);
106 //replay until we're done 105 //replay until we're done
107 replayNextRevision().exec(); 106 replayNextRevision().exec();
108 }, 107 },
109 [this, revision, recordReplayedRevision](int, QString) { 108 [this, revision, recordReplayedRevision](int, QString) {
110 Trace() << "Change replay failed" << revision; 109 SinkTrace() << "Change replay failed" << revision;
111 //We're probably not online or so, so postpone retrying 110 //We're probably not online or so, so postpone retrying
112 mReplayInProgress = false; 111 mReplayInProgress = false;
113 emit changesReplayed(); 112 emit changesReplayed();
114 }); 113 });
115 } else { 114 } else {
116 Trace() << "No changes to replay"; 115 SinkTrace() << "No changes to replay";
117 mReplayInProgress = false; 116 mReplayInProgress = false;
118 emit changesReplayed(); 117 emit changesReplayed();
119 } 118 }
diff --git a/common/configstore.cpp b/common/configstore.cpp
index a8469ba..c8809ea 100644
--- a/common/configstore.cpp
+++ b/common/configstore.cpp
@@ -24,6 +24,8 @@
24#include <QFile> 24#include <QFile>
25#include <log.h> 25#include <log.h>
26 26
27SINK_DEBUG_AREA("configstore")
28
27static QSharedPointer<QSettings> getConfig(const QByteArray &identifier) 29static QSharedPointer<QSettings> getConfig(const QByteArray &identifier)
28{ 30{
29 return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink/" + identifier + ".ini", QSettings::IniFormat); 31 return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink/" + identifier + ".ini", QSettings::IniFormat);
@@ -50,7 +52,7 @@ QMap<QByteArray, QByteArray> ConfigStore::getEntries()
50 52
51void ConfigStore::add(const QByteArray &identifier, const QByteArray &type) 53void ConfigStore::add(const QByteArray &identifier, const QByteArray &type)
52{ 54{
53 Trace() << "Adding " << identifier; 55 SinkTrace() << "Adding " << identifier;
54 mConfig->beginGroup(QString::fromLatin1(identifier)); 56 mConfig->beginGroup(QString::fromLatin1(identifier));
55 mConfig->setValue("type", type); 57 mConfig->setValue("type", type);
56 mConfig->endGroup(); 58 mConfig->endGroup();
@@ -59,7 +61,7 @@ void ConfigStore::add(const QByteArray &identifier, const QByteArray &type)
59 61
60void ConfigStore::remove(const QByteArray &identifier) 62void ConfigStore::remove(const QByteArray &identifier)
61{ 63{
62 Trace() << "Removing " << identifier; 64 SinkTrace() << "Removing " << identifier;
63 mConfig->beginGroup(QString::fromLatin1(identifier)); 65 mConfig->beginGroup(QString::fromLatin1(identifier));
64 mConfig->remove(""); 66 mConfig->remove("");
65 mConfig->endGroup(); 67 mConfig->endGroup();
@@ -75,7 +77,7 @@ void ConfigStore::clear()
75 77
76void ConfigStore::modify(const QByteArray &identifier, const QMap<QByteArray, QVariant> &configuration) 78void ConfigStore::modify(const QByteArray &identifier, const QMap<QByteArray, QVariant> &configuration)
77{ 79{
78 Trace() << "Modifying " << identifier; 80 SinkTrace() << "Modifying " << identifier;
79 auto config = getConfig(identifier); 81 auto config = getConfig(identifier);
80 config->clear(); 82 config->clear();
81 for (const auto &key : configuration.keys()) { 83 for (const auto &key : configuration.keys()) {
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp
index 44eeb13..57919ff 100644
--- a/common/domain/applicationdomaintype.cpp
+++ b/common/domain/applicationdomaintype.cpp
@@ -24,6 +24,8 @@
24#include "storage.h" //for generateUid() 24#include "storage.h" //for generateUid()
25#include <QFile> 25#include <QFile>
26 26
27SINK_DEBUG_AREA("applicationdomaintype");
28
27namespace Sink { 29namespace Sink {
28namespace ApplicationDomain { 30namespace ApplicationDomain {
29 31
@@ -82,7 +84,7 @@ QVariant ApplicationDomainType::getProperty(const QByteArray &key) const
82{ 84{
83 Q_ASSERT(mAdaptor); 85 Q_ASSERT(mAdaptor);
84 if (!mAdaptor->availableProperties().contains(key)) { 86 if (!mAdaptor->availableProperties().contains(key)) {
85 Warning() << "No such property available " << key; 87 SinkWarning() << "No such property available " << key;
86 } 88 }
87 return mAdaptor->getProperty(key); 89 return mAdaptor->getProperty(key);
88} 90}
@@ -105,7 +107,7 @@ QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const
105 const auto path = getProperty(key).toByteArray(); 107 const auto path = getProperty(key).toByteArray();
106 QFile file(path); 108 QFile file(path);
107 if (!file.open(QIODevice::ReadOnly)) { 109 if (!file.open(QIODevice::ReadOnly)) {
108 ErrorMsg() << "Failed to open the file: " << file.errorString() << path; 110 SinkError() << "Failed to open the file: " << file.errorString() << path;
109 return QByteArray(); 111 return QByteArray();
110 } 112 }
111 return file.readAll(); 113 return file.readAll();
@@ -116,7 +118,7 @@ void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteAr
116 const auto path = Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); 118 const auto path = Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString();
117 QFile file(path); 119 QFile file(path);
118 if (!file.open(QIODevice::WriteOnly)) { 120 if (!file.open(QIODevice::WriteOnly)) {
119 ErrorMsg() << "Failed to open the file: " << file.errorString() << path; 121 SinkError() << "Failed to open the file: " << file.errorString() << path;
120 return; 122 return;
121 } 123 }
122 file.write(value); 124 file.write(value);
diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp
index 309ca3f..ddb0c10 100644
--- a/common/domain/folder.cpp
+++ b/common/domain/folder.cpp
@@ -35,6 +35,8 @@
35 35
36#include "folder_generated.h" 36#include "folder_generated.h"
37 37
38SINK_DEBUG_AREA("folder");
39
38static QMutex sMutex; 40static QMutex sMutex;
39 41
40using namespace Sink::ApplicationDomain; 42using namespace Sink::ApplicationDomain;
@@ -58,7 +60,7 @@ ResultSet TypeImplementation<Folder>::queryIndexes(const Sink::Query &query, con
58 60
59void TypeImplementation<Folder>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 61void TypeImplementation<Folder>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction)
60{ 62{
61 Trace() << "Indexing " << identifier; 63 SinkTrace() << "Indexing " << identifier;
62 getIndex().add(identifier, bufferAdaptor, transaction); 64 getIndex().add(identifier, bufferAdaptor, transaction);
63} 65}
64 66
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp
index 5b35a9a..13e1305 100644
--- a/common/domain/mail.cpp
+++ b/common/domain/mail.cpp
@@ -35,6 +35,8 @@
35 35
36#include "mail_generated.h" 36#include "mail_generated.h"
37 37
38SINK_DEBUG_AREA("mail");
39
38static QMutex sMutex; 40static QMutex sMutex;
39 41
40using namespace Sink::ApplicationDomain; 42using namespace Sink::ApplicationDomain;
@@ -63,7 +65,7 @@ ResultSet TypeImplementation<Mail>::queryIndexes(const Sink::Query &query, const
63 65
64void TypeImplementation<Mail>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 66void TypeImplementation<Mail>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction)
65{ 67{
66 Trace() << "Indexing " << identifier; 68 SinkTrace() << "Indexing " << identifier;
67 getIndex().add(identifier, bufferAdaptor, transaction); 69 getIndex().add(identifier, bufferAdaptor, transaction);
68} 70}
69 71
diff --git a/common/domainadaptor.h b/common/domainadaptor.h
index 8ac8171..25448f3 100644
--- a/common/domainadaptor.h
+++ b/common/domainadaptor.h
@@ -47,12 +47,12 @@ createBufferPart(const Sink::ApplicationDomain::ApplicationDomainType &domainObj
47 // First create a primitives such as strings using the mappings 47 // First create a primitives such as strings using the mappings
48 QList<std::function<void(Builder &)>> propertiesToAddToResource; 48 QList<std::function<void(Builder &)>> propertiesToAddToResource;
49 for (const auto &property : domainObject.changedProperties()) { 49 for (const auto &property : domainObject.changedProperties()) {
50 // Trace() << "copying property " << property; 50 // SinkTrace() << "copying property " << property;
51 const auto value = domainObject.getProperty(property); 51 const auto value = domainObject.getProperty(property);
52 if (mapper.hasMapping(property)) { 52 if (mapper.hasMapping(property)) {
53 mapper.setProperty(property, domainObject.getProperty(property), propertiesToAddToResource, fbb); 53 mapper.setProperty(property, domainObject.getProperty(property), propertiesToAddToResource, fbb);
54 } else { 54 } else {
55 // Trace() << "no mapping for property available " << property; 55 // SinkTrace() << "no mapping for property available " << property;
56 } 56 }
57 } 57 }
58 58
@@ -79,7 +79,7 @@ static void createBufferPartBuffer(const Sink::ApplicationDomain::ApplicationDom
79 fbb.Finish(pos, "AKFB"); 79 fbb.Finish(pos, "AKFB");
80 flatbuffers::Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize()); 80 flatbuffers::Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize());
81 if (!verifier.VerifyBuffer<Buffer>()) { 81 if (!verifier.VerifyBuffer<Buffer>()) {
82 Warning() << "Created invalid uffer"; 82 SinkWarning_(0, "bufferadaptor") << "Created invalid uffer";
83 } 83 }
84} 84}
85 85
@@ -89,6 +89,7 @@ static void createBufferPartBuffer(const Sink::ApplicationDomain::ApplicationDom
89template <class LocalBuffer, class ResourceBuffer> 89template <class LocalBuffer, class ResourceBuffer>
90class GenericBufferAdaptor : public Sink::ApplicationDomain::BufferAdaptor 90class GenericBufferAdaptor : public Sink::ApplicationDomain::BufferAdaptor
91{ 91{
92 SINK_DEBUG_AREA("bufferadaptor")
92public: 93public:
93 GenericBufferAdaptor() : BufferAdaptor() 94 GenericBufferAdaptor() : BufferAdaptor()
94 { 95 {
@@ -96,7 +97,7 @@ public:
96 97
97 virtual void setProperty(const QByteArray &key, const QVariant &value) Q_DECL_OVERRIDE 98 virtual void setProperty(const QByteArray &key, const QVariant &value) Q_DECL_OVERRIDE
98 { 99 {
99 Warning() << "Can't set property " << key; 100 SinkWarning() << "Can't set property " << key;
100 Q_ASSERT(false); 101 Q_ASSERT(false);
101 } 102 }
102 103
@@ -107,7 +108,7 @@ public:
107 } else if (mLocalBuffer && mLocalMapper->hasMapping(key)) { 108 } else if (mLocalBuffer && mLocalMapper->hasMapping(key)) {
108 return mLocalMapper->getProperty(key, mLocalBuffer); 109 return mLocalMapper->getProperty(key, mLocalBuffer);
109 } 110 }
110 Warning() << "No mapping available for key " << key << mLocalBuffer << mResourceBuffer; 111 SinkWarning() << "No mapping available for key " << key << mLocalBuffer << mResourceBuffer;
111 return QVariant(); 112 return QVariant();
112 } 113 }
113 114
@@ -168,13 +169,13 @@ public:
168 { 169 {
169 flatbuffers::FlatBufferBuilder localFbb; 170 flatbuffers::FlatBufferBuilder localFbb;
170 if (mLocalWriteMapper) { 171 if (mLocalWriteMapper) {
171 // Trace() << "Creating local buffer part"; 172 // SinkTrace() << "Creating local buffer part";
172 createBufferPartBuffer<LocalBuffer, LocalBuilder>(domainObject, localFbb, *mLocalWriteMapper); 173 createBufferPartBuffer<LocalBuffer, LocalBuilder>(domainObject, localFbb, *mLocalWriteMapper);
173 } 174 }
174 175
175 flatbuffers::FlatBufferBuilder resFbb; 176 flatbuffers::FlatBufferBuilder resFbb;
176 if (mResourceWriteMapper) { 177 if (mResourceWriteMapper) {
177 // Trace() << "Creating resouce buffer part"; 178 // SinkTrace() << "Creating resouce buffer part";
178 createBufferPartBuffer<ResourceBuffer, ResourceBuilder>(domainObject, resFbb, *mResourceWriteMapper); 179 createBufferPartBuffer<ResourceBuffer, ResourceBuilder>(domainObject, resFbb, *mResourceWriteMapper);
179 } 180 }
180 181
diff --git a/common/entityreader.cpp b/common/entityreader.cpp
index c15f73f..411e7e4 100644
--- a/common/entityreader.cpp
+++ b/common/entityreader.cpp
@@ -23,6 +23,8 @@
23#include "storage.h" 23#include "storage.h"
24#include "query.h" 24#include "query.h"
25 25
26SINK_DEBUG_AREA("entityreader")
27
26using namespace Sink; 28using namespace Sink;
27 29
28QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> EntityReaderUtils::getLatest(const Sink::Storage::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory, qint64 &retrievedRevision) 30QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> EntityReaderUtils::getLatest(const Sink::Storage::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory, qint64 &retrievedRevision)
@@ -32,15 +34,15 @@ QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> EntityReaderUtils::getLat
32 [&current, &adaptorFactory, &retrievedRevision](const QByteArray &key, const QByteArray &data) -> bool { 34 [&current, &adaptorFactory, &retrievedRevision](const QByteArray &key, const QByteArray &data) -> bool {
33 Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); 35 Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size());
34 if (!buffer.isValid()) { 36 if (!buffer.isValid()) {
35 Warning() << "Read invalid buffer from disk"; 37 SinkWarning() << "Read invalid buffer from disk";
36 } else { 38 } else {
37 Trace() << "Found value " << key; 39 SinkTrace() << "Found value " << key;
38 current = adaptorFactory.createAdaptor(buffer.entity()); 40 current = adaptorFactory.createAdaptor(buffer.entity());
39 retrievedRevision = Sink::Storage::revisionFromKey(key); 41 retrievedRevision = Sink::Storage::revisionFromKey(key);
40 } 42 }
41 return false; 43 return false;
42 }, 44 },
43 [](const Sink::Storage::Error &error) { Warning() << "Failed to read current value from storage: " << error.message; }); 45 [](const Sink::Storage::Error &error) { SinkWarning() << "Failed to read current value from storage: " << error.message; });
44 return current; 46 return current;
45} 47}
46 48
@@ -51,14 +53,14 @@ QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> EntityReaderUtils::get(co
51 [&current, &adaptorFactory, &retrievedRevision](const QByteArray &key, const QByteArray &data) -> bool { 53 [&current, &adaptorFactory, &retrievedRevision](const QByteArray &key, const QByteArray &data) -> bool {
52 Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); 54 Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size());
53 if (!buffer.isValid()) { 55 if (!buffer.isValid()) {
54 Warning() << "Read invalid buffer from disk"; 56 SinkWarning() << "Read invalid buffer from disk";
55 } else { 57 } else {
56 current = adaptorFactory.createAdaptor(buffer.entity()); 58 current = adaptorFactory.createAdaptor(buffer.entity());
57 retrievedRevision = Sink::Storage::revisionFromKey(key); 59 retrievedRevision = Sink::Storage::revisionFromKey(key);
58 } 60 }
59 return false; 61 return false;
60 }, 62 },
61 [](const Sink::Storage::Error &error) { Warning() << "Failed to read current value from storage: " << error.message; }); 63 [](const Sink::Storage::Error &error) { SinkWarning() << "Failed to read current value from storage: " << error.message; });
62 return current; 64 return current;
63} 65}
64 66
@@ -74,7 +76,7 @@ QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> EntityReaderUtils::getPre
74 } 76 }
75 return true; 77 return true;
76 }, 78 },
77 [](const Sink::Storage::Error &error) { Warning() << "Failed to read current value from storage: " << error.message; }, true); 79 [](const Sink::Storage::Error &error) { SinkWarning() << "Failed to read current value from storage: " << error.message; }, true);
78 return get(db, Sink::Storage::assembleKey(uid, latestRevision), adaptorFactory, retrievedRevision); 80 return get(db, Sink::Storage::assembleKey(uid, latestRevision), adaptorFactory, retrievedRevision);
79} 81}
80 82
@@ -86,7 +88,7 @@ EntityReader<DomainType>::EntityReader(const QByteArray &resourceType, const QBy
86 mDomainTypeAdaptorFactory(*mDomainTypeAdaptorFactoryPtr) 88 mDomainTypeAdaptorFactory(*mDomainTypeAdaptorFactoryPtr)
87{ 89{
88 Q_ASSERT(!resourceType.isEmpty()); 90 Q_ASSERT(!resourceType.isEmpty());
89 Trace() << "resourceType " << resourceType; 91 SinkTrace() << "resourceType " << resourceType;
90 Q_ASSERT(mDomainTypeAdaptorFactoryPtr); 92 Q_ASSERT(mDomainTypeAdaptorFactoryPtr);
91} 93}
92 94
@@ -165,13 +167,13 @@ void EntityReader<DomainType>::readEntity(const Sink::Storage::NamedDatabase &db
165 resultCallback(DomainType::Ptr::create(mResourceInstanceIdentifier, Sink::Storage::uidFromKey(key), revision, adaptor), operation); 167 resultCallback(DomainType::Ptr::create(mResourceInstanceIdentifier, Sink::Storage::uidFromKey(key), revision, adaptor), operation);
166 return false; 168 return false;
167 }, 169 },
168 [&](const Sink::Storage::Error &error) { Warning() << "Error during query: " << error.message << key; }); 170 [&](const Sink::Storage::Error &error) { SinkWarning() << "Error during query: " << error.message << key; });
169} 171}
170 172
171static inline ResultSet fullScan(const Sink::Storage::Transaction &transaction, const QByteArray &bufferType) 173static inline ResultSet fullScan(const Sink::Storage::Transaction &transaction, const QByteArray &bufferType)
172{ 174{
173 // TODO use a result set with an iterator, to read values on demand 175 // TODO use a result set with an iterator, to read values on demand
174 Trace() << "Looking for : " << bufferType; 176 SinkTrace() << "Looking for : " << bufferType;
175 //The scan can return duplicate results if we have multiple revisions, so we use a set to deduplicate. 177 //The scan can return duplicate results if we have multiple revisions, so we use a set to deduplicate.
176 QSet<QByteArray> keys; 178 QSet<QByteArray> keys;
177 Storage::mainDatabase(transaction, bufferType) 179 Storage::mainDatabase(transaction, bufferType)
@@ -179,14 +181,14 @@ static inline ResultSet fullScan(const Sink::Storage::Transaction &transaction,
179 [&](const QByteArray &key, const QByteArray &value) -> bool { 181 [&](const QByteArray &key, const QByteArray &value) -> bool {
180 if (keys.contains(Sink::Storage::uidFromKey(key))) { 182 if (keys.contains(Sink::Storage::uidFromKey(key))) {
181 //Not something that should persist if the replay works, so we keep a message for now. 183 //Not something that should persist if the replay works, so we keep a message for now.
182 Trace() << "Multiple revisions for key: " << key; 184 SinkTrace() << "Multiple revisions for key: " << key;
183 } 185 }
184 keys << Sink::Storage::uidFromKey(key); 186 keys << Sink::Storage::uidFromKey(key);
185 return true; 187 return true;
186 }, 188 },
187 [](const Sink::Storage::Error &error) { Warning() << "Error during query: " << error.message; }); 189 [](const Sink::Storage::Error &error) { SinkWarning() << "Error during query: " << error.message; });
188 190
189 Trace() << "Full scan retrieved " << keys.size() << " results."; 191 SinkTrace() << "Full scan retrieved " << keys.size() << " results.";
190 return ResultSet(keys.toList().toVector()); 192 return ResultSet(keys.toList().toVector());
191} 193}
192 194
@@ -224,7 +226,7 @@ ResultSet EntityReader<DomainType>::loadIncrementalResultSet(qint64 baseRevision
224 while (*revisionCounter <= topRevision) { 226 while (*revisionCounter <= topRevision) {
225 const auto uid = Sink::Storage::getUidFromRevision(mTransaction, *revisionCounter); 227 const auto uid = Sink::Storage::getUidFromRevision(mTransaction, *revisionCounter);
226 const auto type = Sink::Storage::getTypeFromRevision(mTransaction, *revisionCounter); 228 const auto type = Sink::Storage::getTypeFromRevision(mTransaction, *revisionCounter);
227 // Trace() << "Revision" << *revisionCounter << type << uid; 229 // SinkTrace() << "Revision" << *revisionCounter << type << uid;
228 Q_ASSERT(!uid.isEmpty()); 230 Q_ASSERT(!uid.isEmpty());
229 Q_ASSERT(!type.isEmpty()); 231 Q_ASSERT(!type.isEmpty());
230 if (type != bufferType) { 232 if (type != bufferType) {
@@ -236,7 +238,7 @@ ResultSet EntityReader<DomainType>::loadIncrementalResultSet(qint64 baseRevision
236 *revisionCounter += 1; 238 *revisionCounter += 1;
237 return key; 239 return key;
238 } 240 }
239 Trace() << "Finished reading incremental result set:" << *revisionCounter; 241 SinkTrace() << "Finished reading incremental result set:" << *revisionCounter;
240 // We're done 242 // We're done
241 return QByteArray(); 243 return QByteArray();
242 }); 244 });
@@ -248,7 +250,7 @@ ResultSet EntityReader<DomainType>::filterAndSortSet(ResultSet &resultSet, const
248{ 250{
249 const bool sortingRequired = !sortProperty.isEmpty(); 251 const bool sortingRequired = !sortProperty.isEmpty();
250 if (initialQuery && sortingRequired) { 252 if (initialQuery && sortingRequired) {
251 Trace() << "Sorting the resultset in memory according to property: " << sortProperty; 253 SinkTrace() << "Sorting the resultset in memory according to property: " << sortProperty;
252 // Sort the complete set by reading the sort property and filling into a sorted map 254 // Sort the complete set by reading the sort property and filling into a sorted map
253 auto sortedMap = QSharedPointer<QMap<QByteArray, QByteArray>>::create(); 255 auto sortedMap = QSharedPointer<QMap<QByteArray, QByteArray>>::create();
254 while (resultSet.next()) { 256 while (resultSet.next()) {
@@ -271,7 +273,7 @@ ResultSet EntityReader<DomainType>::filterAndSortSet(ResultSet &resultSet, const
271 }); 273 });
272 } 274 }
273 275
274 Trace() << "Sorted " << sortedMap->size() << " values."; 276 SinkTrace() << "Sorted " << sortedMap->size() << " values.";
275 auto iterator = QSharedPointer<QMapIterator<QByteArray, QByteArray>>::create(*sortedMap); 277 auto iterator = QSharedPointer<QMapIterator<QByteArray, QByteArray>>::create(*sortedMap);
276 ResultSet::ValueGenerator generator = [this, iterator, sortedMap, &db, filter, initialQuery]( 278 ResultSet::ValueGenerator generator = [this, iterator, sortedMap, &db, filter, initialQuery](
277 std::function<void(const Sink::ApplicationDomain::ApplicationDomainType::Ptr &, Sink::Operation)> callback) -> bool { 279 std::function<void(const Sink::ApplicationDomain::ApplicationDomainType::Ptr &, Sink::Operation)> callback) -> bool {
@@ -330,11 +332,11 @@ QPair<qint64, qint64> EntityReader<DomainType>::load(const Sink::Query &query, c
330 QSet<QByteArray> remainingFilters; 332 QSet<QByteArray> remainingFilters;
331 QByteArray remainingSorting; 333 QByteArray remainingSorting;
332 auto resultSet = baseSetRetriever(remainingFilters, remainingSorting); 334 auto resultSet = baseSetRetriever(remainingFilters, remainingSorting);
333 Trace() << "Base set retrieved. " << Log::TraceTime(time.elapsed()); 335 SinkTrace() << "Base set retrieved. " << Log::TraceTime(time.elapsed());
334 auto filteredSet = filterAndSortSet(resultSet, getFilter(remainingFilters, query), db, initialQuery, remainingSorting); 336 auto filteredSet = filterAndSortSet(resultSet, getFilter(remainingFilters, query), db, initialQuery, remainingSorting);
335 Trace() << "Filtered set retrieved. " << Log::TraceTime(time.elapsed()); 337 SinkTrace() << "Filtered set retrieved. " << Log::TraceTime(time.elapsed());
336 auto replayedEntities = replaySet(filteredSet, offset, batchSize, callback); 338 auto replayedEntities = replaySet(filteredSet, offset, batchSize, callback);
337 // Trace() << "Filtered set replayed. " << Log::TraceTime(time.elapsed()); 339 // SinkTrace() << "Filtered set replayed. " << Log::TraceTime(time.elapsed());
338 return qMakePair(Sink::Storage::maxRevision(mTransaction), replayedEntities); 340 return qMakePair(Sink::Storage::maxRevision(mTransaction), replayedEntities);
339} 341}
340 342
@@ -346,7 +348,7 @@ QPair<qint64, qint64> EntityReader<DomainType>::executeInitialQuery(const Sink::
346 auto revisionAndReplayedEntities = load(query, [&](QSet<QByteArray> &remainingFilters, QByteArray &remainingSorting) -> ResultSet { 348 auto revisionAndReplayedEntities = load(query, [&](QSet<QByteArray> &remainingFilters, QByteArray &remainingSorting) -> ResultSet {
347 return loadInitialResultSet(query, remainingFilters, remainingSorting); 349 return loadInitialResultSet(query, remainingFilters, remainingSorting);
348 }, true, offset, batchsize, callback); 350 }, true, offset, batchsize, callback);
349 Trace() << "Initial query took: " << Log::TraceTime(time.elapsed()); 351 SinkTrace() << "Initial query took: " << Log::TraceTime(time.elapsed());
350 return revisionAndReplayedEntities; 352 return revisionAndReplayedEntities;
351} 353}
352 354
@@ -359,7 +361,7 @@ QPair<qint64, qint64> EntityReader<DomainType>::executeIncrementalQuery(const Si
359 auto revisionAndReplayedEntities = load(query, [&](QSet<QByteArray> &remainingFilters, QByteArray &remainingSorting) -> ResultSet { 361 auto revisionAndReplayedEntities = load(query, [&](QSet<QByteArray> &remainingFilters, QByteArray &remainingSorting) -> ResultSet {
360 return loadIncrementalResultSet(baseRevision, query, remainingFilters); 362 return loadIncrementalResultSet(baseRevision, query, remainingFilters);
361 }, false, 0, 0, callback); 363 }, false, 0, 0, callback);
362 Trace() << "Initial query took: " << Log::TraceTime(time.elapsed()); 364 SinkTrace() << "Initial query took: " << Log::TraceTime(time.elapsed());
363 return revisionAndReplayedEntities; 365 return revisionAndReplayedEntities;
364} 366}
365 367
@@ -377,7 +379,7 @@ EntityReader<DomainType>::getFilter(const QSet<QByteArray> remainingFilters, con
377 const auto property = domainObject->getProperty(filterProperty); 379 const auto property = domainObject->getProperty(filterProperty);
378 const auto comparator = query.propertyFilter.value(filterProperty); 380 const auto comparator = query.propertyFilter.value(filterProperty);
379 if (!comparator.matches(property)) { 381 if (!comparator.matches(property)) {
380 Trace() << "Filtering entity due to property mismatch on filter: " << filterProperty << property << ":" << comparator.value; 382 SinkTrace() << "Filtering entity due to property mismatch on filter: " << filterProperty << property << ":" << comparator.value;
381 return false; 383 return false;
382 } 384 }
383 } 385 }
@@ -388,7 +390,7 @@ EntityReader<DomainType>::getFilter(const QSet<QByteArray> remainingFilters, con
388template <class DomainType> 390template <class DomainType>
389qint64 EntityReader<DomainType>::replaySet(ResultSet &resultSet, int offset, int batchSize, const std::function<bool(const typename DomainType::Ptr &value, Sink::Operation operation)> &callback) 391qint64 EntityReader<DomainType>::replaySet(ResultSet &resultSet, int offset, int batchSize, const std::function<bool(const typename DomainType::Ptr &value, Sink::Operation operation)> &callback)
390{ 392{
391 Trace() << "Skipping over " << offset << " results"; 393 SinkTrace() << "Skipping over " << offset << " results";
392 resultSet.skip(offset); 394 resultSet.skip(offset);
393 int counter = 0; 395 int counter = 0;
394 while (!batchSize || (counter < batchSize)) { 396 while (!batchSize || (counter < batchSize)) {
@@ -401,7 +403,7 @@ qint64 EntityReader<DomainType>::replaySet(ResultSet &resultSet, int offset, int
401 break; 403 break;
402 } 404 }
403 }; 405 };
404 Trace() << "Replayed " << counter << " results." 406 SinkTrace() << "Replayed " << counter << " results."
405 << "Limit " << batchSize; 407 << "Limit " << batchSize;
406 return counter; 408 return counter;
407} 409}
diff --git a/common/facade.cpp b/common/facade.cpp
index 2660300..72f7414 100644
--- a/common/facade.cpp
+++ b/common/facade.cpp
@@ -30,9 +30,6 @@
30 30
31using namespace Sink; 31using namespace Sink;
32 32
33#undef DEBUG_AREA
34#define DEBUG_AREA "client.facade"
35
36template <class DomainType> 33template <class DomainType>
37GenericFacade<DomainType>::GenericFacade( 34GenericFacade<DomainType>::GenericFacade(
38 const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory, const QSharedPointer<Sink::ResourceAccessInterface> resourceAccess) 35 const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory, const QSharedPointer<Sink::ResourceAccessInterface> resourceAccess)
@@ -59,7 +56,7 @@ template <class DomainType>
59KAsync::Job<void> GenericFacade<DomainType>::create(const DomainType &domainObject) 56KAsync::Job<void> GenericFacade<DomainType>::create(const DomainType &domainObject)
60{ 57{
61 if (!mDomainTypeAdaptorFactory) { 58 if (!mDomainTypeAdaptorFactory) {
62 Warning() << "No domain type adaptor factory available"; 59 SinkWarning() << "No domain type adaptor factory available";
63 return KAsync::error<void>(); 60 return KAsync::error<void>();
64 } 61 }
65 flatbuffers::FlatBufferBuilder entityFbb; 62 flatbuffers::FlatBufferBuilder entityFbb;
@@ -71,10 +68,10 @@ template <class DomainType>
71KAsync::Job<void> GenericFacade<DomainType>::modify(const DomainType &domainObject) 68KAsync::Job<void> GenericFacade<DomainType>::modify(const DomainType &domainObject)
72{ 69{
73 if (!mDomainTypeAdaptorFactory) { 70 if (!mDomainTypeAdaptorFactory) {
74 Warning() << "No domain type adaptor factory available"; 71 SinkWarning() << "No domain type adaptor factory available";
75 return KAsync::error<void>(); 72 return KAsync::error<void>();
76 } 73 }
77 Trace() << "Modifying entity: " << domainObject.identifier() << domainObject.changedProperties(); 74 SinkTrace() << "Modifying entity: " << domainObject.identifier() << domainObject.changedProperties();
78 flatbuffers::FlatBufferBuilder entityFbb; 75 flatbuffers::FlatBufferBuilder entityFbb;
79 mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); 76 mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb);
80 return mResourceAccess->sendModifyCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType(), QByteArrayList(), BufferUtils::extractBuffer(entityFbb), domainObject.changedProperties()); 77 return mResourceAccess->sendModifyCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType(), QByteArrayList(), BufferUtils::extractBuffer(entityFbb), domainObject.changedProperties());
diff --git a/common/facade.h b/common/facade.h
index 658ccb8..b193580 100644
--- a/common/facade.h
+++ b/common/facade.h
@@ -46,6 +46,9 @@ namespace Sink {
46template <typename DomainType> 46template <typename DomainType>
47class SINK_EXPORT GenericFacade : public Sink::StoreFacade<DomainType> 47class SINK_EXPORT GenericFacade : public Sink::StoreFacade<DomainType>
48{ 48{
49protected:
50 SINK_DEBUG_AREA("facade")
51 SINK_DEBUG_COMPONENT(mResourceInstanceIdentifier)
49public: 52public:
50 /** 53 /**
51 * Create a new GenericFacade 54 * Create a new GenericFacade
diff --git a/common/genericresource.cpp b/common/genericresource.cpp
index ed7dd46..7136882 100644
--- a/common/genericresource.cpp
+++ b/common/genericresource.cpp
@@ -46,9 +46,6 @@ static int sCommitInterval = 10;
46 46
47using namespace Sink; 47using namespace Sink;
48 48
49#undef DEBUG_AREA
50#define DEBUG_AREA "resource.commandprocessor"
51
52/** 49/**
53 * Drives the pipeline using the output from all command queues 50 * Drives the pipeline using the output from all command queues
54 */ 51 */
@@ -56,12 +53,13 @@ class CommandProcessor : public QObject
56{ 53{
57 Q_OBJECT 54 Q_OBJECT
58 typedef std::function<KAsync::Job<void>(void const *, size_t)> InspectionFunction; 55 typedef std::function<KAsync::Job<void>(void const *, size_t)> InspectionFunction;
56 SINK_DEBUG_AREA("commandprocessor")
59 57
60public: 58public:
61 CommandProcessor(Sink::Pipeline *pipeline, QList<MessageQueue *> commandQueues) : QObject(), mPipeline(pipeline), mCommandQueues(commandQueues), mProcessingLock(false) 59 CommandProcessor(Sink::Pipeline *pipeline, QList<MessageQueue *> commandQueues) : QObject(), mPipeline(pipeline), mCommandQueues(commandQueues), mProcessingLock(false)
62 { 60 {
63 mLowerBoundRevision = Storage::maxRevision(mPipeline->storage().createTransaction(Storage::ReadOnly, [](const Sink::Storage::Error &error) { 61 mLowerBoundRevision = Storage::maxRevision(mPipeline->storage().createTransaction(Storage::ReadOnly, [](const Sink::Storage::Error &error) {
64 Warning() << error.message; 62 SinkWarning() << error.message;
65 })); 63 }));
66 64
67 for (auto queue : mCommandQueues) { 65 for (auto queue : mCommandQueues) {
@@ -80,7 +78,6 @@ public:
80 mInspect = f; 78 mInspect = f;
81 } 79 }
82 80
83
84signals: 81signals:
85 void error(int errorCode, const QString &errorMessage); 82 void error(int errorCode, const QString &errorMessage);
86 83
@@ -114,7 +111,7 @@ private slots:
114 111
115 KAsync::Job<qint64> processQueuedCommand(const Sink::QueuedCommand *queuedCommand) 112 KAsync::Job<qint64> processQueuedCommand(const Sink::QueuedCommand *queuedCommand)
116 { 113 {
117 Trace() << "Processing command: " << Sink::Commands::name(queuedCommand->commandId()); 114 SinkTrace() << "Processing command: " << Sink::Commands::name(queuedCommand->commandId());
118 // Throw command into appropriate pipeline 115 // Throw command into appropriate pipeline
119 switch (queuedCommand->commandId()) { 116 switch (queuedCommand->commandId()) {
120 case Sink::Commands::DeleteEntityCommand: 117 case Sink::Commands::DeleteEntityCommand:
@@ -138,21 +135,21 @@ private slots:
138 { 135 {
139 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(data.constData()), data.size()); 136 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(data.constData()), data.size());
140 if (!Sink::VerifyQueuedCommandBuffer(verifyer)) { 137 if (!Sink::VerifyQueuedCommandBuffer(verifyer)) {
141 Warning() << "invalid buffer"; 138 SinkWarning() << "invalid buffer";
142 // return KAsync::error<void, qint64>(1, "Invalid Buffer"); 139 // return KAsync::error<void, qint64>(1, "Invalid Buffer");
143 } 140 }
144 auto queuedCommand = Sink::GetQueuedCommand(data.constData()); 141 auto queuedCommand = Sink::GetQueuedCommand(data.constData());
145 const auto commandId = queuedCommand->commandId(); 142 const auto commandId = queuedCommand->commandId();
146 Trace() << "Dequeued Command: " << Sink::Commands::name(commandId); 143 SinkTrace() << "Dequeued Command: " << Sink::Commands::name(commandId);
147 return processQueuedCommand(queuedCommand) 144 return processQueuedCommand(queuedCommand)
148 .then<qint64, qint64>( 145 .then<qint64, qint64>(
149 [commandId](qint64 createdRevision) -> qint64 { 146 [this, commandId](qint64 createdRevision) -> qint64 {
150 Trace() << "Command pipeline processed: " << Sink::Commands::name(commandId); 147 SinkTrace() << "Command pipeline processed: " << Sink::Commands::name(commandId);
151 return createdRevision; 148 return createdRevision;
152 }, 149 },
153 [](int errorCode, QString errorMessage) { 150 [](int errorCode, QString errorMessage) {
154 // FIXME propagate error, we didn't handle it 151 // FIXME propagate error, we didn't handle it
155 Warning() << "Error while processing queue command: " << errorMessage; 152 SinkWarning() << "Error while processing queue command: " << errorMessage;
156 }); 153 });
157 } 154 }
158 155
@@ -169,7 +166,7 @@ private slots:
169 return KAsync::start<void>([this, data, time](KAsync::Future<void> &future) { 166 return KAsync::start<void>([this, data, time](KAsync::Future<void> &future) {
170 processQueuedCommand(data) 167 processQueuedCommand(data)
171 .then<void, qint64>([&future, this, time](qint64 createdRevision) { 168 .then<void, qint64>([&future, this, time](qint64 createdRevision) {
172 Trace() << "Created revision " << createdRevision << ". Processing took: " << Log::TraceTime(time->elapsed()); 169 SinkTrace() << "Created revision " << createdRevision << ". Processing took: " << Log::TraceTime(time->elapsed());
173 future.setFinished(); 170 future.setFinished();
174 }) 171 })
175 .exec(); 172 .exec();
@@ -178,7 +175,7 @@ private slots:
178 .then<void>([&future, queue]() { future.setFinished(); }, 175 .then<void>([&future, queue]() { future.setFinished(); },
179 [&future](int i, QString error) { 176 [&future](int i, QString error) {
180 if (i != MessageQueue::ErrorCodes::NoMessageFound) { 177 if (i != MessageQueue::ErrorCodes::NoMessageFound) {
181 Warning() << "Error while getting message from messagequeue: " << error; 178 SinkWarning() << "Error while getting message from messagequeue: " << error;
182 } 179 }
183 future.setFinished(); 180 future.setFinished();
184 }) 181 })
@@ -192,12 +189,12 @@ private slots:
192 auto time = QSharedPointer<QTime>::create(); 189 auto time = QSharedPointer<QTime>::create();
193 time->start(); 190 time->start();
194 mPipeline->startTransaction(); 191 mPipeline->startTransaction();
195 Trace() << "Cleaning up from " << mPipeline->cleanedUpRevision() + 1 << " to " << mLowerBoundRevision; 192 SinkTrace() << "Cleaning up from " << mPipeline->cleanedUpRevision() + 1 << " to " << mLowerBoundRevision;
196 for (qint64 revision = mPipeline->cleanedUpRevision() + 1; revision <= mLowerBoundRevision; revision++) { 193 for (qint64 revision = mPipeline->cleanedUpRevision() + 1; revision <= mLowerBoundRevision; revision++) {
197 mPipeline->cleanupRevision(revision); 194 mPipeline->cleanupRevision(revision);
198 } 195 }
199 mPipeline->commit(); 196 mPipeline->commit();
200 Trace() << "Cleanup done." << Log::TraceTime(time->elapsed()); 197 SinkTrace() << "Cleanup done." << Log::TraceTime(time->elapsed());
201 198
202 // Go through all message queues 199 // Go through all message queues
203 auto it = QSharedPointer<QListIterator<MessageQueue *>>::create(mCommandQueues); 200 auto it = QSharedPointer<QListIterator<MessageQueue *>>::create(mCommandQueues);
@@ -208,8 +205,8 @@ private slots:
208 205
209 auto queue = it->next(); 206 auto queue = it->next();
210 processQueue(queue) 207 processQueue(queue)
211 .then<void>([&future, time]() { 208 .then<void>([this, &future, time]() {
212 Trace() << "Queue processed." << Log::TraceTime(time->elapsed()); 209 SinkTrace() << "Queue processed." << Log::TraceTime(time->elapsed());
213 future.setFinished(); 210 future.setFinished();
214 }) 211 })
215 .exec(); 212 .exec();
@@ -226,9 +223,6 @@ private:
226 InspectionFunction mInspect; 223 InspectionFunction mInspect;
227}; 224};
228 225
229#undef DEBUG_AREA
230#define DEBUG_AREA "resource"
231
232GenericResource::GenericResource(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, const QSharedPointer<Pipeline> &pipeline ) 226GenericResource::GenericResource(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, const QSharedPointer<Pipeline> &pipeline )
233 : Sink::Resource(), 227 : Sink::Resource(),
234 mUserQueue(Sink::storageLocation(), resourceInstanceIdentifier + ".userqueue"), 228 mUserQueue(Sink::storageLocation(), resourceInstanceIdentifier + ".userqueue"),
@@ -301,7 +295,7 @@ GenericResource::~GenericResource()
301KAsync::Job<void> GenericResource::inspect( 295KAsync::Job<void> GenericResource::inspect(
302 int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) 296 int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue)
303{ 297{
304 Warning() << "Inspection not implemented"; 298 SinkWarning() << "Inspection not implemented";
305 return KAsync::null<void>(); 299 return KAsync::null<void>();
306} 300}
307 301
@@ -363,7 +357,7 @@ void GenericResource::setupChangereplay(const QSharedPointer<ChangeReplay> &chan
363 357
364void GenericResource::removeDataFromDisk() 358void GenericResource::removeDataFromDisk()
365{ 359{
366 Log() << "Removing the resource from disk: " << mResourceInstanceIdentifier; 360 SinkLog() << "Removing the resource from disk: " << mResourceInstanceIdentifier;
367 //Ensure we have no transaction or databases open 361 //Ensure we have no transaction or databases open
368 mSynchronizer.clear(); 362 mSynchronizer.clear();
369 mChangeReplay.clear(); 363 mChangeReplay.clear();
@@ -391,7 +385,7 @@ qint64 GenericResource::diskUsage(const QByteArray &instanceIdentifier)
391 385
392void GenericResource::onProcessorError(int errorCode, const QString &errorMessage) 386void GenericResource::onProcessorError(int errorCode, const QString &errorMessage)
393{ 387{
394 Warning() << "Received error from Processor: " << errorCode << errorMessage; 388 SinkWarning() << "Received error from Processor: " << errorCode << errorMessage;
395 mError = errorCode; 389 mError = errorCode;
396} 390}
397 391
@@ -435,12 +429,12 @@ KAsync::Job<void> GenericResource::synchronizeWithSource()
435 n.code = Sink::ApplicationDomain::BusyStatus; 429 n.code = Sink::ApplicationDomain::BusyStatus;
436 emit notify(n); 430 emit notify(n);
437 431
438 Log() << " Synchronizing"; 432 SinkLog() << " Synchronizing";
439 // Changereplay would deadlock otherwise when trying to open the synchronization store 433 // Changereplay would deadlock otherwise when trying to open the synchronization store
440 enableChangeReplay(false); 434 enableChangeReplay(false);
441 mSynchronizer->synchronize() 435 mSynchronizer->synchronize()
442 .then<void>([this, &future]() { 436 .then<void>([this, &future]() {
443 Log() << "Done Synchronizing"; 437 SinkLog() << "Done Synchronizing";
444 Sink::Notification n; 438 Sink::Notification n;
445 n.id = "sync"; 439 n.id = "sync";
446 n.type = Sink::Notification::Status; 440 n.type = Sink::Notification::Status;
diff --git a/common/genericresource.h b/common/genericresource.h
index 2254172..25892ca 100644
--- a/common/genericresource.h
+++ b/common/genericresource.h
@@ -40,6 +40,9 @@ class Synchronizer;
40 */ 40 */
41class SINK_EXPORT GenericResource : public Resource 41class SINK_EXPORT GenericResource : public Resource
42{ 42{
43protected:
44 SINK_DEBUG_AREA("resource")
45 SINK_DEBUG_COMPONENT(mResourceInstanceIdentifier)
43public: 46public:
44 GenericResource(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, const QSharedPointer<Pipeline> &pipeline); 47 GenericResource(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, const QSharedPointer<Pipeline> &pipeline);
45 virtual ~GenericResource(); 48 virtual ~GenericResource();
diff --git a/common/index.cpp b/common/index.cpp
index 151f7af..beed45c 100644
--- a/common/index.cpp
+++ b/common/index.cpp
@@ -2,8 +2,7 @@
2 2
3#include "log.h" 3#include "log.h"
4 4
5#undef Trace 5SINK_DEBUG_AREA("index")
6#define Trace() Trace_area("index." + mName.toLatin1())
7 6
8Index::Index(const QString &storageRoot, const QString &name, Sink::Storage::AccessMode mode) 7Index::Index(const QString &storageRoot, const QString &name, Sink::Storage::AccessMode mode)
9 : mTransaction(Sink::Storage(storageRoot, name, mode).createTransaction(mode)), 8 : mTransaction(Sink::Storage(storageRoot, name, mode).createTransaction(mode)),
@@ -34,8 +33,8 @@ void Index::lookup(const QByteArray &key, const std::function<void(const QByteAr
34 resultHandler(value); 33 resultHandler(value);
35 return true; 34 return true;
36 }, 35 },
37 [errorHandler](const Sink::Storage::Error &error) { 36 [this, errorHandler](const Sink::Storage::Error &error) {
38 Warning() << "Error while retrieving value" << error.message; 37 SinkWarning() << "Error while retrieving value" << error.message;
39 errorHandler(Error(error.store, error.code, error.message)); 38 errorHandler(Error(error.store, error.code, error.message));
40 }, 39 },
41 matchSubStringKeys); 40 matchSubStringKeys);
@@ -45,6 +44,6 @@ QByteArray Index::lookup(const QByteArray &key)
45{ 44{
46 QByteArray result; 45 QByteArray result;
47 //We have to create a deep copy, otherwise the returned data may become invalid when the transaction ends. 46 //We have to create a deep copy, otherwise the returned data may become invalid when the transaction ends.
48 lookup(key, [&result](const QByteArray &value) { result = QByteArray(value.constData(), value.size()); }, [this](const Index::Error &error) { Trace() << "Error while retrieving value" << error.message; }); 47 lookup(key, [&result](const QByteArray &value) { result = QByteArray(value.constData(), value.size()); }, [this](const Index::Error &error) { SinkTrace() << "Error while retrieving value" << error.message; });
49 return result; 48 return result;
50} 49}
diff --git a/common/index.h b/common/index.h
index 0345f56..bfedf9a 100644
--- a/common/index.h
+++ b/common/index.h
@@ -5,6 +5,7 @@
5#include <functional> 5#include <functional>
6#include <QString> 6#include <QString>
7#include "storage.h" 7#include "storage.h"
8#include "log.h"
8 9
9/** 10/**
10 * An index for value pairs. 11 * An index for value pairs.
@@ -43,4 +44,5 @@ private:
43 Sink::Storage::Transaction mTransaction; 44 Sink::Storage::Transaction mTransaction;
44 Sink::Storage::NamedDatabase mDb; 45 Sink::Storage::NamedDatabase mDb;
45 QString mName; 46 QString mName;
47 SINK_DEBUG_COMPONENT(mName.toLatin1())
46}; 48};
diff --git a/common/listener.cpp b/common/listener.cpp
index af8eaa2..2c5c1df 100644
--- a/common/listener.cpp
+++ b/common/listener.cpp
@@ -39,9 +39,6 @@
39#include <QTime> 39#include <QTime>
40#include <QDataStream> 40#include <QDataStream>
41 41
42#undef DEBUG_AREA
43#define DEBUG_AREA "resource.communication"
44
45Listener::Listener(const QByteArray &resourceInstanceIdentifier, const QByteArray &resourceType, QObject *parent) 42Listener::Listener(const QByteArray &resourceInstanceIdentifier, const QByteArray &resourceType, QObject *parent)
46 : QObject(parent), 43 : QObject(parent),
47 m_server(new QLocalServer(this)), 44 m_server(new QLocalServer(this)),
@@ -51,18 +48,18 @@ Listener::Listener(const QByteArray &resourceInstanceIdentifier, const QByteArra
51 m_messageId(0) 48 m_messageId(0)
52{ 49{
53 connect(m_server.get(), &QLocalServer::newConnection, this, &Listener::acceptConnection); 50 connect(m_server.get(), &QLocalServer::newConnection, this, &Listener::acceptConnection);
54 Trace() << "Trying to open " << m_resourceInstanceIdentifier; 51 SinkTrace() << "Trying to open " << m_resourceInstanceIdentifier;
55 52
56 if (!m_server->listen(QString::fromLatin1(m_resourceInstanceIdentifier))) { 53 if (!m_server->listen(QString::fromLatin1(m_resourceInstanceIdentifier))) {
57 m_server->removeServer(m_resourceInstanceIdentifier); 54 m_server->removeServer(m_resourceInstanceIdentifier);
58 if (!m_server->listen(QString::fromLatin1(m_resourceInstanceIdentifier))) { 55 if (!m_server->listen(QString::fromLatin1(m_resourceInstanceIdentifier))) {
59 Warning() << "Utter failure to start server"; 56 SinkWarning() << "Utter failure to start server";
60 exit(-1); 57 exit(-1);
61 } 58 }
62 } 59 }
63 60
64 if (m_server->isListening()) { 61 if (m_server->isListening()) {
65 Log() << QString("Listening on %1").arg(m_server->serverName()); 62 SinkLog() << QString("Listening on %1").arg(m_server->serverName());
66 } 63 }
67 64
68 m_checkConnectionsTimer = std::unique_ptr<QTimer>(new QTimer); 65 m_checkConnectionsTimer = std::unique_ptr<QTimer>(new QTimer);
@@ -70,7 +67,7 @@ Listener::Listener(const QByteArray &resourceInstanceIdentifier, const QByteArra
70 m_checkConnectionsTimer->setInterval(1000); 67 m_checkConnectionsTimer->setInterval(1000);
71 connect(m_checkConnectionsTimer.get(), &QTimer::timeout, [this]() { 68 connect(m_checkConnectionsTimer.get(), &QTimer::timeout, [this]() {
72 if (m_connections.isEmpty()) { 69 if (m_connections.isEmpty()) {
73 Log() << QString("No connections, shutting down."); 70 SinkLog() << QString("No connections, shutting down.");
74 quit(); 71 quit();
75 } 72 }
76 }); 73 });
@@ -91,7 +88,7 @@ void Listener::emergencyAbortAllConnections()
91{ 88{
92 for (Client &client : m_connections) { 89 for (Client &client : m_connections) {
93 if (client.socket) { 90 if (client.socket) {
94 Warning() << "Sending panic"; 91 SinkWarning() << "Sending panic";
95 client.socket->write("PANIC"); 92 client.socket->write("PANIC");
96 client.socket->waitForBytesWritten(); 93 client.socket->waitForBytesWritten();
97 disconnect(client.socket, 0, this, 0); 94 disconnect(client.socket, 0, this, 0);
@@ -120,11 +117,11 @@ void Listener::closeAllConnections()
120 117
121void Listener::acceptConnection() 118void Listener::acceptConnection()
122{ 119{
123 Trace() << "Accepting connection"; 120 SinkTrace() << "Accepting connection";
124 QLocalSocket *socket = m_server->nextPendingConnection(); 121 QLocalSocket *socket = m_server->nextPendingConnection();
125 122
126 if (!socket) { 123 if (!socket) {
127 Warning() << "Accepted connection but didn't get a socket for it"; 124 SinkWarning() << "Accepted connection but didn't get a socket for it";
128 return; 125 return;
129 } 126 }
130 127
@@ -156,13 +153,13 @@ void Listener::clientDropped()
156 const Client &client = it.next(); 153 const Client &client = it.next();
157 if (client.socket == socket) { 154 if (client.socket == socket) {
158 dropped = true; 155 dropped = true;
159 Log() << QString("Dropped connection: %1").arg(client.name) << socket; 156 SinkLog() << QString("Dropped connection: %1").arg(client.name) << socket;
160 it.remove(); 157 it.remove();
161 break; 158 break;
162 } 159 }
163 } 160 }
164 if (!dropped) { 161 if (!dropped) {
165 Warning() << "Failed to find connection for disconnected socket: " << socket; 162 SinkWarning() << "Failed to find connection for disconnected socket: " << socket;
166 } 163 }
167 164
168 checkConnections(); 165 checkConnections();
@@ -188,7 +185,7 @@ void Listener::onDataAvailable()
188 185
189void Listener::readFromSocket(QLocalSocket *socket) 186void Listener::readFromSocket(QLocalSocket *socket)
190{ 187{
191 Trace() << "Reading from socket..."; 188 SinkTrace() << "Reading from socket...";
192 for (Client &client : m_connections) { 189 for (Client &client : m_connections) {
193 if (client.socket == socket) { 190 if (client.socket == socket) {
194 client.commandBuffer += socket->readAll(); 191 client.commandBuffer += socket->readAll();
@@ -231,7 +228,7 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c
231 auto buffer = Sink::Commands::GetHandshake(commandBuffer.constData()); 228 auto buffer = Sink::Commands::GetHandshake(commandBuffer.constData());
232 client.name = buffer->name()->c_str(); 229 client.name = buffer->name()->c_str();
233 } else { 230 } else {
234 Warning() << "received invalid command"; 231 SinkWarning() << "received invalid command";
235 } 232 }
236 break; 233 break;
237 } 234 }
@@ -239,7 +236,7 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c
239 flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); 236 flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size());
240 if (Sink::Commands::VerifySynchronizeBuffer(verifier)) { 237 if (Sink::Commands::VerifySynchronizeBuffer(verifier)) {
241 auto buffer = Sink::Commands::GetSynchronize(commandBuffer.constData()); 238 auto buffer = Sink::Commands::GetSynchronize(commandBuffer.constData());
242 Trace() << QString("Synchronize request (id %1) from %2").arg(messageId).arg(client.name); 239 SinkTrace() << QString("Synchronize request (id %1) from %2").arg(messageId).arg(client.name);
243 auto timer = QSharedPointer<QTime>::create(); 240 auto timer = QSharedPointer<QTime>::create();
244 timer->start(); 241 timer->start();
245 auto job = KAsync::null<void>(); 242 auto job = KAsync::null<void>();
@@ -250,16 +247,16 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c
250 job = job.then<void>(loadResource().processAllMessages()); 247 job = job.then<void>(loadResource().processAllMessages());
251 } 248 }
252 job.then<void>([callback, timer]() { 249 job.then<void>([callback, timer]() {
253 Trace() << "Sync took " << Sink::Log::TraceTime(timer->elapsed()); 250 SinkTrace() << "Sync took " << Sink::Log::TraceTime(timer->elapsed());
254 callback(true); 251 callback(true);
255 }, [callback](int errorCode, const QString &msg) { 252 }, [callback](int errorCode, const QString &msg) {
256 Warning() << "Sync failed: " << msg; 253 SinkWarning() << "Sync failed: " << msg;
257 callback(false); 254 callback(false);
258 }) 255 })
259 .exec(); 256 .exec();
260 return; 257 return;
261 } else { 258 } else {
262 Warning() << "received invalid command"; 259 SinkWarning() << "received invalid command";
263 } 260 }
264 break; 261 break;
265 } 262 }
@@ -268,31 +265,31 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c
268 case Sink::Commands::DeleteEntityCommand: 265 case Sink::Commands::DeleteEntityCommand:
269 case Sink::Commands::ModifyEntityCommand: 266 case Sink::Commands::ModifyEntityCommand:
270 case Sink::Commands::CreateEntityCommand: 267 case Sink::Commands::CreateEntityCommand:
271 Trace() << "Command id " << messageId << " of type \"" << Sink::Commands::name(commandId) << "\" from " << client.name; 268 SinkTrace() << "Command id " << messageId << " of type \"" << Sink::Commands::name(commandId) << "\" from " << client.name;
272 loadResource().processCommand(commandId, commandBuffer); 269 loadResource().processCommand(commandId, commandBuffer);
273 break; 270 break;
274 case Sink::Commands::ShutdownCommand: 271 case Sink::Commands::ShutdownCommand:
275 Log() << QString("Received shutdown command from %1").arg(client.name); 272 SinkLog() << QString("Received shutdown command from %1").arg(client.name);
276 // Immediately reject new connections 273 // Immediately reject new connections
277 m_server->close(); 274 m_server->close();
278 QTimer::singleShot(0, this, &Listener::quit); 275 QTimer::singleShot(0, this, &Listener::quit);
279 break; 276 break;
280 case Sink::Commands::PingCommand: 277 case Sink::Commands::PingCommand:
281 Trace() << QString("Received ping command from %1").arg(client.name); 278 SinkTrace() << QString("Received ping command from %1").arg(client.name);
282 break; 279 break;
283 case Sink::Commands::RevisionReplayedCommand: { 280 case Sink::Commands::RevisionReplayedCommand: {
284 Trace() << QString("Received revision replayed command from %1").arg(client.name); 281 SinkTrace() << QString("Received revision replayed command from %1").arg(client.name);
285 flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); 282 flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size());
286 if (Sink::Commands::VerifyRevisionReplayedBuffer(verifier)) { 283 if (Sink::Commands::VerifyRevisionReplayedBuffer(verifier)) {
287 auto buffer = Sink::Commands::GetRevisionReplayed(commandBuffer.constData()); 284 auto buffer = Sink::Commands::GetRevisionReplayed(commandBuffer.constData());
288 client.currentRevision = buffer->revision(); 285 client.currentRevision = buffer->revision();
289 } else { 286 } else {
290 Warning() << "received invalid command"; 287 SinkWarning() << "received invalid command";
291 } 288 }
292 loadResource().setLowerBoundRevision(lowerBoundRevision()); 289 loadResource().setLowerBoundRevision(lowerBoundRevision());
293 } break; 290 } break;
294 case Sink::Commands::RemoveFromDiskCommand: { 291 case Sink::Commands::RemoveFromDiskCommand: {
295 Log() << QString("Received a remove from disk command from %1").arg(client.name); 292 SinkLog() << QString("Received a remove from disk command from %1").arg(client.name);
296 m_resource.reset(nullptr); 293 m_resource.reset(nullptr);
297 loadResource().removeDataFromDisk(); 294 loadResource().removeDataFromDisk();
298 m_server->close(); 295 m_server->close();
@@ -300,11 +297,11 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c
300 } break; 297 } break;
301 default: 298 default:
302 if (commandId > Sink::Commands::CustomCommand) { 299 if (commandId > Sink::Commands::CustomCommand) {
303 Log() << QString("Received custom command from %1: ").arg(client.name) << commandId; 300 SinkLog() << QString("Received custom command from %1: ").arg(client.name) << commandId;
304 loadResource().processCommand(commandId, commandBuffer); 301 loadResource().processCommand(commandId, commandBuffer);
305 } else { 302 } else {
306 success = false; 303 success = false;
307 ErrorMsg() << QString("\tReceived invalid command from %1: ").arg(client.name) << commandId; 304 SinkError() << QString("\tReceived invalid command from %1: ").arg(client.name) << commandId;
308 } 305 }
309 break; 306 break;
310 } 307 }
@@ -352,7 +349,7 @@ bool Listener::processClientBuffer(Client &client)
352 const uint messageId = *(uint *)client.commandBuffer.constData(); 349 const uint messageId = *(uint *)client.commandBuffer.constData();
353 const int commandId = *(int *)(client.commandBuffer.constData() + sizeof(uint)); 350 const int commandId = *(int *)(client.commandBuffer.constData() + sizeof(uint));
354 const uint size = *(uint *)(client.commandBuffer.constData() + sizeof(int) + sizeof(uint)); 351 const uint size = *(uint *)(client.commandBuffer.constData() + sizeof(int) + sizeof(uint));
355 Trace() << "Received message. Id:" << messageId << " CommandId: " << commandId << " Size: " << size; 352 SinkTrace() << "Received message. Id:" << messageId << " CommandId: " << commandId << " Size: " << size;
356 353
357 // TODO: reject messages above a certain size? 354 // TODO: reject messages above a certain size?
358 355
@@ -365,11 +362,11 @@ bool Listener::processClientBuffer(Client &client)
365 const QByteArray commandBuffer = client.commandBuffer.left(size); 362 const QByteArray commandBuffer = client.commandBuffer.left(size);
366 client.commandBuffer.remove(0, size); 363 client.commandBuffer.remove(0, size);
367 processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName](bool success) { 364 processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName](bool success) {
368 Trace() << QString("Completed command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Sink::Commands::name(commandId))).arg(clientName); 365 SinkTrace() << QString("Completed command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Sink::Commands::name(commandId))).arg(clientName);
369 if (socket) { 366 if (socket) {
370 sendCommandCompleted(socket.data(), messageId, success); 367 sendCommandCompleted(socket.data(), messageId, success);
371 } else { 368 } else {
372 Log() << QString("Socket became invalid before we could send a response. client: %1").arg(clientName); 369 SinkLog() << QString("Socket became invalid before we could send a response. client: %1").arg(clientName);
373 } 370 }
374 }); 371 });
375 372
@@ -406,7 +403,7 @@ void Listener::updateClientsWithRevision(qint64 revision)
406 continue; 403 continue;
407 } 404 }
408 405
409 Trace() << "Sending revision update for " << client.name << revision; 406 SinkTrace() << "Sending revision update for " << client.name << revision;
410 Sink::Commands::write(client.socket, ++m_messageId, Sink::Commands::RevisionUpdateCommand, m_fbb); 407 Sink::Commands::write(client.socket, ++m_messageId, Sink::Commands::RevisionUpdateCommand, m_fbb);
411 } 408 }
412 m_fbb.Clear(); 409 m_fbb.Clear();
@@ -437,15 +434,15 @@ Sink::Resource &Listener::loadResource()
437 if (Sink::ResourceFactory *resourceFactory = Sink::ResourceFactory::load(m_resourceName)) { 434 if (Sink::ResourceFactory *resourceFactory = Sink::ResourceFactory::load(m_resourceName)) {
438 m_resource = std::unique_ptr<Sink::Resource>(resourceFactory->createResource(m_resourceInstanceIdentifier)); 435 m_resource = std::unique_ptr<Sink::Resource>(resourceFactory->createResource(m_resourceInstanceIdentifier));
439 if (!m_resource) { 436 if (!m_resource) {
440 ErrorMsg() << "Failed to instantiate the resource " << m_resourceName; 437 SinkError() << "Failed to instantiate the resource " << m_resourceName;
441 m_resource = std::unique_ptr<Sink::Resource>(new Sink::Resource); 438 m_resource = std::unique_ptr<Sink::Resource>(new Sink::Resource);
442 } 439 }
443 Trace() << QString("Resource factory: %1").arg((qlonglong)resourceFactory); 440 SinkTrace() << QString("Resource factory: %1").arg((qlonglong)resourceFactory);
444 Trace() << QString("\tResource: %1").arg((qlonglong)m_resource.get()); 441 SinkTrace() << QString("\tResource: %1").arg((qlonglong)m_resource.get());
445 connect(m_resource.get(), &Sink::Resource::revisionUpdated, this, &Listener::refreshRevision); 442 connect(m_resource.get(), &Sink::Resource::revisionUpdated, this, &Listener::refreshRevision);
446 connect(m_resource.get(), &Sink::Resource::notify, this, &Listener::notify); 443 connect(m_resource.get(), &Sink::Resource::notify, this, &Listener::notify);
447 } else { 444 } else {
448 ErrorMsg() << "Failed to load resource " << m_resourceName; 445 SinkError() << "Failed to load resource " << m_resourceName;
449 m_resource = std::unique_ptr<Sink::Resource>(new Sink::Resource); 446 m_resource = std::unique_ptr<Sink::Resource>(new Sink::Resource);
450 } 447 }
451 } 448 }
diff --git a/common/listener.h b/common/listener.h
index 67d76e9..d6c537a 100644
--- a/common/listener.h
+++ b/common/listener.h
@@ -25,6 +25,7 @@
25#include <QPointer> 25#include <QPointer>
26#include <QLocalSocket> 26#include <QLocalSocket>
27#include <flatbuffers/flatbuffers.h> 27#include <flatbuffers/flatbuffers.h>
28#include <log.h>
28 29
29namespace Sink { 30namespace Sink {
30class Resource; 31class Resource;
@@ -54,6 +55,7 @@ public:
54class SINK_EXPORT Listener : public QObject 55class SINK_EXPORT Listener : public QObject
55{ 56{
56 Q_OBJECT 57 Q_OBJECT
58 SINK_DEBUG_AREA("communication")
57 59
58public: 60public:
59 Listener(const QByteArray &resourceName, const QByteArray &resourceType, QObject *parent = 0); 61 Listener(const QByteArray &resourceName, const QByteArray &resourceType, QObject *parent = 0);
diff --git a/common/log.cpp b/common/log.cpp
index 83cdc8a..821df06 100644
--- a/common/log.cpp
+++ b/common/log.cpp
@@ -238,27 +238,34 @@ static bool caseInsensitiveContains(const QByteArray &pattern, const QByteArrayL
238 return false; 238 return false;
239} 239}
240 240
241QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char *file, const char *function, const char *debugArea) 241QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char *file, const char *function, const char *debugArea, const char *debugComponent)
242{ 242{
243 static NullStream nullstream; 243 static NullStream nullstream;
244 if (debugLevel < debugOutputLevel()) { 244 if (debugLevel < debugOutputLevel()) {
245 return QDebug(&nullstream); 245 return QDebug(&nullstream);
246 } 246 }
247 247
248 auto areas = debugOutputFilter(Sink::Log::Area); 248 if (sPrimaryComponent.isEmpty()) {
249 if (debugArea && !areas.isEmpty()) { 249 sPrimaryComponent = getProgramName();
250 if (!containsItemStartingWith(debugArea, areas)) {
251 return QDebug(&nullstream);
252 }
253 } 250 }
254 static QByteArray programName = getProgramName(); 251 QString fullDebugArea = sPrimaryComponent + "."+ QString::fromLatin1(debugComponent) + "." + QString::fromLatin1(debugArea);
255 252
256 auto filter = debugOutputFilter(Sink::Log::ApplicationName); 253 //TODO add to autocompletion
257 if (!filter.isEmpty() && !filter.contains(programName)) { 254
258 if (!containsItemStartingWith(programName, filter)) { 255 auto areas = debugOutputFilter(Sink::Log::Area);
256 if (!areas.isEmpty()) {
257 if (!containsItemStartingWith(fullDebugArea.toUtf8(), areas)) {
259 return QDebug(&nullstream); 258 return QDebug(&nullstream);
260 } 259 }
261 } 260 }
261 // static QByteArray programName = getProgramName();
262 //
263 // auto filter = debugOutputFilter(Sink::Log::ApplicationName);
264 // if (!filter.isEmpty() && !filter.contains(programName)) {
265 // if (!containsItemStartingWith(programName, filter)) {
266 // return QDebug(&nullstream);
267 // }
268 // }
262 269
263 QString prefix; 270 QString prefix;
264 int prefixColorCode = ANSI_Colors::DoNothing; 271 int prefixColorCode = ANSI_Colors::DoNothing;
@@ -299,19 +306,17 @@ QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char *file,
299 } 306 }
300 if (showProgram) { 307 if (showProgram) {
301 int width = 10; 308 int width = 10;
302 output += QString(" %1(%2)").arg(QString::fromLatin1(programName).leftJustified(width, ' ', true)).arg(unsigned(getpid())).rightJustified(width + 8, ' '); 309 output += QString(" %1(%2)").arg(QString::fromLatin1(getProgramName()).leftJustified(width, ' ', true)).arg(unsigned(getpid())).rightJustified(width + 8, ' ');
303 } 310 }
304 if (debugArea) { 311 if (useColor) {
305 if (useColor) { 312 output += colorCommand(QList<int>() << ANSI_Colors::Bold << prefixColorCode);
306 output += colorCommand(QList<int>() << ANSI_Colors::Bold << prefixColorCode); 313 }
307 } 314 output += QString(" %1 ").arg(fullDebugArea.leftJustified(25, ' ', true));
308 output += QString(" %1 ").arg(QString::fromLatin1(debugArea).leftJustified(25, ' ', true)); 315 if (useColor) {
309 if (useColor) { 316 output += resetColor;
310 output += resetColor;
311 }
312 } 317 }
313 if (showFunction) { 318 if (showFunction) {
314 output += QString(" %3").arg(QString::fromLatin1(function).leftJustified(25, ' ', true)); 319 output += QString(" %3").arg(fullDebugArea.leftJustified(25, ' ', true));
315 } 320 }
316 if (showLocation) { 321 if (showLocation) {
317 const auto filename = QString::fromLatin1(file).split('/').last(); 322 const auto filename = QString::fromLatin1(file).split('/').last();
diff --git a/common/log.h b/common/log.h
index 36b8efe..d801ed9 100644
--- a/common/log.h
+++ b/common/log.h
@@ -57,7 +57,7 @@ QByteArrayList SINK_EXPORT debugOutputFilter(FilterType type);
57void SINK_EXPORT setDebugOutputFields(const QByteArrayList &filter); 57void SINK_EXPORT setDebugOutputFields(const QByteArrayList &filter);
58QByteArrayList SINK_EXPORT debugOutputFields(); 58QByteArrayList SINK_EXPORT debugOutputFields();
59 59
60QDebug SINK_EXPORT debugStream(DebugLevel debugLevel, int line, const char *file, const char *function, const char *debugArea = 0); 60QDebug SINK_EXPORT debugStream(DebugLevel debugLevel, int line, const char *file, const char *function, const char *debugArea = 0, const char *debugComponent = 0);
61 61
62struct SINK_EXPORT TraceTime 62struct SINK_EXPORT TraceTime
63{ 63{
@@ -73,18 +73,23 @@ inline QDebug SINK_EXPORT operator<<(QDebug d, const TraceTime &time)
73} 73}
74} 74}
75 75
76#define DEBUG_AREA nullptr 76static const char *getComponentName() { return nullptr; }
77
78#define Trace_() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO)
79#define Log_() Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO)
80 77
81#define Trace_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, AREA) 78#define Trace_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
82#define Log_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, AREA) 79#define Log_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
83#define Warning_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, AREA) 80#define Warning_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
84#define Error_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, AREA) 81#define Error_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
85 82
86#define Trace() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA) 83#define SinkTrace_(COMPONENT, AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, AREA, COMPONENT)
87#define Log() Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA) 84#define SinkLog_(COMPONENT, AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, AREA, COMPONENT)
88#define Warning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA) 85#define SinkWarning_(COMPONENT, AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, AREA, COMPONENT)
89// FIXME Error clashes with Storage::Error and MessageQueue::Error 86#define SinkError_(COMPONENT, AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, AREA, COMPONENT)
90#define ErrorMsg() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA) 87
88#define SinkTrace() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName())
89#define SinkLog() Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName())
90#define SinkWarning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName())
91#define SinkError() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName())
92
93#define SINK_DEBUG_AREA(AREA) static constexpr const char* s_sinkDebugArea{AREA};
94#define SINK_DEBUG_COMPONENT(COMPONENT) const char* getComponentName() const { return COMPONENT; };
95#define SINK_DEBUG_COMPONENT_STATIC(COMPONENT) static const char* getComponentName() { return COMPONENT; };
diff --git a/common/mailpreprocessor.cpp b/common/mailpreprocessor.cpp
index c38035e..2863ad4 100644
--- a/common/mailpreprocessor.cpp
+++ b/common/mailpreprocessor.cpp
@@ -29,6 +29,8 @@
29 29
30using namespace Sink; 30using namespace Sink;
31 31
32SINK_DEBUG_AREA("mailpreprocessor")
33
32QString MailPropertyExtractor::getFilePathFromMimeMessagePath(const QString &s) const 34QString MailPropertyExtractor::getFilePathFromMimeMessagePath(const QString &s) const
33{ 35{
34 return s; 36 return s;
@@ -38,23 +40,23 @@ void MailPropertyExtractor::updatedIndexedProperties(Sink::ApplicationDomain::Ma
38{ 40{
39 const auto mimeMessagePath = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); 41 const auto mimeMessagePath = getFilePathFromMimeMessagePath(mail.getMimeMessagePath());
40 if (mimeMessagePath.isNull()) { 42 if (mimeMessagePath.isNull()) {
41 Trace() << "No mime message"; 43 SinkTrace() << "No mime message";
42 return; 44 return;
43 } 45 }
44 Trace() << "Updating indexed properties " << mimeMessagePath; 46 SinkTrace() << "Updating indexed properties " << mimeMessagePath;
45 QFile f(mimeMessagePath); 47 QFile f(mimeMessagePath);
46 if (!f.open(QIODevice::ReadOnly)) { 48 if (!f.open(QIODevice::ReadOnly)) {
47 Warning() << "Failed to open the file: " << mimeMessagePath; 49 SinkWarning() << "Failed to open the file: " << mimeMessagePath;
48 return; 50 return;
49 } 51 }
50 if (!f.size()) { 52 if (!f.size()) {
51 Warning() << "The file is empty."; 53 SinkWarning() << "The file is empty.";
52 return; 54 return;
53 } 55 }
54 const auto mappedSize = qMin((qint64)8000, f.size()); 56 const auto mappedSize = qMin((qint64)8000, f.size());
55 auto mapped = f.map(0, mappedSize); 57 auto mapped = f.map(0, mappedSize);
56 if (!mapped) { 58 if (!mapped) {
57 Warning() << "Failed to map the file: " << f.errorString(); 59 SinkWarning() << "Failed to map the file: " << f.errorString();
58 return; 60 return;
59 } 61 }
60 62
@@ -89,15 +91,15 @@ QString MimeMessageMover::moveMessage(const QString &oldPath, const Sink::Applic
89 const auto filePath = directory + "/" + mail.identifier(); 91 const auto filePath = directory + "/" + mail.identifier();
90 if (oldPath != filePath) { 92 if (oldPath != filePath) {
91 if (!QDir().mkpath(directory)) { 93 if (!QDir().mkpath(directory)) {
92 Warning() << "Failed to create the directory: " << directory; 94 SinkWarning() << "Failed to create the directory: " << directory;
93 } 95 }
94 QFile::remove(filePath); 96 QFile::remove(filePath);
95 QFile origFile(oldPath); 97 QFile origFile(oldPath);
96 if (!origFile.open(QIODevice::ReadWrite)) { 98 if (!origFile.open(QIODevice::ReadWrite)) {
97 Warning() << "Failed to open the original file with write rights: " << origFile.errorString(); 99 SinkWarning() << "Failed to open the original file with write rights: " << origFile.errorString();
98 } 100 }
99 if (!origFile.rename(filePath)) { 101 if (!origFile.rename(filePath)) {
100 Warning() << "Failed to move the file from: " << oldPath << " to " << filePath << ". " << origFile.errorString(); 102 SinkWarning() << "Failed to move the file from: " << oldPath << " to " << filePath << ". " << origFile.errorString();
101 } 103 }
102 origFile.close(); 104 origFile.close();
103 return filePath; 105 return filePath;
diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp
index b9f11f8..a6e44e3 100644
--- a/common/messagequeue.cpp
+++ b/common/messagequeue.cpp
@@ -3,6 +3,8 @@
3#include <QDebug> 3#include <QDebug>
4#include <log.h> 4#include <log.h>
5 5
6SINK_DEBUG_AREA("messagequeue")
7
6static KAsync::Job<void> waitForCompletion(QList<KAsync::Future<void>> &futures) 8static KAsync::Job<void> waitForCompletion(QList<KAsync::Future<void>> &futures)
7{ 9{
8 auto context = new QObject; 10 auto context = new QObject;
@@ -128,7 +130,7 @@ KAsync::Job<void> MessageQueue::dequeueBatch(int maxBatchSize, const std::functi
128 return false; 130 return false;
129 }, 131 },
130 [](const Sink::Storage::Error &error) { 132 [](const Sink::Storage::Error &error) {
131 ErrorMsg() << "Error while retrieving value" << error.message; 133 SinkError() << "Error while retrieving value" << error.message;
132 // errorHandler(Error(error.store, error.code, error.message)); 134 // errorHandler(Error(error.store, error.code, error.message));
133 }); 135 });
134 136
@@ -164,7 +166,7 @@ bool MessageQueue::isEmpty()
164 } 166 }
165 return true; 167 return true;
166 }, 168 },
167 [](const Sink::Storage::Error &error) { ErrorMsg() << "Error while checking if empty" << error.message; }); 169 [](const Sink::Storage::Error &error) { SinkError() << "Error while checking if empty" << error.message; });
168 } 170 }
169 return count == 0; 171 return count == 0;
170} 172}
diff --git a/common/modelresult.cpp b/common/modelresult.cpp
index 3778d4d..56a39ee 100644
--- a/common/modelresult.cpp
+++ b/common/modelresult.cpp
@@ -25,8 +25,7 @@
25#include "domain/folder.h" 25#include "domain/folder.h"
26#include "log.h" 26#include "log.h"
27 27
28#undef DEBUG_AREA 28SINK_DEBUG_AREA("modelresult")
29#define DEBUG_AREA "client.modelresult"
30 29
31static uint qHash(const Sink::ApplicationDomain::ApplicationDomainType &type) 30static uint qHash(const Sink::ApplicationDomain::ApplicationDomainType &type)
32{ 31{
@@ -123,7 +122,7 @@ QModelIndex ModelResult<T, Ptr>::index(int row, int column, const QModelIndex &p
123 const auto childId = list.at(row); 122 const auto childId = list.at(row);
124 return createIndex(row, column, childId); 123 return createIndex(row, column, childId);
125 } 124 }
126 Warning() << "Index not available " << row << column << parent; 125 SinkWarning() << "Index not available " << row << column << parent;
127 Q_ASSERT(false); 126 Q_ASSERT(false);
128 return QModelIndex(); 127 return QModelIndex();
129} 128}
@@ -174,7 +173,7 @@ bool ModelResult<T, Ptr>::canFetchMore(const QModelIndex &parent) const
174template <class T, class Ptr> 173template <class T, class Ptr>
175void ModelResult<T, Ptr>::fetchMore(const QModelIndex &parent) 174void ModelResult<T, Ptr>::fetchMore(const QModelIndex &parent)
176{ 175{
177 Trace() << "Fetching more: " << parent; 176 SinkTrace() << "Fetching more: " << parent;
178 fetchEntities(parent); 177 fetchEntities(parent);
179} 178}
180 179
@@ -185,7 +184,7 @@ void ModelResult<T, Ptr>::add(const Ptr &value)
185 const auto id = parentId(value); 184 const auto id = parentId(value);
186 // Ignore updates we get before the initial fetch is done 185 // Ignore updates we get before the initial fetch is done
187 if (!mEntityChildrenFetched.contains(id)) { 186 if (!mEntityChildrenFetched.contains(id)) {
188 Trace() << "Too early" << id; 187 SinkTrace() << "Too early" << id;
189 return; 188 return;
190 } 189 }
191 auto parent = createIndexFromId(id); 190 auto parent = createIndexFromId(id);
@@ -198,7 +197,7 @@ void ModelResult<T, Ptr>::add(const Ptr &value)
198 } 197 }
199 } 198 }
200 if (mEntities.contains(childId)) { 199 if (mEntities.contains(childId)) {
201 Warning() << "Entity already in model " << value->identifier(); 200 SinkWarning() << "Entity already in model " << value->identifier();
202 return; 201 return;
203 } 202 }
204 // qDebug() << "Inserting rows " << index << parent; 203 // qDebug() << "Inserting rows " << index << parent;
@@ -234,18 +233,18 @@ void ModelResult<T, Ptr>::fetchEntities(const QModelIndex &parent)
234 const auto id = getIdentifier(parent); 233 const auto id = getIdentifier(parent);
235 mEntityChildrenFetchComplete.remove(id); 234 mEntityChildrenFetchComplete.remove(id);
236 mEntityChildrenFetched.insert(id); 235 mEntityChildrenFetched.insert(id);
237 Trace() << "Loading child entities of parent " << id; 236 SinkTrace() << "Loading child entities of parent " << id;
238 if (loadEntities) { 237 if (loadEntities) {
239 loadEntities(parent.data(DomainObjectRole).template value<Ptr>()); 238 loadEntities(parent.data(DomainObjectRole).template value<Ptr>());
240 } else { 239 } else {
241 Warning() << "No way to fetch entities"; 240 SinkWarning() << "No way to fetch entities";
242 } 241 }
243} 242}
244 243
245template <class T, class Ptr> 244template <class T, class Ptr>
246void ModelResult<T, Ptr>::setFetcher(const std::function<void(const Ptr &parent)> &fetcher) 245void ModelResult<T, Ptr>::setFetcher(const std::function<void(const Ptr &parent)> &fetcher)
247{ 246{
248 Trace() << "Setting fetcher"; 247 SinkTrace() << "Setting fetcher";
249 loadEntities = fetcher; 248 loadEntities = fetcher;
250} 249}
251 250
@@ -270,7 +269,7 @@ void ModelResult<T, Ptr>::setEmitter(const typename Sink::ResultEmitter<Ptr>::Pt
270 }); 269 });
271 }); 270 });
272 emitter->onInitialResultSetComplete([this](const Ptr &parent) { 271 emitter->onInitialResultSetComplete([this](const Ptr &parent) {
273 Trace() << "Initial result set complete"; 272 SinkTrace() << "Initial result set complete";
274 const qint64 parentId = parent ? qHash(*parent) : 0; 273 const qint64 parentId = parent ? qHash(*parent) : 0;
275 const auto parentIndex = createIndexFromId(parentId); 274 const auto parentIndex = createIndexFromId(parentId);
276 mEntityChildrenFetchComplete.insert(parentId); 275 mEntityChildrenFetchComplete.insert(parentId);
diff --git a/common/pipeline.cpp b/common/pipeline.cpp
index 034f913..f1a4a32 100644
--- a/common/pipeline.cpp
+++ b/common/pipeline.cpp
@@ -38,8 +38,7 @@
38#include "definitions.h" 38#include "definitions.h"
39#include "bufferutils.h" 39#include "bufferutils.h"
40 40
41#undef DEBUG_AREA 41SINK_DEBUG_AREA("pipeline")
42#define DEBUG_AREA "resource.pipeline"
43 42
44namespace Sink { 43namespace Sink {
45 44
@@ -63,10 +62,10 @@ public:
63 62
64void Pipeline::Private::storeNewRevision(qint64 newRevision, const flatbuffers::FlatBufferBuilder &fbb, const QByteArray &bufferType, const QByteArray &uid) 63void Pipeline::Private::storeNewRevision(qint64 newRevision, const flatbuffers::FlatBufferBuilder &fbb, const QByteArray &bufferType, const QByteArray &uid)
65{ 64{
66 Trace() << "Committing new revision: " << uid << newRevision; 65 SinkTrace() << "Committing new revision: " << uid << newRevision;
67 Storage::mainDatabase(transaction, bufferType) 66 Storage::mainDatabase(transaction, bufferType)
68 .write(Storage::assembleKey(uid, newRevision), BufferUtils::extractBuffer(fbb), 67 .write(Storage::assembleKey(uid, newRevision), BufferUtils::extractBuffer(fbb),
69 [uid, newRevision](const Storage::Error &error) { Warning() << "Failed to write entity" << uid << newRevision; }); 68 [uid, newRevision](const Storage::Error &error) { SinkWarning() << "Failed to write entity" << uid << newRevision; });
70 revisionChanged = true; 69 revisionChanged = true;
71 Storage::setMaxRevision(transaction, newRevision); 70 Storage::setMaxRevision(transaction, newRevision);
72 Storage::recordRevision(transaction, newRevision, uid, bufferType); 71 Storage::recordRevision(transaction, newRevision, uid, bufferType);
@@ -107,11 +106,11 @@ void Pipeline::startTransaction()
107 if (d->transaction) { 106 if (d->transaction) {
108 return; 107 return;
109 } 108 }
110 Trace() << "Starting transaction."; 109 SinkTrace() << "Starting transaction.";
111 d->transactionTime.start(); 110 d->transactionTime.start();
112 d->transactionItemCount = 0; 111 d->transactionItemCount = 0;
113 d->transaction = storage().createTransaction(Storage::ReadWrite, [](const Sink::Storage::Error &error) { 112 d->transaction = storage().createTransaction(Storage::ReadWrite, [](const Sink::Storage::Error &error) {
114 Warning() << error.message; 113 SinkWarning() << error.message;
115 }); 114 });
116 115
117 //FIXME this is a temporary measure to recover from a failure to open the named databases correctly. 116 //FIXME this is a temporary measure to recover from a failure to open the named databases correctly.
@@ -119,9 +118,9 @@ void Pipeline::startTransaction()
119 //It seems like the validateNamedDatabase calls actually stops the mdb_put failures during sync... 118 //It seems like the validateNamedDatabase calls actually stops the mdb_put failures during sync...
120 if (d->storage.exists()) { 119 if (d->storage.exists()) {
121 while (!d->transaction.validateNamedDatabases()) { 120 while (!d->transaction.validateNamedDatabases()) {
122 Warning() << "Opened an invalid transaction!!!!!!"; 121 SinkWarning() << "Opened an invalid transaction!!!!!!";
123 d->transaction = std::move(storage().createTransaction(Storage::ReadWrite, [](const Sink::Storage::Error &error) { 122 d->transaction = std::move(storage().createTransaction(Storage::ReadWrite, [](const Sink::Storage::Error &error) {
124 Warning() << error.message; 123 SinkWarning() << error.message;
125 })); 124 }));
126 } 125 }
127 } 126 }
@@ -141,7 +140,7 @@ void Pipeline::commit()
141 } 140 }
142 const auto revision = Storage::maxRevision(d->transaction); 141 const auto revision = Storage::maxRevision(d->transaction);
143 const auto elapsed = d->transactionTime.elapsed(); 142 const auto elapsed = d->transactionTime.elapsed();
144 Log() << "Committing revision: " << revision << ":" << d->transactionItemCount << " items in: " << Log::TraceTime(elapsed) << " " 143 SinkLog() << "Committing revision: " << revision << ":" << d->transactionItemCount << " items in: " << Log::TraceTime(elapsed) << " "
145 << (double)elapsed / (double)qMax(d->transactionItemCount, 1) << "[ms/item]"; 144 << (double)elapsed / (double)qMax(d->transactionItemCount, 1) << "[ms/item]";
146 if (d->transaction) { 145 if (d->transaction) {
147 d->transaction.commit(); 146 d->transaction.commit();
@@ -170,7 +169,7 @@ KAsync::Job<qint64> Pipeline::newEntity(void const *command, size_t size)
170 { 169 {
171 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(command), size); 170 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(command), size);
172 if (!Commands::VerifyCreateEntityBuffer(verifyer)) { 171 if (!Commands::VerifyCreateEntityBuffer(verifyer)) {
173 Warning() << "invalid buffer, not a create entity buffer"; 172 SinkWarning() << "invalid buffer, not a create entity buffer";
174 return KAsync::error<qint64>(0); 173 return KAsync::error<qint64>(0);
175 } 174 }
176 } 175 }
@@ -182,7 +181,7 @@ KAsync::Job<qint64> Pipeline::newEntity(void const *command, size_t size)
182 if (createEntity->entityId()) { 181 if (createEntity->entityId()) {
183 key = QByteArray(reinterpret_cast<char const *>(createEntity->entityId()->Data()), createEntity->entityId()->size()); 182 key = QByteArray(reinterpret_cast<char const *>(createEntity->entityId()->Data()), createEntity->entityId()->size());
184 if (Storage::mainDatabase(d->transaction, bufferType).contains(key)) { 183 if (Storage::mainDatabase(d->transaction, bufferType).contains(key)) {
185 ErrorMsg() << "An entity with this id already exists: " << key; 184 SinkError() << "An entity with this id already exists: " << key;
186 return KAsync::error<qint64>(0); 185 return KAsync::error<qint64>(0);
187 } 186 }
188 } 187 }
@@ -190,25 +189,25 @@ KAsync::Job<qint64> Pipeline::newEntity(void const *command, size_t size)
190 if (key.isEmpty()) { 189 if (key.isEmpty()) {
191 key = Sink::Storage::generateUid(); 190 key = Sink::Storage::generateUid();
192 } 191 }
193 Log() << "New Entity. Type: " << bufferType << "uid: "<< key << " replayToSource: " << replayToSource; 192 SinkLog() << "New Entity. Type: " << bufferType << "uid: "<< key << " replayToSource: " << replayToSource;
194 Q_ASSERT(!key.isEmpty()); 193 Q_ASSERT(!key.isEmpty());
195 194
196 { 195 {
197 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(createEntity->delta()->Data()), createEntity->delta()->size()); 196 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(createEntity->delta()->Data()), createEntity->delta()->size());
198 if (!VerifyEntityBuffer(verifyer)) { 197 if (!VerifyEntityBuffer(verifyer)) {
199 Warning() << "invalid buffer, not an entity buffer"; 198 SinkWarning() << "invalid buffer, not an entity buffer";
200 return KAsync::error<qint64>(0); 199 return KAsync::error<qint64>(0);
201 } 200 }
202 } 201 }
203 auto entity = GetEntity(createEntity->delta()->Data()); 202 auto entity = GetEntity(createEntity->delta()->Data());
204 if (!entity->resource()->size() && !entity->local()->size()) { 203 if (!entity->resource()->size() && !entity->local()->size()) {
205 Warning() << "No local and no resource buffer while trying to create entity."; 204 SinkWarning() << "No local and no resource buffer while trying to create entity.";
206 return KAsync::error<qint64>(0); 205 return KAsync::error<qint64>(0);
207 } 206 }
208 207
209 auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(d->resourceType, bufferType); 208 auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(d->resourceType, bufferType);
210 if (!adaptorFactory) { 209 if (!adaptorFactory) {
211 Warning() << "no adaptor factory for type " << bufferType; 210 SinkWarning() << "no adaptor factory for type " << bufferType;
212 return KAsync::error<qint64>(0); 211 return KAsync::error<qint64>(0);
213 } 212 }
214 213
@@ -244,7 +243,7 @@ KAsync::Job<qint64> Pipeline::modifiedEntity(void const *command, size_t size)
244 { 243 {
245 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(command), size); 244 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(command), size);
246 if (!Commands::VerifyModifyEntityBuffer(verifyer)) { 245 if (!Commands::VerifyModifyEntityBuffer(verifyer)) {
247 Warning() << "invalid buffer, not a modify entity buffer"; 246 SinkWarning() << "invalid buffer, not a modify entity buffer";
248 return KAsync::error<qint64>(0); 247 return KAsync::error<qint64>(0);
249 } 248 }
250 } 249 }
@@ -254,21 +253,21 @@ KAsync::Job<qint64> Pipeline::modifiedEntity(void const *command, size_t size)
254 if (modifyEntity->modifiedProperties()) { 253 if (modifyEntity->modifiedProperties()) {
255 changeset = BufferUtils::fromVector(*modifyEntity->modifiedProperties()); 254 changeset = BufferUtils::fromVector(*modifyEntity->modifiedProperties());
256 } else { 255 } else {
257 Warning() << "No changeset available"; 256 SinkWarning() << "No changeset available";
258 } 257 }
259 const qint64 baseRevision = modifyEntity->revision(); 258 const qint64 baseRevision = modifyEntity->revision();
260 const bool replayToSource = modifyEntity->replayToSource(); 259 const bool replayToSource = modifyEntity->replayToSource();
261 const QByteArray bufferType = QByteArray(reinterpret_cast<char const *>(modifyEntity->domainType()->Data()), modifyEntity->domainType()->size()); 260 const QByteArray bufferType = QByteArray(reinterpret_cast<char const *>(modifyEntity->domainType()->Data()), modifyEntity->domainType()->size());
262 const QByteArray key = QByteArray(reinterpret_cast<char const *>(modifyEntity->entityId()->Data()), modifyEntity->entityId()->size()); 261 const QByteArray key = QByteArray(reinterpret_cast<char const *>(modifyEntity->entityId()->Data()), modifyEntity->entityId()->size());
263 Log() << "Modified Entity. Type: " << bufferType << "uid: "<< key << " replayToSource: " << replayToSource; 262 SinkLog() << "Modified Entity. Type: " << bufferType << "uid: "<< key << " replayToSource: " << replayToSource;
264 if (bufferType.isEmpty() || key.isEmpty()) { 263 if (bufferType.isEmpty() || key.isEmpty()) {
265 Warning() << "entity type or key " << bufferType << key; 264 SinkWarning() << "entity type or key " << bufferType << key;
266 return KAsync::error<qint64>(0); 265 return KAsync::error<qint64>(0);
267 } 266 }
268 { 267 {
269 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(modifyEntity->delta()->Data()), modifyEntity->delta()->size()); 268 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(modifyEntity->delta()->Data()), modifyEntity->delta()->size());
270 if (!VerifyEntityBuffer(verifyer)) { 269 if (!VerifyEntityBuffer(verifyer)) {
271 Warning() << "invalid buffer, not an entity buffer"; 270 SinkWarning() << "invalid buffer, not an entity buffer";
272 return KAsync::error<qint64>(0); 271 return KAsync::error<qint64>(0);
273 } 272 }
274 } 273 }
@@ -276,7 +275,7 @@ KAsync::Job<qint64> Pipeline::modifiedEntity(void const *command, size_t size)
276 // TODO use only readPropertyMapper and writePropertyMapper 275 // TODO use only readPropertyMapper and writePropertyMapper
277 auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(d->resourceType, bufferType); 276 auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(d->resourceType, bufferType);
278 if (!adaptorFactory) { 277 if (!adaptorFactory) {
279 Warning() << "no adaptor factory for type " << bufferType; 278 SinkWarning() << "no adaptor factory for type " << bufferType;
280 return KAsync::error<qint64>(0); 279 return KAsync::error<qint64>(0);
281 } 280 }
282 281
@@ -290,16 +289,16 @@ KAsync::Job<qint64> Pipeline::modifiedEntity(void const *command, size_t size)
290 [&current, adaptorFactory](const QByteArray &key, const QByteArray &data) -> bool { 289 [&current, adaptorFactory](const QByteArray &key, const QByteArray &data) -> bool {
291 EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); 290 EntityBuffer buffer(const_cast<const char *>(data.data()), data.size());
292 if (!buffer.isValid()) { 291 if (!buffer.isValid()) {
293 Warning() << "Read invalid buffer from disk"; 292 SinkWarning() << "Read invalid buffer from disk";
294 } else { 293 } else {
295 current = adaptorFactory->createAdaptor(buffer.entity()); 294 current = adaptorFactory->createAdaptor(buffer.entity());
296 } 295 }
297 return false; 296 return false;
298 }, 297 },
299 [baseRevision](const Storage::Error &error) { Warning() << "Failed to read old revision from storage: " << error.message << "Revision: " << baseRevision; }); 298 [baseRevision](const Storage::Error &error) { SinkWarning() << "Failed to read old revision from storage: " << error.message << "Revision: " << baseRevision; });
300 299
301 if (!current) { 300 if (!current) {
302 Warning() << "Failed to read local value " << key; 301 SinkWarning() << "Failed to read local value " << key;
303 return KAsync::error<qint64>(0); 302 return KAsync::error<qint64>(0);
304 } 303 }
305 304
@@ -307,7 +306,7 @@ KAsync::Job<qint64> Pipeline::modifiedEntity(void const *command, size_t size)
307 306
308 // Apply diff 307 // Apply diff
309 // FIXME only apply the properties that are available in the buffer 308 // FIXME only apply the properties that are available in the buffer
310 Trace() << "Applying changed properties: " << changeset; 309 SinkTrace() << "Applying changed properties: " << changeset;
311 for (const auto &property : changeset) { 310 for (const auto &property : changeset) {
312 const auto value = diff->getProperty(property); 311 const auto value = diff->getProperty(property);
313 if (value.isValid()) { 312 if (value.isValid()) {
@@ -357,7 +356,7 @@ KAsync::Job<qint64> Pipeline::deletedEntity(void const *command, size_t size)
357 { 356 {
358 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(command), size); 357 flatbuffers::Verifier verifyer(reinterpret_cast<const uint8_t *>(command), size);
359 if (!Commands::VerifyDeleteEntityBuffer(verifyer)) { 358 if (!Commands::VerifyDeleteEntityBuffer(verifyer)) {
360 Warning() << "invalid buffer, not a delete entity buffer"; 359 SinkWarning() << "invalid buffer, not a delete entity buffer";
361 return KAsync::error<qint64>(0); 360 return KAsync::error<qint64>(0);
362 } 361 }
363 } 362 }
@@ -366,7 +365,7 @@ KAsync::Job<qint64> Pipeline::deletedEntity(void const *command, size_t size)
366 const bool replayToSource = deleteEntity->replayToSource(); 365 const bool replayToSource = deleteEntity->replayToSource();
367 const QByteArray bufferType = QByteArray(reinterpret_cast<char const *>(deleteEntity->domainType()->Data()), deleteEntity->domainType()->size()); 366 const QByteArray bufferType = QByteArray(reinterpret_cast<char const *>(deleteEntity->domainType()->Data()), deleteEntity->domainType()->size());
368 const QByteArray key = QByteArray(reinterpret_cast<char const *>(deleteEntity->entityId()->Data()), deleteEntity->entityId()->size()); 367 const QByteArray key = QByteArray(reinterpret_cast<char const *>(deleteEntity->entityId()->Data()), deleteEntity->entityId()->size());
369 Log() << "Deleted Entity. Type: " << bufferType << "uid: "<< key << " replayToSource: " << replayToSource; 368 SinkLog() << "Deleted Entity. Type: " << bufferType << "uid: "<< key << " replayToSource: " << replayToSource;
370 369
371 bool found = false; 370 bool found = false;
372 bool alreadyRemoved = false; 371 bool alreadyRemoved = false;
@@ -383,14 +382,14 @@ KAsync::Job<qint64> Pipeline::deletedEntity(void const *command, size_t size)
383 } 382 }
384 return false; 383 return false;
385 }, 384 },
386 [](const Storage::Error &error) { Warning() << "Failed to read old revision from storage: " << error.message; }); 385 [](const Storage::Error &error) { SinkWarning() << "Failed to read old revision from storage: " << error.message; });
387 386
388 if (!found) { 387 if (!found) {
389 Warning() << "Failed to find entity " << key; 388 SinkWarning() << "Failed to find entity " << key;
390 return KAsync::error<qint64>(0); 389 return KAsync::error<qint64>(0);
391 } 390 }
392 if (alreadyRemoved) { 391 if (alreadyRemoved) {
393 Warning() << "Entity is already removed " << key; 392 SinkWarning() << "Entity is already removed " << key;
394 return KAsync::error<qint64>(0); 393 return KAsync::error<qint64>(0);
395 } 394 }
396 395
@@ -410,7 +409,7 @@ KAsync::Job<qint64> Pipeline::deletedEntity(void const *command, size_t size)
410 409
411 auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(d->resourceType, bufferType); 410 auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(d->resourceType, bufferType);
412 if (!adaptorFactory) { 411 if (!adaptorFactory) {
413 Warning() << "no adaptor factory for type " << bufferType; 412 SinkWarning() << "no adaptor factory for type " << bufferType;
414 return KAsync::error<qint64>(0); 413 return KAsync::error<qint64>(0);
415 } 414 }
416 415
@@ -420,13 +419,13 @@ KAsync::Job<qint64> Pipeline::deletedEntity(void const *command, size_t size)
420 [this, bufferType, newRevision, adaptorFactory, key, &current](const QByteArray &, const QByteArray &data) -> bool { 419 [this, bufferType, newRevision, adaptorFactory, key, &current](const QByteArray &, const QByteArray &data) -> bool {
421 EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); 420 EntityBuffer buffer(const_cast<const char *>(data.data()), data.size());
422 if (!buffer.isValid()) { 421 if (!buffer.isValid()) {
423 Warning() << "Read invalid buffer from disk"; 422 SinkWarning() << "Read invalid buffer from disk";
424 } else { 423 } else {
425 current = adaptorFactory->createAdaptor(buffer.entity()); 424 current = adaptorFactory->createAdaptor(buffer.entity());
426 } 425 }
427 return false; 426 return false;
428 }, 427 },
429 [this](const Storage::Error &error) { ErrorMsg() << "Failed to find value in pipeline: " << error.message; }); 428 [this](const Storage::Error &error) { SinkError() << "Failed to find value in pipeline: " << error.message; });
430 429
431 d->storeNewRevision(newRevision, fbb, bufferType, key); 430 d->storeNewRevision(newRevision, fbb, bufferType, key);
432 431
@@ -442,13 +441,13 @@ void Pipeline::cleanupRevision(qint64 revision)
442 d->revisionChanged = true; 441 d->revisionChanged = true;
443 const auto uid = Storage::getUidFromRevision(d->transaction, revision); 442 const auto uid = Storage::getUidFromRevision(d->transaction, revision);
444 const auto bufferType = Storage::getTypeFromRevision(d->transaction, revision); 443 const auto bufferType = Storage::getTypeFromRevision(d->transaction, revision);
445 Trace() << "Cleaning up revision " << revision << uid << bufferType; 444 SinkTrace() << "Cleaning up revision " << revision << uid << bufferType;
446 Storage::mainDatabase(d->transaction, bufferType) 445 Storage::mainDatabase(d->transaction, bufferType)
447 .scan(uid, 446 .scan(uid,
448 [&](const QByteArray &key, const QByteArray &data) -> bool { 447 [&](const QByteArray &key, const QByteArray &data) -> bool {
449 EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); 448 EntityBuffer buffer(const_cast<const char *>(data.data()), data.size());
450 if (!buffer.isValid()) { 449 if (!buffer.isValid()) {
451 Warning() << "Read invalid buffer from disk"; 450 SinkWarning() << "Read invalid buffer from disk";
452 } else { 451 } else {
453 const auto metadata = flatbuffers::GetRoot<Metadata>(buffer.metadataBuffer()); 452 const auto metadata = flatbuffers::GetRoot<Metadata>(buffer.metadataBuffer());
454 const qint64 rev = metadata->revision(); 453 const qint64 rev = metadata->revision();
@@ -461,7 +460,7 @@ void Pipeline::cleanupRevision(qint64 revision)
461 460
462 return true; 461 return true;
463 }, 462 },
464 [](const Storage::Error &error) { Warning() << "Error while reading: " << error.message; }, true); 463 [](const Storage::Error &error) { SinkWarning() << "Error while reading: " << error.message; }, true);
465 Storage::setCleanedUpRevision(d->transaction, revision); 464 Storage::setCleanedUpRevision(d->transaction, revision);
466} 465}
467 466
diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp
index 0be2ae1..2e2e96d 100644
--- a/common/queryrunner.cpp
+++ b/common/queryrunner.cpp
@@ -29,8 +29,7 @@
29#include "asyncutils.h" 29#include "asyncutils.h"
30#include "entityreader.h" 30#include "entityreader.h"
31 31
32#undef DEBUG_AREA 32SINK_DEBUG_AREA("queryrunner")
33#define DEBUG_AREA "client.queryrunner"
34 33
35using namespace Sink; 34using namespace Sink;
36 35
@@ -43,6 +42,8 @@ using namespace Sink;
43template <typename DomainType> 42template <typename DomainType>
44class QueryWorker : public QObject 43class QueryWorker : public QObject
45{ 44{
45 // SINK_DEBUG_COMPONENT(mResourceInstanceIdentifier, mId)
46 SINK_DEBUG_COMPONENT(mResourceInstanceIdentifier)
46public: 47public:
47 QueryWorker(const Sink::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &, const QByteArray &bufferType, 48 QueryWorker(const Sink::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &, const QByteArray &bufferType,
48 const QueryRunnerBase::ResultTransformation &transformation); 49 const QueryRunnerBase::ResultTransformation &transformation);
@@ -61,22 +62,19 @@ private:
61 QByteArray mId; //Used for identification in debug output 62 QByteArray mId; //Used for identification in debug output
62}; 63};
63 64
64#undef Trace
65#define Trace() Trace_area(DEBUG_AREA)
66
67template <class DomainType> 65template <class DomainType>
68QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::ResourceAccessInterface::Ptr &resourceAccess, const QByteArray &instanceIdentifier, 66QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::ResourceAccessInterface::Ptr &resourceAccess, const QByteArray &instanceIdentifier,
69 const DomainTypeAdaptorFactoryInterface::Ptr &factory, const QByteArray &bufferType) 67 const DomainTypeAdaptorFactoryInterface::Ptr &factory, const QByteArray &bufferType)
70 : QueryRunnerBase(), mResourceAccess(resourceAccess), mResultProvider(new ResultProvider<typename DomainType::Ptr>), mBatchSize(query.limit) 68 : QueryRunnerBase(), mResourceAccess(resourceAccess), mResultProvider(new ResultProvider<typename DomainType::Ptr>), mBatchSize(query.limit)
71{ 69{
72 Trace() << "Starting query"; 70 SinkTrace() << "Starting query";
73 if (query.limit && query.sortProperty.isEmpty()) { 71 if (query.limit && query.sortProperty.isEmpty()) {
74 Warning() << "A limited query without sorting is typically a bad idea."; 72 SinkWarning() << "A limited query without sorting is typically a bad idea.";
75 } 73 }
76 // We delegate loading of initial data to the result provider, so it can decide for itself what it needs to load. 74 // We delegate loading of initial data to the result provider, so it can decide for itself what it needs to load.
77 mResultProvider->setFetcher([=](const typename DomainType::Ptr &parent) { 75 mResultProvider->setFetcher([=](const typename DomainType::Ptr &parent) {
78 const QByteArray parentId = parent ? parent->identifier() : QByteArray(); 76 const QByteArray parentId = parent ? parent->identifier() : QByteArray();
79 Trace() << "Running fetcher. Offset: " << mOffset[parentId] << " Batchsize: " << mBatchSize; 77 SinkTrace() << "Running fetcher. Offset: " << mOffset[parentId] << " Batchsize: " << mBatchSize;
80 auto resultProvider = mResultProvider; 78 auto resultProvider = mResultProvider;
81 if (query.synchronousQuery) { 79 if (query.synchronousQuery) {
82 QueryWorker<DomainType> worker(query, instanceIdentifier, factory, bufferType, mResultTransformation); 80 QueryWorker<DomainType> worker(query, instanceIdentifier, factory, bufferType, mResultTransformation);
@@ -131,7 +129,7 @@ QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::Resou
131template <class DomainType> 129template <class DomainType>
132QueryRunner<DomainType>::~QueryRunner() 130QueryRunner<DomainType>::~QueryRunner()
133{ 131{
134 Trace() << "Stopped query"; 132 SinkTrace() << "Stopped query";
135} 133}
136 134
137template <class DomainType> 135template <class DomainType>
@@ -147,21 +145,18 @@ typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr QueryRunner<DomainTy
147} 145}
148 146
149 147
150#undef Trace
151#define Trace() Trace_area("client.queryrunner." + mId)
152
153template <class DomainType> 148template <class DomainType>
154QueryWorker<DomainType>::QueryWorker(const Sink::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &factory, 149QueryWorker<DomainType>::QueryWorker(const Sink::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &factory,
155 const QByteArray &bufferType, const QueryRunnerBase::ResultTransformation &transformation) 150 const QByteArray &bufferType, const QueryRunnerBase::ResultTransformation &transformation)
156 : QObject(), mResultTransformation(transformation), mDomainTypeAdaptorFactory(factory), mResourceInstanceIdentifier(instanceIdentifier), mId(QUuid::createUuid().toByteArray()) 151 : QObject(), mResultTransformation(transformation), mDomainTypeAdaptorFactory(factory), mResourceInstanceIdentifier(instanceIdentifier), mId(QUuid::createUuid().toByteArray())
157{ 152{
158 Trace() << "Starting query worker"; 153 SinkTrace() << "Starting query worker";
159} 154}
160 155
161template <class DomainType> 156template <class DomainType>
162QueryWorker<DomainType>::~QueryWorker() 157QueryWorker<DomainType>::~QueryWorker()
163{ 158{
164 Trace() << "Stopped query worker"; 159 SinkTrace() << "Stopped query worker";
165} 160}
166 161
167template <class DomainType> 162template <class DomainType>
@@ -174,15 +169,15 @@ std::function<bool(const typename DomainType::Ptr &, Sink::Operation)> QueryWork
174 } 169 }
175 switch (operation) { 170 switch (operation) {
176 case Sink::Operation_Creation: 171 case Sink::Operation_Creation:
177 // Trace() << "Got creation"; 172 // SinkTrace() << "Got creation";
178 resultProvider.add(valueCopy); 173 resultProvider.add(valueCopy);
179 break; 174 break;
180 case Sink::Operation_Modification: 175 case Sink::Operation_Modification:
181 // Trace() << "Got modification"; 176 // SinkTrace() << "Got modification";
182 resultProvider.modify(valueCopy); 177 resultProvider.modify(valueCopy);
183 break; 178 break;
184 case Sink::Operation_Removal: 179 case Sink::Operation_Removal:
185 // Trace() << "Got removal"; 180 // SinkTrace() << "Got removal";
186 resultProvider.remove(valueCopy); 181 resultProvider.remove(valueCopy);
187 break; 182 break;
188 } 183 }
@@ -200,7 +195,7 @@ QPair<qint64, qint64> QueryWorker<DomainType>::executeIncrementalQuery(const Sin
200 195
201 Sink::EntityReader<DomainType> reader(*mDomainTypeAdaptorFactory, mResourceInstanceIdentifier, transaction); 196 Sink::EntityReader<DomainType> reader(*mDomainTypeAdaptorFactory, mResourceInstanceIdentifier, transaction);
202 auto revisionAndReplayedEntities = reader.executeIncrementalQuery(query, resultProvider.revision(), resultProviderCallback(query, resultProvider)); 197 auto revisionAndReplayedEntities = reader.executeIncrementalQuery(query, resultProvider.revision(), resultProviderCallback(query, resultProvider));
203 Trace() << "Incremental query took: " << Log::TraceTime(time.elapsed()); 198 SinkTrace() << "Incremental query took: " << Log::TraceTime(time.elapsed());
204 return revisionAndReplayedEntities; 199 return revisionAndReplayedEntities;
205} 200}
206 201
@@ -212,10 +207,10 @@ Storage::Transaction QueryWorker<DomainType>::getTransaction()
212 Sink::Storage storage(Sink::storageLocation(), mResourceInstanceIdentifier); 207 Sink::Storage storage(Sink::storageLocation(), mResourceInstanceIdentifier);
213 if (!storage.exists()) { 208 if (!storage.exists()) {
214 //This is not an error if the resource wasn't started before 209 //This is not an error if the resource wasn't started before
215 Log() << "Store doesn't exist: " << mResourceInstanceIdentifier; 210 SinkLog() << "Store doesn't exist: " << mResourceInstanceIdentifier;
216 return Sink::Storage::Transaction(); 211 return Sink::Storage::Transaction();
217 } 212 }
218 storage.setDefaultErrorHandler([](const Sink::Storage::Error &error) { Warning() << "Error during query: " << error.store << error.message; }); 213 storage.setDefaultErrorHandler([this](const Sink::Storage::Error &error) { SinkWarning() << "Error during query: " << error.store << error.message; });
219 transaction = storage.createTransaction(Sink::Storage::ReadOnly); 214 transaction = storage.createTransaction(Sink::Storage::ReadOnly);
220 } 215 }
221 216
@@ -238,10 +233,10 @@ QPair<qint64, qint64> QueryWorker<DomainType>::executeInitialQuery(
238 auto modifiedQuery = query; 233 auto modifiedQuery = query;
239 if (!query.parentProperty.isEmpty()) { 234 if (!query.parentProperty.isEmpty()) {
240 if (parent) { 235 if (parent) {
241 Trace() << "Running initial query for parent:" << parent->identifier(); 236 SinkTrace() << "Running initial query for parent:" << parent->identifier();
242 modifiedQuery.propertyFilter.insert(query.parentProperty, Query::Comparator(parent->identifier())); 237 modifiedQuery.propertyFilter.insert(query.parentProperty, Query::Comparator(parent->identifier()));
243 } else { 238 } else {
244 Trace() << "Running initial query for toplevel"; 239 SinkTrace() << "Running initial query for toplevel";
245 modifiedQuery.propertyFilter.insert(query.parentProperty, Query::Comparator(QVariant())); 240 modifiedQuery.propertyFilter.insert(query.parentProperty, Query::Comparator(QVariant()));
246 } 241 }
247 } 242 }
@@ -250,7 +245,7 @@ QPair<qint64, qint64> QueryWorker<DomainType>::executeInitialQuery(
250 245
251 Sink::EntityReader<DomainType> reader(*mDomainTypeAdaptorFactory, mResourceInstanceIdentifier, transaction); 246 Sink::EntityReader<DomainType> reader(*mDomainTypeAdaptorFactory, mResourceInstanceIdentifier, transaction);
252 auto revisionAndReplayedEntities = reader.executeInitialQuery(modifiedQuery, offset, batchsize, resultProviderCallback(query, resultProvider)); 247 auto revisionAndReplayedEntities = reader.executeInitialQuery(modifiedQuery, offset, batchsize, resultProviderCallback(query, resultProvider));
253 Trace() << "Initial query took: " << Log::TraceTime(time.elapsed()); 248 SinkTrace() << "Initial query took: " << Log::TraceTime(time.elapsed());
254 return revisionAndReplayedEntities; 249 return revisionAndReplayedEntities;
255} 250}
256 251
diff --git a/common/queryrunner.h b/common/queryrunner.h
index e6d5a54..155528e 100644
--- a/common/queryrunner.h
+++ b/common/queryrunner.h
@@ -32,6 +32,8 @@
32class QueryRunnerBase : public QObject 32class QueryRunnerBase : public QObject
33{ 33{
34 Q_OBJECT 34 Q_OBJECT
35protected:
36 SINK_DEBUG_AREA("queryrunner")
35public: 37public:
36 typedef std::function<void(Sink::ApplicationDomain::ApplicationDomainType &domainObject)> ResultTransformation; 38 typedef std::function<void(Sink::ApplicationDomain::ApplicationDomainType &domainObject)> ResultTransformation;
37 39
@@ -52,7 +54,7 @@ protected slots:
52 */ 54 */
53 void revisionChanged(qint64 newRevision) 55 void revisionChanged(qint64 newRevision)
54 { 56 {
55 Trace() << "New revision: " << newRevision; 57 SinkTrace() << "New revision: " << newRevision;
56 run().exec(); 58 run().exec();
57 } 59 }
58 60
diff --git a/common/remoteidmap.cpp b/common/remoteidmap.cpp
index bbcd641..20a054d 100644
--- a/common/remoteidmap.cpp
+++ b/common/remoteidmap.cpp
@@ -25,6 +25,8 @@
25 25
26using namespace Sink; 26using namespace Sink;
27 27
28SINK_DEBUG_AREA("remoteidmap")
29
28RemoteIdMap::RemoteIdMap(Sink::Storage::Transaction &transaction) 30RemoteIdMap::RemoteIdMap(Sink::Storage::Transaction &transaction)
29 : mTransaction(transaction) 31 : mTransaction(transaction)
30{ 32{
@@ -67,7 +69,7 @@ QByteArray RemoteIdMap::resolveLocalId(const QByteArray &bufferType, const QByte
67{ 69{
68 QByteArray remoteId = Index("localid.mapping." + bufferType, mTransaction).lookup(localId); 70 QByteArray remoteId = Index("localid.mapping." + bufferType, mTransaction).lookup(localId);
69 if (remoteId.isEmpty()) { 71 if (remoteId.isEmpty()) {
70 Warning() << "Couldn't find the remote id for " << localId; 72 SinkWarning() << "Couldn't find the remote id for " << localId;
71 return QByteArray(); 73 return QByteArray();
72 } 74 }
73 return remoteId; 75 return remoteId;
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp
index 93f97e8..c878143 100644
--- a/common/resourceaccess.cpp
+++ b/common/resourceaccess.cpp
@@ -44,12 +44,6 @@
44#include <QBuffer> 44#include <QBuffer>
45#include <QTime> 45#include <QTime>
46 46
47#undef Trace
48#define TracePrivate() Trace_area("client.communication." + resourceInstanceIdentifier)
49#define Trace() Trace_area("client.communication." + d->resourceInstanceIdentifier)
50#undef Log
51#define Log() Log_area("client.communication." + d->resourceInstanceIdentifier)
52
53static void queuedInvoke(const std::function<void()> &f, QObject *context = 0) 47static void queuedInvoke(const std::function<void()> &f, QObject *context = 0)
54{ 48{
55 auto timer = QSharedPointer<QTimer>::create(); 49 auto timer = QSharedPointer<QTimer>::create();
@@ -100,8 +94,10 @@ public:
100 QHash<uint, bool> completeCommands; 94 QHash<uint, bool> completeCommands;
101 uint messageId; 95 uint messageId;
102 bool openingSocket; 96 bool openingSocket;
97 SINK_DEBUG_COMPONENT(resourceInstanceIdentifier)
103}; 98};
104 99
100
105ResourceAccess::Private::Private(const QByteArray &name, const QByteArray &instanceIdentifier, ResourceAccess *q) 101ResourceAccess::Private::Private(const QByteArray &name, const QByteArray &instanceIdentifier, ResourceAccess *q)
106 : resourceName(name), resourceInstanceIdentifier(instanceIdentifier), messageId(0), openingSocket(false) 102 : resourceName(name), resourceInstanceIdentifier(instanceIdentifier), messageId(0), openingSocket(false)
107{ 103{
@@ -111,7 +107,7 @@ void ResourceAccess::Private::abortPendingOperations()
111{ 107{
112 callCallbacks(); 108 callCallbacks();
113 if (!resultHandler.isEmpty()) { 109 if (!resultHandler.isEmpty()) {
114 Warning() << "Aborting pending operations " << resultHandler.keys(); 110 SinkWarning() << "Aborting pending operations " << resultHandler.keys();
115 } 111 }
116 auto handlers = resultHandler.values(); 112 auto handlers = resultHandler.values();
117 resultHandler.clear(); 113 resultHandler.clear();
@@ -165,7 +161,7 @@ KAsync::Job<void> ResourceAccess::Private::tryToConnect()
165 auto counter = QSharedPointer<int>::create(0); 161 auto counter = QSharedPointer<int>::create(0);
166 return KAsync::dowhile([this]() -> bool { return !socket; }, 162 return KAsync::dowhile([this]() -> bool { return !socket; },
167 [this, counter](KAsync::Future<void> &future) { 163 [this, counter](KAsync::Future<void> &future) {
168 TracePrivate() << "Loop"; 164 SinkTrace() << "Loop";
169 connectToServer(resourceInstanceIdentifier) 165 connectToServer(resourceInstanceIdentifier)
170 .then<void, QSharedPointer<QLocalSocket>>( 166 .then<void, QSharedPointer<QLocalSocket>>(
171 [this, &future](const QSharedPointer<QLocalSocket> &s) { 167 [this, &future](const QSharedPointer<QLocalSocket> &s) {
@@ -178,7 +174,7 @@ KAsync::Job<void> ResourceAccess::Private::tryToConnect()
178 static int timeout = 500; 174 static int timeout = 500;
179 static int maxRetries = timeout / waitTime; 175 static int maxRetries = timeout / waitTime;
180 if (*counter > maxRetries) { 176 if (*counter > maxRetries) {
181 TracePrivate() << "Giving up"; 177 SinkTrace() << "Giving up";
182 future.setError(-1, "Failed to connect to socket"); 178 future.setError(-1, "Failed to connect to socket");
183 } else { 179 } else {
184 KAsync::wait(waitTime).then<void>([&future]() { future.setFinished(); }).exec(); 180 KAsync::wait(waitTime).then<void>([&future]() { future.setFinished(); }).exec();
@@ -192,17 +188,17 @@ KAsync::Job<void> ResourceAccess::Private::tryToConnect()
192KAsync::Job<void> ResourceAccess::Private::initializeSocket() 188KAsync::Job<void> ResourceAccess::Private::initializeSocket()
193{ 189{
194 return KAsync::start<void>([this](KAsync::Future<void> &future) { 190 return KAsync::start<void>([this](KAsync::Future<void> &future) {
195 TracePrivate() << "Trying to connect"; 191 SinkTrace() << "Trying to connect";
196 connectToServer(resourceInstanceIdentifier) 192 connectToServer(resourceInstanceIdentifier)
197 .then<void, QSharedPointer<QLocalSocket>>( 193 .then<void, QSharedPointer<QLocalSocket>>(
198 [this, &future](const QSharedPointer<QLocalSocket> &s) { 194 [this, &future](const QSharedPointer<QLocalSocket> &s) {
199 TracePrivate() << "Connected to resource, without having to start it."; 195 SinkTrace() << "Connected to resource, without having to start it.";
200 Q_ASSERT(s); 196 Q_ASSERT(s);
201 socket = s; 197 socket = s;
202 future.setFinished(); 198 future.setFinished();
203 }, 199 },
204 [this, &future](int errorCode, const QString &errorString) { 200 [this, &future](int errorCode, const QString &errorString) {
205 TracePrivate() << "Failed to connect, starting resource"; 201 SinkTrace() << "Failed to connect, starting resource";
206 // We failed to connect, so let's start the resource 202 // We failed to connect, so let's start the resource
207 QStringList args; 203 QStringList args;
208 if (Sink::Test::testModeEnabled()) { 204 if (Sink::Test::testModeEnabled()) {
@@ -211,16 +207,16 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket()
211 args << resourceInstanceIdentifier << resourceName; 207 args << resourceInstanceIdentifier << resourceName;
212 qint64 pid = 0; 208 qint64 pid = 0;
213 if (QProcess::startDetached("sink_synchronizer", args, QDir::homePath(), &pid)) { 209 if (QProcess::startDetached("sink_synchronizer", args, QDir::homePath(), &pid)) {
214 TracePrivate() << "Started resource " << pid; 210 SinkTrace() << "Started resource " << pid;
215 tryToConnect() 211 tryToConnect()
216 .then<void>([&future]() { future.setFinished(); }, 212 .then<void>([&future]() { future.setFinished(); },
217 [this, &future](int errorCode, const QString &errorString) { 213 [this, &future](int errorCode, const QString &errorString) {
218 Warning() << "Failed to connect to started resource"; 214 SinkWarning() << "Failed to connect to started resource";
219 future.setError(errorCode, errorString); 215 future.setError(errorCode, errorString);
220 }) 216 })
221 .exec(); 217 .exec();
222 } else { 218 } else {
223 Warning() << "Failed to start resource"; 219 SinkWarning() << "Failed to start resource";
224 } 220 }
225 }) 221 })
226 .exec(); 222 .exec();
@@ -231,14 +227,14 @@ ResourceAccess::ResourceAccess(const QByteArray &resourceInstanceIdentifier, con
231 : ResourceAccessInterface(), d(new Private(resourceType, resourceInstanceIdentifier, this)) 227 : ResourceAccessInterface(), d(new Private(resourceType, resourceInstanceIdentifier, this))
232{ 228{
233 mResourceStatus = Sink::ApplicationDomain::OfflineStatus; 229 mResourceStatus = Sink::ApplicationDomain::OfflineStatus;
234 Trace() << "Starting access"; 230 SinkTrace() << "Starting access";
235} 231}
236 232
237ResourceAccess::~ResourceAccess() 233ResourceAccess::~ResourceAccess()
238{ 234{
239 Log() << "Closing access"; 235 SinkLog() << "Closing access";
240 if (!d->resultHandler.isEmpty()) { 236 if (!d->resultHandler.isEmpty()) {
241 Warning() << "Left jobs running while shutting down ResourceAccess: " << d->resultHandler.keys(); 237 SinkWarning() << "Left jobs running while shutting down ResourceAccess: " << d->resultHandler.keys();
242 } 238 }
243} 239}
244 240
@@ -295,7 +291,7 @@ KAsync::Job<void> ResourceAccess::sendCommand(int commandId, flatbuffers::FlatBu
295 291
296KAsync::Job<void> ResourceAccess::synchronizeResource(bool sourceSync, bool localSync) 292KAsync::Job<void> ResourceAccess::synchronizeResource(bool sourceSync, bool localSync)
297{ 293{
298 Trace() << "Sending synchronize command: " << sourceSync << localSync; 294 SinkTrace() << "Sending synchronize command: " << sourceSync << localSync;
299 flatbuffers::FlatBufferBuilder fbb; 295 flatbuffers::FlatBufferBuilder fbb;
300 auto command = Sink::Commands::CreateSynchronize(fbb, sourceSync, localSync); 296 auto command = Sink::Commands::CreateSynchronize(fbb, sourceSync, localSync);
301 Sink::Commands::FinishSynchronizeBuffer(fbb, command); 297 Sink::Commands::FinishSynchronizeBuffer(fbb, command);
@@ -376,7 +372,7 @@ ResourceAccess::sendInspectionCommand(int inspectionType, const QByteArray &insp
376void ResourceAccess::open() 372void ResourceAccess::open()
377{ 373{
378 if (d->socket && d->socket->isValid()) { 374 if (d->socket && d->socket->isValid()) {
379 // Trace() << "Socket valid, so not opening again"; 375 // SinkTrace() << "Socket valid, so not opening again";
380 return; 376 return;
381 } 377 }
382 if (d->openingSocket) { 378 if (d->openingSocket) {
@@ -388,7 +384,7 @@ void ResourceAccess::open()
388 d->initializeSocket() 384 d->initializeSocket()
389 .then<void>( 385 .then<void>(
390 [this, time]() { 386 [this, time]() {
391 Trace() << "Socket is initialized." << Log::TraceTime(time->elapsed()); 387 SinkTrace() << "Socket is initialized." << Log::TraceTime(time->elapsed());
392 d->openingSocket = false; 388 d->openingSocket = false;
393 QObject::connect(d->socket.data(), &QLocalSocket::disconnected, this, &ResourceAccess::disconnected); 389 QObject::connect(d->socket.data(), &QLocalSocket::disconnected, this, &ResourceAccess::disconnected);
394 QObject::connect(d->socket.data(), SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(connectionError(QLocalSocket::LocalSocketError))); 390 QObject::connect(d->socket.data(), SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(connectionError(QLocalSocket::LocalSocketError)));
@@ -397,16 +393,16 @@ void ResourceAccess::open()
397 }, 393 },
398 [this](int error, const QString &errorString) { 394 [this](int error, const QString &errorString) {
399 d->openingSocket = false; 395 d->openingSocket = false;
400 Warning() << "Failed to initialize socket " << errorString; 396 SinkWarning() << "Failed to initialize socket " << errorString;
401 }) 397 })
402 .exec(); 398 .exec();
403} 399}
404 400
405void ResourceAccess::close() 401void ResourceAccess::close()
406{ 402{
407 Log() << QString("Closing %1").arg(d->socket->fullServerName()); 403 SinkLog() << QString("Closing %1").arg(d->socket->fullServerName());
408 Trace() << "Pending commands: " << d->pendingCommands.size(); 404 SinkTrace() << "Pending commands: " << d->pendingCommands.size();
409 Trace() << "Queued commands: " << d->commandQueue.size(); 405 SinkTrace() << "Queued commands: " << d->commandQueue.size();
410 d->socket->close(); 406 d->socket->close();
411} 407}
412 408
@@ -416,10 +412,10 @@ void ResourceAccess::sendCommand(const QSharedPointer<QueuedCommand> &command)
416 // TODO: we should have a timeout for commands 412 // TODO: we should have a timeout for commands
417 d->messageId++; 413 d->messageId++;
418 const auto messageId = d->messageId; 414 const auto messageId = d->messageId;
419 Trace() << QString("Sending command \"%1\" with messageId %2").arg(QString(Sink::Commands::name(command->commandId))).arg(d->messageId); 415 SinkTrace() << QString("Sending command \"%1\" with messageId %2").arg(QString(Sink::Commands::name(command->commandId))).arg(d->messageId);
420 Q_ASSERT(command->callback); 416 Q_ASSERT(command->callback);
421 registerCallback(d->messageId, [this, messageId, command](int errorCode, QString errorMessage) { 417 registerCallback(d->messageId, [this, messageId, command](int errorCode, QString errorMessage) {
422 Trace() << "Command complete " << messageId; 418 SinkTrace() << "Command complete " << messageId;
423 d->pendingCommands.remove(messageId); 419 d->pendingCommands.remove(messageId);
424 command->callback(errorCode, errorMessage); 420 command->callback(errorCode, errorMessage);
425 }); 421 });
@@ -431,8 +427,8 @@ void ResourceAccess::sendCommand(const QSharedPointer<QueuedCommand> &command)
431void ResourceAccess::processCommandQueue() 427void ResourceAccess::processCommandQueue()
432{ 428{
433 // TODO: serialize instead of blast them all through the socket? 429 // TODO: serialize instead of blast them all through the socket?
434 Trace() << "We have " << d->commandQueue.size() << " queued commands"; 430 SinkTrace() << "We have " << d->commandQueue.size() << " queued commands";
435 Trace() << "Pending commands: " << d->pendingCommands.size(); 431 SinkTrace() << "Pending commands: " << d->pendingCommands.size();
436 for (auto command : d->commandQueue) { 432 for (auto command : d->commandQueue) {
437 sendCommand(command); 433 sendCommand(command);
438 } 434 }
@@ -441,9 +437,9 @@ void ResourceAccess::processCommandQueue()
441 437
442void ResourceAccess::processPendingCommandQueue() 438void ResourceAccess::processPendingCommandQueue()
443{ 439{
444 Trace() << "We have " << d->pendingCommands.size() << " pending commands"; 440 SinkTrace() << "We have " << d->pendingCommands.size() << " pending commands";
445 for (auto command : d->pendingCommands) { 441 for (auto command : d->pendingCommands) {
446 Trace() << "Reenquing command " << command->commandId; 442 SinkTrace() << "Reenquing command " << command->commandId;
447 d->commandQueue << command; 443 d->commandQueue << command;
448 } 444 }
449 d->pendingCommands.clear(); 445 d->pendingCommands.clear();
@@ -453,11 +449,11 @@ void ResourceAccess::processPendingCommandQueue()
453void ResourceAccess::connected() 449void ResourceAccess::connected()
454{ 450{
455 if (!isReady()) { 451 if (!isReady()) {
456 Trace() << "Connected but not ready?"; 452 SinkTrace() << "Connected but not ready?";
457 return; 453 return;
458 } 454 }
459 455
460 Trace() << QString("Connected: %1").arg(d->socket->fullServerName()); 456 SinkTrace() << QString("Connected: %1").arg(d->socket->fullServerName());
461 457
462 { 458 {
463 flatbuffers::FlatBufferBuilder fbb; 459 flatbuffers::FlatBufferBuilder fbb;
@@ -477,7 +473,7 @@ void ResourceAccess::connected()
477 473
478void ResourceAccess::disconnected() 474void ResourceAccess::disconnected()
479{ 475{
480 Log() << QString("Disconnected from %1").arg(d->socket->fullServerName()); 476 SinkLog() << QString("Disconnected from %1").arg(d->socket->fullServerName());
481 d->socket->close(); 477 d->socket->close();
482 emit ready(false); 478 emit ready(false);
483} 479}
@@ -486,15 +482,15 @@ void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error)
486{ 482{
487 const bool resourceCrashed = d->partialMessageBuffer.contains("PANIC"); 483 const bool resourceCrashed = d->partialMessageBuffer.contains("PANIC");
488 if (resourceCrashed) { 484 if (resourceCrashed) {
489 ErrorMsg() << "The resource crashed!"; 485 SinkError() << "The resource crashed!";
490 d->abortPendingOperations(); 486 d->abortPendingOperations();
491 } else if (error == QLocalSocket::PeerClosedError) { 487 } else if (error == QLocalSocket::PeerClosedError) {
492 Log() << "The resource closed the connection."; 488 SinkLog() << "The resource closed the connection.";
493 d->abortPendingOperations(); 489 d->abortPendingOperations();
494 } else { 490 } else {
495 Warning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString()); 491 SinkWarning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString());
496 if (d->pendingCommands.size()) { 492 if (d->pendingCommands.size()) {
497 Trace() << "Reconnecting due to pending operations: " << d->pendingCommands.size(); 493 SinkTrace() << "Reconnecting due to pending operations: " << d->pendingCommands.size();
498 open(); 494 open();
499 } 495 }
500 } 496 }
@@ -503,7 +499,7 @@ void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error)
503void ResourceAccess::readResourceMessage() 499void ResourceAccess::readResourceMessage()
504{ 500{
505 if (!d->socket || !d->socket->isValid()) { 501 if (!d->socket || !d->socket->isValid()) {
506 Warning() << "No socket available"; 502 SinkWarning() << "No socket available";
507 return; 503 return;
508 } 504 }
509 505
@@ -534,7 +530,7 @@ bool ResourceAccess::processMessageBuffer()
534{ 530{
535 static const int headerSize = Commands::headerSize(); 531 static const int headerSize = Commands::headerSize();
536 if (d->partialMessageBuffer.size() < headerSize) { 532 if (d->partialMessageBuffer.size() < headerSize) {
537 Warning() << "command too small"; 533 SinkWarning() << "command too small";
538 return false; 534 return false;
539 } 535 }
540 536
@@ -543,14 +539,14 @@ bool ResourceAccess::processMessageBuffer()
543 const uint size = *(int *)(d->partialMessageBuffer.constData() + sizeof(int) + sizeof(uint)); 539 const uint size = *(int *)(d->partialMessageBuffer.constData() + sizeof(int) + sizeof(uint));
544 540
545 if (size > (uint)(d->partialMessageBuffer.size() - headerSize)) { 541 if (size > (uint)(d->partialMessageBuffer.size() - headerSize)) {
546 Warning() << "command too small"; 542 SinkWarning() << "command too small";
547 return false; 543 return false;
548 } 544 }
549 545
550 switch (commandId) { 546 switch (commandId) {
551 case Commands::RevisionUpdateCommand: { 547 case Commands::RevisionUpdateCommand: {
552 auto buffer = Commands::GetRevisionUpdate(d->partialMessageBuffer.constData() + headerSize); 548 auto buffer = Commands::GetRevisionUpdate(d->partialMessageBuffer.constData() + headerSize);
553 Trace() << QString("Revision updated to: %1").arg(buffer->revision()); 549 SinkTrace() << QString("Revision updated to: %1").arg(buffer->revision());
554 Notification n; 550 Notification n;
555 n.type = Sink::Notification::RevisionUpdate; 551 n.type = Sink::Notification::RevisionUpdate;
556 emit notification(n); 552 emit notification(n);
@@ -560,7 +556,7 @@ bool ResourceAccess::processMessageBuffer()
560 } 556 }
561 case Commands::CommandCompletionCommand: { 557 case Commands::CommandCompletionCommand: {
562 auto buffer = Commands::GetCommandCompletion(d->partialMessageBuffer.constData() + headerSize); 558 auto buffer = Commands::GetCommandCompletion(d->partialMessageBuffer.constData() + headerSize);
563 Trace() << QString("Command with messageId %1 completed %2").arg(buffer->id()).arg(buffer->success() ? "sucessfully" : "unsuccessfully"); 559 SinkTrace() << QString("Command with messageId %1 completed %2").arg(buffer->id()).arg(buffer->success() ? "sucessfully" : "unsuccessfully");
564 560
565 d->completeCommands.insert(buffer->id(), buffer->success()); 561 d->completeCommands.insert(buffer->id(), buffer->success());
566 // The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first 562 // The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first
@@ -571,33 +567,33 @@ bool ResourceAccess::processMessageBuffer()
571 auto buffer = Commands::GetNotification(d->partialMessageBuffer.constData() + headerSize); 567 auto buffer = Commands::GetNotification(d->partialMessageBuffer.constData() + headerSize);
572 switch (buffer->type()) { 568 switch (buffer->type()) {
573 case Sink::Notification::Shutdown: 569 case Sink::Notification::Shutdown:
574 Log() << "Received shutdown notification."; 570 SinkLog() << "Received shutdown notification.";
575 close(); 571 close();
576 break; 572 break;
577 case Sink::Notification::Inspection: { 573 case Sink::Notification::Inspection: {
578 Trace() << "Received inspection notification."; 574 SinkTrace() << "Received inspection notification.";
579 auto n = getNotification(buffer); 575 auto n = getNotification(buffer);
580 // The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first 576 // The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first
581 queuedInvoke([=]() { emit notification(n); }, this); 577 queuedInvoke([=]() { emit notification(n); }, this);
582 } break; 578 } break;
583 case Sink::Notification::Status: 579 case Sink::Notification::Status:
584 if (mResourceStatus == buffer->code()) { 580 if (mResourceStatus == buffer->code()) {
585 Trace() << "Got an unnecessary status notification"; 581 SinkTrace() << "Got an unnecessary status notification";
586 break; 582 break;
587 } 583 }
588 mResourceStatus = buffer->code(); 584 mResourceStatus = buffer->code();
589 Trace() << "Updated status: " << mResourceStatus; 585 SinkTrace() << "Updated status: " << mResourceStatus;
590 [[clang::fallthrough]]; 586 [[clang::fallthrough]];
591 case Sink::Notification::Warning: 587 case Sink::Notification::Warning:
592 [[clang::fallthrough]]; 588 [[clang::fallthrough]];
593 case Sink::Notification::Progress: { 589 case Sink::Notification::Progress: {
594 auto n = getNotification(buffer); 590 auto n = getNotification(buffer);
595 Trace() << "Received notification: " << n.type; 591 SinkTrace() << "Received notification: " << n.type;
596 emit notification(n); 592 emit notification(n);
597 } break; 593 } break;
598 case Sink::Notification::RevisionUpdate: 594 case Sink::Notification::RevisionUpdate:
599 default: 595 default:
600 Warning() << "Received unknown notification: " << buffer->type(); 596 SinkWarning() << "Received unknown notification: " << buffer->type();
601 break; 597 break;
602 } 598 }
603 break; 599 break;
diff --git a/common/resourceaccess.h b/common/resourceaccess.h
index 47b848e..5d66246 100644
--- a/common/resourceaccess.h
+++ b/common/resourceaccess.h
@@ -29,6 +29,7 @@
29 29
30#include <flatbuffers/flatbuffers.h> 30#include <flatbuffers/flatbuffers.h>
31#include "notification.h" 31#include "notification.h"
32#include "log.h"
32 33
33namespace Sink { 34namespace Sink {
34 35
@@ -93,6 +94,7 @@ protected:
93class SINK_EXPORT ResourceAccess : public ResourceAccessInterface 94class SINK_EXPORT ResourceAccess : public ResourceAccessInterface
94{ 95{
95 Q_OBJECT 96 Q_OBJECT
97 SINK_DEBUG_AREA("communication")
96public: 98public:
97 typedef QSharedPointer<ResourceAccess> Ptr; 99 typedef QSharedPointer<ResourceAccess> Ptr;
98 100
@@ -138,6 +140,7 @@ private:
138 140
139 class Private; 141 class Private;
140 Private *const d; 142 Private *const d;
143 // SINK_DEBUG_COMPONENT(d->resourceInstanceIdentifier)
141}; 144};
142 145
143/** 146/**
@@ -147,6 +150,7 @@ private:
147 */ 150 */
148class SINK_EXPORT ResourceAccessFactory 151class SINK_EXPORT ResourceAccessFactory
149{ 152{
153 SINK_DEBUG_AREA("ResourceAccessFactory")
150public: 154public:
151 static ResourceAccessFactory &instance(); 155 static ResourceAccessFactory &instance();
152 Sink::ResourceAccess::Ptr getAccess(const QByteArray &instanceIdentifier, const QByteArray resourceType); 156 Sink::ResourceAccess::Ptr getAccess(const QByteArray &instanceIdentifier, const QByteArray resourceType);
diff --git a/common/resourcecontrol.cpp b/common/resourcecontrol.cpp
index 5c2cd06..7d092a4 100644
--- a/common/resourcecontrol.cpp
+++ b/common/resourcecontrol.cpp
@@ -30,14 +30,13 @@
30#include "log.h" 30#include "log.h"
31#include "notifier.h" 31#include "notifier.h"
32 32
33#undef DEBUG_AREA 33SINK_DEBUG_AREA("resourcecontrol")
34#define DEBUG_AREA "client.resourcecontrol"
35 34
36namespace Sink { 35namespace Sink {
37 36
38KAsync::Job<void> ResourceControl::shutdown(const QByteArray &identifier) 37KAsync::Job<void> ResourceControl::shutdown(const QByteArray &identifier)
39{ 38{
40 Trace() << "shutdown " << identifier; 39 SinkTrace() << "shutdown " << identifier;
41 auto time = QSharedPointer<QTime>::create(); 40 auto time = QSharedPointer<QTime>::create();
42 time->start(); 41 time->start();
43 return ResourceAccess::connectToServer(identifier) 42 return ResourceAccess::connectToServer(identifier)
@@ -50,33 +49,33 @@ KAsync::Job<void> ResourceControl::shutdown(const QByteArray &identifier)
50 resourceAccess->sendCommand(Sink::Commands::ShutdownCommand) 49 resourceAccess->sendCommand(Sink::Commands::ShutdownCommand)
51 .then<void>([&future, resourceAccess, time]() { 50 .then<void>([&future, resourceAccess, time]() {
52 resourceAccess->close(); 51 resourceAccess->close();
53 Trace() << "Shutdown complete." << Log::TraceTime(time->elapsed()); 52 SinkTrace() << "Shutdown complete." << Log::TraceTime(time->elapsed());
54 future.setFinished(); 53 future.setFinished();
55 }) 54 })
56 .exec(); 55 .exec();
57 }, 56 },
58 [](int, const QString &) { 57 [](int, const QString &) {
59 Trace() << "Resource is already closed."; 58 SinkTrace() << "Resource is already closed.";
60 // Resource isn't started, nothing to shutdown 59 // Resource isn't started, nothing to shutdown
61 }); 60 });
62} 61}
63 62
64KAsync::Job<void> ResourceControl::start(const QByteArray &identifier) 63KAsync::Job<void> ResourceControl::start(const QByteArray &identifier)
65{ 64{
66 Trace() << "start " << identifier; 65 SinkTrace() << "start " << identifier;
67 auto time = QSharedPointer<QTime>::create(); 66 auto time = QSharedPointer<QTime>::create();
68 time->start(); 67 time->start();
69 auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier, ResourceConfig::getResourceType(identifier)); 68 auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier, ResourceConfig::getResourceType(identifier));
70 resourceAccess->open(); 69 resourceAccess->open();
71 return resourceAccess->sendCommand(Sink::Commands::PingCommand).then<void>([resourceAccess, time]() { Trace() << "Start complete." << Log::TraceTime(time->elapsed()); }); 70 return resourceAccess->sendCommand(Sink::Commands::PingCommand).then<void>([resourceAccess, time]() { SinkTrace() << "Start complete." << Log::TraceTime(time->elapsed()); });
72} 71}
73 72
74KAsync::Job<void> ResourceControl::flushMessageQueue(const QByteArrayList &resourceIdentifier) 73KAsync::Job<void> ResourceControl::flushMessageQueue(const QByteArrayList &resourceIdentifier)
75{ 74{
76 Trace() << "flushMessageQueue" << resourceIdentifier; 75 SinkTrace() << "flushMessageQueue" << resourceIdentifier;
77 return KAsync::iterate(resourceIdentifier) 76 return KAsync::iterate(resourceIdentifier)
78 .template each<void, QByteArray>([](const QByteArray &resource, KAsync::Future<void> &future) { 77 .template each<void, QByteArray>([](const QByteArray &resource, KAsync::Future<void> &future) {
79 Trace() << "Flushing message queue " << resource; 78 SinkTrace() << "Flushing message queue " << resource;
80 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); 79 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource));
81 resourceAccess->open(); 80 resourceAccess->open();
82 resourceAccess->synchronizeResource(false, true).then<void>([&future, resourceAccess]() { future.setFinished(); }).exec(); 81 resourceAccess->synchronizeResource(false, true).then<void>([&future, resourceAccess]() { future.setFinished(); }).exec();
@@ -95,7 +94,7 @@ KAsync::Job<void> ResourceControl::inspect(const Inspection &inspectionCommand)
95 94
96 auto time = QSharedPointer<QTime>::create(); 95 auto time = QSharedPointer<QTime>::create();
97 time->start(); 96 time->start();
98 Trace() << "Sending inspection " << resource; 97 SinkTrace() << "Sending inspection " << resource;
99 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); 98 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource));
100 resourceAccess->open(); 99 resourceAccess->open();
101 auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess); 100 auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess);
@@ -104,7 +103,7 @@ KAsync::Job<void> ResourceControl::inspect(const Inspection &inspectionCommand)
104 .template then<void>([resourceAccess, notifier, id, time](KAsync::Future<void> &future) { 103 .template then<void>([resourceAccess, notifier, id, time](KAsync::Future<void> &future) {
105 notifier->registerHandler([&future, id, time](const Notification &notification) { 104 notifier->registerHandler([&future, id, time](const Notification &notification) {
106 if (notification.id == id) { 105 if (notification.id == id) {
107 Trace() << "Inspection complete." << Log::TraceTime(time->elapsed()); 106 SinkTrace() << "Inspection complete." << Log::TraceTime(time->elapsed());
108 if (notification.code) { 107 if (notification.code) {
109 future.setError(-1, "Inspection returned an error: " + notification.message); 108 future.setError(-1, "Inspection returned an error: " + notification.message);
110 } else { 109 } else {
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp
index 0bcc6b9..bdb5841 100644
--- a/common/resourcefacade.cpp
+++ b/common/resourcefacade.cpp
@@ -28,6 +28,8 @@
28 28
29using namespace Sink; 29using namespace Sink;
30 30
31SINK_DEBUG_AREA("ResourceFacade")
32
31template<typename DomainType> 33template<typename DomainType>
32ConfigNotifier LocalStorageFacade<DomainType>::sConfigNotifier; 34ConfigNotifier LocalStorageFacade<DomainType>::sConfigNotifier;
33 35
@@ -67,7 +69,7 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query,
67 const auto type = entries.value(res); 69 const auto type = entries.value(res);
68 70
69 if (query.propertyFilter.contains("type") && query.propertyFilter.value("type").value.toByteArray() != type) { 71 if (query.propertyFilter.contains("type") && query.propertyFilter.value("type").value.toByteArray() != type) {
70 Trace() << "Skipping due to type."; 72 SinkTrace() << "Skipping due to type.";
71 continue; 73 continue;
72 } 74 }
73 if (!query.ids.isEmpty() && !query.ids.contains(res)) { 75 if (!query.ids.isEmpty() && !query.ids.contains(res)) {
@@ -75,10 +77,10 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query,
75 } 77 }
76 const auto configurationValues = mConfigStore.get(res); 78 const auto configurationValues = mConfigStore.get(res);
77 if (!matchesFilter(query.propertyFilter, configurationValues)){ 79 if (!matchesFilter(query.propertyFilter, configurationValues)){
78 Trace() << "Skipping due to filter."; 80 SinkTrace() << "Skipping due to filter.";
79 continue; 81 continue;
80 } 82 }
81 Trace() << "Found match " << res; 83 SinkTrace() << "Found match " << res;
82 auto entity = readFromConfig<DomainType>(mConfigStore, res, type); 84 auto entity = readFromConfig<DomainType>(mConfigStore, res, type);
83 updateStatus(*entity); 85 updateStatus(*entity);
84 mResultProvider->add(entity); 86 mResultProvider->add(entity);
@@ -137,7 +139,7 @@ void LocalStorageQueryRunner<DomainType>::setStatusUpdater(const std::function<v
137template<typename DomainType> 139template<typename DomainType>
138void LocalStorageQueryRunner<DomainType>::statusChanged(const QByteArray &identifier) 140void LocalStorageQueryRunner<DomainType>::statusChanged(const QByteArray &identifier)
139{ 141{
140 Trace() << "Status changed " << identifier; 142 SinkTrace() << "Status changed " << identifier;
141 auto entity = readFromConfig<DomainType>(mConfigStore, identifier, ApplicationDomain::getTypeName<DomainType>()); 143 auto entity = readFromConfig<DomainType>(mConfigStore, identifier, ApplicationDomain::getTypeName<DomainType>());
142 updateStatus(*entity); 144 updateStatus(*entity);
143 mResultProvider->modify(entity); 145 mResultProvider->modify(entity);
@@ -195,7 +197,7 @@ KAsync::Job<void> LocalStorageFacade<DomainType>::modify(const DomainType &domai
195 return KAsync::start<void>([domainObject, this]() { 197 return KAsync::start<void>([domainObject, this]() {
196 const QByteArray identifier = domainObject.identifier(); 198 const QByteArray identifier = domainObject.identifier();
197 if (identifier.isEmpty()) { 199 if (identifier.isEmpty()) {
198 Warning() << "We need an \"identifier\" property to identify the entity to configure."; 200 SinkWarning() << "We need an \"identifier\" property to identify the entity to configure.";
199 return; 201 return;
200 } 202 }
201 auto changedProperties = domainObject.changedProperties(); 203 auto changedProperties = domainObject.changedProperties();
@@ -221,10 +223,10 @@ KAsync::Job<void> LocalStorageFacade<DomainType>::remove(const DomainType &domai
221 return KAsync::start<void>([domainObject, this]() { 223 return KAsync::start<void>([domainObject, this]() {
222 const QByteArray identifier = domainObject.identifier(); 224 const QByteArray identifier = domainObject.identifier();
223 if (identifier.isEmpty()) { 225 if (identifier.isEmpty()) {
224 Warning() << "We need an \"identifier\" property to identify the entity to configure"; 226 SinkWarning() << "We need an \"identifier\" property to identify the entity to configure";
225 return; 227 return;
226 } 228 }
227 Trace() << "Removing: " << identifier; 229 SinkTrace() << "Removing: " << identifier;
228 mConfigStore.remove(identifier); 230 mConfigStore.remove(identifier);
229 sConfigNotifier.remove(QSharedPointer<DomainType>::create(domainObject)); 231 sConfigNotifier.remove(QSharedPointer<DomainType>::create(domainObject));
230 }); 232 });
@@ -259,7 +261,7 @@ QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain
259 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); 261 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier()));
260 if (!monitoredResources->contains(resource.identifier())) { 262 if (!monitoredResources->contains(resource.identifier())) {
261 auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess](const Notification &notification) { 263 auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess](const Notification &notification) {
262 Trace() << "Received notification in facade: " << notification.type; 264 SinkTrace() << "Received notification in facade: " << notification.type;
263 if (notification.type == Notification::Status) { 265 if (notification.type == Notification::Status) {
264 runner->statusChanged(resource.identifier()); 266 runner->statusChanged(resource.identifier());
265 } 267 }
diff --git a/common/sourcewriteback.cpp b/common/sourcewriteback.cpp
index a277606..7d21ea6 100644
--- a/common/sourcewriteback.cpp
+++ b/common/sourcewriteback.cpp
@@ -26,6 +26,8 @@
26#define ENTITY_TYPE_MAIL "mail" 26#define ENTITY_TYPE_MAIL "mail"
27#define ENTITY_TYPE_FOLDER "folder" 27#define ENTITY_TYPE_FOLDER "folder"
28 28
29SINK_DEBUG_AREA("sourcewriteback")
30
29using namespace Sink; 31using namespace Sink;
30 32
31SourceWriteBack::SourceWriteBack(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier) 33SourceWriteBack::SourceWriteBack(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier)
@@ -55,14 +57,14 @@ RemoteIdMap &SourceWriteBack::syncStore()
55 57
56KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) 58KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value)
57{ 59{
58 Trace() << "Replaying" << type << key; 60 SinkTrace() << "Replaying" << type << key;
59 61
60 Sink::EntityBuffer buffer(value); 62 Sink::EntityBuffer buffer(value);
61 const Sink::Entity &entity = buffer.entity(); 63 const Sink::Entity &entity = buffer.entity();
62 const auto metadataBuffer = Sink::EntityBuffer::readBuffer<Sink::Metadata>(entity.metadata()); 64 const auto metadataBuffer = Sink::EntityBuffer::readBuffer<Sink::Metadata>(entity.metadata());
63 Q_ASSERT(metadataBuffer); 65 Q_ASSERT(metadataBuffer);
64 if (!metadataBuffer->replayToSource()) { 66 if (!metadataBuffer->replayToSource()) {
65 Trace() << "Change is coming from the source"; 67 SinkTrace() << "Change is coming from the source";
66 return KAsync::null<void>(); 68 return KAsync::null<void>();
67 } 69 }
68 Q_ASSERT(!mSyncStore); 70 Q_ASSERT(!mSyncStore);
@@ -81,11 +83,11 @@ KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArr
81 if (operation != Sink::Operation_Creation) { 83 if (operation != Sink::Operation_Creation) {
82 oldRemoteId = syncStore().resolveLocalId(type, uid); 84 oldRemoteId = syncStore().resolveLocalId(type, uid);
83 if (oldRemoteId.isEmpty()) { 85 if (oldRemoteId.isEmpty()) {
84 Warning() << "Couldn't find the remote id for: " << type << uid; 86 SinkWarning() << "Couldn't find the remote id for: " << type << uid;
85 return KAsync::error<void>(1, "Couldn't find the remote id."); 87 return KAsync::error<void>(1, "Couldn't find the remote id.");
86 } 88 }
87 } 89 }
88 Trace() << "Replaying " << key << type << uid << oldRemoteId; 90 SinkTrace() << "Replaying " << key << type << uid << oldRemoteId;
89 91
90 KAsync::Job<QByteArray> job = KAsync::null<QByteArray>(); 92 KAsync::Job<QByteArray> job = KAsync::null<QByteArray>();
91 if (type == ENTITY_TYPE_FOLDER) { 93 if (type == ENTITY_TYPE_FOLDER) {
@@ -98,24 +100,24 @@ KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArr
98 100
99 return job.then<void, QByteArray>([this, operation, type, uid, oldRemoteId](const QByteArray &remoteId) { 101 return job.then<void, QByteArray>([this, operation, type, uid, oldRemoteId](const QByteArray &remoteId) {
100 if (operation == Sink::Operation_Creation) { 102 if (operation == Sink::Operation_Creation) {
101 Trace() << "Replayed creation with remote id: " << remoteId; 103 SinkTrace() << "Replayed creation with remote id: " << remoteId;
102 if (remoteId.isEmpty()) { 104 if (remoteId.isEmpty()) {
103 Warning() << "Returned an empty remoteId from the creation"; 105 SinkWarning() << "Returned an empty remoteId from the creation";
104 } else { 106 } else {
105 syncStore().recordRemoteId(type, uid, remoteId); 107 syncStore().recordRemoteId(type, uid, remoteId);
106 } 108 }
107 } else if (operation == Sink::Operation_Modification) { 109 } else if (operation == Sink::Operation_Modification) {
108 Trace() << "Replayed modification with remote id: " << remoteId; 110 SinkTrace() << "Replayed modification with remote id: " << remoteId;
109 if (remoteId.isEmpty()) { 111 if (remoteId.isEmpty()) {
110 Warning() << "Returned an empty remoteId from the creation"; 112 SinkWarning() << "Returned an empty remoteId from the creation";
111 } else { 113 } else {
112 syncStore().updateRemoteId(type, uid, remoteId); 114 syncStore().updateRemoteId(type, uid, remoteId);
113 } 115 }
114 } else if (operation == Sink::Operation_Removal) { 116 } else if (operation == Sink::Operation_Removal) {
115 Trace() << "Replayed removal with remote id: " << oldRemoteId; 117 SinkTrace() << "Replayed removal with remote id: " << oldRemoteId;
116 syncStore().removeRemoteId(type, uid, oldRemoteId); 118 syncStore().removeRemoteId(type, uid, oldRemoteId);
117 } else { 119 } else {
118 ErrorMsg() << "Unkown operation" << operation; 120 SinkError() << "Unkown operation" << operation;
119 } 121 }
120 122
121 mSyncStore.clear(); 123 mSyncStore.clear();
@@ -123,7 +125,7 @@ KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArr
123 mTransaction.abort(); 125 mTransaction.abort();
124 mSyncTransaction.commit(); 126 mSyncTransaction.commit();
125 }, [this](int errorCode, const QString &errorMessage) { 127 }, [this](int errorCode, const QString &errorMessage) {
126 Warning() << "Failed to replay change: " << errorMessage; 128 SinkWarning() << "Failed to replay change: " << errorMessage;
127 mSyncStore.clear(); 129 mSyncStore.clear();
128 mEntityStore.clear(); 130 mEntityStore.clear();
129 mTransaction.abort(); 131 mTransaction.abort();
diff --git a/common/specialpurposepreprocessor.cpp b/common/specialpurposepreprocessor.cpp
index 2892105..0985880 100644
--- a/common/specialpurposepreprocessor.cpp
+++ b/common/specialpurposepreprocessor.cpp
@@ -5,6 +5,8 @@
5 5
6using namespace Sink; 6using namespace Sink;
7 7
8SINK_DEBUG_AREA("SpecialPurposeProcessor")
9
8static QHash<QByteArray, QString> specialPurposeFolders() 10static QHash<QByteArray, QString> specialPurposeFolders()
9{ 11{
10 QHash<QByteArray, QString> hash; 12 QHash<QByteArray, QString> hash;
@@ -53,7 +55,7 @@ QByteArray SpecialPurposeProcessor::ensureFolder(Sink::Storage::Transaction &tra
53 return false; 55 return false;
54 }); 56 });
55 if (!mSpecialPurposeFolders.contains(specialPurpose)) { 57 if (!mSpecialPurposeFolders.contains(specialPurpose)) {
56 Trace() << "Failed to find a drafts folder, creating a new one"; 58 SinkTrace() << "Failed to find a drafts folder, creating a new one";
57 auto folder = ApplicationDomain::Folder::create(mResourceInstanceIdentifier); 59 auto folder = ApplicationDomain::Folder::create(mResourceInstanceIdentifier);
58 folder.setSpecialPurpose(QByteArrayList() << specialPurpose); 60 folder.setSpecialPurpose(QByteArrayList() << specialPurpose);
59 folder.setName(sSpecialPurposeFolders.value(specialPurpose)); 61 folder.setName(sSpecialPurposeFolders.value(specialPurpose));
diff --git a/common/storage_common.cpp b/common/storage_common.cpp
index 6982a4c..1f2594e 100644
--- a/common/storage_common.cpp
+++ b/common/storage_common.cpp
@@ -24,6 +24,8 @@
24#include "log.h" 24#include "log.h"
25#include <QUuid> 25#include <QUuid>
26 26
27SINK_DEBUG_AREA("storage")
28
27namespace Sink { 29namespace Sink {
28 30
29static const char *s_internalPrefix = "__internal"; 31static const char *s_internalPrefix = "__internal";
@@ -31,7 +33,7 @@ static const int s_internalPrefixSize = strlen(s_internalPrefix);
31 33
32void errorHandler(const Storage::Error &error) 34void errorHandler(const Storage::Error &error)
33{ 35{
34 Warning() << "Database error in " << error.store << ", code " << error.code << ", message: " << error.message; 36 SinkWarning() << "Database error in " << error.store << ", code " << error.code << ", message: " << error.message;
35} 37}
36 38
37std::function<void(const Storage::Error &error)> Storage::basicErrorHandler() 39std::function<void(const Storage::Error &error)> Storage::basicErrorHandler()
@@ -67,7 +69,7 @@ qint64 Storage::maxRevision(const Sink::Storage::Transaction &transaction)
67 }, 69 },
68 [](const Error &error) { 70 [](const Error &error) {
69 if (error.code != Sink::Storage::NotFound) { 71 if (error.code != Sink::Storage::NotFound) {
70 Warning() << "Coultn'd find the maximum revision."; 72 SinkWarning() << "Coultn'd find the maximum revision.";
71 } 73 }
72 }); 74 });
73 return r; 75 return r;
@@ -88,7 +90,7 @@ qint64 Storage::cleanedUpRevision(const Sink::Storage::Transaction &transaction)
88 }, 90 },
89 [](const Error &error) { 91 [](const Error &error) {
90 if (error.code != Sink::Storage::NotFound) { 92 if (error.code != Sink::Storage::NotFound) {
91 Warning() << "Coultn'd find the maximum revision."; 93 SinkWarning() << "Coultn'd find the maximum revision.";
92 } 94 }
93 }); 95 });
94 return r; 96 return r;
@@ -103,7 +105,7 @@ QByteArray Storage::getUidFromRevision(const Sink::Storage::Transaction &transac
103 uid = value; 105 uid = value;
104 return false; 106 return false;
105 }, 107 },
106 [revision](const Error &error) { Warning() << "Coultn'd find uid for revision: " << revision << error.message; }); 108 [revision](const Error &error) { SinkWarning() << "Coultn'd find uid for revision: " << revision << error.message; });
107 return uid; 109 return uid;
108} 110}
109 111
@@ -116,7 +118,7 @@ QByteArray Storage::getTypeFromRevision(const Sink::Storage::Transaction &transa
116 type = value; 118 type = value;
117 return false; 119 return false;
118 }, 120 },
119 [revision](const Error &error) { Warning() << "Coultn'd find type for revision " << revision; }); 121 [revision](const Error &error) { SinkWarning() << "Coultn'd find type for revision " << revision; });
120 return type; 122 return type;
121} 123}
122 124
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp
index 352e250..79f4465 100644
--- a/common/storage_lmdb.cpp
+++ b/common/storage_lmdb.cpp
@@ -34,10 +34,8 @@
34#include <lmdb.h> 34#include <lmdb.h>
35#include "log.h" 35#include "log.h"
36 36
37#undef Trace 37SINK_DEBUG_AREA("storage")
38#define Trace() Trace_area("storage." + d->storageRoot.toLatin1() + '/' + d->name.toLatin1()) 38// SINK_DEBUG_COMPONENT(d->storageRoot.toLatin1() + '/' + d->name.toLatin1())
39#undef Warning
40#define Warning() Warning_area("storage")
41 39
42namespace Sink { 40namespace Sink {
43 41
@@ -354,7 +352,7 @@ qint64 Storage::NamedDatabase::getSize()
354 MDB_stat stat; 352 MDB_stat stat;
355 rc = mdb_stat(d->transaction, d->dbi, &stat); 353 rc = mdb_stat(d->transaction, d->dbi, &stat);
356 if (rc) { 354 if (rc) {
357 Warning() << "Something went wrong " << QByteArray(mdb_strerror(rc)); 355 SinkWarning() << "Something went wrong " << QByteArray(mdb_strerror(rc));
358 } 356 }
359 // std::cout << "overflow_pages: " << stat.ms_overflow_pages << std::endl; 357 // std::cout << "overflow_pages: " << stat.ms_overflow_pages << std::endl;
360 // std::cout << "page size: " << stat.ms_psize << std::endl; 358 // std::cout << "page size: " << stat.ms_psize << std::endl;
@@ -482,7 +480,7 @@ static bool ensureCorrectDb(Storage::NamedDatabase &database, const QByteArray &
482 bool openedTheWrongDatabase = false; 480 bool openedTheWrongDatabase = false;
483 auto count = database.scan("__internal_dbname", [db, &openedTheWrongDatabase](const QByteArray &key, const QByteArray &value) ->bool { 481 auto count = database.scan("__internal_dbname", [db, &openedTheWrongDatabase](const QByteArray &key, const QByteArray &value) ->bool {
484 if (value != db) { 482 if (value != db) {
485 Warning() << "Opened the wrong database, got " << value << " instead of " << db; 483 SinkWarning() << "Opened the wrong database, got " << value << " instead of " << db;
486 openedTheWrongDatabase = true; 484 openedTheWrongDatabase = true;
487 } 485 }
488 return false; 486 return false;
@@ -505,7 +503,7 @@ bool Storage::Transaction::validateNamedDatabases()
505 for (const auto &dbName : databases) { 503 for (const auto &dbName : databases) {
506 auto db = openDatabase(dbName); 504 auto db = openDatabase(dbName);
507 if (!db) { 505 if (!db) {
508 Warning() << "Failed to open the database: " << dbName; 506 SinkWarning() << "Failed to open the database: " << dbName;
509 return false; 507 return false;
510 } 508 }
511 } 509 }
@@ -527,7 +525,7 @@ Storage::NamedDatabase Storage::Transaction::openDatabase(const QByteArray &db,
527 } 525 }
528 auto database = Storage::NamedDatabase(p); 526 auto database = Storage::NamedDatabase(p);
529 if (!ensureCorrectDb(database, db, d->requestedRead)) { 527 if (!ensureCorrectDb(database, db, d->requestedRead)) {
530 Warning() << "Failed to open the database" << db; 528 SinkWarning() << "Failed to open the database" << db;
531 return Storage::NamedDatabase(); 529 return Storage::NamedDatabase();
532 } 530 }
533 return database; 531 return database;
@@ -536,7 +534,7 @@ Storage::NamedDatabase Storage::Transaction::openDatabase(const QByteArray &db,
536QList<QByteArray> Storage::Transaction::getDatabaseNames() const 534QList<QByteArray> Storage::Transaction::getDatabaseNames() const
537{ 535{
538 if (!d) { 536 if (!d) {
539 Warning() << "Invalid transaction"; 537 SinkWarning() << "Invalid transaction";
540 return QList<QByteArray>(); 538 return QList<QByteArray>();
541 } 539 }
542 540
@@ -559,12 +557,12 @@ QList<QByteArray> Storage::Transaction::getDatabaseNames() const
559 rc = 0; 557 rc = 0;
560 } 558 }
561 if (rc) { 559 if (rc) {
562 Warning() << "Failed to get a value" << rc; 560 SinkWarning() << "Failed to get a value" << rc;
563 } 561 }
564 } 562 }
565 mdb_cursor_close(cursor); 563 mdb_cursor_close(cursor);
566 } else { 564 } else {
567 Warning() << "Failed to open db" << rc << QByteArray(mdb_strerror(rc)); 565 SinkWarning() << "Failed to open db" << rc << QByteArray(mdb_strerror(rc));
568 } 566 }
569 return list; 567 return list;
570} 568}
@@ -611,7 +609,7 @@ Storage::Private::Private(const QString &s, const QString &n, AccessMode m) : st
611 int rc = 0; 609 int rc = 0;
612 if ((rc = mdb_env_create(&env))) { 610 if ((rc = mdb_env_create(&env))) {
613 // TODO: handle error 611 // TODO: handle error
614 Warning() << "mdb_env_create: " << rc << " " << mdb_strerror(rc); 612 SinkWarning() << "mdb_env_create: " << rc << " " << mdb_strerror(rc);
615 } else { 613 } else {
616 mdb_env_set_maxdbs(env, 50); 614 mdb_env_set_maxdbs(env, 50);
617 unsigned int flags = MDB_NOTLS; 615 unsigned int flags = MDB_NOTLS;
@@ -619,7 +617,7 @@ Storage::Private::Private(const QString &s, const QString &n, AccessMode m) : st
619 flags |= MDB_RDONLY; 617 flags |= MDB_RDONLY;
620 } 618 }
621 if ((rc = mdb_env_open(env, fullPath.toStdString().data(), flags, 0664))) { 619 if ((rc = mdb_env_open(env, fullPath.toStdString().data(), flags, 0664))) {
622 Warning() << "mdb_env_open: " << rc << " " << mdb_strerror(rc); 620 SinkWarning() << "mdb_env_open: " << rc << " " << mdb_strerror(rc);
623 mdb_env_close(env); 621 mdb_env_close(env);
624 env = 0; 622 env = 0;
625 } else { 623 } else {
@@ -681,7 +679,7 @@ qint64 Storage::diskUsage() const
681{ 679{
682 QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb"); 680 QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb");
683 if (!info.exists()) { 681 if (!info.exists()) {
684 Warning() << "Tried to get filesize for non-existant file: " << info.path(); 682 SinkWarning() << "Tried to get filesize for non-existant file: " << info.path();
685 } 683 }
686 return info.size(); 684 return info.size();
687} 685}
@@ -691,7 +689,7 @@ void Storage::removeFromDisk() const
691 const QString fullPath(d->storageRoot + '/' + d->name); 689 const QString fullPath(d->storageRoot + '/' + d->name);
692 QMutexLocker locker(&d->sMutex); 690 QMutexLocker locker(&d->sMutex);
693 QDir dir(fullPath); 691 QDir dir(fullPath);
694 Trace() << "Removing database from disk: " << fullPath; 692 SinkTrace() << "Removing database from disk: " << fullPath;
695 if (!dir.removeRecursively()) { 693 if (!dir.removeRecursively()) {
696 Error error(d->name.toLatin1(), ErrorCodes::GenericError, QString("Failed to remove directory %1 %2").arg(d->storageRoot).arg(d->name).toLatin1()); 694 Error error(d->name.toLatin1(), ErrorCodes::GenericError, QString("Failed to remove directory %1 %2").arg(d->storageRoot).arg(d->name).toLatin1());
697 defaultErrorHandler()(error); 695 defaultErrorHandler()(error);
diff --git a/common/store.cpp b/common/store.cpp
index 1162a18..a58287b 100644
--- a/common/store.cpp
+++ b/common/store.cpp
@@ -36,8 +36,7 @@
36#include "storage.h" 36#include "storage.h"
37#include "log.h" 37#include "log.h"
38 38
39#undef DEBUG_AREA 39SINK_DEBUG_AREA("store")
40#define DEBUG_AREA "client.store"
41 40
42namespace Sink { 41namespace Sink {
43 42
@@ -88,24 +87,24 @@ static QMap<QByteArray, QByteArray> getResources(const QList<QByteArray> &resour
88 } 87 }
89 resources.insert(res, configuredResources.value(res)); 88 resources.insert(res, configuredResources.value(res));
90 } else { 89 } else {
91 Warning() << "Resource is not existing: " << res; 90 SinkWarning() << "Resource is not existing: " << res;
92 } 91 }
93 } 92 }
94 } 93 }
95 Trace() << "Found resources: " << resources; 94 SinkTrace() << "Found resources: " << resources;
96 return resources; 95 return resources;
97} 96}
98 97
99template <class DomainType> 98template <class DomainType>
100QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) 99QSharedPointer<QAbstractItemModel> Store::loadModel(Query query)
101{ 100{
102 Trace() << "Query: " << ApplicationDomain::getTypeName<DomainType>(); 101 SinkTrace() << "Query: " << ApplicationDomain::getTypeName<DomainType>();
103 Trace() << " Requested: " << query.requestedProperties; 102 SinkTrace() << " Requested: " << query.requestedProperties;
104 Trace() << " Filter: " << query.propertyFilter; 103 SinkTrace() << " Filter: " << query.propertyFilter;
105 Trace() << " Parent: " << query.parentProperty; 104 SinkTrace() << " Parent: " << query.parentProperty;
106 Trace() << " Ids: " << query.ids; 105 SinkTrace() << " Ids: " << query.ids;
107 Trace() << " IsLive: " << query.liveQuery; 106 SinkTrace() << " IsLive: " << query.liveQuery;
108 Trace() << " Sorting: " << query.sortProperty; 107 SinkTrace() << " Sorting: " << query.sortProperty;
109 auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr>>::create(query, query.requestedProperties); 108 auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr>>::create(query, query.requestedProperties);
110 109
111 //* Client defines lifetime of model 110 //* Client defines lifetime of model
@@ -123,16 +122,16 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query)
123 const auto resourceType = resources.value(resourceInstanceIdentifier); 122 const auto resourceType = resources.value(resourceInstanceIdentifier);
124 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier); 123 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier);
125 if (facade) { 124 if (facade) {
126 Trace() << "Trying to fetch from resource " << resourceInstanceIdentifier; 125 SinkTrace() << "Trying to fetch from resource " << resourceInstanceIdentifier;
127 auto result = facade->load(query); 126 auto result = facade->load(query);
128 if (result.second) { 127 if (result.second) {
129 aggregatingEmitter->addEmitter(result.second); 128 aggregatingEmitter->addEmitter(result.second);
130 } else { 129 } else {
131 Warning() << "Null emitter for resource " << resourceInstanceIdentifier; 130 SinkWarning() << "Null emitter for resource " << resourceInstanceIdentifier;
132 } 131 }
133 result.first.template then<void>([&future]() { future.setFinished(); }).exec(); 132 result.first.template then<void>([&future]() { future.setFinished(); }).exec();
134 } else { 133 } else {
135 Trace() << "Couldn' find a facade for " << resourceInstanceIdentifier; 134 SinkTrace() << "Couldn' find a facade for " << resourceInstanceIdentifier;
136 // Ignore the error and carry on 135 // Ignore the error and carry on
137 future.setFinished(); 136 future.setFinished();
138 } 137 }
@@ -164,7 +163,7 @@ KAsync::Job<void> Store::create(const DomainType &domainObject)
164{ 163{
165 // Potentially move to separate thread as well 164 // Potentially move to separate thread as well
166 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); 165 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier());
167 return facade->create(domainObject).template then<void>([facade]() {}, [](int errorCode, const QString &error) { Warning() << "Failed to create"; }); 166 return facade->create(domainObject).template then<void>([facade]() {}, [](int errorCode, const QString &error) { SinkWarning() << "Failed to create"; });
168} 167}
169 168
170template <class DomainType> 169template <class DomainType>
@@ -172,7 +171,7 @@ KAsync::Job<void> Store::modify(const DomainType &domainObject)
172{ 171{
173 // Potentially move to separate thread as well 172 // Potentially move to separate thread as well
174 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); 173 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier());
175 return facade->modify(domainObject).template then<void>([facade]() {}, [](int errorCode, const QString &error) { Warning() << "Failed to modify"; }); 174 return facade->modify(domainObject).template then<void>([facade]() {}, [](int errorCode, const QString &error) { SinkWarning() << "Failed to modify"; });
176} 175}
177 176
178template <class DomainType> 177template <class DomainType>
@@ -180,7 +179,7 @@ KAsync::Job<void> Store::remove(const DomainType &domainObject)
180{ 179{
181 // Potentially move to separate thread as well 180 // Potentially move to separate thread as well
182 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); 181 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier());
183 return facade->remove(domainObject).template then<void>([facade]() {}, [](int errorCode, const QString &error) { Warning() << "Failed to remove"; }); 182 return facade->remove(domainObject).template then<void>([facade]() {}, [](int errorCode, const QString &error) { SinkWarning() << "Failed to remove"; });
184} 183}
185 184
186KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier) 185KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier)
@@ -188,28 +187,28 @@ KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier)
188 // All databases are going to become invalid, nuke the environments 187 // All databases are going to become invalid, nuke the environments
189 // TODO: all clients should react to a notification the resource 188 // TODO: all clients should react to a notification the resource
190 Sink::Storage::clearEnv(); 189 Sink::Storage::clearEnv();
191 Trace() << "Remove data from disk " << identifier; 190 SinkTrace() << "Remove data from disk " << identifier;
192 auto time = QSharedPointer<QTime>::create(); 191 auto time = QSharedPointer<QTime>::create();
193 time->start(); 192 time->start();
194 auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier, ResourceConfig::getResourceType(identifier)); 193 auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier, ResourceConfig::getResourceType(identifier));
195 resourceAccess->open(); 194 resourceAccess->open();
196 return resourceAccess->sendCommand(Sink::Commands::RemoveFromDiskCommand) 195 return resourceAccess->sendCommand(Sink::Commands::RemoveFromDiskCommand)
197 .then<void>([resourceAccess, time]() { Trace() << "Remove from disk complete." << Log::TraceTime(time->elapsed()); }); 196 .then<void>([resourceAccess, time]() { SinkTrace() << "Remove from disk complete." << Log::TraceTime(time->elapsed()); });
198} 197}
199 198
200KAsync::Job<void> Store::synchronize(const Sink::Query &query) 199KAsync::Job<void> Store::synchronize(const Sink::Query &query)
201{ 200{
202 Trace() << "synchronize" << query.resources; 201 SinkTrace() << "synchronize" << query.resources;
203 auto resources = getResources(query.resources, query.accounts).keys(); 202 auto resources = getResources(query.resources, query.accounts).keys();
204 //FIXME only necessary because each doesn't propagate errors 203 //FIXME only necessary because each doesn't propagate errors
205 auto error = new bool; 204 auto error = new bool;
206 return KAsync::iterate(resources) 205 return KAsync::iterate(resources)
207 .template each<void, QByteArray>([query, error](const QByteArray &resource, KAsync::Future<void> &future) { 206 .template each<void, QByteArray>([query, error](const QByteArray &resource, KAsync::Future<void> &future) {
208 Trace() << "Synchronizing " << resource; 207 SinkTrace() << "Synchronizing " << resource;
209 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); 208 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource));
210 resourceAccess->open(); 209 resourceAccess->open();
211 resourceAccess->synchronizeResource(true, false).then<void>([resourceAccess, &future]() {Trace() << "synced."; future.setFinished(); }, 210 resourceAccess->synchronizeResource(true, false).then<void>([resourceAccess, &future]() {SinkTrace() << "synced."; future.setFinished(); },
212 [&future, error](int errorCode, QString msg) { *error = true; Warning() << "Error during sync."; future.setError(errorCode, msg); }).exec(); 211 [&future, error](int errorCode, QString msg) { *error = true; SinkWarning() << "Error during sync."; future.setError(errorCode, msg); }).exec();
213 }).then<void>([error](KAsync::Future<void> &future) { 212 }).then<void>([error](KAsync::Future<void> &future) {
214 if (*error) { 213 if (*error) {
215 future.setError(1, "Error during sync."); 214 future.setError(1, "Error during sync.");
@@ -306,25 +305,25 @@ QList<DomainType> Store::read(const Sink::Query &q)
306 auto resources = getResources(query.resources, query.accounts, ApplicationDomain::getTypeName<DomainType>()); 305 auto resources = getResources(query.resources, query.accounts, ApplicationDomain::getTypeName<DomainType>());
307 auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); 306 auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create();
308 aggregatingEmitter->onAdded([&list](const typename DomainType::Ptr &value){ 307 aggregatingEmitter->onAdded([&list](const typename DomainType::Ptr &value){
309 Trace() << "Found value: " << value->identifier(); 308 SinkTrace() << "Found value: " << value->identifier();
310 list << *value; 309 list << *value;
311 }); 310 });
312 for (const auto resourceInstanceIdentifier : resources.keys()) { 311 for (const auto resourceInstanceIdentifier : resources.keys()) {
313 const auto resourceType = resources.value(resourceInstanceIdentifier); 312 const auto resourceType = resources.value(resourceInstanceIdentifier);
314 Trace() << "Looking for " << resourceType << resourceInstanceIdentifier; 313 SinkTrace() << "Looking for " << resourceType << resourceInstanceIdentifier;
315 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier); 314 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier);
316 if (facade) { 315 if (facade) {
317 Trace() << "Trying to fetch from resource " << resourceInstanceIdentifier; 316 SinkTrace() << "Trying to fetch from resource " << resourceInstanceIdentifier;
318 auto result = facade->load(query); 317 auto result = facade->load(query);
319 if (result.second) { 318 if (result.second) {
320 aggregatingEmitter->addEmitter(result.second); 319 aggregatingEmitter->addEmitter(result.second);
321 } else { 320 } else {
322 Warning() << "Null emitter for resource " << resourceInstanceIdentifier; 321 SinkWarning() << "Null emitter for resource " << resourceInstanceIdentifier;
323 } 322 }
324 result.first.exec(); 323 result.first.exec();
325 aggregatingEmitter->fetch(typename DomainType::Ptr()); 324 aggregatingEmitter->fetch(typename DomainType::Ptr());
326 } else { 325 } else {
327 Trace() << "Couldn't find a facade for " << resourceInstanceIdentifier; 326 SinkTrace() << "Couldn't find a facade for " << resourceInstanceIdentifier;
328 // Ignore the error and carry on 327 // Ignore the error and carry on
329 } 328 }
330 } 329 }
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp
index 1374d00..2d4fb8d 100644
--- a/common/synchronizer.cpp
+++ b/common/synchronizer.cpp
@@ -29,6 +29,8 @@
29#include "modifyentity_generated.h" 29#include "modifyentity_generated.h"
30#include "deleteentity_generated.h" 30#include "deleteentity_generated.h"
31 31
32SINK_DEBUG_AREA("synchronizer")
33
32using namespace Sink; 34using namespace Sink;
33 35
34Synchronizer::Synchronizer(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier) 36Synchronizer::Synchronizer(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier)
@@ -37,7 +39,7 @@ Synchronizer::Synchronizer(const QByteArray &resourceType, const QByteArray &res
37 mResourceType(resourceType), 39 mResourceType(resourceType),
38 mResourceInstanceIdentifier(resourceInstanceIdentifier) 40 mResourceInstanceIdentifier(resourceInstanceIdentifier)
39{ 41{
40 Trace() << "Starting synchronizer: " << resourceType << resourceInstanceIdentifier; 42 SinkTrace() << "Starting synchronizer: " << resourceType << resourceInstanceIdentifier;
41} 43}
42 44
43Synchronizer::~Synchronizer() 45Synchronizer::~Synchronizer()
@@ -129,11 +131,11 @@ void Synchronizer::scanForRemovals(const QByteArray &bufferType, const std::func
129 entryGenerator([this, bufferType, &exists](const QByteArray &key) { 131 entryGenerator([this, bufferType, &exists](const QByteArray &key) {
130 auto sinkId = Sink::Storage::uidFromKey(key); 132 auto sinkId = Sink::Storage::uidFromKey(key);
131 const auto remoteId = syncStore().resolveLocalId(bufferType, sinkId); 133 const auto remoteId = syncStore().resolveLocalId(bufferType, sinkId);
132 Trace() << "Checking for removal " << key << remoteId; 134 SinkTrace() << "Checking for removal " << key << remoteId;
133 // If we have no remoteId, the entity hasn't been replayed to the source yet 135 // If we have no remoteId, the entity hasn't been replayed to the source yet
134 if (!remoteId.isEmpty()) { 136 if (!remoteId.isEmpty()) {
135 if (!exists(remoteId)) { 137 if (!exists(remoteId)) {
136 Trace() << "Found a removed entity: " << sinkId; 138 SinkTrace() << "Found a removed entity: " << sinkId;
137 deleteEntity(sinkId, Sink::Storage::maxRevision(transaction()), bufferType, 139 deleteEntity(sinkId, Sink::Storage::maxRevision(transaction()), bufferType,
138 [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::DeleteEntityCommand, buffer); }); 140 [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::DeleteEntityCommand, buffer); });
139 } 141 }
@@ -143,14 +145,14 @@ void Synchronizer::scanForRemovals(const QByteArray &bufferType, const std::func
143 145
144void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) 146void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity)
145{ 147{
146 Trace() << "Create or modify" << bufferType << remoteId; 148 SinkTrace() << "Create or modify" << bufferType << remoteId;
147 auto mainDatabase = Storage::mainDatabase(transaction(), bufferType); 149 auto mainDatabase = Storage::mainDatabase(transaction(), bufferType);
148 const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); 150 const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId);
149 const auto found = mainDatabase.contains(sinkId); 151 const auto found = mainDatabase.contains(sinkId);
150 auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(mResourceType, bufferType); 152 auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(mResourceType, bufferType);
151 Q_ASSERT(adaptorFactory); 153 Q_ASSERT(adaptorFactory);
152 if (!found) { 154 if (!found) {
153 Trace() << "Found a new entity: " << remoteId; 155 SinkTrace() << "Found a new entity: " << remoteId;
154 createEntity( 156 createEntity(
155 sinkId, bufferType, entity, *adaptorFactory, [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::CreateEntityCommand, buffer); }); 157 sinkId, bufferType, entity, *adaptorFactory, [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::CreateEntityCommand, buffer); });
156 } else { // modification 158 } else { // modification
@@ -159,17 +161,17 @@ void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray
159 bool changed = false; 161 bool changed = false;
160 for (const auto &property : entity.changedProperties()) { 162 for (const auto &property : entity.changedProperties()) {
161 if (entity.getProperty(property) != current->getProperty(property)) { 163 if (entity.getProperty(property) != current->getProperty(property)) {
162 Trace() << "Property changed " << sinkId << property; 164 SinkTrace() << "Property changed " << sinkId << property;
163 changed = true; 165 changed = true;
164 } 166 }
165 } 167 }
166 if (changed) { 168 if (changed) {
167 Trace() << "Found a modified entity: " << remoteId; 169 SinkTrace() << "Found a modified entity: " << remoteId;
168 modifyEntity(sinkId, Sink::Storage::maxRevision(transaction()), bufferType, entity, *adaptorFactory, 170 modifyEntity(sinkId, Sink::Storage::maxRevision(transaction()), bufferType, entity, *adaptorFactory,
169 [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::ModifyEntityCommand, buffer); }); 171 [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::ModifyEntityCommand, buffer); });
170 } 172 }
171 } else { 173 } else {
172 Warning() << "Failed to get current entity"; 174 SinkWarning() << "Failed to get current entity";
173 } 175 }
174 } 176 }
175} 177}
@@ -178,7 +180,7 @@ template<typename DomainType>
178void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const DomainType &entity, const QHash<QByteArray, Sink::Query::Comparator> &mergeCriteria) 180void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const DomainType &entity, const QHash<QByteArray, Sink::Query::Comparator> &mergeCriteria)
179{ 181{
180 182
181 Trace() << "Create or modify" << bufferType << remoteId; 183 SinkTrace() << "Create or modify" << bufferType << remoteId;
182 auto mainDatabase = Storage::mainDatabase(transaction(), bufferType); 184 auto mainDatabase = Storage::mainDatabase(transaction(), bufferType);
183 const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); 185 const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId);
184 const auto found = mainDatabase.contains(sinkId); 186 const auto found = mainDatabase.contains(sinkId);
@@ -192,17 +194,17 @@ void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray
192 reader.query(query, 194 reader.query(query,
193 [this, bufferType, remoteId, &merge](const DomainType &o) -> bool{ 195 [this, bufferType, remoteId, &merge](const DomainType &o) -> bool{
194 merge = true; 196 merge = true;
195 Trace() << "Merging local entity with remote entity: " << o.identifier() << remoteId; 197 SinkTrace() << "Merging local entity with remote entity: " << o.identifier() << remoteId;
196 syncStore().recordRemoteId(bufferType, o.identifier(), remoteId); 198 syncStore().recordRemoteId(bufferType, o.identifier(), remoteId);
197 return false; 199 return false;
198 }); 200 });
199 if (!merge) { 201 if (!merge) {
200 Trace() << "Found a new entity: " << remoteId; 202 SinkTrace() << "Found a new entity: " << remoteId;
201 createEntity( 203 createEntity(
202 sinkId, bufferType, entity, *adaptorFactory, [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::CreateEntityCommand, buffer); }); 204 sinkId, bufferType, entity, *adaptorFactory, [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::CreateEntityCommand, buffer); });
203 } 205 }
204 } else { 206 } else {
205 Trace() << "Found a new entity: " << remoteId; 207 SinkTrace() << "Found a new entity: " << remoteId;
206 createEntity( 208 createEntity(
207 sinkId, bufferType, entity, *adaptorFactory, [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::CreateEntityCommand, buffer); }); 209 sinkId, bufferType, entity, *adaptorFactory, [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::CreateEntityCommand, buffer); });
208 } 210 }
@@ -212,17 +214,17 @@ void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray
212 bool changed = false; 214 bool changed = false;
213 for (const auto &property : entity.changedProperties()) { 215 for (const auto &property : entity.changedProperties()) {
214 if (entity.getProperty(property) != current->getProperty(property)) { 216 if (entity.getProperty(property) != current->getProperty(property)) {
215 Trace() << "Property changed " << sinkId << property; 217 SinkTrace() << "Property changed " << sinkId << property;
216 changed = true; 218 changed = true;
217 } 219 }
218 } 220 }
219 if (changed) { 221 if (changed) {
220 Trace() << "Found a modified entity: " << remoteId; 222 SinkTrace() << "Found a modified entity: " << remoteId;
221 modifyEntity(sinkId, Sink::Storage::maxRevision(transaction()), bufferType, entity, *adaptorFactory, 223 modifyEntity(sinkId, Sink::Storage::maxRevision(transaction()), bufferType, entity, *adaptorFactory,
222 [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::ModifyEntityCommand, buffer); }); 224 [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::ModifyEntityCommand, buffer); });
223 } 225 }
224 } else { 226 } else {
225 Warning() << "Failed to get current entity"; 227 SinkWarning() << "Failed to get current entity";
226 } 228 }
227 } 229 }
228} 230}
@@ -239,7 +241,7 @@ void Synchronizer::modify(const DomainType &entity)
239 241
240KAsync::Job<void> Synchronizer::synchronize() 242KAsync::Job<void> Synchronizer::synchronize()
241{ 243{
242 Trace() << "Synchronizing"; 244 SinkTrace() << "Synchronizing";
243 mSyncInProgress = true; 245 mSyncInProgress = true;
244 mMessageQueue->startTransaction(); 246 mMessageQueue->startTransaction();
245 return synchronizeWithSource().then<void>([this]() { 247 return synchronizeWithSource().then<void>([this]() {
@@ -265,7 +267,7 @@ void Synchronizer::commit()
265Sink::Storage::Transaction &Synchronizer::transaction() 267Sink::Storage::Transaction &Synchronizer::transaction()
266{ 268{
267 if (!mTransaction) { 269 if (!mTransaction) {
268 Trace() << "Starting transaction"; 270 SinkTrace() << "Starting transaction";
269 mTransaction = mStorage.createTransaction(Sink::Storage::ReadOnly); 271 mTransaction = mStorage.createTransaction(Sink::Storage::ReadOnly);
270 } 272 }
271 return mTransaction; 273 return mTransaction;
@@ -274,7 +276,7 @@ Sink::Storage::Transaction &Synchronizer::transaction()
274Sink::Storage::Transaction &Synchronizer::syncTransaction() 276Sink::Storage::Transaction &Synchronizer::syncTransaction()
275{ 277{
276 if (!mSyncTransaction) { 278 if (!mSyncTransaction) {
277 Trace() << "Starting transaction"; 279 SinkTrace() << "Starting transaction";
278 mSyncTransaction = mSyncStorage.createTransaction(Sink::Storage::ReadWrite); 280 mSyncTransaction = mSyncStorage.createTransaction(Sink::Storage::ReadWrite);
279 } 281 }
280 return mSyncTransaction; 282 return mSyncTransaction;
diff --git a/common/test.cpp b/common/test.cpp
index c7d84cc..99e51c8 100644
--- a/common/test.cpp
+++ b/common/test.cpp
@@ -28,6 +28,8 @@
28#include "query.h" 28#include "query.h"
29#include "resourceconfig.h" 29#include "resourceconfig.h"
30 30
31SINK_DEBUG_AREA("test")
32
31using namespace Sink; 33using namespace Sink;
32 34
33void Sink::Test::initTest() 35void Sink::Test::initTest()
@@ -103,7 +105,7 @@ public:
103 { 105 {
104 auto resultProvider = new Sink::ResultProvider<typename T::Ptr>(); 106 auto resultProvider = new Sink::ResultProvider<typename T::Ptr>();
105 resultProvider->onDone([resultProvider]() { 107 resultProvider->onDone([resultProvider]() {
106 Trace() << "Result provider is done"; 108 SinkTrace() << "Result provider is done";
107 delete resultProvider; 109 delete resultProvider;
108 }); 110 });
109 // We have to do it this way, otherwise we're not setting the fetcher right 111 // We have to do it this way, otherwise we're not setting the fetcher right
@@ -111,11 +113,11 @@ public:
111 113
112 resultProvider->setFetcher([query, resultProvider, this](const typename T::Ptr &parent) { 114 resultProvider->setFetcher([query, resultProvider, this](const typename T::Ptr &parent) {
113 if (parent) { 115 if (parent) {
114 Trace() << "Running the fetcher " << parent->identifier(); 116 SinkTrace() << "Running the fetcher " << parent->identifier();
115 } else { 117 } else {
116 Trace() << "Running the fetcher."; 118 SinkTrace() << "Running the fetcher.";
117 } 119 }
118 Trace() << "-------------------------."; 120 SinkTrace() << "-------------------------.";
119 for (const auto &res : mTestAccount->entities<T>()) { 121 for (const auto &res : mTestAccount->entities<T>()) {
120 qDebug() << "Parent filter " << query.propertyFilter.value("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray(); 122 qDebug() << "Parent filter " << query.propertyFilter.value("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray();
121 auto parentProperty = res->getProperty("parent").toByteArray(); 123 auto parentProperty = res->getProperty("parent").toByteArray();
diff --git a/common/typeindex.cpp b/common/typeindex.cpp
index 05bbf5c..78195d3 100644
--- a/common/typeindex.cpp
+++ b/common/typeindex.cpp
@@ -22,8 +22,7 @@
22#include "index.h" 22#include "index.h"
23#include <QDateTime> 23#include <QDateTime>
24 24
25#undef DEBUG_AREA 25SINK_DEBUG_AREA("typeindex")
26#define DEBUG_AREA "common.typeindex"
27 26
28static QByteArray getByteArray(const QVariant &value) 27static QByteArray getByteArray(const QVariant &value)
29{ 28{
@@ -63,7 +62,7 @@ template <>
63void TypeIndex::addProperty<QByteArray>(const QByteArray &property) 62void TypeIndex::addProperty<QByteArray>(const QByteArray &property)
64{ 63{
65 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { 64 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) {
66 // Trace() << "Indexing " << mType + ".index." + property << value.toByteArray(); 65 // SinkTrace() << "Indexing " << mType + ".index." + property << value.toByteArray();
67 Index(indexName(property), transaction).add(getByteArray(value), identifier); 66 Index(indexName(property), transaction).add(getByteArray(value), identifier);
68 }; 67 };
69 mIndexer.insert(property, indexer); 68 mIndexer.insert(property, indexer);
@@ -74,7 +73,7 @@ template <>
74void TypeIndex::addProperty<QString>(const QByteArray &property) 73void TypeIndex::addProperty<QString>(const QByteArray &property)
75{ 74{
76 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { 75 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) {
77 // Trace() << "Indexing " << mType + ".index." + property << value.toByteArray(); 76 // SinkTrace() << "Indexing " << mType + ".index." + property << value.toByteArray();
78 Index(indexName(property), transaction).add(getByteArray(value), identifier); 77 Index(indexName(property), transaction).add(getByteArray(value), identifier);
79 }; 78 };
80 mIndexer.insert(property, indexer); 79 mIndexer.insert(property, indexer);
@@ -85,7 +84,7 @@ template <>
85void TypeIndex::addProperty<QDateTime>(const QByteArray &property) 84void TypeIndex::addProperty<QDateTime>(const QByteArray &property)
86{ 85{
87 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { 86 auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) {
88 // Trace() << "Indexing " << mType + ".index." + property << date.toString(); 87 // SinkTrace() << "Indexing " << mType + ".index." + property << date.toString();
89 Index(indexName(property), transaction).add(getByteArray(value), identifier); 88 Index(indexName(property), transaction).add(getByteArray(value), identifier);
90 }; 89 };
91 mIndexer.insert(property, indexer); 90 mIndexer.insert(property, indexer);
@@ -143,12 +142,12 @@ ResultSet TypeIndex::query(const Sink::Query &query, QSet<QByteArray> &appliedFi
143 if (query.propertyFilter.contains(it.key()) && query.sortProperty == it.value()) { 142 if (query.propertyFilter.contains(it.key()) && query.sortProperty == it.value()) {
144 Index index(indexName(it.key(), it.value()), transaction); 143 Index index(indexName(it.key(), it.value()), transaction);
145 const auto lookupKey = getByteArray(query.propertyFilter.value(it.key()).value); 144 const auto lookupKey = getByteArray(query.propertyFilter.value(it.key()).value);
146 Trace() << "looking for " << lookupKey; 145 SinkTrace() << "looking for " << lookupKey;
147 index.lookup(lookupKey, [&](const QByteArray &value) { keys << value; }, 146 index.lookup(lookupKey, [&](const QByteArray &value) { keys << value; },
148 [it](const Index::Error &error) { Warning() << "Error in index: " << error.message << it.key() << it.value(); }, true); 147 [it](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << it.key() << it.value(); }, true);
149 appliedFilters << it.key(); 148 appliedFilters << it.key();
150 appliedSorting = it.value(); 149 appliedSorting = it.value();
151 Trace() << "Index lookup on " << it.key() << it.value() << " found " << keys.size() << " keys."; 150 SinkTrace() << "Index lookup on " << it.key() << it.value() << " found " << keys.size() << " keys.";
152 return ResultSet(keys); 151 return ResultSet(keys);
153 } 152 }
154 } 153 }
@@ -157,12 +156,12 @@ ResultSet TypeIndex::query(const Sink::Query &query, QSet<QByteArray> &appliedFi
157 Index index(indexName(property), transaction); 156 Index index(indexName(property), transaction);
158 const auto lookupKey = getByteArray(query.propertyFilter.value(property).value); 157 const auto lookupKey = getByteArray(query.propertyFilter.value(property).value);
159 index.lookup( 158 index.lookup(
160 lookupKey, [&](const QByteArray &value) { keys << value; }, [property](const Index::Error &error) { Warning() << "Error in index: " << error.message << property; }); 159 lookupKey, [&](const QByteArray &value) { keys << value; }, [property](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << property; });
161 appliedFilters << property; 160 appliedFilters << property;
162 Trace() << "Index lookup on " << property << " found " << keys.size() << " keys."; 161 SinkTrace() << "Index lookup on " << property << " found " << keys.size() << " keys.";
163 return ResultSet(keys); 162 return ResultSet(keys);
164 } 163 }
165 } 164 }
166 Trace() << "No matching index"; 165 SinkTrace() << "No matching index";
167 return ResultSet(keys); 166 return ResultSet(keys);
168} 167}
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp
index 21a76ad..0f7463f 100644
--- a/examples/dummyresource/resourcefactory.cpp
+++ b/examples/dummyresource/resourcefactory.cpp
@@ -48,6 +48,8 @@
48#define ENTITY_TYPE_MAIL "mail" 48#define ENTITY_TYPE_MAIL "mail"
49#define ENTITY_TYPE_FOLDER "folder" 49#define ENTITY_TYPE_FOLDER "folder"
50 50
51SINK_DEBUG_AREA("dummyresource")
52
51class DummySynchronizer : public Sink::Synchronizer { 53class DummySynchronizer : public Sink::Synchronizer {
52 public: 54 public:
53 55
@@ -105,12 +107,12 @@ class DummySynchronizer : public Sink::Synchronizer {
105 auto entity = createEntity(remoteId, it.value()); 107 auto entity = createEntity(remoteId, it.value());
106 createOrModify(bufferType, remoteId, *entity); 108 createOrModify(bufferType, remoteId, *entity);
107 } 109 }
108 Trace() << "Sync of " << count << " entities of type " << bufferType << " done." << Sink::Log::TraceTime(time->elapsed()); 110 SinkTrace() << "Sync of " << count << " entities of type " << bufferType << " done." << Sink::Log::TraceTime(time->elapsed());
109 } 111 }
110 112
111 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE 113 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE
112 { 114 {
113 Log() << " Synchronizing with the source"; 115 SinkLog() << " Synchronizing with the source";
114 return KAsync::start<void>([this]() { 116 return KAsync::start<void>([this]() {
115 synchronize(ENTITY_TYPE_EVENT, DummyStore::instance().events(), [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) { 117 synchronize(ENTITY_TYPE_EVENT, DummyStore::instance().events(), [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) {
116 return createEvent(ridBuffer, data); 118 return createEvent(ridBuffer, data);
@@ -121,7 +123,7 @@ class DummySynchronizer : public Sink::Synchronizer {
121 synchronize(ENTITY_TYPE_FOLDER, DummyStore::instance().folders(), [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) { 123 synchronize(ENTITY_TYPE_FOLDER, DummyStore::instance().folders(), [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) {
122 return createFolder(ridBuffer, data); 124 return createFolder(ridBuffer, data);
123 }); 125 });
124 Log() << "Done Synchronizing"; 126 SinkLog() << "Done Synchronizing";
125 }); 127 });
126 } 128 }
127 129
@@ -147,7 +149,7 @@ DummyResource::~DummyResource()
147 149
148KAsync::Job<void> DummyResource::synchronizeWithSource() 150KAsync::Job<void> DummyResource::synchronizeWithSource()
149{ 151{
150 Trace() << "Synchronize with source and sending a notification about it"; 152 SinkTrace() << "Synchronize with source and sending a notification about it";
151 Sink::Notification n; 153 Sink::Notification n;
152 n.id = "connected"; 154 n.id = "connected";
153 n.type = Sink::Notification::Status; 155 n.type = Sink::Notification::Status;
@@ -160,7 +162,7 @@ KAsync::Job<void> DummyResource::synchronizeWithSource()
160KAsync::Job<void> DummyResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) 162KAsync::Job<void> DummyResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue)
161{ 163{
162 164
163 Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; 165 SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue;
164 if (property == "testInspection") { 166 if (property == "testInspection") {
165 if (expectedValue.toBool()) { 167 if (expectedValue.toBool()) {
166 //Success 168 //Success
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp
index e23add8..92f64bf 100644
--- a/examples/imapresource/imapresource.cpp
+++ b/examples/imapresource/imapresource.cpp
@@ -54,8 +54,7 @@
54#define ENTITY_TYPE_MAIL "mail" 54#define ENTITY_TYPE_MAIL "mail"
55#define ENTITY_TYPE_FOLDER "folder" 55#define ENTITY_TYPE_FOLDER "folder"
56 56
57#undef DEBUG_AREA 57SINK_DEBUG_AREA("imapresource")
58#define DEBUG_AREA "resource.imap"
59 58
60using namespace Imap; 59using namespace Imap;
61using namespace Sink; 60using namespace Sink;
@@ -95,7 +94,7 @@ public:
95 94
96 QByteArray createFolder(const QString &folderName, const QString &folderPath, const QString &parentFolderRid, const QByteArray &icon) 95 QByteArray createFolder(const QString &folderName, const QString &folderPath, const QString &parentFolderRid, const QByteArray &icon)
97 { 96 {
98 Trace() << "Creating folder: " << folderName << parentFolderRid; 97 SinkTrace() << "Creating folder: " << folderName << parentFolderRid;
99 const auto remoteId = folderPath.toUtf8(); 98 const auto remoteId = folderPath.toUtf8();
100 const auto bufferType = ENTITY_TYPE_FOLDER; 99 const auto bufferType = ENTITY_TYPE_FOLDER;
101 Sink::ApplicationDomain::Folder folder; 100 Sink::ApplicationDomain::Folder folder;
@@ -118,7 +117,7 @@ public:
118 void synchronizeFolders(const QVector<Folder> &folderList) 117 void synchronizeFolders(const QVector<Folder> &folderList)
119 { 118 {
120 const QByteArray bufferType = ENTITY_TYPE_FOLDER; 119 const QByteArray bufferType = ENTITY_TYPE_FOLDER;
121 Trace() << "Found folders " << folderList.size(); 120 SinkTrace() << "Found folders " << folderList.size();
122 121
123 scanForRemovals(bufferType, 122 scanForRemovals(bufferType,
124 [this, &bufferType](const std::function<void(const QByteArray &)> &callback) { 123 [this, &bufferType](const std::function<void(const QByteArray &)> &callback) {
@@ -154,7 +153,7 @@ public:
154 time->start(); 153 time->start();
155 const QByteArray bufferType = ENTITY_TYPE_MAIL; 154 const QByteArray bufferType = ENTITY_TYPE_MAIL;
156 155
157 Trace() << "Importing new mail." << path; 156 SinkTrace() << "Importing new mail." << path;
158 157
159 const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8()); 158 const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8());
160 159
@@ -163,7 +162,7 @@ public:
163 count++; 162 count++;
164 const auto remoteId = assembleMailRid(folderLocalId, message.uid); 163 const auto remoteId = assembleMailRid(folderLocalId, message.uid);
165 164
166 Trace() << "Found a mail " << remoteId << message.msg->subject(true)->asUnicodeString() << message.flags; 165 SinkTrace() << "Found a mail " << remoteId << message.msg->subject(true)->asUnicodeString() << message.flags;
167 166
168 auto mail = Sink::ApplicationDomain::Mail::create(mResourceInstanceIdentifier); 167 auto mail = Sink::ApplicationDomain::Mail::create(mResourceInstanceIdentifier);
169 mail.setFolder(folderLocalId); 168 mail.setFolder(folderLocalId);
@@ -174,7 +173,7 @@ public:
174 createOrModify(bufferType, remoteId, mail); 173 createOrModify(bufferType, remoteId, mail);
175 } 174 }
176 const auto elapsed = time->elapsed(); 175 const auto elapsed = time->elapsed();
177 Log() << "Synchronized " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; 176 SinkLog() << "Synchronized " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]";
178 } 177 }
179 178
180 void synchronizeRemovals(const QString &path, const QSet<qint64> &messages) 179 void synchronizeRemovals(const QString &path, const QSet<qint64> &messages)
@@ -183,7 +182,7 @@ public:
183 time->start(); 182 time->start();
184 const QByteArray bufferType = ENTITY_TYPE_MAIL; 183 const QByteArray bufferType = ENTITY_TYPE_MAIL;
185 184
186 Trace() << "Finding removed mail."; 185 SinkTrace() << "Finding removed mail.";
187 186
188 const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8()); 187 const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8());
189 188
@@ -196,7 +195,7 @@ public:
196 callback(sinkId); 195 callback(sinkId);
197 }, 196 },
198 [&](const Index::Error &error) { 197 [&](const Index::Error &error) {
199 Warning() << "Error in index: " << error.message << property; 198 SinkWarning() << "Error in index: " << error.message << property;
200 }); 199 });
201 }, 200 },
202 [messages, path, &count](const QByteArray &remoteId) -> bool { 201 [messages, path, &count](const QByteArray &remoteId) -> bool {
@@ -209,24 +208,24 @@ public:
209 ); 208 );
210 209
211 const auto elapsed = time->elapsed(); 210 const auto elapsed = time->elapsed();
212 Log() << "Removed " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; 211 SinkLog() << "Removed " << count << " mails in " << path << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]";
213 } 212 }
214 213
215 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE 214 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE
216 { 215 {
217 Log() << " Synchronizing"; 216 SinkLog() << " Synchronizing";
218 return KAsync::start<void>([this](KAsync::Future<void> future) { 217 return KAsync::start<void>([this](KAsync::Future<void> future) {
219 Trace() << "Connecting to:" << mServer << mPort; 218 SinkTrace() << "Connecting to:" << mServer << mPort;
220 Trace() << "as:" << mUser; 219 SinkTrace() << "as:" << mUser;
221 ImapServerProxy imap(mServer, mPort); 220 ImapServerProxy imap(mServer, mPort);
222 auto loginFuture = imap.login(mUser, mPassword).exec(); 221 auto loginFuture = imap.login(mUser, mPassword).exec();
223 loginFuture.waitForFinished(); 222 loginFuture.waitForFinished();
224 if (loginFuture.errorCode()) { 223 if (loginFuture.errorCode()) {
225 Warning() << "Login failed."; 224 SinkWarning() << "Login failed.";
226 future.setError(1, "Login failed"); 225 future.setError(1, "Login failed");
227 return; 226 return;
228 } else { 227 } else {
229 Trace() << "Login was successful"; 228 SinkTrace() << "Login was successful";
230 } 229 }
231 230
232 QVector<Folder> folderList; 231 QVector<Folder> folderList;
@@ -238,11 +237,11 @@ public:
238 }).exec(); 237 }).exec();
239 folderFuture.waitForFinished(); 238 folderFuture.waitForFinished();
240 if (folderFuture.errorCode()) { 239 if (folderFuture.errorCode()) {
241 Warning() << "Folder sync failed."; 240 SinkWarning() << "Folder sync failed.";
242 future.setError(1, "Folder list sync failed"); 241 future.setError(1, "Folder list sync failed");
243 return; 242 return;
244 } else { 243 } else {
245 Trace() << "Folder sync was successful"; 244 SinkTrace() << "Folder sync was successful";
246 } 245 }
247 246
248 for (const auto &folder : folderList) { 247 for (const auto &folder : folderList) {
@@ -251,7 +250,7 @@ public:
251 } 250 }
252 QSet<qint64> uids; 251 QSet<qint64> uids;
253 auto messagesFuture = imap.fetchMessages(folder, [this, folder, &uids](const QVector<Message> &messages) { 252 auto messagesFuture = imap.fetchMessages(folder, [this, folder, &uids](const QVector<Message> &messages) {
254 Trace() << "Synchronizing mails" << folder.normalizedPath(); 253 SinkTrace() << "Synchronizing mails" << folder.normalizedPath();
255 for (const auto &msg : messages) { 254 for (const auto &msg : messages) {
256 uids << msg.uid; 255 uids << msg.uid;
257 } 256 }
@@ -260,16 +259,16 @@ public:
260 messagesFuture.waitForFinished(); 259 messagesFuture.waitForFinished();
261 commit(); 260 commit();
262 if (messagesFuture.errorCode()) { 261 if (messagesFuture.errorCode()) {
263 Warning() << "Folder sync failed: " << folder.normalizedPath(); 262 SinkWarning() << "Folder sync failed: " << folder.normalizedPath();
264 continue; 263 continue;
265 } 264 }
266 //Remove what there is to remove 265 //Remove what there is to remove
267 synchronizeRemovals(folder.normalizedPath(), uids); 266 synchronizeRemovals(folder.normalizedPath(), uids);
268 commit(); 267 commit();
269 Trace() << "Folder synchronized: " << folder.normalizedPath(); 268 SinkTrace() << "Folder synchronized: " << folder.normalizedPath();
270 } 269 }
271 270
272 Log() << "Done Synchronizing"; 271 SinkLog() << "Done Synchronizing";
273 future.setFinished(); 272 future.setFinished();
274 }); 273 });
275 } 274 }
@@ -310,7 +309,7 @@ public:
310 .then<void, qint64>([imap, mailbox, rid, mail](qint64 uid) { 309 .then<void, qint64>([imap, mailbox, rid, mail](qint64 uid) {
311 const auto remoteId = assembleMailRid(mail, uid); 310 const auto remoteId = assembleMailRid(mail, uid);
312 //FIXME this get's called after the final error handler? WTF? 311 //FIXME this get's called after the final error handler? WTF?
313 Trace() << "Finished creating a new mail: " << remoteId; 312 SinkTrace() << "Finished creating a new mail: " << remoteId;
314 *rid = remoteId; 313 *rid = remoteId;
315 }).then<QByteArray>([rid, imap]() { //FIXME fix KJob so we don't need this extra clause 314 }).then<QByteArray>([rid, imap]() { //FIXME fix KJob so we don't need this extra clause
316 return *rid; 315 return *rid;
@@ -319,19 +318,19 @@ public:
319 const auto folderId = folderIdFromMailRid(oldRemoteId); 318 const auto folderId = folderIdFromMailRid(oldRemoteId);
320 const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId); 319 const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId);
321 const auto uid = uidFromMailRid(oldRemoteId); 320 const auto uid = uidFromMailRid(oldRemoteId);
322 Trace() << "Removing a mail: " << oldRemoteId << "in the mailbox: " << mailbox; 321 SinkTrace() << "Removing a mail: " << oldRemoteId << "in the mailbox: " << mailbox;
323 KIMAP::ImapSet set; 322 KIMAP::ImapSet set;
324 set.add(uid); 323 set.add(uid);
325 return login.then(imap->remove(mailbox, set)) 324 return login.then(imap->remove(mailbox, set))
326 .then<QByteArray>([imap, oldRemoteId]() { 325 .then<QByteArray>([imap, oldRemoteId]() {
327 Trace() << "Finished removing a mail: " << oldRemoteId; 326 SinkTrace() << "Finished removing a mail: " << oldRemoteId;
328 return QByteArray(); 327 return QByteArray();
329 }); 328 });
330 } else if (operation == Sink::Operation_Modification) { 329 } else if (operation == Sink::Operation_Modification) {
331 const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); 330 const QString mailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder());
332 const auto uid = uidFromMailRid(oldRemoteId); 331 const auto uid = uidFromMailRid(oldRemoteId);
333 332
334 Trace() << "Modifying a mail: " << oldRemoteId << " in the mailbox: " << mailbox << changedProperties; 333 SinkTrace() << "Modifying a mail: " << oldRemoteId << " in the mailbox: " << mailbox << changedProperties;
335 334
336 QByteArrayList flags; 335 QByteArrayList flags;
337 if (!mail.getUnread()) { 336 if (!mail.getUnread()) {
@@ -344,7 +343,7 @@ public:
344 const bool messageMoved = changedProperties.contains(ApplicationDomain::Mail::Folder::name); 343 const bool messageMoved = changedProperties.contains(ApplicationDomain::Mail::Folder::name);
345 const bool messageChanged = changedProperties.contains(ApplicationDomain::Mail::MimeMessage::name); 344 const bool messageChanged = changedProperties.contains(ApplicationDomain::Mail::MimeMessage::name);
346 if (messageChanged || messageMoved) { 345 if (messageChanged || messageMoved) {
347 Trace() << "Replacing message."; 346 SinkTrace() << "Replacing message.";
348 const auto folderId = folderIdFromMailRid(oldRemoteId); 347 const auto folderId = folderIdFromMailRid(oldRemoteId);
349 const QString oldMailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId); 348 const QString oldMailbox = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folderId);
350 QByteArray content = KMime::LFtoCRLF(mail.getMimeMessage()); 349 QByteArray content = KMime::LFtoCRLF(mail.getMimeMessage());
@@ -355,7 +354,7 @@ public:
355 return login.then(imap->append(mailbox, content, flags, internalDate)) 354 return login.then(imap->append(mailbox, content, flags, internalDate))
356 .then<void, qint64>([imap, mailbox, rid, mail](qint64 uid) { 355 .then<void, qint64>([imap, mailbox, rid, mail](qint64 uid) {
357 const auto remoteId = assembleMailRid(mail, uid); 356 const auto remoteId = assembleMailRid(mail, uid);
358 Trace() << "Finished creating a modified mail: " << remoteId; 357 SinkTrace() << "Finished creating a modified mail: " << remoteId;
359 *rid = remoteId; 358 *rid = remoteId;
360 }) 359 })
361 .then(imap->remove(oldMailbox, set)) 360 .then(imap->remove(oldMailbox, set))
@@ -363,13 +362,13 @@ public:
363 return *rid; 362 return *rid;
364 }); 363 });
365 } else { 364 } else {
366 Trace() << "Updating flags only."; 365 SinkTrace() << "Updating flags only.";
367 KIMAP::ImapSet set; 366 KIMAP::ImapSet set;
368 set.add(uid); 367 set.add(uid);
369 return login.then(imap->select(mailbox)) 368 return login.then(imap->select(mailbox))
370 .then(imap->storeFlags(set, flags)) 369 .then(imap->storeFlags(set, flags))
371 .then<void>([imap, mailbox]() { 370 .then<void>([imap, mailbox]() {
372 Trace() << "Finished modifying mail"; 371 SinkTrace() << "Finished modifying mail";
373 }) 372 })
374 .then<QByteArray>([oldRemoteId, imap]() { 373 .then<QByteArray>([oldRemoteId, imap]() {
375 return oldRemoteId; 374 return oldRemoteId;
@@ -388,11 +387,11 @@ public:
388 if (!folder.getParent().isEmpty()) { 387 if (!folder.getParent().isEmpty()) {
389 parentFolder = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folder.getParent()); 388 parentFolder = syncStore().resolveLocalId(ENTITY_TYPE_FOLDER, folder.getParent());
390 } 389 }
391 Trace() << "Creating a new folder: " << parentFolder << folder.getName(); 390 SinkTrace() << "Creating a new folder: " << parentFolder << folder.getName();
392 auto rid = QSharedPointer<QByteArray>::create(); 391 auto rid = QSharedPointer<QByteArray>::create();
393 auto createFolder = login.then<QString>(imap->createSubfolder(parentFolder, folder.getName())) 392 auto createFolder = login.then<QString>(imap->createSubfolder(parentFolder, folder.getName()))
394 .then<void, QString>([imap, rid](const QString &createdFolder) { 393 .then<void, QString>([imap, rid](const QString &createdFolder) {
395 Trace() << "Finished creating a new folder: " << createdFolder; 394 SinkTrace() << "Finished creating a new folder: " << createdFolder;
396 *rid = createdFolder.toUtf8(); 395 *rid = createdFolder.toUtf8();
397 }); 396 });
398 if (folder.getSpecialPurpose().isEmpty()) { 397 if (folder.getSpecialPurpose().isEmpty()) {
@@ -414,15 +413,15 @@ public:
414 for (const auto &purpose : folder.getSpecialPurpose()) { 413 for (const auto &purpose : folder.getSpecialPurpose()) {
415 if (specialPurposeFolders->contains(purpose)) { 414 if (specialPurposeFolders->contains(purpose)) {
416 auto f = specialPurposeFolders->value(purpose); 415 auto f = specialPurposeFolders->value(purpose);
417 Trace() << "Merging specialpurpose folder with: " << f << " with purpose: " << purpose; 416 SinkTrace() << "Merging specialpurpose folder with: " << f << " with purpose: " << purpose;
418 *rid = f.toUtf8(); 417 *rid = f.toUtf8();
419 return KAsync::null<void>(); 418 return KAsync::null<void>();
420 } 419 }
421 } 420 }
422 Trace() << "No match found for merging, creating a new folder"; 421 SinkTrace() << "No match found for merging, creating a new folder";
423 return imap->createSubfolder(parentFolder, folder.getName()) 422 return imap->createSubfolder(parentFolder, folder.getName())
424 .then<void, QString>([imap, rid](const QString &createdFolder) { 423 .then<void, QString>([imap, rid](const QString &createdFolder) {
425 Trace() << "Finished creating a new folder: " << createdFolder; 424 SinkTrace() << "Finished creating a new folder: " << createdFolder;
426 *rid = createdFolder.toUtf8(); 425 *rid = createdFolder.toUtf8();
427 }); 426 });
428 427
@@ -433,18 +432,18 @@ public:
433 return mergeJob; 432 return mergeJob;
434 } 433 }
435 } else if (operation == Sink::Operation_Removal) { 434 } else if (operation == Sink::Operation_Removal) {
436 Trace() << "Removing a folder: " << oldRemoteId; 435 SinkTrace() << "Removing a folder: " << oldRemoteId;
437 return login.then<void>(imap->remove(oldRemoteId)) 436 return login.then<void>(imap->remove(oldRemoteId))
438 .then<QByteArray>([oldRemoteId, imap]() { 437 .then<QByteArray>([oldRemoteId, imap]() {
439 Trace() << "Finished removing a folder: " << oldRemoteId; 438 SinkTrace() << "Finished removing a folder: " << oldRemoteId;
440 return QByteArray(); 439 return QByteArray();
441 }); 440 });
442 } else if (operation == Sink::Operation_Modification) { 441 } else if (operation == Sink::Operation_Modification) {
443 Trace() << "Renaming a folder: " << oldRemoteId << folder.getName(); 442 SinkTrace() << "Renaming a folder: " << oldRemoteId << folder.getName();
444 auto rid = QSharedPointer<QByteArray>::create(); 443 auto rid = QSharedPointer<QByteArray>::create();
445 return login.then<QString>(imap->renameSubfolder(oldRemoteId, folder.getName())) 444 return login.then<QString>(imap->renameSubfolder(oldRemoteId, folder.getName()))
446 .then<void, QString>([imap, rid](const QString &createdFolder) { 445 .then<void, QString>([imap, rid](const QString &createdFolder) {
447 Trace() << "Finished renaming a folder: " << createdFolder; 446 SinkTrace() << "Finished renaming a folder: " << createdFolder;
448 *rid = createdFolder.toUtf8(); 447 *rid = createdFolder.toUtf8();
449 }) 448 })
450 .then<QByteArray>([rid](){ 449 .then<QByteArray>([rid](){
@@ -515,7 +514,7 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in
515 auto entityStore = QSharedPointer<Sink::EntityStore>::create(mResourceType, mResourceInstanceIdentifier, transaction); 514 auto entityStore = QSharedPointer<Sink::EntityStore>::create(mResourceType, mResourceInstanceIdentifier, transaction);
516 auto syncStore = QSharedPointer<Sink::RemoteIdMap>::create(synchronizationTransaction); 515 auto syncStore = QSharedPointer<Sink::RemoteIdMap>::create(synchronizationTransaction);
517 516
518 Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; 517 SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue;
519 518
520 if (domainType == ENTITY_TYPE_MAIL) { 519 if (domainType == ENTITY_TYPE_MAIL) {
521 const auto mail = entityStore->read<Sink::ApplicationDomain::Mail>(entityId); 520 const auto mail = entityStore->read<Sink::ApplicationDomain::Mail>(entityId);
@@ -523,11 +522,11 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in
523 const auto folderRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder()); 522 const auto folderRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_FOLDER, mail.getFolder());
524 const auto mailRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_MAIL, mail.identifier()); 523 const auto mailRemoteId = syncStore->resolveLocalId(ENTITY_TYPE_MAIL, mail.identifier());
525 if (mailRemoteId.isEmpty() || folderRemoteId.isEmpty()) { 524 if (mailRemoteId.isEmpty() || folderRemoteId.isEmpty()) {
526 Warning() << "Missing remote id for folder or mail. " << mailRemoteId << folderRemoteId; 525 SinkWarning() << "Missing remote id for folder or mail. " << mailRemoteId << folderRemoteId;
527 return KAsync::error<void>(); 526 return KAsync::error<void>();
528 } 527 }
529 const auto uid = uidFromMailRid(mailRemoteId); 528 const auto uid = uidFromMailRid(mailRemoteId);
530 Trace() << "Mail remote id: " << folderRemoteId << mailRemoteId << mail.identifier() << folder.identifier(); 529 SinkTrace() << "Mail remote id: " << folderRemoteId << mailRemoteId << mail.identifier() << folder.identifier();
531 530
532 KIMAP::ImapSet set; 531 KIMAP::ImapSet set;
533 set.add(uid); 532 set.add(uid);
@@ -538,8 +537,8 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in
538 scope.mode = KIMAP::FetchJob::FetchScope::Full; 537 scope.mode = KIMAP::FetchJob::FetchScope::Full;
539 auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); 538 auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort);
540 auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create(); 539 auto messageByUid = QSharedPointer<QHash<qint64, Imap::Message>>::create();
541 Trace() << "Connecting to:" << mServer << mPort; 540 SinkTrace() << "Connecting to:" << mServer << mPort;
542 Trace() << "as:" << mUser; 541 SinkTrace() << "as:" << mUser;
543 auto inspectionJob = imap->login(mUser, mPassword) 542 auto inspectionJob = imap->login(mUser, mPassword)
544 .then<void>(imap->select(folderRemoteId)) 543 .then<void>(imap->select(folderRemoteId))
545 .then<void>(imap->fetch(set, scope, [imap, messageByUid](const QVector<Imap::Message> &messages) { 544 .then<void>(imap->fetch(set, scope, [imap, messageByUid](const QVector<Imap::Message> &messages) {
@@ -574,8 +573,8 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in
574 if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { 573 if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) {
575 return inspectionJob.then<void, KAsync::Job<void>>([=]() { 574 return inspectionJob.then<void, KAsync::Job<void>>([=]() {
576 if (!messageByUid->contains(uid)) { 575 if (!messageByUid->contains(uid)) {
577 Warning() << "Existing messages are: " << messageByUid->keys(); 576 SinkWarning() << "Existing messages are: " << messageByUid->keys();
578 Warning() << "We're looking for: " << uid; 577 SinkWarning() << "We're looking for: " << uid;
579 return KAsync::error<void>(1, "Couldn't find message: " + mailRemoteId); 578 return KAsync::error<void>(1, "Couldn't find message: " + mailRemoteId);
580 } 579 }
581 return KAsync::null<void>(); 580 return KAsync::null<void>();
@@ -587,7 +586,7 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in
587 const auto folder = entityStore->read<Sink::ApplicationDomain::Folder>(entityId); 586 const auto folder = entityStore->read<Sink::ApplicationDomain::Folder>(entityId);
588 587
589 if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) { 588 if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) {
590 Log() << "Inspecting cache integrity" << remoteId; 589 SinkLog() << "Inspecting cache integrity" << remoteId;
591 590
592 int expectedCount = 0; 591 int expectedCount = 0;
593 Index index("mail.index.folder", transaction); 592 Index index("mail.index.folder", transaction);
@@ -595,7 +594,7 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in
595 expectedCount++; 594 expectedCount++;
596 }, 595 },
597 [&](const Index::Error &error) { 596 [&](const Index::Error &error) {
598 Warning() << "Error in index: " << error.message << property; 597 SinkWarning() << "Error in index: " << error.message << property;
599 }); 598 });
600 599
601 auto set = KIMAP::ImapSet::fromImapSequenceSet("1:*"); 600 auto set = KIMAP::ImapSet::fromImapSequenceSet("1:*");
@@ -630,10 +629,10 @@ KAsync::Job<void> ImapResource::inspect(int inspectionType, const QByteArray &in
630 *folderByName << f.pathParts.last(); 629 *folderByName << f.pathParts.last();
631 } 630 }
632 })) 631 }))
633 .then<void, KAsync::Job<void>>([folderByName, folderByPath, folder, remoteId, imap]() { 632 .then<void, KAsync::Job<void>>([this, folderByName, folderByPath, folder, remoteId, imap]() {
634 if (!folderByName->contains(folder.getName())) { 633 if (!folderByName->contains(folder.getName())) {
635 Warning() << "Existing folders are: " << *folderByPath; 634 SinkWarning() << "Existing folders are: " << *folderByPath;
636 Warning() << "We're looking for: " << folder.getName(); 635 SinkWarning() << "We're looking for: " << folder.getName();
637 return KAsync::error<void>(1, "Wrong folder name: " + remoteId); 636 return KAsync::error<void>(1, "Wrong folder name: " + remoteId);
638 } 637 }
639 return KAsync::null<void>(); 638 return KAsync::null<void>();
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp
index 1b0a2ec..73ec654 100644
--- a/examples/imapresource/imapserverproxy.cpp
+++ b/examples/imapresource/imapserverproxy.cpp
@@ -37,6 +37,8 @@
37 37
38#include "log.h" 38#include "log.h"
39 39
40SINK_DEBUG_AREA("imapserverproxy")
41
40using namespace Imap; 42using namespace Imap;
41 43
42const char* Imap::Flags::Seen = "\\Seen"; 44const char* Imap::Flags::Seen = "\\Seen";
@@ -54,16 +56,16 @@ static KAsync::Job<T> runJob(KJob *job, const std::function<T(KJob*)> &f)
54{ 56{
55 return KAsync::start<T>([job, f](KAsync::Future<T> &future) { 57 return KAsync::start<T>([job, f](KAsync::Future<T> &future) {
56 QObject::connect(job, &KJob::result, [&future, f](KJob *job) { 58 QObject::connect(job, &KJob::result, [&future, f](KJob *job) {
57 Trace() << "Job done: " << job->metaObject()->className(); 59 SinkTrace() << "Job done: " << job->metaObject()->className();
58 if (job->error()) { 60 if (job->error()) {
59 Warning() << "Job failed: " << job->errorString(); 61 SinkWarning() << "Job failed: " << job->errorString();
60 future.setError(job->error(), job->errorString()); 62 future.setError(job->error(), job->errorString());
61 } else { 63 } else {
62 future.setValue(f(job)); 64 future.setValue(f(job));
63 future.setFinished(); 65 future.setFinished();
64 } 66 }
65 }); 67 });
66 Trace() << "Starting job: " << job->metaObject()->className(); 68 SinkTrace() << "Starting job: " << job->metaObject()->className();
67 job->start(); 69 job->start();
68 }); 70 });
69} 71}
@@ -72,15 +74,15 @@ static KAsync::Job<void> runJob(KJob *job)
72{ 74{
73 return KAsync::start<void>([job](KAsync::Future<void> &future) { 75 return KAsync::start<void>([job](KAsync::Future<void> &future) {
74 QObject::connect(job, &KJob::result, [&future](KJob *job) { 76 QObject::connect(job, &KJob::result, [&future](KJob *job) {
75 Trace() << "Job done: " << job->metaObject()->className(); 77 SinkTrace() << "Job done: " << job->metaObject()->className();
76 if (job->error()) { 78 if (job->error()) {
77 Warning() << "Job failed: " << job->errorString(); 79 SinkWarning() << "Job failed: " << job->errorString();
78 future.setError(job->error(), job->errorString()); 80 future.setError(job->error(), job->errorString());
79 } else { 81 } else {
80 future.setFinished(); 82 future.setFinished();
81 } 83 }
82 }); 84 });
83 Trace() << "Starting job: " << job->metaObject()->className(); 85 SinkTrace() << "Starting job: " << job->metaObject()->className();
84 job->start(); 86 job->start();
85 }); 87 });
86} 88}
@@ -117,11 +119,11 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString
117 auto namespaceJob = new KIMAP::NamespaceJob(mSession); 119 auto namespaceJob = new KIMAP::NamespaceJob(mSession);
118 120
119 return runJob(loginJob).then(runJob(capabilitiesJob)).then<void>([this](){ 121 return runJob(loginJob).then(runJob(capabilitiesJob)).then<void>([this](){
120 Trace() << "Supported capabilities: " << mCapabilities; 122 SinkTrace() << "Supported capabilities: " << mCapabilities;
121 QStringList requiredExtensions = QStringList() << "UIDPLUS" << "NAMESPACE"; 123 QStringList requiredExtensions = QStringList() << "UIDPLUS" << "NAMESPACE";
122 for (const auto &requiredExtension : requiredExtensions) { 124 for (const auto &requiredExtension : requiredExtensions) {
123 if (!mCapabilities.contains(requiredExtension)) { 125 if (!mCapabilities.contains(requiredExtension)) {
124 Warning() << "Server doesn't support required capability: " << requiredExtension; 126 SinkWarning() << "Server doesn't support required capability: " << requiredExtension;
125 //TODO fail the job 127 //TODO fail the job
126 } 128 }
127 } 129 }
@@ -138,9 +140,9 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString
138 mUserNamespaces << ns.name; 140 mUserNamespaces << ns.name;
139 mUserNamespaceSeparator = ns.separator; 141 mUserNamespaceSeparator = ns.separator;
140 } 142 }
141 Trace() << "Found personal namespaces: " << mPersonalNamespaces << mPersonalNamespaceSeparator; 143 SinkTrace() << "Found personal namespaces: " << mPersonalNamespaces << mPersonalNamespaceSeparator;
142 Trace() << "Found shared namespaces: " << mSharedNamespaces << mSharedNamespaceSeparator; 144 SinkTrace() << "Found shared namespaces: " << mSharedNamespaces << mSharedNamespaceSeparator;
143 Trace() << "Found user namespaces: " << mUserNamespaces << mUserNamespaceSeparator; 145 SinkTrace() << "Found user namespaces: " << mUserNamespaces << mUserNamespaceSeparator;
144 }); 146 });
145} 147}
146 148
@@ -291,8 +293,8 @@ KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox)
291 const QMap<qint64,KIMAP::MessageAttribute> &attrs, 293 const QMap<qint64,KIMAP::MessageAttribute> &attrs,
292 const QMap<qint64,KIMAP::MessageFlags> &flags, 294 const QMap<qint64,KIMAP::MessageFlags> &flags,
293 const QMap<qint64,KIMAP::MessagePtr> &messages) { 295 const QMap<qint64,KIMAP::MessagePtr> &messages) {
294 Trace() << "Received " << uids.size() << " headers from " << mailbox; 296 SinkTrace() << "Received " << uids.size() << " headers from " << mailbox;
295 Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); 297 SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
296 298
297 //TODO based on the data available here, figure out which messages to actually fetch 299 //TODO based on the data available here, figure out which messages to actually fetch
298 //(we only fetched headers and structure so far) 300 //(we only fetched headers and structure so far)
@@ -344,7 +346,7 @@ KAsync::Job<QString> ImapServerProxy::createSubfolder(const QString &parentMailb
344 } else { 346 } else {
345 *folder = parentMailbox + mPersonalNamespaceSeparator + folderName; 347 *folder = parentMailbox + mPersonalNamespaceSeparator + folderName;
346 } 348 }
347 Trace() << "Creating subfolder: " << *folder; 349 SinkTrace() << "Creating subfolder: " << *folder;
348 return create(*folder); 350 return create(*folder);
349 }) 351 })
350 .then<QString>([=]() { 352 .then<QString>([=]() {
@@ -360,7 +362,7 @@ KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox,
360 auto parts = oldMailbox.split(mPersonalNamespaceSeparator); 362 auto parts = oldMailbox.split(mPersonalNamespaceSeparator);
361 parts.removeLast(); 363 parts.removeLast();
362 *folder = parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName; 364 *folder = parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName;
363 Trace() << "Renaming subfolder: " << oldMailbox << *folder; 365 SinkTrace() << "Renaming subfolder: " << oldMailbox << *folder;
364 return rename(oldMailbox, *folder); 366 return rename(oldMailbox, *folder);
365 }) 367 })
366 .then<QString>([=]() { 368 .then<QString>([=]() {
@@ -370,14 +372,14 @@ KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox,
370 372
371KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const QVector<Folder> &)> callback) 373KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const QVector<Folder> &)> callback)
372{ 374{
373 Trace() << "Fetching folders"; 375 SinkTrace() << "Fetching folders";
374 return list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList<KIMAP::MailBoxDescriptor> &mailboxes, const QList<QList<QByteArray> > &flags){ 376 return list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList<KIMAP::MailBoxDescriptor> &mailboxes, const QList<QList<QByteArray> > &flags){
375 QVector<Folder> list; 377 QVector<Folder> list;
376 for (int i = 0; i < mailboxes.size(); i++) { 378 for (int i = 0; i < mailboxes.size(); i++) {
377 const auto mailbox = mailboxes[i]; 379 const auto mailbox = mailboxes[i];
378 const auto mailboxFlags = flags[i]; 380 const auto mailboxFlags = flags[i];
379 bool noselect = mailboxFlags.contains(QByteArray(FolderFlags::Noselect).toLower()) || mailboxFlags.contains(QByteArray(FolderFlags::Noselect)); 381 bool noselect = mailboxFlags.contains(QByteArray(FolderFlags::Noselect).toLower()) || mailboxFlags.contains(QByteArray(FolderFlags::Noselect));
380 Log() << "Found mailbox: " << mailbox.name << mailboxFlags << FolderFlags::Noselect << noselect; 382 SinkLog() << "Found mailbox: " << mailbox.name << mailboxFlags << FolderFlags::Noselect << noselect;
381 list << Folder{mailbox.name.split(mailbox.separator), mailbox.name, mailbox.separator, noselect}; 383 list << Folder{mailbox.name.split(mailbox.separator), mailbox.name, mailbox.separator, noselect};
382 } 384 }
383 callback(list); 385 callback(list);
@@ -395,9 +397,9 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, std::func
395 Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); 397 Q_ASSERT(!mPersonalNamespaceSeparator.isNull());
396 return select(mailboxFromFolder(folder)).then<void, KAsync::Job<void>>([this, callback, folder]() -> KAsync::Job<void> { 398 return select(mailboxFromFolder(folder)).then<void, KAsync::Job<void>>([this, callback, folder]() -> KAsync::Job<void> {
397 return fetchHeaders(mailboxFromFolder(folder)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback](const QList<qint64> &uidsToFetch){ 399 return fetchHeaders(mailboxFromFolder(folder)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback](const QList<qint64> &uidsToFetch){
398 Trace() << "Uids to fetch: " << uidsToFetch; 400 SinkTrace() << "Uids to fetch: " << uidsToFetch;
399 if (uidsToFetch.isEmpty()) { 401 if (uidsToFetch.isEmpty()) {
400 Trace() << "Nothing to fetch"; 402 SinkTrace() << "Nothing to fetch";
401 callback(QVector<Message>()); 403 callback(QVector<Message>());
402 return KAsync::null<void>(); 404 return KAsync::null<void>();
403 } 405 }
diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp
index 6819685..d9af453 100644
--- a/examples/imapresource/tests/imapserverproxytest.cpp
+++ b/examples/imapresource/tests/imapserverproxytest.cpp
@@ -12,6 +12,8 @@
12 12
13using namespace Imap; 13using namespace Imap;
14 14
15SINK_DEBUG_AREA("imapserverproxytest")
16
15/** 17/**
16 */ 18 */
17class ImapServerProxyTest : public QObject 19class ImapServerProxyTest : public QObject
@@ -81,8 +83,8 @@ private slots:
81 const QMap<qint64,KIMAP::MessageAttribute> &attrs, 83 const QMap<qint64,KIMAP::MessageAttribute> &attrs,
82 const QMap<qint64,KIMAP::MessageFlags> &flags, 84 const QMap<qint64,KIMAP::MessageFlags> &flags,
83 const QMap<qint64,KIMAP::MessagePtr> &messages) { 85 const QMap<qint64,KIMAP::MessagePtr> &messages) {
84 Trace() << "Received " << uids.size() << " messages from " << mailbox; 86 SinkTrace() << "Received " << uids.size() << " messages from " << mailbox;
85 Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); 87 SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
86 count += uids.size(); 88 count += uids.size();
87 })); 89 }));
88 90
@@ -106,8 +108,8 @@ private slots:
106 const QMap<qint64,KIMAP::MessageAttribute> &attrs, 108 const QMap<qint64,KIMAP::MessageAttribute> &attrs,
107 const QMap<qint64,KIMAP::MessageFlags> &flags, 109 const QMap<qint64,KIMAP::MessageFlags> &flags,
108 const QMap<qint64,KIMAP::MessagePtr> &messages) { 110 const QMap<qint64,KIMAP::MessagePtr> &messages) {
109 Trace() << "Received " << uids.size() << " messages from " << mailbox; 111 SinkTrace() << "Received " << uids.size() << " messages from " << mailbox;
110 Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); 112 SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
111 count += uids.size(); 113 count += uids.size();
112 })); 114 }));
113 115
diff --git a/examples/maildirresource/facade.cpp b/examples/maildirresource/facade.cpp
index d8fc02d..256b255 100644
--- a/examples/maildirresource/facade.cpp
+++ b/examples/maildirresource/facade.cpp
@@ -38,11 +38,11 @@ MaildirResourceMailFacade::MaildirResourceMailFacade(const QByteArray &instanceI
38 const auto folderPath = parts.join('/'); 38 const auto folderPath = parts.join('/');
39 const auto path = folderPath + "/cur/"; 39 const auto path = folderPath + "/cur/";
40 40
41 Trace() << "Looking for mail in: " << path << key; 41 SinkTrace_("", "maildirfacade") << "Looking for mail in: " << path << key;
42 QDir dir(path); 42 QDir dir(path);
43 const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files); 43 const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files);
44 if (list.size() != 1) { 44 if (list.size() != 1) {
45 Warning() << "Failed to find message " << path << key << list.size(); 45 SinkWarning_("", "maildirfacade") << "Failed to find message " << path << key << list.size();
46 value.setProperty("mimeMessage", QVariant()); 46 value.setProperty("mimeMessage", QVariant());
47 } else { 47 } else {
48 value.setProperty("mimeMessage", list.at(0).filePath()); 48 value.setProperty("mimeMessage", list.at(0).filePath());
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp
index e1fcfdf..d7a6fff 100644
--- a/examples/maildirresource/maildirresource.cpp
+++ b/examples/maildirresource/maildirresource.cpp
@@ -51,8 +51,7 @@
51#define ENTITY_TYPE_MAIL "mail" 51#define ENTITY_TYPE_MAIL "mail"
52#define ENTITY_TYPE_FOLDER "folder" 52#define ENTITY_TYPE_FOLDER "folder"
53 53
54#undef DEBUG_AREA 54SINK_DEBUG_AREA("maildirresource")
55#define DEBUG_AREA "resource.maildir"
56 55
57using namespace Sink; 56using namespace Sink;
58 57
@@ -65,8 +64,8 @@ static QString getFilePathFromMimeMessagePath(const QString &mimeMessagePath)
65 QDir dir(path); 64 QDir dir(path);
66 const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files); 65 const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files);
67 if (list.size() != 1) { 66 if (list.size() != 1) {
68 Warning() << "Failed to find message " << mimeMessagePath; 67 SinkWarning() << "Failed to find message " << mimeMessagePath;
69 Warning() << "Failed to find message " << path; 68 SinkWarning() << "Failed to find message " << path;
70 return QString(); 69 return QString();
71 } 70 }
72 return list.first().filePath(); 71 return list.first().filePath();
@@ -115,7 +114,7 @@ public:
115 const auto path = getPath(folder, transaction); 114 const auto path = getPath(folder, transaction);
116 KPIM::Maildir maildir(path, false); 115 KPIM::Maildir maildir(path, false);
117 if (!maildir.isValid(true)) { 116 if (!maildir.isValid(true)) {
118 Warning() << "Maildir is not existing: " << path; 117 SinkWarning() << "Maildir is not existing: " << path;
119 } 118 }
120 auto identifier = maildir.addEntryFromPath(oldPath); 119 auto identifier = maildir.addEntryFromPath(oldPath);
121 return path + "/" + identifier; 120 return path + "/" + identifier;
@@ -124,7 +123,7 @@ public:
124 const auto path = getPath(folder, transaction); 123 const auto path = getPath(folder, transaction);
125 KPIM::Maildir maildir(path, false); 124 KPIM::Maildir maildir(path, false);
126 if (!maildir.isValid(true)) { 125 if (!maildir.isValid(true)) {
127 Warning() << "Maildir is not existing: " << path; 126 SinkWarning() << "Maildir is not existing: " << path;
128 } 127 }
129 auto oldIdentifier = KPIM::Maildir::getKeyFromFile(oldPath); 128 auto oldIdentifier = KPIM::Maildir::getKeyFromFile(oldPath);
130 auto pathParts = oldPath.split('/'); 129 auto pathParts = oldPath.split('/');
@@ -135,7 +134,7 @@ public:
135 } 134 }
136 KPIM::Maildir oldMaildir(oldDirectory, false); 135 KPIM::Maildir oldMaildir(oldDirectory, false);
137 if (!oldMaildir.isValid(false)) { 136 if (!oldMaildir.isValid(false)) {
138 Warning() << "Maildir is not existing: " << path; 137 SinkWarning() << "Maildir is not existing: " << path;
139 } 138 }
140 auto identifier = oldMaildir.moveEntryTo(oldIdentifier, maildir); 139 auto identifier = oldMaildir.moveEntryTo(oldIdentifier, maildir);
141 return path + "/" + identifier; 140 return path + "/" + identifier;
@@ -158,7 +157,7 @@ public:
158 const bool mimeMessageChanged = mimeMessage.isValid() && mimeMessage.toString() != oldEntity.getProperty("mimeMessage").toString(); 157 const bool mimeMessageChanged = mimeMessage.isValid() && mimeMessage.toString() != oldEntity.getProperty("mimeMessage").toString();
159 const bool folderChanged = newFolder.isValid() && newFolder.toString() != oldEntity.getProperty("mimeMessage").toString(); 158 const bool folderChanged = newFolder.isValid() && newFolder.toString() != oldEntity.getProperty("mimeMessage").toString();
160 if (mimeMessageChanged || folderChanged) { 159 if (mimeMessageChanged || folderChanged) {
161 Trace() << "Moving mime message: " << mimeMessageChanged << folderChanged; 160 SinkTrace() << "Moving mime message: " << mimeMessageChanged << folderChanged;
162 auto newPath = moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction); 161 auto newPath = moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction);
163 if (newPath != oldEntity.getProperty("mimeMessage").toString()) { 162 if (newPath != oldEntity.getProperty("mimeMessage").toString()) {
164 const auto oldPath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); 163 const auto oldPath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString());
@@ -278,7 +277,7 @@ public:
278 { 277 {
279 const QByteArray bufferType = ENTITY_TYPE_FOLDER; 278 const QByteArray bufferType = ENTITY_TYPE_FOLDER;
280 QStringList folderList = listAvailableFolders(); 279 QStringList folderList = listAvailableFolders();
281 Trace() << "Found folders " << folderList; 280 SinkTrace() << "Found folders " << folderList;
282 281
283 scanForRemovals(bufferType, 282 scanForRemovals(bufferType,
284 [this, &bufferType](const std::function<void(const QByteArray &)> &callback) { 283 [this, &bufferType](const std::function<void(const QByteArray &)> &callback) {
@@ -304,23 +303,23 @@ public:
304 303
305 void synchronizeMails(const QString &path) 304 void synchronizeMails(const QString &path)
306 { 305 {
307 Trace() << "Synchronizing mails" << path; 306 SinkTrace() << "Synchronizing mails" << path;
308 auto time = QSharedPointer<QTime>::create(); 307 auto time = QSharedPointer<QTime>::create();
309 time->start(); 308 time->start();
310 const QByteArray bufferType = ENTITY_TYPE_MAIL; 309 const QByteArray bufferType = ENTITY_TYPE_MAIL;
311 310
312 KPIM::Maildir maildir(path, true); 311 KPIM::Maildir maildir(path, true);
313 if (!maildir.isValid()) { 312 if (!maildir.isValid()) {
314 Warning() << "Failed to sync folder."; 313 SinkWarning() << "Failed to sync folder.";
315 return; 314 return;
316 } 315 }
317 316
318 Trace() << "Importing new mail."; 317 SinkTrace() << "Importing new mail.";
319 maildir.importNewMails(); 318 maildir.importNewMails();
320 319
321 auto listingPath = maildir.pathToCurrent(); 320 auto listingPath = maildir.pathToCurrent();
322 auto entryIterator = QSharedPointer<QDirIterator>::create(listingPath, QDir::Files); 321 auto entryIterator = QSharedPointer<QDirIterator>::create(listingPath, QDir::Files);
323 Trace() << "Looking into " << listingPath; 322 SinkTrace() << "Looking into " << listingPath;
324 323
325 const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8()); 324 const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, path.toUtf8());
326 325
@@ -332,7 +331,7 @@ public:
332 callback(sinkId); 331 callback(sinkId);
333 }, 332 },
334 [&](const Index::Error &error) { 333 [&](const Index::Error &error) {
335 Warning() << "Error in index: " << error.message << property; 334 SinkWarning() << "Error in index: " << error.message << property;
336 }); 335 });
337 }, 336 },
338 [](const QByteArray &remoteId) -> bool { 337 [](const QByteArray &remoteId) -> bool {
@@ -350,7 +349,7 @@ public:
350 const auto flags = maildir.readEntryFlags(fileName); 349 const auto flags = maildir.readEntryFlags(fileName);
351 const auto maildirKey = maildir.getKeyFromFile(fileName); 350 const auto maildirKey = maildir.getKeyFromFile(fileName);
352 351
353 Trace() << "Found a mail " << filePath << " : " << fileName; 352 SinkTrace() << "Found a mail " << filePath << " : " << fileName;
354 353
355 Sink::ApplicationDomain::Mail mail; 354 Sink::ApplicationDomain::Mail mail;
356 mail.setProperty("folder", folderLocalId); 355 mail.setProperty("folder", folderLocalId);
@@ -362,12 +361,12 @@ public:
362 createOrModify(bufferType, remoteId, mail); 361 createOrModify(bufferType, remoteId, mail);
363 } 362 }
364 const auto elapsed = time->elapsed(); 363 const auto elapsed = time->elapsed();
365 Log() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; 364 SinkLog() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]";
366 } 365 }
367 366
368 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE 367 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE
369 { 368 {
370 Log() << " Synchronizing"; 369 SinkLog() << " Synchronizing";
371 return KAsync::start<void, KAsync::Job<void> >([this]() { 370 return KAsync::start<void, KAsync::Job<void> >([this]() {
372 KPIM::Maildir maildir(mMaildirPath, true); 371 KPIM::Maildir maildir(mMaildirPath, true);
373 if (!maildir.isValid(false)) { 372 if (!maildir.isValid(false)) {
@@ -381,7 +380,7 @@ public:
381 //Don't let the transaction grow too much 380 //Don't let the transaction grow too much
382 commit(); 381 commit();
383 } 382 }
384 Log() << "Done Synchronizing"; 383 SinkLog() << "Done Synchronizing";
385 return KAsync::null<void>(); 384 return KAsync::null<void>();
386 }); 385 });
387 } 386 }
@@ -402,15 +401,15 @@ public:
402 { 401 {
403 if (operation == Sink::Operation_Creation) { 402 if (operation == Sink::Operation_Creation) {
404 const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); 403 const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath());
405 Trace() << "Mail created: " << remoteId; 404 SinkTrace() << "Mail created: " << remoteId;
406 return KAsync::start<QByteArray>([=]() -> QByteArray { 405 return KAsync::start<QByteArray>([=]() -> QByteArray {
407 return remoteId.toUtf8(); 406 return remoteId.toUtf8();
408 }); 407 });
409 } else if (operation == Sink::Operation_Removal) { 408 } else if (operation == Sink::Operation_Removal) {
410 Trace() << "Removing a mail: " << oldRemoteId; 409 SinkTrace() << "Removing a mail: " << oldRemoteId;
411 return KAsync::null<QByteArray>(); 410 return KAsync::null<QByteArray>();
412 } else if (operation == Sink::Operation_Modification) { 411 } else if (operation == Sink::Operation_Modification) {
413 Trace() << "Modifying a mail: " << oldRemoteId; 412 SinkTrace() << "Modifying a mail: " << oldRemoteId;
414 const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath()); 413 const auto remoteId = getFilePathFromMimeMessagePath(mail.getMimeMessagePath());
415 return KAsync::start<QByteArray>([=]() -> QByteArray { 414 return KAsync::start<QByteArray>([=]() -> QByteArray {
416 return remoteId.toUtf8(); 415 return remoteId.toUtf8();
@@ -425,7 +424,7 @@ public:
425 auto folderName = folder.getName(); 424 auto folderName = folder.getName();
426 //FIXME handle non toplevel folders 425 //FIXME handle non toplevel folders
427 auto path = mMaildirPath + "/" + folderName; 426 auto path = mMaildirPath + "/" + folderName;
428 Trace() << "Creating a new folder: " << path; 427 SinkTrace() << "Creating a new folder: " << path;
429 KPIM::Maildir maildir(path, false); 428 KPIM::Maildir maildir(path, false);
430 maildir.create(); 429 maildir.create();
431 return KAsync::start<QByteArray>([=]() -> QByteArray { 430 return KAsync::start<QByteArray>([=]() -> QByteArray {
@@ -433,12 +432,12 @@ public:
433 }); 432 });
434 } else if (operation == Sink::Operation_Removal) { 433 } else if (operation == Sink::Operation_Removal) {
435 const auto path = oldRemoteId; 434 const auto path = oldRemoteId;
436 Trace() << "Removing a folder: " << path; 435 SinkTrace() << "Removing a folder: " << path;
437 KPIM::Maildir maildir(path, false); 436 KPIM::Maildir maildir(path, false);
438 maildir.remove(); 437 maildir.remove();
439 return KAsync::null<QByteArray>(); 438 return KAsync::null<QByteArray>();
440 } else if (operation == Sink::Operation_Modification) { 439 } else if (operation == Sink::Operation_Modification) {
441 Warning() << "Folder modifications are not implemented"; 440 SinkWarning() << "Folder modifications are not implemented";
442 return KAsync::start<QByteArray>([=]() -> QByteArray { 441 return KAsync::start<QByteArray>([=]() -> QByteArray {
443 return oldRemoteId; 442 return oldRemoteId;
444 }); 443 });
@@ -472,7 +471,7 @@ MaildirResource::MaildirResource(const QByteArray &instanceIdentifier, const QSh
472 setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << new FolderPreprocessor(mMaildirPath) << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); 471 setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << new FolderPreprocessor(mMaildirPath) << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>);
473 472
474 KPIM::Maildir dir(mMaildirPath, true); 473 KPIM::Maildir dir(mMaildirPath, true);
475 Trace() << "Started maildir resource for maildir: " << mMaildirPath; 474 SinkTrace() << "Started maildir resource for maildir: " << mMaildirPath;
476 { 475 {
477 auto draftsFolder = dir.addSubFolder("Drafts"); 476 auto draftsFolder = dir.addSubFolder("Drafts");
478 auto remoteId = synchronizer->createFolder(draftsFolder, "folder", QByteArrayList() << "drafts"); 477 auto remoteId = synchronizer->createFolder(draftsFolder, "folder", QByteArrayList() << "drafts");
@@ -503,7 +502,7 @@ KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray
503 auto entityStore = QSharedPointer<EntityStore>::create(mResourceType, mResourceInstanceIdentifier, transaction); 502 auto entityStore = QSharedPointer<EntityStore>::create(mResourceType, mResourceInstanceIdentifier, transaction);
504 auto syncStore = QSharedPointer<RemoteIdMap>::create(synchronizationTransaction); 503 auto syncStore = QSharedPointer<RemoteIdMap>::create(synchronizationTransaction);
505 504
506 Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; 505 SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue;
507 506
508 if (domainType == ENTITY_TYPE_MAIL) { 507 if (domainType == ENTITY_TYPE_MAIL) {
509 auto mail = entityStore->read<Sink::ApplicationDomain::Mail>(entityId); 508 auto mail = entityStore->read<Sink::ApplicationDomain::Mail>(entityId);
@@ -542,7 +541,7 @@ KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray
542 auto folder = entityStore->read<Sink::ApplicationDomain::Folder>(entityId); 541 auto folder = entityStore->read<Sink::ApplicationDomain::Folder>(entityId);
543 542
544 if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) { 543 if (inspectionType == Sink::ResourceControl::Inspection::CacheIntegrityInspectionType) {
545 Trace() << "Inspecting cache integrity" << remoteId; 544 SinkTrace() << "Inspecting cache integrity" << remoteId;
546 if (!QDir(remoteId).exists()) { 545 if (!QDir(remoteId).exists()) {
547 return KAsync::error<void>(1, "The directory is not existing: " + remoteId); 546 return KAsync::error<void>(1, "The directory is not existing: " + remoteId);
548 } 547 }
@@ -553,14 +552,14 @@ KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray
553 expectedCount++; 552 expectedCount++;
554 }, 553 },
555 [&](const Index::Error &error) { 554 [&](const Index::Error &error) {
556 Warning() << "Error in index: " << error.message << property; 555 SinkWarning() << "Error in index: " << error.message << property;
557 }); 556 });
558 557
559 QDir dir(remoteId + "/cur"); 558 QDir dir(remoteId + "/cur");
560 const QFileInfoList list = dir.entryInfoList(QDir::Files); 559 const QFileInfoList list = dir.entryInfoList(QDir::Files);
561 if (list.size() != expectedCount) { 560 if (list.size() != expectedCount) {
562 for (const auto &fileInfo : list) { 561 for (const auto &fileInfo : list) {
563 Warning() << "Found in cache: " << fileInfo.fileName(); 562 SinkWarning() << "Found in cache: " << fileInfo.fileName();
564 } 563 }
565 return KAsync::error<void>(1, QString("Wrong number of files; found %1 instead of %2.").arg(list.size()).arg(expectedCount)); 564 return KAsync::error<void>(1, QString("Wrong number of files; found %1 instead of %2.").arg(list.size()).arg(expectedCount));
566 } 565 }
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp
index 1e93bdf..a729d4d 100644
--- a/examples/mailtransportresource/mailtransportresource.cpp
+++ b/examples/mailtransportresource/mailtransportresource.cpp
@@ -44,6 +44,8 @@
44 44
45#define ENTITY_TYPE_MAIL "mail" 45#define ENTITY_TYPE_MAIL "mail"
46 46
47SINK_DEBUG_AREA("mailtransportresource")
48
47using namespace Sink; 49using namespace Sink;
48 50
49//TODO fold into synchronizer 51//TODO fold into synchronizer
@@ -58,7 +60,7 @@ public:
58 KAsync::Job<QByteArray> replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE 60 KAsync::Job<QByteArray> replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE
59 { 61 {
60 if (operation == Sink::Operation_Creation) { 62 if (operation == Sink::Operation_Creation) {
61 Trace() << "Dispatching message."; 63 SinkTrace() << "Dispatching message.";
62 // return send(mail, mSettings); 64 // return send(mail, mSettings);
63 } else if (operation == Sink::Operation_Removal) { 65 } else if (operation == Sink::Operation_Removal) {
64 } else if (operation == Sink::Operation_Modification) { 66 } else if (operation == Sink::Operation_Modification) {
@@ -86,9 +88,9 @@ public:
86 msg->setHead(KMime::CRLFtoLF(data)); 88 msg->setHead(KMime::CRLFtoLF(data));
87 msg->parse(); 89 msg->parse();
88 if (settings.testMode) { 90 if (settings.testMode) {
89 Log() << "I would totally send that mail, but I'm in test mode." << mail.identifier(); 91 SinkLog() << "I would totally send that mail, but I'm in test mode." << mail.identifier();
90 auto path = resourceStorageLocation(mResourceInstanceIdentifier) + "/test/"; 92 auto path = resourceStorageLocation(mResourceInstanceIdentifier) + "/test/";
91 Trace() << path; 93 SinkTrace() << path;
92 QDir dir; 94 QDir dir;
93 dir.mkpath(path); 95 dir.mkpath(path);
94 QFile f(path+ mail.identifier()); 96 QFile f(path+ mail.identifier());
@@ -97,9 +99,9 @@ public:
97 f.close(); 99 f.close();
98 } else { 100 } else {
99 if (MailTransport::sendMessage(msg, settings.server.toUtf8(), settings.username.toUtf8(), settings.password.toUtf8(), settings.cacert.toUtf8())) { 101 if (MailTransport::sendMessage(msg, settings.server.toUtf8(), settings.username.toUtf8(), settings.password.toUtf8(), settings.cacert.toUtf8())) {
100 Log() << "Sent message successfully"; 102 SinkLog() << "Sent message successfully";
101 } else { 103 } else {
102 Log() << "Failed to send message"; 104 SinkLog() << "Failed to send message";
103 return KAsync::error<void>(1, "Failed to send the message."); 105 return KAsync::error<void>(1, "Failed to send the message.");
104 } 106 }
105 } 107 }
@@ -108,13 +110,13 @@ public:
108 110
109 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE 111 KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE
110 { 112 {
111 Log() << " Synchronizing"; 113 SinkLog() << " Synchronizing";
112 return KAsync::start<void>([this](KAsync::Future<void> future) { 114 return KAsync::start<void>([this](KAsync::Future<void> future) {
113 Sink::Query query; 115 Sink::Query query;
114 QList<ApplicationDomain::Mail> toSend; 116 QList<ApplicationDomain::Mail> toSend;
115 Log() << " Looking for mail"; 117 SinkLog() << " Looking for mail";
116 store().reader<ApplicationDomain::Mail>().query(query, [&](const ApplicationDomain::Mail &mail) -> bool { 118 store().reader<ApplicationDomain::Mail>().query(query, [&](const ApplicationDomain::Mail &mail) -> bool {
117 Trace() << "Found mail: " << mail.identifier(); 119 SinkTrace() << "Found mail: " << mail.identifier();
118 if (!mail.getSent()) { 120 if (!mail.getSent()) {
119 toSend << mail; 121 toSend << mail;
120 } 122 }
diff --git a/synchronizer/main.cpp b/synchronizer/main.cpp
index b3decf6..e9dd6cb 100644
--- a/synchronizer/main.cpp
+++ b/synchronizer/main.cpp
@@ -34,8 +34,7 @@
34#include "log.h" 34#include "log.h"
35#include "test.h" 35#include "test.h"
36 36
37#undef DEBUG_AREA 37SINK_DEBUG_AREA("main")
38#define DEBUG_AREA "resource"
39 38
40static Listener *listener = nullptr; 39static Listener *listener = nullptr;
41 40
@@ -149,13 +148,13 @@ int main(int argc, char *argv[])
149 arguments << argv[i]; 148 arguments << argv[i];
150 } 149 }
151 if (arguments.contains("--test")) { 150 if (arguments.contains("--test")) {
152 Log() << "Running in test-mode"; 151 SinkLog() << "Running in test-mode";
153 arguments.removeAll("--test"); 152 arguments.removeAll("--test");
154 Sink::Test::setTestModeEnabled(true); 153 Sink::Test::setTestModeEnabled(true);
155 } 154 }
156 155
157 if (arguments.count() < 3) { 156 if (arguments.count() < 3) {
158 Warning() << "Not enough args passed, no resource loaded."; 157 SinkWarning() << "Not enough args passed, no resource loaded.";
159 return app.exec(); 158 return app.exec();
160 } 159 }
161 160
@@ -163,12 +162,12 @@ int main(int argc, char *argv[])
163 const QByteArray resourceType = arguments.at(2); 162 const QByteArray resourceType = arguments.at(2);
164 app.setApplicationName(instanceIdentifier); 163 app.setApplicationName(instanceIdentifier);
165 Sink::Log::setPrimaryComponent(instanceIdentifier); 164 Sink::Log::setPrimaryComponent(instanceIdentifier);
166 Log() << "Starting: " << instanceIdentifier; 165 SinkLog() << "Starting: " << instanceIdentifier;
167 166
168 QLockFile lockfile(instanceIdentifier + ".lock"); 167 QLockFile lockfile(instanceIdentifier + ".lock");
169 lockfile.setStaleLockTime(500); 168 lockfile.setStaleLockTime(500);
170 if (!lockfile.tryLock(0)) { 169 if (!lockfile.tryLock(0)) {
171 Warning() << "Failed to acquire exclusive lock on socket."; 170 SinkWarning() << "Failed to acquire exclusive lock on socket.";
172 return -1; 171 return -1;
173 } 172 }
174 173
@@ -178,6 +177,6 @@ int main(int argc, char *argv[])
178 QObject::connect(listener, &Listener::noClients, &app, &QCoreApplication::quit); 177 QObject::connect(listener, &Listener::noClients, &app, &QCoreApplication::quit);
179 178
180 auto ret = app.exec(); 179 auto ret = app.exec();
181 Log() << "Exiting: " << instanceIdentifier; 180 SinkLog() << "Exiting: " << instanceIdentifier;
182 return ret; 181 return ret;
183} 182}
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp
index 8c5866d..ec74cbd 100644
--- a/tests/clientapitest.cpp
+++ b/tests/clientapitest.cpp
@@ -9,6 +9,8 @@
9#include "resultprovider.h" 9#include "resultprovider.h"
10#include "facadefactory.h" 10#include "facadefactory.h"
11 11
12SINK_DEBUG_AREA("clientapitest")
13
12template <typename T> 14template <typename T>
13class TestDummyResourceFacade : public Sink::StoreFacade<T> 15class TestDummyResourceFacade : public Sink::StoreFacade<T>
14{ 16{
@@ -44,7 +46,7 @@ public:
44 { 46 {
45 auto resultProvider = new Sink::ResultProvider<typename T::Ptr>(); 47 auto resultProvider = new Sink::ResultProvider<typename T::Ptr>();
46 resultProvider->onDone([resultProvider]() { 48 resultProvider->onDone([resultProvider]() {
47 Trace() << "Result provider is done"; 49 SinkTrace() << "Result provider is done";
48 delete resultProvider; 50 delete resultProvider;
49 }); 51 });
50 // We have to do it this way, otherwise we're not setting the fetcher right 52 // We have to do it this way, otherwise we're not setting the fetcher right
@@ -52,11 +54,11 @@ public:
52 54
53 resultProvider->setFetcher([query, resultProvider, this](const typename T::Ptr &parent) { 55 resultProvider->setFetcher([query, resultProvider, this](const typename T::Ptr &parent) {
54 if (parent) { 56 if (parent) {
55 Trace() << "Running the fetcher " << parent->identifier(); 57 SinkTrace() << "Running the fetcher " << parent->identifier();
56 } else { 58 } else {
57 Trace() << "Running the fetcher."; 59 SinkTrace() << "Running the fetcher.";
58 } 60 }
59 Trace() << "-------------------------."; 61 SinkTrace() << "-------------------------.";
60 for (const auto &res : results) { 62 for (const auto &res : results) {
61 qDebug() << "Parent filter " << query.propertyFilter.value("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray(); 63 qDebug() << "Parent filter " << query.propertyFilter.value("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray();
62 auto parentProperty = res->getProperty("parent").toByteArray(); 64 auto parentProperty = res->getProperty("parent").toByteArray();
diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp
index 953adbf..4401f27 100644
--- a/tests/mailsynctest.cpp
+++ b/tests/mailsynctest.cpp
@@ -31,6 +31,8 @@
31using namespace Sink; 31using namespace Sink;
32using namespace Sink::ApplicationDomain; 32using namespace Sink::ApplicationDomain;
33 33
34SINK_DEBUG_AREA("mailsynctest")
35
34void MailSyncTest::initTestCase() 36void MailSyncTest::initTestCase()
35{ 37{
36 Test::initTest(); 38 Test::initTest();
@@ -73,7 +75,7 @@ void MailSyncTest::testListFolders()
73 for (const auto &folder : folders) { 75 for (const auto &folder : folders) {
74 names << folder->getName(); 76 names << folder->getName();
75 } 77 }
76 Trace() << "base folder: " << names; 78 SinkTrace() << "base folder: " << names;
77 baseCount = folders.size(); 79 baseCount = folders.size();
78 }); 80 });
79 VERIFYEXEC(job); 81 VERIFYEXEC(job);
diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp
index 8031cf1..0537175 100644
--- a/tests/mailtest.cpp
+++ b/tests/mailtest.cpp
@@ -31,6 +31,8 @@
31using namespace Sink; 31using namespace Sink;
32using namespace Sink::ApplicationDomain; 32using namespace Sink::ApplicationDomain;
33 33
34SINK_DEBUG_AREA("mailtest")
35
34void MailTest::initTestCase() 36void MailTest::initTestCase()
35{ 37{
36 Test::initTest(); 38 Test::initTest();
@@ -251,7 +253,7 @@ void MailTest::testMoveMail()
251 auto mail = *mails.first(); 253 auto mail = *mails.first();
252 modifiedMail = mail; 254 modifiedMail = mail;
253 QCOMPARE(mail.getFolder(), folder.identifier()); 255 QCOMPARE(mail.getFolder(), folder.identifier());
254 Warning() << "path: " << mail.getMimeMessagePath(); 256 SinkWarning() << "path: " << mail.getMimeMessagePath();
255 QVERIFY(QFile(mail.getMimeMessagePath()).exists()); 257 QVERIFY(QFile(mail.getMimeMessagePath()).exists());
256 }); 258 });
257 VERIFYEXEC(job); 259 VERIFYEXEC(job);
@@ -270,7 +272,7 @@ void MailTest::testMoveMail()
270 auto mail = *mails.first(); 272 auto mail = *mails.first();
271 QCOMPARE(mail.getFolder(), folder1.identifier()); 273 QCOMPARE(mail.getFolder(), folder1.identifier());
272 QVERIFY(QFile(mail.getMimeMessagePath()).exists()); 274 QVERIFY(QFile(mail.getMimeMessagePath()).exists());
273 Trace() << "Mime message path: " << mail.getMimeMessagePath(); 275 SinkTrace() << "Mime message path: " << mail.getMimeMessagePath();
274 }); 276 });
275 VERIFYEXEC(job); 277 VERIFYEXEC(job);
276 } 278 }
diff --git a/tests/messagequeuetest.cpp b/tests/messagequeuetest.cpp
index 484ff86..a8d0d4d 100644
--- a/tests/messagequeuetest.cpp
+++ b/tests/messagequeuetest.cpp
@@ -8,6 +8,8 @@
8#include "messagequeue.h" 8#include "messagequeue.h"
9#include "log.h" 9#include "log.h"
10 10
11SINK_DEBUG_AREA("messagequeuetest")
12
11/** 13/**
12 * Test of the messagequeue implementation. 14 * Test of the messagequeue implementation.
13 */ 15 */
@@ -80,7 +82,7 @@ private slots:
80 } 82 }
81 83
82 while (!queue.isEmpty()) { 84 while (!queue.isEmpty()) {
83 Log() << "start"; 85 SinkLog() << "start";
84 const auto expected = values.dequeue(); 86 const auto expected = values.dequeue();
85 bool gotValue = false; 87 bool gotValue = false;
86 bool gotError = false; 88 bool gotError = false;