PIVX Core  5.6.99
P2P Digital Currency
rpcexecutor.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2017 The Bitcoin developers
2 // Copyright (c) 2015-2021 The PIVX Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef PIVX_QT_RPCEXECUTOR_H
7 #define PIVX_QT_RPCEXECUTOR_H
8 
9 #include "rpc/server.h"
10 
11 #include <QObject>
12 #include <QString>
13 #include <QTimer>
14 
15 /*
16  * Object for executing console RPC commands in a separate thread.
17 */
18 class RPCExecutor : public QObject
19 {
20  Q_OBJECT
21 public:
22  enum CommandClass {
25  CMD_ERROR
26  };
27 
28  static QString categoryClass(int category);
29 
30 public Q_SLOTS:
31  void request(const QString& command);
32 
33 Q_SIGNALS:
34  void reply(int category, const QString& command);
35 
36 private:
37  bool ExecuteCommandLine(std::string& strResult, const std::string& strCommand);
38 };
39 
40 
41 /*
42  * Class for handling RPC timers
43  * (used for e.g. re-locking the wallet after a timeout)
44  */
45 class QtRPCTimerBase: public QObject, public RPCTimerBase
46 {
47  Q_OBJECT
48 public:
49  QtRPCTimerBase(std::function<void(void)>& _func, int64_t millis):
50  func(_func)
51  {
52  timer.setSingleShot(true);
53  connect(&timer, &QTimer::timeout, [this]{ func(); });
54  timer.start(millis);
55  }
57 
58 private:
59  QTimer timer;
60  std::function<void(void)> func;
61 };
62 
63 /*
64  * Specialization of the RPCTimer interface
65 */
67 {
68 public:
70  const char *Name() { return "Qt"; }
71  RPCTimerBase* NewTimer(std::function<void(void)>& func, int64_t millis)
72  {
73  return new QtRPCTimerBase(func, millis);
74  }
75 };
76 
77 
78 #endif // PIVX_QT_RPCEXECUTOR_H
std::function< void(void)> func
Definition: rpcexecutor.h:60
QtRPCTimerBase(std::function< void(void)> &_func, int64_t millis)
Definition: rpcexecutor.h:49
const char * Name()
Implementation name.
Definition: rpcexecutor.h:70
RPCTimerBase * NewTimer(std::function< void(void)> &func, int64_t millis)
Factory function for timers.
Definition: rpcexecutor.h:71
void reply(int category, const QString &command)
void request(const QString &command)
Definition: rpcexecutor.cpp:35
static QString categoryClass(int category)
Definition: rpcexecutor.cpp:18
bool ExecuteCommandLine(std::string &strResult, const std::string &strCommand)
Split shell command line into a list of arguments and execute the command(s).
Opaque base class for timers returned by NewTimerFunc.
Definition: server.h:95
RPC timer "driver".
Definition: server.h:104