Baloo

extractorprocess.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Vishesh Handa <[email protected]>
3  SPDX-FileCopyrightText: 2015 Pinak Ahuja <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7 
8 #include "baloodebug.h"
9 #include "extractorprocess.h"
10 
11 using namespace Baloo;
12 
13 ExtractorProcess::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 
60 ExtractorProcess::~ExtractorProcess()
61 {
62  m_extractorProcess.closeWriteChannel();
63  m_extractorProcess.waitForFinished();
64  m_extractorProcess.close();
65 }
66 
68 {
69  m_extractorProcess.start(QIODevice::Unbuffered | QIODevice::ReadWrite);
70  m_extractorProcess.waitForStarted();
71  m_extractorProcess.setReadChannel(QProcess::StandardOutput);
72 }
73 
74 void ExtractorProcess::index(const QVector<quint64>& fileIds)
75 {
76  Q_ASSERT(!fileIds.isEmpty());
77  m_controller.processIds(fileIds);
78 }
79 
80 #include "moc_extractorprocess.cpp"
bool isEmpty() const const
Q_SCRIPTABLE Q_NOREPLY void start()
void finished(int exitCode)
Implements storage for docIds without any associated data Instantiated for:
Definition: coding.cpp:11
void readyRead()
Bidirectional communication pipe.
Definition: commandpipe.h:23
ForwardedErrorChannel
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.