[go: up one dir, main page]

File: idxstatus.h

package info (click to toggle)
recoll 1.43.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 16,400 kB
  • sloc: cpp: 103,890; python: 9,349; xml: 7,305; ansic: 6,447; sh: 1,212; perl: 130; makefile: 72
file content (92 lines) | stat: -rw-r--r-- 3,442 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* Copyright (C) 2017-2018 J.F.Dockes
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program 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 General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef _IDXSTATUS_H_INCLUDED_
#define _IDXSTATUS_H_INCLUDED_

#include <string>

// Current status of an indexing operation. This is updated in
// $RECOLL_CONFDIR/idxstatus.txt
class DbIxStatus {
public:
    enum Phase {DBIXS_NONE, DBIXS_FILES, DBIXS_FLUSH, DBIXS_PURGE, DBIXS_STEMDB, DBIXS_CLOSING, 
                DBIXS_MONITOR, DBIXS_DONE};
    Phase phase;
    std::string fn;   // Last file processed
    int docsdone;  // Documents actually updated
    int filesdone; // Files tested (updated or not)
    int fileerrors; // Failed files (e.g.: missing input handler).
    int dbtotdocs;  // Doc count in index at start
    // Total files in index.This is actually difficult to compute from
    // the index so it's preserved from last indexing
    int totfiles;
    // Is this indexer a monitoring one? This is a permanent value
    // telling if option -m was set, not about what we are currently
    // doing
    bool hasmonitor{false};
    
    void reset() {
        phase = DBIXS_FILES;
        fn.erase();
        docsdone = filesdone = fileerrors = dbtotdocs = totfiles = 0;
    }
    DbIxStatus() {reset();}
    bool operator==(const DbIxStatus& other) {
        return
            phase == other.phase &&
            fn == other.fn &&
            docsdone == other.docsdone &&
            filesdone == other.filesdone &&
            fileerrors == other.fileerrors &&
            dbtotdocs == other.dbtotdocs &&
            totfiles == other.totfiles;
    }
    bool operator!=(const DbIxStatus& other) {
        return !operator==(other);
    }
};

class RclConfig;
extern void readIdxStatus(RclConfig *config, DbIxStatus &status);

/** Callback to say what we're doing. If the update func returns false, we
 * stop as soon as possible without corrupting state */
class DbIxStatusUpdater {
public:
    DbIxStatusUpdater(const RclConfig *config, bool nox11monitor);
    virtual ~DbIxStatusUpdater(){}
    DbIxStatusUpdater(const DbIxStatusUpdater&) = delete;
    DbIxStatusUpdater& operator=(const DbIxStatusUpdater&) = delete;

    enum Incr {IncrNone, IncrDocsDone = 0x1, IncrFilesDone = 0x2, IncrFileErrors = 0x4};
    // Change phase/fn and update
    virtual bool update(DbIxStatus::Phase phase, const std::string& fn, int incr = IncrNone);

    void setMonitor(bool onoff);
    void setDbTotDocs(int totdocs);
    
    class Internal;
private:
    Internal *m;
};

// We use the updater as a singleton everywhere. It is instanciated in
// idxstatus.cpp. Must be called once with non-null config at first.
extern DbIxStatusUpdater *statusUpdater(RclConfig *config=nullptr, bool nox11monitor=false);

#endif /* _IDXSTATUS_H_INCLUDED_ */