LeechCraft  0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
consistencychecker.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #pragma once
10 
11 #include <memory>
12 #include <variant>
13 #include <QObject>
14 #include "dbconfig.h"
15 
16 template<typename>
17 class QFuture;
18 
19 template<typename>
21 
22 namespace LC::Util
23 {
24  class UTIL_DB_API ConsistencyChecker : public QObject
25  , public std::enable_shared_from_this<ConsistencyChecker>
26  {
27  const QString DBPath_;
28  const QString DialogContext_;
29 
30  friend class FailedImpl;
31 
32  ConsistencyChecker (QString dbPath, QString dialogContext, QObject* = nullptr);
33  public:
34  static std::shared_ptr<ConsistencyChecker> Create (QString dbPath, QString dialogContext);
35 
36  struct DumpFinished
37  {
38  qint64 OldFileSize_;
39  qint64 NewFileSize_;
40  };
41  struct DumpError
42  {
43  QString Error_;
44  };
45  using DumpResult_t = std::variant<DumpFinished, DumpError>;
46 
47  struct Succeeded {};
48  struct IFailed
49  {
50  virtual QFuture<DumpResult_t> DumpReinit () = 0;
51 
52  // Not having a virtual dtor here is fine, since its subclasses will
53  // only be deleted through a shared_ptr, which remembers the exact
54  // type of the constructed object.
55  };
56  using Failed = std::shared_ptr<IFailed>;
57 
58  using CheckResult_t = std::variant<Succeeded, Failed>;
59 
60  QFuture<CheckResult_t> StartCheck ();
61  private:
62  CheckResult_t CheckDB ();
63 
64  QFuture<DumpResult_t> DumpReinit ();
65  void DumpReinitImpl (QFutureInterface<DumpResult_t>);
66 
67  void HandleDumperFinished (QFutureInterface<DumpResult_t>, const QString&);
68  };
69 }
std::shared_ptr< IFailed > Failed
std::variant< Succeeded, Failed > CheckResult_t
#define UTIL_DB_API
Definition: dbconfig.h:16
std::variant< DumpFinished, DumpError > DumpResult_t