-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataAccessController.h
executable file
·168 lines (125 loc) · 5.08 KB
/
DataAccessController.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#pragma once
#include"RxStreamer/IncludeExtLibs.h"
#include"RxStreamer/ReactorFactory.h"
#include"RxStreamer/DataAccessControllerPolicy.h"
#include"RxStreamer/DataAccessGroupChain.h"
#include"RxStreamer/DataAccessGroupChainIterator.h"
#include"RxStreamer/Export.h"
namespace Reactor {
class DataAccessController;
FORWARD_CLASS_TRAITS(DataAccessController)
// ---------------------------------------------------
// DataAccessControllerData
// ---------------------------------------------------
class DLL_STATE DataAccessControllerData
{
public:
typedef Concurrent::Scheduler<RxThreadPool::Ptr, Templates::Schedulable<Duration>*> Scheduler;
public:
DataAccessControllerData(DataAccessGroupChain chain, RxThreadPool::Ptr pool);
virtual ~DataAccessControllerData();
Templates::BooleanTrigger & triggered();
const Templates::BooleanTrigger& triggered() const;
DataAccessControllerData::Scheduler& scheduler();
DataAccessGroupChain & chain();
const DataAccessGroupChain& chain() const;
const DataAccessGroupChainIterator& iterator() const;
DataAccessGroupChainIterator & iterator();
bool Initialize(DataAccessController* controller);
Mutex& schedulingMutex();
private:
Templates::BooleanTrigger triggered_;
RxThreadPool::Ptr pool_;
Scheduler scheduler_;
DataAccessGroupChain chain_;
DataAccessGroupChainIterator iterator_;
Mutex schedulingMutex_;
};
// ---------------------------------------------------
// DataAccessControllerBase
// ---------------------------------------------------
class DLL_STATE DataAccessControllerBase
: public Templates::IsSuccessMethod
, public Templates::CancelMethod
, public Templates::SubscribeMethod<bool>
, public Templates::UnsubscribeMethod<bool>
, public Templates::IsSubscribedMethod
, public Templates::IsCancelledMethod
, public Templates::RefreshMethod<bool>
, public Templates::WaitForMethod1<bool, int64>
, public Templates::PolicyMethod<DataAccessControllerPolicy>
{
public:
virtual ~DataAccessControllerBase()
{ }
CLASS_TRAITS(DataAccessControllerBase)
};
// ---------------------------------------------------
// DataAccessController
// ---------------------------------------------------
class DLL_STATE DataAccessController
: public DataAccessControllerBase
, public RxObserverNew<DataAccessBase::Ptr>
, public Templates::Schedulable<Duration>
, public Templates::NotifyableShared<DataAccessController>
, public Templates::ContextObjectShared<DataAccessControllerPolicy, DataAccessControllerData, Status::ExecutionStatus>
, public ENABLE_SHARED_FROM_THIS(DataAccessController)
{
private:
static const int64 ACQUIRE_LOCK_TIMEOUT_IN_MS = 5000;
public:
DataAccessController(DataAccessControllerPolicy policy, DataAccessGroupChain chain, RxThreadPool::Ptr pool);
virtual ~DataAccessController();
CLASS_TRAITS(DataAccessController)
DataAccessController::Ptr GetPtr();
// ---------------------------------------------------
// Schedulable interface
// ---------------------------------------------------
virtual void run();
virtual bool HasNext() const;
virtual Duration Next();
// ---------------------------------------------------
// DataAccessControllerBase interface
// ---------------------------------------------------
virtual DataAccessControllerPolicy Policy() const;
virtual bool Cancel();
virtual bool Refresh();
virtual bool IsSubscribed() const;
virtual bool IsCancelled() const;
virtual bool Unsubscribe();
virtual bool Subscribe();
virtual bool IsSuccess() const;
virtual bool WaitFor(int64 msecs = LONG_MAX) const;
// ---------------------------------------------------
// RxObserverNew<DataAccessBase::Ptr> interface
// ---------------------------------------------------
virtual bool OnComplete();
virtual bool OnNext(DataAccessBase::Ptr dataAccess);
virtual bool OnError(GeneralException exception);
private:
bool scheduleFromRun();
bool schedule();
// -----------------------------------------------------------
// process call-backs
// -----------------------------------------------------------
bool processOnNext(DataAccessBase::Ptr dataAccess);
bool processOnError(BaseLib::GeneralException exception);
// ---------------------------------------------------
// private functions
// ---------------------------------------------------
bool execute(DataAccessGroupIterator group, DataAccessGroupPolicy policy);
bool executeAll(DataAccessGroupIterator group);
bool executeNext(DataAccessGroupIterator group);
bool setupNext();
bool executionStart();
void executionFinished();
void executionFailure(Exception exception);
void executionCancelled(Exception exception);
void connect(DataAccessGroup group);
void disconnect(DataAccessGroup group);
void unsubscribeAndDisconnect(DataAccessGroup group);
bool isReady();
bool isTimeout();
bool isExecutionFailure();
};
}