Baloo

extractorprocess.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org>
3 SPDX-FileCopyrightText: 2015 Pinak Ahuja <pinak.ahuja@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#include "baloodebug.h"
9#include "extractorprocess.h"
10
11using namespace Baloo;
12
13ExtractorProcess::ExtractorProcess(const QString& extractorPath, QObject* parent)
14 : QObject(parent)
15 , m_extractorPath(extractorPath)
16 , m_extractorProcess(this)
17 , m_controller(&m_extractorProcess, &m_extractorProcess)
18{
19 using ControllerPipe = Baloo::Private::ControllerPipe;
20
21 connect(&m_extractorProcess, &QProcess::readyRead, &m_controller, &ControllerPipe::processStatusData);
22 connect(&m_controller, &ControllerPipe::urlStarted, this, &ExtractorProcess::startedIndexingFile);
23 connect(&m_controller, &ControllerPipe::urlFinished, this, [this](const QString& url) {
24 Q_EMIT finishedIndexingFile(url, true);
25 });
26 connect(&m_controller, &ControllerPipe::urlFailed, this, [this](const QString& url) {
27 Q_EMIT finishedIndexingFile(url, false);
28 });
29 connect(&m_controller, &ControllerPipe::batchFinished, this, [this]() {
30 qCDebug(BALOO) << "Batch finished";
31 Q_EMIT done();
32 });
33
34 connect(&m_extractorProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), [=](int exitCode, QProcess::ExitStatus exitStatus) {
35 if (exitStatus == QProcess::CrashExit) {
36 qCWarning(BALOO) << "Extractor crashed";
37 Q_EMIT failed();
38 } else if (exitCode == 1) {
39 // DB open error
40 Q_EMIT failed();
41 } else if (exitCode == 2) {
42 // DB transaction commit error
43 Q_EMIT failed();
44 } else if (exitCode == 253) {
45 // DrKonqi mangles signals depending on the core_pattern
46 // and does a regular exit with status 253 instead
47 qCWarning(BALOO) << "Extractor probably crashed";
48 Q_EMIT failed();
49 } else if (exitCode != 0) {
50 qCWarning(BALOO) << "Unexpected exit code:" << exitCode;
51 Q_EMIT failed();
52 }
53 });
54
55 m_extractorProcess.setProgram(m_extractorPath);
56 m_extractorProcess.setProcessChannelMode(QProcess::ForwardedErrorChannel);
57 m_extractorProcess.start();
58}
59
60ExtractorProcess::~ExtractorProcess()
61{
62 m_extractorProcess.closeWriteChannel();
63 m_extractorProcess.waitForFinished();
64 m_extractorProcess.close();
65}
66
67void ExtractorProcess::start()
68{
70 m_extractorProcess.waitForStarted();
71 m_extractorProcess.setReadChannel(QProcess::StandardOutput);
72}
73
74void ExtractorProcess::index(const QVector<quint64>& fileIds)
75{
77 m_controller.processIds(fileIds);
78}
79
80#include "moc_extractorprocess.cpp"
Bidirectional communication pipe.
Definition commandpipe.h:24
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
void readyRead()
bool isEmpty() const const
ForwardedErrorChannel
virtual void close() override
void closeWriteChannel()
void finished(int exitCode, QProcess::ExitStatus exitStatus)
void setReadChannel(ProcessChannel channel)
void start(OpenMode mode)
bool waitForFinished(int msecs)
bool waitForStarted(int msecs)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.