-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamer.cpp
executable file
·204 lines (174 loc) · 5.36 KB
/
Streamer.cpp
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "RxStreamer/Streamer.h"
namespace Reactor {
Streamer::Streamer(
Templates::ActionContextPtr rxContext,
RxData::CacheDescription masterCacheId,
DataAccessControllerPolicy policy,
DataAccessPolicy dataAccessPolicy,
StreamerPolicy streamerPolicy
)
: Templates::ContextObjectShared<StreamerPolicy, StreamerState>
(
new StreamerPolicy(streamerPolicy),
new StreamerState(RxActionChain::Create(rxContext, masterCacheId, policy), masterCacheId, dataAccessPolicy)
)
{ }
Streamer::~Streamer()
{
if(this->config()->IsCacheUntilFinalize())
{
this->data()->Release();
}
}
// --------------------------------------------------
// Factory functions
// --------------------------------------------------
Streamer Streamer::Create(Templates::ActionContextPtr rxContext, RxData::CacheDescription masterCacheId, DataAccessControllerPolicy policy, DataAccessPolicy rxPolicy)
{
return Streamer(
rxContext,
masterCacheId,
policy,
rxPolicy,
StreamerPolicy::Unrelated()
);
}
Streamer Streamer::Create(Templates::ActionContextPtr rxContext, RxData::CacheDescription masterCacheId, DataAccessPolicy rxPolicy)
{
return Streamer(
rxContext,
masterCacheId,
DataAccessControllerPolicy::Default(),
rxPolicy,
StreamerPolicy::Unrelated()
);
}
Streamer Streamer::Create(Templates::ActionContextPtr rxContext, RxData::CacheDescription masterCacheId)
{
return Streamer(
rxContext,
masterCacheId,
DataAccessControllerPolicy::Default(),
DataAccessPolicy::Default(),
StreamerPolicy::Unrelated()
);
}
Streamer Streamer::CreateUnique(Templates::ActionContextPtr rxContext)
{
return Streamer(
rxContext,
RxData::CacheDescription::CreateUnique(),
DataAccessControllerPolicy::Default(),
DataAccessPolicy::Default(),
StreamerPolicy::Unrelated()
);
}
Streamer Streamer::Create(RxData::CacheDescription masterCacheId)
{
return Streamer(
Templates::ActionContext::Empty(),
masterCacheId,
DataAccessControllerPolicy::Default(),
DataAccessPolicy::Default(),
StreamerPolicy::Unrelated()
);
}
Streamer Streamer::CreateUnique()
{
return Streamer(
Templates::ActionContext::Empty(),
RxData::CacheDescription::CreateUnique(),
DataAccessControllerPolicy::Default(),
DataAccessPolicy::Default(),
StreamerPolicy::Unrelated()
);
}
Streamer Streamer::CreateUniqueScoped()
{
return Streamer(
Templates::ActionContext::Empty(),
RxData::CacheDescription::CreateUnique(),
DataAccessControllerPolicy::Default(),
DataAccessPolicy::Default(),
StreamerPolicy::CacheUntilFinalize()
);
}
// --------------------------------------------------
// Create sequential group
// --------------------------------------------------
StreamerGroup Streamer::Sequential()
{
RxDataAccessGroup group = this->data()->actionChain_.Sequential();
return StreamerGroup::Create(this->data()->masterCacheId_, this->data()->rxPolicy_, group);
}
StreamerGroup Streamer::Sequential(RxData::CacheDescription masterCacheId)
{
RxDataAccessGroup group = this->data()->actionChain_.Sequential();
return StreamerGroup::Create(masterCacheId, this->data()->rxPolicy_, group);
}
StreamerGroup Streamer::Sequential(RxData::CacheDescription masterCacheId, DataAccessPolicy rxPolicy)
{
RxDataAccessGroup group = this->data()->actionChain_.Sequential();
return StreamerGroup::Create(masterCacheId, rxPolicy, group);
}
// --------------------------------------------------
// Create parallel group
// --------------------------------------------------
StreamerGroup Streamer::Parallel()
{
RxDataAccessGroup group = this->data()->actionChain_.Parallel();
return StreamerGroup::Create(this->data()->masterCacheId_, this->data()->rxPolicy_, group);
}
StreamerGroup Streamer::Parallel(RxData::CacheDescription masterCacheId)
{
RxDataAccessGroup group = this->data()->actionChain_.Parallel();
return StreamerGroup::Create(masterCacheId, this->data()->rxPolicy_, group);
}
StreamerGroup Streamer::Parallel(RxData::CacheDescription masterCacheId, DataAccessPolicy rxPolicy)
{
RxDataAccessGroup group = this->data()->actionChain_.Parallel();
return StreamerGroup::Create(masterCacheId, rxPolicy, group);
}
// --------------------------------------------------
// Fluent API
// --------------------------------------------------
Streamer& Streamer::Subscribe()
{
this->data()->actionChain_.Subscribe();
return *this;
}
bool Streamer::Unsubscribe()
{
return this->data()->actionChain_.Controller()->Unsubscribe();
}
Streamer& Streamer::Refresh()
{
this->data()->actionChain_.Controller()->Refresh();
return *this;
}
void Streamer::Cancel()
{
this->data()->actionChain_.Controller()->Cancel();
}
bool Streamer::IsSubscribed() const
{
return this->data()->actionChain_.Controller()->IsSubscribed();
}
bool Streamer::IsSuccess() const
{
return this->data()->actionChain_.Controller()->IsSuccess();
}
bool Streamer::IsCancelled() const
{
return this->data()->actionChain_.Controller()->IsCancelled();
}
Streamer& Streamer::WaitFor(int64 msecs)
{
this->data()->actionChain_.Controller()->WaitFor(msecs);
return *this;
}
void Streamer::Release()
{
this->data()->Release();
}
}