summaryrefslogtreecommitdiffstats
path: root/common/typeindex.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-07 22:23:49 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-07 22:23:49 +0200
commitda2b049e248c1ad7efeb53685158a205335e4e36 (patch)
tree1e7e5e940e9b760b2108081b1d2f3879cebdb0ff /common/typeindex.cpp
parent9bcb822963fc96c94dbe7dcc4134dcd2dac454ff (diff)
downloadsink-da2b049e248c1ad7efeb53685158a205335e4e36.tar.gz
sink-da2b049e248c1ad7efeb53685158a205335e4e36.zip
A new debug system.
Instead of a single #define as debug area the new system allows for an identifier for each debug message with the structure component.area. The component is a dot separated identifier of the runtime component, such as the process or the plugin. The area is the code component, and can be as such defined at compiletime. The idea of this system is that it becomes possible to i.e. look at the output of all messages in the query subsystem of a specific resource (something that happens in the client process, but in the resource-specific subcomponent). The new macros are supposed to be less likely to clash with other names, hence the new names.
Diffstat (limited to 'common/typeindex.cpp')
-rw-r--r--common/typeindex.cpp21
1 files changed, 10 insertions, 11 deletions
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}