-
Notifications
You must be signed in to change notification settings - Fork 621
/
BDM_mainthread.h
119 lines (89 loc) · 2.96 KB
/
BDM_mainthread.h
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
////////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2011-2015, Armory Technologies, Inc. //
// Distributed under the GNU Affero General Public License (AGPL v3) //
// See LICENSE or http://www.gnu.org/licenses/agpl.html //
// //
////////////////////////////////////////////////////////////////////////////////
#ifndef BDM_MAINTHREAD_H
#define BDM_MAINTHREAD_H
#include <string>
#include <stdint.h>
#ifdef _MSC_VER
#ifndef _WIN32_
#define _WIN32_
#endif
#endif
#include "UniversalTimer.h"
#include "bdmenums.h"
#include "BlockUtils.h"
struct BlockDataManagerConfig;
class BinaryData;
class BDM_CallBack
{
public:
virtual ~BDM_CallBack();
virtual void run(BDMAction action, void* ptr, int block=0)=0;
virtual void progress(
BDMPhase phase,
const vector<string> &walletIdVec,
float progress, unsigned secondsRem,
unsigned progressNumeric
)=0;
};
// let an outsider call functions from the BDM thread
class BDMFailure : public std::exception
{
public:
BDMFailure() { }
};
class BDM_Inject : public BlockDataManager_LevelDB::Notifier
{
struct BDM_Inject_Impl;
BDM_Inject_Impl *pimpl;
public:
BDM_Inject();
virtual ~BDM_Inject();
virtual void run()=0;
// instruct the BDM to wake up and call run() ASAP
void notify();
// Block for 'ms' milliseconds or until someone
// notify()es me
void wait(unsigned ms);
// once notify() is called, only returns on your
// thread after run() is called
void waitRun();
// the BDM thread will call this if it fails
void setFailureFlag();
};
class BlockDataManager_LevelDB;
class BlockDataViewer;
class BlockDataManagerThread
{
struct BlockDataManagerThreadImpl;
BlockDataManagerThreadImpl *pimpl;
public:
BlockDataManagerThread(const BlockDataManagerConfig &config);
~BlockDataManagerThread();
// start the BDM thread
void start(int mode, BDM_CallBack *callback, BDM_Inject *inject);
BlockDataManager_LevelDB *bdm();
BlockDataViewer *bdv();
void setConfig(const BlockDataManagerConfig &config);
// stop the BDM thread
void shutdownAndWait();
// return true if the caller is should wait on callback notification
bool requestShutdown();
private:
static void* thrun(void *);
void run();
private:
BlockDataManagerThread(const BlockDataManagerThread&);
};
inline void StartCppLogging(string fname, int lvl) { STARTLOGGING(fname, (LogLevel)lvl); }
inline void ChangeCppLogLevel(int lvl) { SETLOGLEVEL((LogLevel)lvl); }
inline void DisableCppLogging() { SETLOGLEVEL(LogLvlDisabled); }
inline void EnableCppLogStdOut() { LOGENABLESTDOUT(); }
inline void DisableCppLogStdOut() { LOGDISABLESTDOUT(); }
// kate: indent-width 3; replace-tabs on;
#endif