From 3dd90236e7927028ff5c98635f8075189c9869c2 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Mon, 15 Dec 2014 19:28:05 +0100 Subject: namespace everything in libs with Akonadi2 --- client/main.cpp | 7 +++---- client/resourceaccess.cpp | 5 +++++ client/resourceaccess.h | 5 +++++ common/commands.cpp | 7 ++++++- common/commands.h | 5 +++++ common/console.cpp | 5 +++++ common/console.h | 5 +++++ common/storage.h | 5 +++++ common/storage_common.cpp | 4 ++++ common/storage_lmdb.cpp | 5 +++++ common/storage_unqlite.cpp | 4 ++++ dummyresource/facade.cpp | 7 ++++--- synchronizer/listener.cpp | 28 ++++++++++++++-------------- synchronizer/main.cpp | 6 +++--- tests/dummyresourcefacadetest.cpp | 6 +++--- tests/hawd/dataset.cpp | 6 +++--- tests/hawd/dataset.h | 2 +- tests/storagebenchmark.cpp | 14 +++++++------- tests/storagetest.cpp | 22 +++++++++++----------- 19 files changed, 98 insertions(+), 50 deletions(-) diff --git a/client/main.cpp b/client/main.cpp index 1748331..4f86792 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -9,9 +9,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - new Console("Akonadi2 Client"); + new Akonadi2::Console("Akonadi2 Client"); - ResourceAccess *resAccess = 0; QCommandLineParser cliOptions; cliOptions.addPositionalArgument(QObject::tr("[resource]"), QObject::tr("A resource to connect to")); @@ -22,9 +21,9 @@ int main(int argc, char *argv[]) } for (const QString &resource: resources) { - resAccess = new ResourceAccess(resource); + Akonadi2::ResourceAccess *resAccess = new Akonadi2::ResourceAccess(resource); QObject::connect(&app, &QCoreApplication::aboutToQuit, - resAccess, &ResourceAccess::close); + resAccess, &Akonadi2::ResourceAccess::close); resAccess->open(); } diff --git a/client/resourceaccess.cpp b/client/resourceaccess.cpp index bbc7f8b..82490ca 100644 --- a/client/resourceaccess.cpp +++ b/client/resourceaccess.cpp @@ -8,6 +8,9 @@ #include #include +namespace Akonadi2 +{ + ResourceAccess::ResourceAccess(const QString &resourceName, QObject *parent) : QObject(parent), m_resourceName(resourceName), @@ -154,3 +157,5 @@ void ResourceAccess::log(const QString &message) { Console::main()->log(m_resourceName + ": " + message); } + +} diff --git a/client/resourceaccess.h b/client/resourceaccess.h index a77fe48..5877b1d 100644 --- a/client/resourceaccess.h +++ b/client/resourceaccess.h @@ -6,6 +6,9 @@ #include +namespace Akonadi2 +{ + class ResourceAccess : public QObject { Q_OBJECT @@ -41,3 +44,5 @@ private: QByteArray m_partialMessageBuffer; flatbuffers::FlatBufferBuilder m_fbb; }; + +} diff --git a/common/commands.cpp b/common/commands.cpp index b5773e7..474b091 100644 --- a/common/commands.cpp +++ b/common/commands.cpp @@ -2,6 +2,9 @@ #include +namespace Akonadi2 +{ + namespace Commands { @@ -13,4 +16,6 @@ void write(QIODevice *device, int commandId, flatbuffers::FlatBufferBuilder &fbb device->write((const char*)fbb.GetBufferPointer(), dataSize); } -} \ No newline at end of file +} // namespace Commands + +} // namespace Akonadi2 diff --git a/common/commands.h b/common/commands.h index 5f2b006..3db1d3b 100644 --- a/common/commands.h +++ b/common/commands.h @@ -5,6 +5,9 @@ class QIODevice; +namespace Akonadi2 +{ + namespace Commands { @@ -18,3 +21,5 @@ enum CommandIds { void AKONADI2COMMON_EXPORT write(QIODevice *device, int commandId, flatbuffers::FlatBufferBuilder &fbb); } + +} // namespace Akonadi2 diff --git a/common/console.cpp b/common/console.cpp index 6fb174a..a878355 100644 --- a/common/console.cpp +++ b/common/console.cpp @@ -5,6 +5,9 @@ #include #include +namespace Akonadi2 +{ + static Console *s_console = 0; Console *Console::main() @@ -53,3 +56,5 @@ void Console::log(const QString &message) { m_textDisplay->append(QString::number(m_timestamper.elapsed()).rightJustified(6) + ": " + message); } + +} // namespace Akonadi2 diff --git a/common/console.h b/common/console.h index 0df5c38..e0b803c 100644 --- a/common/console.h +++ b/common/console.h @@ -7,6 +7,9 @@ class QTextBrowser; +namespace Akonadi2 +{ + class AKONADI2COMMON_EXPORT Console : public QWidget { Q_OBJECT @@ -22,3 +25,5 @@ private: QTime m_timestamper; static Console *s_output; }; + +} // namespace Akonadi2 diff --git a/common/storage.h b/common/storage.h index 2fac068..b6d6a07 100644 --- a/common/storage.h +++ b/common/storage.h @@ -5,6 +5,9 @@ #include #include +namespace Akonadi2 +{ + class AKONADI2COMMON_EXPORT Storage { public: enum AccessMode { ReadOnly, ReadWrite }; @@ -52,3 +55,5 @@ private: Private * const d; }; +} // namespace Akonadi2 + diff --git a/common/storage_common.cpp b/common/storage_common.cpp index 6263bf2..099eb36 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp @@ -2,6 +2,9 @@ #include +namespace Akonadi2 +{ + void errorHandler(const Storage::Error &error) { //TODO: allow this to be turned on / off globally @@ -29,3 +32,4 @@ void Storage::scan(const std::string &sKey, const std::function +namespace Akonadi2 +{ + class Storage::Private { public: @@ -309,3 +312,5 @@ void Storage::removeFromDisk() const dir.remove("data.mdb"); dir.remove("lock.mdb"); } + +} // namespace Akonadi2 diff --git a/common/storage_unqlite.cpp b/common/storage_unqlite.cpp index 67f910b..69dc288 100644 --- a/common/storage_unqlite.cpp +++ b/common/storage_unqlite.cpp @@ -13,6 +13,9 @@ extern "C" { #include "unqlite/unqlite.h" } +namespace Akonadi2 +{ + static const char *s_unqliteDir = "/unqlite/"; class Storage::Private @@ -289,3 +292,4 @@ void Storage::removeFromDisk() const QFile::remove(d->storageRoot + s_unqliteDir + d->name); } +} // namespace Akonadi2 diff --git a/dummyresource/facade.cpp b/dummyresource/facade.cpp index 44056f8..668749e 100644 --- a/dummyresource/facade.cpp +++ b/dummyresource/facade.cpp @@ -44,7 +44,8 @@ void DummyResourceFacade::remove(const Akonadi2::Domain::Event &domainObject) //-how do we free/munmap the data if we don't know when no one references it any longer? => no munmap needed, but read transaction to keep pointer alive //-we could bind the lifetime to the query //=> perhaps do heap allocate and use smart pointer? -class DummyEventAdaptor : public Akonadi2::Domain::Event { +class DummyEventAdaptor : public Akonadi2::Domain::Event +{ public: DummyEventAdaptor(const QString &resource, const QString &identifier, qint64 revision) :Akonadi2::Domain::Event(resource, identifier, revision) @@ -71,13 +72,13 @@ public: DummyEvent const *buffer; //Keep query alive so values remain valid - QSharedPointer storage; + QSharedPointer storage; }; void DummyResourceFacade::load(const Akonadi2::Query &query, const std::function &resultCallback) { qDebug() << "load called"; - auto storage = QSharedPointer::create(Akonadi2::Store::storageLocation(), "dummyresource"); + auto storage = QSharedPointer::create(Akonadi2::Store::storageLocation(), "dummyresource"); //Compose some functions to make query matching fast. //This way we can process the query once, and convert all values into something that can be compared quickly diff --git a/synchronizer/listener.cpp b/synchronizer/listener.cpp index 01daf5d..7905038 100644 --- a/synchronizer/listener.cpp +++ b/synchronizer/listener.cpp @@ -15,18 +15,18 @@ Listener::Listener(const QString &resource, QObject *parent) { connect(m_server, &QLocalServer::newConnection, this, &Listener::acceptConnection); - Console::main()->log(QString("Trying to open %1").arg(resource)); + Akonadi2::Console::main()->log(QString("Trying to open %1").arg(resource)); if (!m_server->listen(resource)) { // FIXME: multiple starts need to be handled here m_server->removeServer(resource); if (!m_server->listen(resource)) { - Console::main()->log("Utter failure to start server"); + Akonadi2::Console::main()->log("Utter failure to start server"); exit(-1); } } if (m_server->isListening()) { - Console::main()->log(QString("Listening on %1").arg(m_server->serverName())); + Akonadi2::Console::main()->log(QString("Listening on %1").arg(m_server->serverName())); } QTimer::singleShot(2000, this, SLOT(checkConnections())); @@ -63,14 +63,14 @@ void Listener::closeAllConnections() void Listener::acceptConnection() { - Console::main()->log(QString("Accepting connection")); + Akonadi2::Console::main()->log(QString("Accepting connection")); QLocalSocket *socket = m_server->nextPendingConnection(); if (!socket) { return; } - Console::main()->log("Got a connection"); + Akonadi2::Console::main()->log("Got a connection"); Client client("Unknown Client" /*fixme: actual names!*/, socket); connect(socket, &QIODevice::readyRead, this, &Listener::readFromSocket); @@ -87,12 +87,12 @@ void Listener::clientDropped() return; } - Console::main()->log("Dropping connection..."); + Akonadi2::Console::main()->log("Dropping connection..."); QMutableVectorIterator it(m_connections); while (it.hasNext()) { const Client &client = it.next(); if (client.socket == socket) { - Console::main()->log(QString(" dropped... %1").arg(client.name)); + Akonadi2::Console::main()->log(QString(" dropped... %1").arg(client.name)); it.remove(); break; } @@ -116,10 +116,10 @@ void Listener::readFromSocket() return; } - Console::main()->log("Reading from socket..."); + Akonadi2::Console::main()->log("Reading from socket..."); for (Client &client: m_connections) { if (client.socket == socket) { - Console::main()->log(QString(" Client: %1").arg(client.name)); + Akonadi2::Console::main()->log(QString(" Client: %1").arg(client.name)); client.commandBuffer += socket->readAll(); // FIXME: schedule these rather than process them all at once // right now this can lead to starvation of clients due to @@ -133,7 +133,7 @@ void Listener::readFromSocket() bool Listener::processClientBuffer(Client &client) { static const int headerSize = (sizeof(int) * 2); - Console::main()->log(QString("processing %1").arg(client.commandBuffer.size())); + Akonadi2::Console::main()->log(QString("processing %1").arg(client.commandBuffer.size())); if (client.commandBuffer.size() < headerSize) { return false; } @@ -147,9 +147,9 @@ bool Listener::processClientBuffer(Client &client) client.commandBuffer.remove(0, headerSize + size); switch (commandId) { - case Commands::HandshakeCommand: { + case Akonadi2::Commands::HandshakeCommand: { auto buffer = Akonadi2::GetHandshake(data.constData()); - Console::main()->log(QString(" Handshake from %1").arg(buffer->name()->c_str())); + Akonadi2::Console::main()->log(QString(" Handshake from %1").arg(buffer->name()->c_str())); sendCurrentRevision(client); break; } @@ -172,7 +172,7 @@ void Listener::sendCurrentRevision(Client &client) auto command = Akonadi2::CreateRevisionUpdate(m_fbb, m_revision); Akonadi2::FinishRevisionUpdateBuffer(m_fbb, command); - Commands::write(client.socket, Commands::RevisionUpdateCommand, m_fbb); + Akonadi2::Commands::write(client.socket, Akonadi2::Commands::RevisionUpdateCommand, m_fbb); m_fbb.Clear(); } @@ -186,7 +186,7 @@ void Listener::updateClientsWithRevision() continue; } - Commands::write(client.socket, Commands::RevisionUpdateCommand, m_fbb); + Akonadi2::Commands::write(client.socket, Akonadi2::Commands::RevisionUpdateCommand, m_fbb); } m_fbb.Clear(); } diff --git a/synchronizer/main.cpp b/synchronizer/main.cpp index f4091df..fbb3c00 100644 --- a/synchronizer/main.cpp +++ b/synchronizer/main.cpp @@ -9,12 +9,12 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); if (argc < 2) { - new Console(QString("Resource: ???")); - Console::main()->log("Not enough args passed, no resource loaded."); + new Akonadi2::Console(QString("Resource: ???")); + Akonadi2::Console::main()->log("Not enough args passed, no resource loaded."); return app.exec(); } - new Console(QString("Resource: %1").arg(argv[1])); + new Akonadi2::Console(QString("Resource: %1").arg(argv[1])); Listener *listener = new Listener(argv[1]); QObject::connect(&app, &QCoreApplication::aboutToQuit, diff --git a/tests/dummyresourcefacadetest.cpp b/tests/dummyresourcefacadetest.cpp index 26daa23..d815e9b 100644 --- a/tests/dummyresourcefacadetest.cpp +++ b/tests/dummyresourcefacadetest.cpp @@ -19,7 +19,7 @@ private: void populate(int count) { - Storage storage(testDataPath, dbName, Storage::ReadWrite); + Akonadi2::Storage storage(testDataPath, dbName, Akonadi2::Storage::ReadWrite); for (int i = 0; i < count; i++) { storage.write(keyPrefix + std::to_string(i), keyPrefix + std::to_string(i)); } @@ -38,7 +38,7 @@ private Q_SLOTS: void cleanupTestCase() { - Storage storage(testDataPath, dbName); + Akonadi2::Storage storage(testDataPath, dbName); storage.removeFromDisk(); } @@ -63,7 +63,7 @@ private Q_SLOTS: QTRY_VERIFY(complete); QCOMPARE(results.size(), 1); - Storage storage(testDataPath, dbName); + Akonadi2::Storage storage(testDataPath, dbName); storage.removeFromDisk(); } diff --git a/tests/hawd/dataset.cpp b/tests/hawd/dataset.cpp index a5328e4..6e73c5c 100644 --- a/tests/hawd/dataset.cpp +++ b/tests/hawd/dataset.cpp @@ -207,7 +207,7 @@ QString Dataset::Row::toString(const QStringList &cols, int standardCols, const Dataset::Dataset(const QString &name, const State &state) : m_definition(state.datasetDefinition(name)), - m_storage(state.resultsPath(), name, Storage::ReadWrite), + m_storage(state.resultsPath(), name, Akonadi2::Storage::ReadWrite), m_commitHash(state.commitHash()) { m_storage.startTransaction(); @@ -264,7 +264,7 @@ void Dataset::eachRow(const std::function &resultHandler) resultHandler(row); return true; }, - Storage::basicErrorHandler()); + Akonadi2::Storage::basicErrorHandler()); } Dataset::Row Dataset::row(qint64 key) @@ -282,7 +282,7 @@ Dataset::Row Dataset::row(qint64 key) row.fromBinary(array); return true; }, - Storage::basicErrorHandler() + Akonadi2::Storage::basicErrorHandler() ); return row; } diff --git a/tests/hawd/dataset.h b/tests/hawd/dataset.h index 09a5828..dd1d6f2 100644 --- a/tests/hawd/dataset.h +++ b/tests/hawd/dataset.h @@ -83,7 +83,7 @@ public: private: DatasetDefinition m_definition; - Storage m_storage; + Akonadi2::Storage m_storage; QString m_commitHash; }; diff --git a/tests/storagebenchmark.cpp b/tests/storagebenchmark.cpp index 130753f..9cf9a71 100644 --- a/tests/storagebenchmark.cpp +++ b/tests/storagebenchmark.cpp @@ -62,7 +62,7 @@ private Q_SLOTS: void cleanupTestCase() { - Storage store(testDataPath, dbName); + Akonadi2::Storage store(testDataPath, dbName); store.removeFromDisk(); } @@ -80,9 +80,9 @@ private Q_SLOTS: QFETCH(bool, useDb); QFETCH(int, count); - QScopedPointer store; + QScopedPointer store; if (useDb) { - store.reset(new Storage(testDataPath, dbName, Storage::ReadWrite)); + store.reset(new Akonadi2::Storage(testDataPath, dbName, Akonadi2::Storage::ReadWrite)); } std::ofstream myfile; @@ -143,10 +143,10 @@ private Q_SLOTS: qDebug() << "File reading is not implemented."; } } - + void testScan() { - QScopedPointer store(new Storage(testDataPath, dbName, Storage::ReadOnly)); + QScopedPointer store(new Akonadi2::Storage(testDataPath, dbName, Akonadi2::Storage::ReadOnly)); QBENCHMARK { int hit = 0; @@ -163,7 +163,7 @@ private Q_SLOTS: void testKeyLookup() { - QScopedPointer store(new Storage(testDataPath, dbName, Storage::ReadOnly)); + QScopedPointer store(new Akonadi2::Storage(testDataPath, dbName, Akonadi2::Storage::ReadOnly)); QBENCHMARK { int hit = 0; @@ -203,7 +203,7 @@ private Q_SLOTS: void testSizes() { - Storage store(testDataPath, dbName); + Akonadi2::Storage store(testDataPath, dbName); qDebug() << "Database size [kb]: " << store.diskUsage()/1024; QFileInfo fileInfo(filePath); diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 3c20135..a771042 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -19,7 +19,7 @@ private: void populate(int count) { - Storage storage(testDataPath, dbName, Storage::ReadWrite); + Akonadi2::Storage storage(testDataPath, dbName, Akonadi2::Storage::ReadWrite); for (int i = 0; i < count; i++) { //This should perhaps become an implementation detail of the db? if (i % 10000 == 0) { @@ -33,7 +33,7 @@ private: storage.commitTransaction(); } - bool verify(Storage &storage, int i) + bool verify(Akonadi2::Storage &storage, int i) { bool success = true; bool keyMatch = true; @@ -46,7 +46,7 @@ private: } return keyMatch; }, - [&success](const Storage::Error &) { success = false; } + [&success](const Akonadi2::Storage::Error &) { success = false; } ); return success && keyMatch; } @@ -60,7 +60,7 @@ private Q_SLOTS: void cleanupTestCase() { - Storage storage(testDataPath, dbName); + Akonadi2::Storage storage(testDataPath, dbName); storage.removeFromDisk(); } @@ -72,13 +72,13 @@ private Q_SLOTS: //ensure we can read everything back correctly { - Storage storage(testDataPath, dbName); + Akonadi2::Storage storage(testDataPath, dbName); for (int i = 0; i < count; i++) { QVERIFY(verify(storage, i)); } } - Storage storage(testDataPath, dbName); + Akonadi2::Storage storage(testDataPath, dbName); storage.removeFromDisk(); } @@ -90,7 +90,7 @@ private Q_SLOTS: //ensure we can scan for values { int hit = 0; - Storage store(testDataPath, dbName); + Akonadi2::Storage store(testDataPath, dbName); store.scan("", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { if (std::string(static_cast(keyValue), keySize) == "key50") { hit++; @@ -104,7 +104,7 @@ private Q_SLOTS: { int hit = 0; bool foundInvalidValue = false; - Storage store(testDataPath, dbName); + Akonadi2::Storage store(testDataPath, dbName); store.scan("key50", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { if (std::string(static_cast(keyValue), keySize) != "key50") { foundInvalidValue = true; @@ -116,7 +116,7 @@ private Q_SLOTS: QCOMPARE(hit, 1); } - Storage storage(testDataPath, dbName); + Akonadi2::Storage storage(testDataPath, dbName); storage.removeFromDisk(); } @@ -132,7 +132,7 @@ private Q_SLOTS: const int concurrencyLevel = 10; for (int num = 0; num < concurrencyLevel; num++) { futures << QtConcurrent::run([this, count, &error](){ - Storage storage(testDataPath, dbName); + Akonadi2::Storage storage(testDataPath, dbName); for (int i = 0; i < count; i++) { if (!verify(storage, i)) { error = true; @@ -146,7 +146,7 @@ private Q_SLOTS: } QVERIFY(!error); - Storage storage(testDataPath, dbName); + Akonadi2::Storage storage(testDataPath, dbName); storage.removeFromDisk(); } }; -- cgit v1.2.3