Hey Pinak Could you please take a quick look at these patches.
I should use reviewboard but it's a pain to upload all these patches. Specially since most of these are so trivial. -- Vishesh Handa
From 8637cf5d3555039970e473fe1aa259e0fcc69e70 Mon Sep 17 00:00:00 2001 From: Vishesh Handa <m...@vhanda.in> Date: Sun, 4 Oct 2015 23:49:57 +0200 Subject: [PATCH 1/8] WriteTransaction: Extra asserts in replaceDocument --- src/engine/writetransaction.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/engine/writetransaction.cpp b/src/engine/writetransaction.cpp index 1391ba9..f1ff1ad 100644 --- a/src/engine/writetransaction.cpp +++ b/src/engine/writetransaction.cpp @@ -205,6 +205,9 @@ void WriteTransaction::replaceDocument(const Document& doc, DocumentOperations o } if (operations & DocumentTime) { + Q_ASSERT(doc.m_mTime); + Q_ASSERT(doc.m_cTime); + DocumentTimeDB::TimeInfo info; info.mTime = doc.m_mTime; info.cTime = doc.m_cTime; -- 2.5.0
From 63224dc57a8dbe151ac1ff23e93190a1bd6c387c Mon Sep 17 00:00:00 2001 From: Vishesh Handa <m...@vhanda.in> Date: Mon, 5 Oct 2015 12:01:28 +0200 Subject: [PATCH 3/8] FileIndexScheduler: Forcibly kill threads on exit This is not good as we are killing before committing, but as a short term solution, this works. We no longer block when trying to exit. --- src/file/fileindexscheduler.cpp | 5 +++++ src/file/fileindexscheduler.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/file/fileindexscheduler.cpp b/src/file/fileindexscheduler.cpp index e11656f..28cf6db 100644 --- a/src/file/fileindexscheduler.cpp +++ b/src/file/fileindexscheduler.cpp @@ -64,6 +64,11 @@ FileIndexScheduler::FileIndexScheduler(Database* db, FileIndexerConfig* config, this, QDBusConnection::ExportScriptableContents); } +FileIndexScheduler::~FileIndexScheduler() +{ + m_threadPool.waitForDone(0); // wait 0 msecs +} + void FileIndexScheduler::scheduleIndexing() { if (m_threadPool.activeThreadCount() || m_indexerState == Suspended) { diff --git a/src/file/fileindexscheduler.h b/src/file/fileindexscheduler.h index 6292a85..0749f81 100644 --- a/src/file/fileindexscheduler.h +++ b/src/file/fileindexscheduler.h @@ -44,6 +44,7 @@ class FileIndexScheduler : public QObject Q_PROPERTY(int state READ state NOTIFY stateChanged) public: FileIndexScheduler(Database* db, FileIndexerConfig* config, QObject* parent = 0); + ~FileIndexScheduler() Q_DECL_OVERRIDE; int state() const { return m_indexerState; } Q_SIGNALS: -- 2.5.0
From 745893195c9deaf16be6b432320bee0c6e8905de Mon Sep 17 00:00:00 2001 From: Vishesh Handa <m...@vhanda.in> Date: Mon, 5 Oct 2015 00:56:38 +0200 Subject: [PATCH 2/8] WriteTransaction commit: Avoid fetching the positionList unless required The postingList is always required, but that is not the case for the positionList. Lets avoid fetching it unless it is absolutely required. --- src/engine/writetransaction.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/engine/writetransaction.cpp b/src/engine/writetransaction.cpp index f1ff1ad..ae27ad9 100644 --- a/src/engine/writetransaction.cpp +++ b/src/engine/writetransaction.cpp @@ -268,7 +268,9 @@ void WriteTransaction::commit() const QVector<Operation> operations = iter.value(); PostingList list = postingDB.get(term); - QVector<PositionInfo> positionList = positionDB.get(term); // FIXME: We do not need to fetch this for all the terms + + bool fetchedPositionList = false; + QVector<PositionInfo> positionList; for (const Operation& op : operations) { quint64 id = op.data.docId; @@ -277,11 +279,19 @@ void WriteTransaction::commit() insert(list, id); if (!op.data.positions.isEmpty()) { + if (!fetchedPositionList) { + positionList = positionDB.get(term); + fetchedPositionList = true; + } insert(positionList, op.data); } } else { list.removeOne(id); + if (!fetchedPositionList) { + positionList = positionDB.get(term); + fetchedPositionList = true; + } positionList.removeOne(PositionInfo(id)); } } @@ -292,10 +302,12 @@ void WriteTransaction::commit() postingDB.del(term); } - if (!positionList.isEmpty()) { - positionDB.put(term, positionList); - } else { - positionDB.del(term); + if (fetchedPositionList) { + if (!positionList.isEmpty()) { + positionDB.put(term, positionList); + } else { + positionDB.del(term); + } } } -- 2.5.0
From ead963911d70654ed87d6b45e384d2cfc8ed5b6a Mon Sep 17 00:00:00 2001 From: Vishesh Handa <m...@vhanda.in> Date: Mon, 5 Oct 2015 12:31:10 +0200 Subject: [PATCH 4/8] IOHandler: Remove unused function --- src/file/extractor/iohandler.cpp | 5 ----- src/file/extractor/iohandler.h | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/file/extractor/iohandler.cpp b/src/file/extractor/iohandler.cpp index d2d48d2..9192f7f 100644 --- a/src/file/extractor/iohandler.cpp +++ b/src/file/extractor/iohandler.cpp @@ -59,11 +59,6 @@ bool IOHandler::atEnd() return false; } -void IOHandler::indexedId(quint64 id) -{ - write(m_stdoutHandle, reinterpret_cast<void*>(&id), sizeof(quint64)); -} - void IOHandler::batchIndexed() { m_batchSize = 0; diff --git a/src/file/extractor/iohandler.h b/src/file/extractor/iohandler.h index a2e1d5e..959a35c 100644 --- a/src/file/extractor/iohandler.h +++ b/src/file/extractor/iohandler.h @@ -34,8 +34,7 @@ public: IOHandler(int stdin, int stdout); quint64 nextId(); bool atEnd(); - void indexedId(quint64 id); - + //always call this after a batch has been indexed void batchIndexed(); void newBatch(); -- 2.5.0
From 3328555241358b3583e22a79cc555a7e8632d4d7 Mon Sep 17 00:00:00 2001 From: Vishesh Handa <m...@vhanda.in> Date: Mon, 5 Oct 2015 13:08:53 +0200 Subject: [PATCH 5/8] Add dbus notification for when we start/finish indexing a file The extractor process now informs us when it starts and finishes indexing a file. This is propagated to dbus if required. --- src/file/extractor/app.cpp | 5 +++-- src/file/extractor/iohandler.cpp | 13 +++++++++---- src/file/extractor/iohandler.h | 9 ++++++--- src/file/extractorprocess.cpp | 38 +++++++++++++++++++++++++------------- src/file/extractorprocess.h | 6 ++---- src/file/filecontentindexer.cpp | 17 +++++++++++++---- src/file/filecontentindexer.h | 11 +++++++---- src/qml/experimental/monitor.cpp | 2 +- src/tools/balooctl/monitor.cpp | 2 +- 9 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/file/extractor/app.cpp b/src/file/extractor/app.cpp index 2e0872e..f621e7e 100644 --- a/src/file/extractor/app.cpp +++ b/src/file/extractor/app.cpp @@ -89,8 +89,9 @@ void App::processNextFile() return; } - m_io.indexingUrl(url); + m_io.writeStartedIndexingUrl(url); index(m_tr, url, id); + m_io.writeFinishedIndexingUrl(url); m_updatedFiles << url; QTimer::singleShot(delay, this, &App::processNextFile); @@ -119,7 +120,7 @@ void App::processNextFile() // Enable the SocketNotifier for the next batch m_notifyNewData.setEnabled(true); - m_io.batchIndexed(); + m_io.writeBatchIndexed(); } } diff --git a/src/file/extractor/iohandler.cpp b/src/file/extractor/iohandler.cpp index 9192f7f..9ec2bd0 100644 --- a/src/file/extractor/iohandler.cpp +++ b/src/file/extractor/iohandler.cpp @@ -59,13 +59,18 @@ bool IOHandler::atEnd() return false; } -void IOHandler::batchIndexed() +void IOHandler::writeBatchIndexed() { m_batchSize = 0; - m_stdout << "batch commited" << endl; + m_stdout << "B" << endl; } -void IOHandler::indexingUrl(QString url) +void IOHandler::writeStartedIndexingUrl(const QString& url) { - m_stdout << url << endl; + m_stdout << "S " << url << endl; +} + +void IOHandler::writeFinishedIndexingUrl(const QString& url) +{ + m_stdout << "F " << url << endl; } diff --git a/src/file/extractor/iohandler.h b/src/file/extractor/iohandler.h index 959a35c..b197f84 100644 --- a/src/file/extractor/iohandler.h +++ b/src/file/extractor/iohandler.h @@ -35,10 +35,13 @@ public: quint64 nextId(); bool atEnd(); - //always call this after a batch has been indexed - void batchIndexed(); void newBatch(); - void indexingUrl(QString url); + + void writeStartedIndexingUrl(const QString& url); + void writeFinishedIndexingUrl(const QString& url); + + // always call this after a batch has been indexed + void writeBatchIndexed(); private: int m_stdinHandle; diff --git a/src/file/extractorprocess.cpp b/src/file/extractorprocess.cpp index dac653e..8c81f17 100644 --- a/src/file/extractorprocess.cpp +++ b/src/file/extractorprocess.cpp @@ -29,8 +29,6 @@ ExtractorProcess::ExtractorProcess(QObject* parent) : QObject(parent) , m_extractorPath(QStandardPaths::findExecutable(QLatin1String("baloo_file_extractor"))) , m_extractorProcess(this) - , m_batchSize(0) - , m_indexedFiles(0) , m_extractorIdle(true) { connect(&m_extractorProcess, &QProcess::readyRead, this, &ExtractorProcess::slotIndexingFile); @@ -52,29 +50,43 @@ void ExtractorProcess::index(const QVector<quint64>& fileIds) QByteArray batchData; - m_batchSize = fileIds.size(); - batchData.append(reinterpret_cast<char*>(&m_batchSize), sizeof(quint32)); + quint32 batchSize = fileIds.size(); + batchData.append(reinterpret_cast<char*>(&batchSize), sizeof(quint32)); for (quint64 id : fileIds) { batchData.append(reinterpret_cast<char*>(&id), sizeof(quint64)); } m_extractorIdle = false; - m_indexedFiles = 0; m_extractorProcess.write(batchData.data(), batchData.size()); } void ExtractorProcess::slotIndexingFile() { while (m_extractorProcess.canReadLine()) { - QString filePath = m_extractorProcess.readLine().trimmed(); - if (m_indexedFiles < m_batchSize) { - Q_EMIT indexingFile(filePath); + QString line = m_extractorProcess.readLine().trimmed(); + if (line.isEmpty()) { + continue; } - ++m_indexedFiles; - } - if (m_indexedFiles == m_batchSize + 1) { - Q_EMIT done(); - m_extractorIdle = true; + char command = line[0].toLatin1(); + QString arg = line.mid(2); + + switch (command) { + case 'S': + Q_EMIT startedIndexingFile(arg); + break; + + case 'F': + Q_EMIT finishedIndexingFile(arg); + break; + + case 'B': + Q_EMIT done(); + m_extractorIdle = true; + break; + + default: + qCritical() << "Got unknown result from extractor" << command << arg; + } } } diff --git a/src/file/extractorprocess.h b/src/file/extractorprocess.h index c8e029a..e4ac3a1 100644 --- a/src/file/extractorprocess.h +++ b/src/file/extractorprocess.h @@ -37,7 +37,8 @@ public: void index(const QVector<quint64>& fileIds); Q_SIGNALS: - void indexingFile(QString filePath); + void startedIndexingFile(QString filePath); + void finishedIndexingFile(QString filePath); void done(); private Q_SLOTS: @@ -50,9 +51,6 @@ private: QTimer m_timeCurrentFile; int m_processTimeout; - quint32 m_batchSize; - quint32 m_indexedFiles; - bool m_extractorIdle; }; } diff --git a/src/file/filecontentindexer.cpp b/src/file/filecontentindexer.cpp index 237612b..91554b0 100644 --- a/src/file/filecontentindexer.cpp +++ b/src/file/filecontentindexer.cpp @@ -48,7 +48,8 @@ FileContentIndexer::FileContentIndexer(FileContentIndexerProvider* provider, QOb void FileContentIndexer::run() { ExtractorProcess process; - connect(&process, &ExtractorProcess::indexingFile, this, &FileContentIndexer::slotIndexingFile); + connect(&process, &ExtractorProcess::startedIndexingFile, this, &FileContentIndexer::slotStartedIndexingFile); + connect(&process, &ExtractorProcess::startedIndexingFile, this, &FileContentIndexer::slotFinishedIndexingFile); m_stop.store(false); while (m_provider->size() && !m_stop.load()) { @@ -76,11 +77,19 @@ void FileContentIndexer::run() QMetaObject::invokeMethod(this, "done", Qt::QueuedConnection); } -void FileContentIndexer::slotIndexingFile(QString filePath) +void FileContentIndexer::slotStartedIndexingFile(const QString& filePath) { m_currentFile = filePath; if (!m_registeredMonitors.isEmpty()) { - Q_EMIT indexingFile(filePath); + Q_EMIT startedIndexingFile(filePath); + } +} + +void FileContentIndexer::slotFinishedIndexingFile(const QString& filePath) +{ + Q_UNUSED(filePath); + if (!m_registeredMonitors.isEmpty()) { + Q_EMIT finishedIndexingFile(filePath); } } @@ -98,7 +107,7 @@ void FileContentIndexer::unregisterMonitor(const QDBusMessage& message) m_monitorWatcher.removeWatchedService(message.service()); } -void FileContentIndexer::monitorClosed(QString service) +void FileContentIndexer::monitorClosed(const QString& service) { m_registeredMonitors.removeAll(service); m_monitorWatcher.removeWatchedService(service); diff --git a/src/file/filecontentindexer.h b/src/file/filecontentindexer.h index 6ecd41c..841dc32 100644 --- a/src/file/filecontentindexer.h +++ b/src/file/filecontentindexer.h @@ -37,7 +37,7 @@ class FileContentIndexer : public QObject, public QRunnable Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.baloo.fileindexer") - Q_PROPERTY(QString currentFile READ currentFile NOTIFY indexingFile) + Q_PROPERTY(QString currentFile READ currentFile NOTIFY startedIndexingFile) public: FileContentIndexer(FileContentIndexerProvider* provider, QObject* parent = 0); @@ -54,13 +54,16 @@ public Q_SLOTS: Q_SCRIPTABLE void unregisterMonitor(const QDBusMessage& message); Q_SIGNALS: - Q_SCRIPTABLE void indexingFile(QString filePath); + Q_SCRIPTABLE void startedIndexingFile(const QString& filePath); + Q_SCRIPTABLE void finishedIndexingFile(const QString& filePath); + void done(); void newBatchTime(uint time); private Q_SLOTS: - void monitorClosed(QString service); - void slotIndexingFile(QString filePath); + void monitorClosed(const QString& service); + void slotStartedIndexingFile(const QString& filePath); + void slotFinishedIndexingFile(const QString& filePath); private: FileContentIndexerProvider* m_provider; diff --git a/src/qml/experimental/monitor.cpp b/src/qml/experimental/monitor.cpp index 731a1a7..dfc7037 100644 --- a/src/qml/experimental/monitor.cpp +++ b/src/qml/experimental/monitor.cpp @@ -52,7 +52,7 @@ Monitor::Monitor(QObject *parent) QStringLiteral("/fileindexer"), m_bus, this); - connect(m_fileindexer, &org::kde::baloo::fileindexer::indexingFile, + connect(m_fileindexer, &org::kde::baloo::fileindexer::startedIndexingFile, this, &Monitor::newFile); connect(m_scheduler, &org::kde::baloo::scheduler::stateChanged, diff --git a/src/tools/balooctl/monitor.cpp b/src/tools/balooctl/monitor.cpp index f18cec5..fc31cd7 100644 --- a/src/tools/balooctl/monitor.cpp +++ b/src/tools/balooctl/monitor.cpp @@ -39,7 +39,7 @@ Monitor::Monitor(QObject *parent) QCoreApplication::exit(); } m_interface->registerMonitor(); - connect(m_interface, &org::kde::baloo::fileindexer::indexingFile, this, &Monitor::newFile); + connect(m_interface, &org::kde::baloo::fileindexer::startedIndexingFile, this, &Monitor::newFile); m_out << "Press ctrl+c to exit monitor" << endl; } -- 2.5.0
From 39dc7a7eb77dd74eb59f1894447f02db954da674 Mon Sep 17 00:00:00 2001 From: Vishesh Handa <m...@vhanda.in> Date: Mon, 5 Oct 2015 13:29:09 +0200 Subject: [PATCH 6/8] Balooctl monitor: Move to a proper command class --- src/tools/balooctl/CMakeLists.txt | 2 +- src/tools/balooctl/main.cpp | 6 ++-- src/tools/balooctl/monitor.cpp | 49 ---------------------------- src/tools/balooctl/monitor.h | 47 --------------------------- src/tools/balooctl/monitorcommand.cpp | 57 ++++++++++++++++++++++++++++++++ src/tools/balooctl/monitorcommand.h | 61 +++++++++++++++++++++++++++++++++++ 6 files changed, 122 insertions(+), 100 deletions(-) delete mode 100644 src/tools/balooctl/monitor.cpp delete mode 100644 src/tools/balooctl/monitor.h create mode 100644 src/tools/balooctl/monitorcommand.cpp create mode 100644 src/tools/balooctl/monitorcommand.h diff --git a/src/tools/balooctl/CMakeLists.txt b/src/tools/balooctl/CMakeLists.txt index d039233..b29eb4c 100644 --- a/src/tools/balooctl/CMakeLists.txt +++ b/src/tools/balooctl/CMakeLists.txt @@ -5,8 +5,8 @@ set(SRCS indexer.cpp command.cpp configcommand.cpp + monitorcommand.cpp ${CMAKE_SOURCE_DIR}/src/file/extractor/result.cpp - monitor.cpp ) set(DBUS_INTERFACES diff --git a/src/tools/balooctl/main.cpp b/src/tools/balooctl/main.cpp index da1ea21..bf66f38 100644 --- a/src/tools/balooctl/main.cpp +++ b/src/tools/balooctl/main.cpp @@ -47,7 +47,7 @@ #include "indexerconfig.h" #include "idutils.h" #include "fileindexerconfig.h" -#include "monitor.h" +#include "monitorcommand.h" #include "schedulerinterface.h" #include "maininterface.h" #include "indexerstate.h" @@ -384,8 +384,8 @@ int main(int argc, char* argv[]) } if (command == QStringLiteral("monitor")) { - Monitor mon; - app.exec(); + MonitorCommand mon; + return mon.exec(parser); } if (command == QStringLiteral("checkDb")) { diff --git a/src/tools/balooctl/monitor.cpp b/src/tools/balooctl/monitor.cpp deleted file mode 100644 index fc31cd7..0000000 --- a/src/tools/balooctl/monitor.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of the KDE Baloo Project - * Copyright (C) 2015 Pinak Ahuja <pinak.ah...@gmail.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "monitor.h" - -#include <QDBusConnection> - -using namespace Baloo; -Monitor::Monitor(QObject *parent) - : QObject(parent) - , m_out(stdout) -{ - m_interface = new org::kde::baloo::fileindexer(QStringLiteral("org.kde.baloo"), - QStringLiteral("/fileindexer"), - QDBusConnection::sessionBus(), - this); - - if (!m_interface->isValid()) { - m_out << "Baloo is not running" << endl; - QCoreApplication::exit(); - } - m_interface->registerMonitor(); - connect(m_interface, &org::kde::baloo::fileindexer::startedIndexingFile, this, &Monitor::newFile); - m_out << "Press ctrl+c to exit monitor" << endl; -} - -void Monitor::newFile(const QString& url) -{ - m_out << "Indexing: " << url << endl; -} diff --git a/src/tools/balooctl/monitor.h b/src/tools/balooctl/monitor.h deleted file mode 100644 index f769c57..0000000 --- a/src/tools/balooctl/monitor.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of the KDE Baloo Project - * Copyright (C) 2015 Pinak Ahuja <pinak.ah...@gmail.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef MONITOR_H -#define MONITOR_H - -#include <QObject> -#include <QTextStream> - -#include "fileindexerinterface.h" - -namespace Baloo { -class Monitor : public QObject -{ - Q_OBJECT -public: - Monitor(QObject* parent = 0); - -private Q_SLOTS: - void newFile(const QString& url); - -private: - QTextStream m_out; - org::kde::baloo::fileindexer* m_interface; - -}; -} -#endif // MONITOR_H diff --git a/src/tools/balooctl/monitorcommand.cpp b/src/tools/balooctl/monitorcommand.cpp new file mode 100644 index 0000000..07bccb1 --- /dev/null +++ b/src/tools/balooctl/monitorcommand.cpp @@ -0,0 +1,57 @@ +/* + * This file is part of the KDE Baloo Project + * Copyright (C) 2015 Pinak Ahuja <pinak.ah...@gmail.com> + * Copyright (C) 2015 Vishesh Handa <vha...@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include "monitorcommand.h" + +#include <QDBusConnection> + +using namespace Baloo; + +MonitorCommand::MonitorCommand(QObject *parent) + : QObject(parent) + , m_out(stdout) +{ + m_interface = new org::kde::baloo::fileindexer(QStringLiteral("org.kde.baloo"), + QStringLiteral("/fileindexer"), + QDBusConnection::sessionBus(), + this); + + if (!m_interface->isValid()) { + m_out << "Baloo is not running" << endl; + QCoreApplication::exit(); + } + m_interface->registerMonitor(); + connect(m_interface, &org::kde::baloo::fileindexer::startedIndexingFile, this, &MonitorCommand::newFile); + m_out << "Press ctrl+c to exit monitor" << endl; +} + +void MonitorCommand::newFile(const QString& url) +{ + m_out << "Indexing: " << url << endl; +} + +int MonitorCommand::exec(const QCommandLineParser& parser) +{ + Q_UNUSED(parser); + return QCoreApplication::instance()->exec(); +} diff --git a/src/tools/balooctl/monitorcommand.h b/src/tools/balooctl/monitorcommand.h new file mode 100644 index 0000000..01123bc --- /dev/null +++ b/src/tools/balooctl/monitorcommand.h @@ -0,0 +1,61 @@ +/* + * This file is part of the KDE Baloo Project + * Copyright (C) 2015 Pinak Ahuja <pinak.ah...@gmail.com> + * Copyright (C) 2015 Vishesh Handa <vha...@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef MONITOR_H +#define MONITOR_H + +#include <QObject> +#include <QTextStream> +#include <KLocalizedString> + +#include "command.h" +#include "fileindexerinterface.h" + +namespace Baloo { + +class MonitorCommand : public QObject, public Command +{ + Q_OBJECT +public: + MonitorCommand(QObject* parent = 0); + + QString command() Q_DECL_OVERRIDE { + return QStringLiteral("monitor"); + } + + QString description() Q_DECL_OVERRIDE { + return i18n("CLI interface for monitoring Baloo"); + } + + int exec(const QCommandLineParser& parser); + +private Q_SLOTS: + void newFile(const QString& url); + +private: + QTextStream m_out; + org::kde::baloo::fileindexer* m_interface; + +}; +} +#endif // MONITOR_H -- 2.5.0
From aa6779b5a9ff7ebf604bfd9778bfe1e7d83737e8 Mon Sep 17 00:00:00 2001 From: Vishesh Handa <m...@vhanda.in> Date: Mon, 5 Oct 2015 14:01:41 +0200 Subject: [PATCH 7/8] MonitorCommand: Use both the started and finished signals This is just an intermediate commit before we add extra output in the middle to indicate that we are actually indexing the file right now. --- src/tools/balooctl/monitorcommand.cpp | 22 ++++++++++++++++------ src/tools/balooctl/monitorcommand.h | 4 +++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/tools/balooctl/monitorcommand.cpp b/src/tools/balooctl/monitorcommand.cpp index 07bccb1..dfe26c1 100644 --- a/src/tools/balooctl/monitorcommand.cpp +++ b/src/tools/balooctl/monitorcommand.cpp @@ -41,17 +41,27 @@ MonitorCommand::MonitorCommand(QObject *parent) QCoreApplication::exit(); } m_interface->registerMonitor(); - connect(m_interface, &org::kde::baloo::fileindexer::startedIndexingFile, this, &MonitorCommand::newFile); + connect(m_interface, &org::kde::baloo::fileindexer::startedIndexingFile, this, &MonitorCommand::startedIndexingFile); + connect(m_interface, &org::kde::baloo::fileindexer::finishedIndexingFile, this, &MonitorCommand::finishedIndexingFile); m_out << "Press ctrl+c to exit monitor" << endl; } -void MonitorCommand::newFile(const QString& url) -{ - m_out << "Indexing: " << url << endl; -} - int MonitorCommand::exec(const QCommandLineParser& parser) { Q_UNUSED(parser); return QCoreApplication::instance()->exec(); } + +void MonitorCommand::startedIndexingFile(const QString& filePath) +{ + m_currentFile = filePath; + m_out << "Indexing: " << filePath; +} + +void MonitorCommand::finishedIndexingFile(const QString& filePath) +{ + Q_UNUSED(filePath); + + m_currentFile.clear(); + m_out << endl; +} diff --git a/src/tools/balooctl/monitorcommand.h b/src/tools/balooctl/monitorcommand.h index 01123bc..72c5755 100644 --- a/src/tools/balooctl/monitorcommand.h +++ b/src/tools/balooctl/monitorcommand.h @@ -50,12 +50,14 @@ public: int exec(const QCommandLineParser& parser); private Q_SLOTS: - void newFile(const QString& url); + void startedIndexingFile(const QString& filePath); + void finishedIndexingFile(const QString& filePath); private: QTextStream m_out; org::kde::baloo::fileindexer* m_interface; + QString m_currentFile; }; } #endif // MONITOR_H -- 2.5.0
From fdb1d502713a90b8ad6883ebfe0b1e16e90557df Mon Sep 17 00:00:00 2001 From: Vishesh Handa <m...@vhanda.in> Date: Mon, 5 Oct 2015 14:13:19 +0200 Subject: [PATCH 8/8] Balooctl monitor: stop if baloo dies --- src/tools/balooctl/monitorcommand.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tools/balooctl/monitorcommand.cpp b/src/tools/balooctl/monitorcommand.cpp index dfe26c1..a9fdd74 100644 --- a/src/tools/balooctl/monitorcommand.cpp +++ b/src/tools/balooctl/monitorcommand.cpp @@ -24,6 +24,7 @@ #include "monitorcommand.h" #include <QDBusConnection> +#include <QDBusServiceWatcher> using namespace Baloo; @@ -44,6 +45,13 @@ MonitorCommand::MonitorCommand(QObject *parent) connect(m_interface, &org::kde::baloo::fileindexer::startedIndexingFile, this, &MonitorCommand::startedIndexingFile); connect(m_interface, &org::kde::baloo::fileindexer::finishedIndexingFile, this, &MonitorCommand::finishedIndexingFile); m_out << "Press ctrl+c to exit monitor" << endl; + + auto balooWatcher = new QDBusServiceWatcher(QStringLiteral("org.kde.baloo"), QDBusConnection::sessionBus()); + balooWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); + connect(balooWatcher, &QDBusServiceWatcher::serviceUnregistered, this, [&]() { + m_out << "Baloo died" << endl; + QCoreApplication::instance()->quit(); + }); } int MonitorCommand::exec(const QCommandLineParser& parser) -- 2.5.0
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<