OnixS C++ CME Market Data Handler  5.4.0
API documentation
Feed.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
23 #include <cassert>
24 #include <string>
25 
26 #include <OnixS/CME/MDH/Atomic.h>
27 #include <OnixS/CME/MDH/Time.h>
28 
31 
32 #include <OnixS/CME/MDH/FeedLink.h>
33 
35 
37 (
38  NetFeedListener
39 );
40 
42 (
43  NetFeedConsumer
44 );
45 
46 /// Defines possible states for the feeds.
48 {
49  /// Defines possible states for the feeds.
50  enum Enum
51  {
55  Connecting
56  };
57 };
58 
59 /// Base attributes of market data feed.
61 {
62  typedef
63  Atomic<NetFeedState::Enum>
64  AtomicState;
65 
66  mutable volatile NetFeedState::Enum state_;
67 
68  NetFeedConsumer* consumer_;
69  NetFeedListener* listener_;
70 
71  NetFeedLink* link_;
72 
73  TimeSpan receiveTimeout_;
74  TimeSpan expirationTime_;
75 
76  NetFeedConnection connection_;
77 
78  NetFeedType::Enum type_;
79  NetFeedRole::Enum role_;
80 
81  NetFeedId id_;
82 
83  NetFeed(
84  const NetFeed&);
85 
86  NetFeed&
87  operator =(
88  const NetFeed&);
89 
90 public:
91  /// Initializes the instance.
93  : state_(
94  NetFeedState::Disconnected)
95  , consumer_(NULL)
96  , listener_(NULL)
97  , link_(NULL)
98  {
99  }
100 
102  {
103  assert(
104  state() ==
105  NetFeedState::Disconnected);
106 
107  if (link_)
108  link_->release(*this);
109  }
110 
111  /// Identifier associated with feed.
112  const NetFeedId& id() const
113  {
114  return id_;
115  }
116 
117  /// Assigns identifier.
118  void
119  id(
120  const NetFeedId& id)
121  {
122  id_ = id;
123  }
124 
125  /// Type of service (incremental, instrument, etc).
127  {
128  return type_;
129  }
130 
131  /// Assigns feed service type.
132  void
134  NetFeedType::Enum type)
135  {
136  type_ = type;
137  }
138 
139  /// Role in a service (primary, secondary).
141  {
142  return role_;
143  }
144 
145  /// Assigns feed service role.
146  void
148  NetFeedRole::Enum role)
149  {
150  role_ = role;
151  }
152 
153  /// Connection attributes (overload for modifications).
155  {
156  return connection_;
157  }
158 
159  /// Connection attributes (read-only access).
160  const
162  connection() const
163  {
164  return connection_;
165  }
166 
167  /// Life time for the feed.
168  ///
169  /// If defined, the given time defines time period
170  /// during which the feed may receive the incoming
171  /// data and deliver it to the associate consumer.
172  /// After that, the feed stop receiving the data
173  /// while staying in the connected state.
174  const
175  TimeSpan&
177  {
178  return expirationTime_;
179  }
180 
181  /// Defines life time for the feed in seconds.
182  ///
183  /// The given attribute defines time period during
184  /// which the feed may receive the incoming data and
185  /// deliver it to the associate consumer. After that,
186  /// the feed stop receiving the data while staying
187  /// in the connected state.
188  void
190  UInt32 expirationTime)
191  {
192  expirationTime_ =
193  TimeSpan(
194  0,
195  0,
196  expirationTime,
197  0);
198  }
199 
200  /// Maximal time interval between two packets transmitted.
201  const
202  TimeSpan&
204  {
205  return receiveTimeout_;
206  }
207 
208  /// Updates time interval between two packets transmitted.
209  void
211  UInt32 timeInterval)
212  {
213  receiveTimeout_ =
214  TimeSpan(
215  0,
216  0,
217  timeInterval,
218  0);
219  }
220 
221  /// Indicates current state.
223  {
224  return AtomicState::read(state_);
225  }
226 
227  /// Binds the given listener to the feed.
228  void
230  NetFeedListener& listener)
231  {
232  assert(
233  state() ==
234  NetFeedState::Disconnected);
235 
236  listener_ = &listener;
237  }
238 
239  /// An instance of data consumer associated
240  /// with the given feed if available.
242  consumer() const
243  {
244  return consumer_;
245  }
246 
247  /// Binds the given consumer to the feed.
248  void
250  NetFeedConsumer& consumer)
251  {
252  assert(
253  state() ==
254  NetFeedState::Disconnected);
255 
256  assert(NULL == link_);
257 
258  consumer_ = &consumer;
259  }
260 
261  /// Associates the given link with the feed.
262  void
264  NetFeedLink& link)
265  {
266  assert(
267  state() ==
268  NetFeedState::Disconnected);
269 
270  NetFeedLink* old = link_;
271 
272  link_ = &link;
273 
274  if (old)
275  old->release(*this);
276  }
277 
278  /// Bring the given instance to the connected state.
279  ///
280  /// Feed must be fully configured and a valid instance
281  /// of the NetFeedLink bound to the feed. Otherwise, an
282  /// exception will be thrown.
283  ///
284  /// Returns 'true' if the feed was connected.
285  /// 'False' is returned if the feed wasn't in the
286  /// disconnected state at the moment of invocation.
288  bool
289  connect(
290  UInt32);
291 
292  /// Instructs the feed to stop delivering
293  /// packets to the associated consumer.
294  ///
295  /// Returns 'true' if the feed was disconnected.
296  /// 'False' is returned if the feed wasn't previously
297  /// connected of was in the process of disconnecting.
299  bool
300  disconnect();
301 
302  /// Send the given message to the source from which the feed
303  /// receives data and delivers to the associated consumer.
304  ///
305  /// @throw the exception if the operation is not supported or
306  /// the given message can't be delivered to the destination.
307  void
309  const void* message,
310  size_t length,
311  UInt32 timeout)
312  {
313  assert(NULL != link_);
314 
315  link_->send
316  (
317  *this,
318  message,
319  length,
320  timeout
321  );
322  }
323 };
324 
#define ONIXS_CMEMDH_LTWT_CLASS
Definition: Bootstrap.h:94
void link(NetFeedLink &link)
Associates the given link with the feed.
Definition: Feed.h:263
NetFeedType::Enum type() const
Type of service (incremental, instrument, etc).
Definition: Feed.h:126
std::string NetFeedId
The feed identifier.
Enum
Defines possible states for the feeds.
Definition: Feed.h:50
NetFeedState::Enum state() const
Indicates current state.
Definition: Feed.h:222
Network feed connection attributes.
UInt32 UInt32
uInt32.
Definition: Fields.h:247
Enum
Feed types based on type of market data service.
void role(NetFeedRole::Enum role)
Assigns feed service role.
Definition: Feed.h:147
#define ONIXS_CMEMDH_EXPORTED_CLASS_DECL(typeName)
Definition: Bootstrap.h:46
const TimeSpan & expirationTime() const
Definition: Feed.h:176
const NetFeedId & id() const
Identifier associated with feed.
Definition: Feed.h:112
NetFeedConsumer * consumer() const
Definition: Feed.h:242
NetFeed()
Initializes the instance.
Definition: Feed.h:92
NetFeedRole::Enum role() const
Role in a service (primary, secondary).
Definition: Feed.h:140
Base attributes of market data feed.
Definition: Feed.h:60
#define ONIXS_CMEMDH_LTWT_STRUCT
Definition: Bootstrap.h:98
Defines possible states for the feeds.
Definition: Feed.h:47
void sendMessage(const void *message, size_t length, UInt32 timeout)
Definition: Feed.h:308
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:152
Enum
List of known feed roles.
NetFeedConnection & connection()
Connection attributes (overload for modifications).
Definition: Feed.h:154
#define ONIXS_CMEMDH_EXPORTED_STRUCT_DECL(typeName)
Definition: Bootstrap.h:50
void receiveTimeout(UInt32 timeInterval)
Updates time interval between two packets transmitted.
Definition: Feed.h:210
#define ONIXS_CMEMDH_LTWT_EXPORTED
Definition: Bootstrap.h:102
void id(const NetFeedId &id)
Assigns identifier.
Definition: Feed.h:119
const TimeSpan & receiveTimeout() const
Maximal time interval between two packets transmitted.
Definition: Feed.h:203
void consumer(NetFeedConsumer &consumer)
Binds the given consumer to the feed.
Definition: Feed.h:249
void expirationTime(UInt32 expirationTime)
Definition: Feed.h:189
void listener(NetFeedListener &listener)
Binds the given listener to the feed.
Definition: Feed.h:229
const NetFeedConnection & connection() const
Connection attributes (read-only access).
Definition: Feed.h:162
void type(NetFeedType::Enum type)
Assigns feed service type.
Definition: Feed.h:133
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:156