OnixS C++ CME MDP Premium Market Data Handler  5.8.3
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 
36 ONIXS_CMEMDH_EXPORTED_STRUCT_DECL(NetFeedListener);
37 
38 ONIXS_CMEMDH_EXPORTED_CLASS_DECL(NetFeedConsumer);
39 
40 /// Defines possible states for the feeds.
42 {
43  /// Defines possible states for the feeds.
44  enum Enum
45  {
49  Connecting
50  };
51 };
52 
53 /// Base attributes of market data feed.
55 {
56 public:
57  /// Initializes the instance.
59  : state_(NetFeedState::Disconnected)
60  , consumer_(ONIXS_CMEMDH_NULLPTR)
61  , listener_(ONIXS_CMEMDH_NULLPTR)
62  , link_(ONIXS_CMEMDH_NULLPTR)
63  {
64  }
65 
67  {
68  assert(state() == NetFeedState::Disconnected);
69 
70  if (link_)
71  link_->release(*this);
72  }
73 
74  /// Identifier associated with feed.
75  const NetFeedId& id() const
76  {
77  return id_;
78  }
79 
80  /// Assigns identifier.
81  void id(const NetFeedId& id)
82  {
83  id_ = id;
84  }
85 
86  /// Type of service (incremental, instrument, etc).
88  {
89  return type_;
90  }
91 
92  /// Assigns feed service type.
94  {
95  type_ = type;
96  }
97 
98  /// Role in a service (primary, secondary).
100  {
101  return role_;
102  }
103 
104  /// Assigns feed service role.
106  {
107  role_ = role;
108  }
109 
110  /// Connection attributes (overload for modifications).
112  {
113  return connection_;
114  }
115 
116  /// Connection attributes (read-only access).
118  {
119  return connection_;
120  }
121 
122  /// Life time for the feed.
123  ///
124  /// If defined, the given time defines time period
125  /// during which the feed may receive the incoming
126  /// data and deliver it to the associate consumer.
127  /// After that, the feed stop receiving the data
128  /// while staying in the connected state.
129  const TimeSpan& expirationTime() const
130  {
131  return expirationTime_;
132  }
133 
134  /// Defines life time for the feed in seconds.
135  ///
136  /// The given attribute defines time period during
137  /// which the feed may receive the incoming data and
138  /// deliver it to the associate consumer. After that,
139  /// the feed stop receiving the data while staying
140  /// in the connected state.
141  void expirationTime(UInt32 expirationTime)
142  {
143  expirationTime_ = TimeSpan(0, 0, expirationTime, 0);
144  }
145 
146  /// Maximal time interval between two packets transmitted.
147  const TimeSpan& receiveTimeout() const
148  {
149  return receiveTimeout_;
150  }
151 
152  /// Updates time interval between two packets transmitted.
153  void receiveTimeout(UInt32 timeInterval)
154  {
155  receiveTimeout_ = TimeSpan(0, 0, timeInterval, 0);
156  }
157 
158  /// Indicates current state.
160  {
161  return AtomicState::read(state_);
162  }
163 
164  /// Binds the given listener to the feed.
165  void listener(NetFeedListener& listener)
166  {
167  assert(state() == NetFeedState::Disconnected);
168 
169  listener_ = &listener;
170  }
171 
172  /// An instance of data consumer associated
173  /// with the given feed if available.
175  {
176  return consumer_;
177  }
178 
179  /// Binds the given consumer to the feed.
180  void consumer(NetFeedConsumer& consumer)
181  {
182  assert(state() == NetFeedState::Disconnected);
183 
184  assert(ONIXS_CMEMDH_NULLPTR == link_);
185 
186  consumer_ = &consumer;
187  }
188 
189  /// Associates the given link with the feed.
190  void link(NetFeedLink& link)
191  {
192  assert(state() == NetFeedState::Disconnected);
193 
194  NetFeedLink* old = link_;
195 
196  link_ = &link;
197 
198  if (old)
199  old->release(*this);
200  }
201 
202  /// Bring the given instance to the connected state.
203  ///
204  /// Feed must be fully configured and a valid instance
205  /// of the NetFeedLink bound to the feed. Otherwise, an
206  /// exception will be thrown.
207  ///
208  /// Returns 'true' if the feed was connected.
209  /// 'False' is returned if the feed wasn't in the
210  /// disconnected state at the moment of invocation.
212  bool connect(UInt32);
213 
214  /// Instructs the feed to stop delivering
215  /// packets to the associated consumer.
216  ///
217  /// Returns 'true' if the feed was disconnected.
218  /// 'False' is returned if the feed wasn't previously
219  /// connected of was in the process of disconnecting.
221  bool disconnect();
222 
223  /// Send the given message to the source from which the feed
224  /// receives data and delivers to the associated consumer.
225  ///
226  /// @throw the exception if the operation is not supported or
227  /// the given message can't be delivered to the destination.
228  void sendMessage(const void* message, size_t length, UInt32 timeout)
229  {
230  assert(ONIXS_CMEMDH_NULLPTR != link_);
231 
232  link_->send(*this, message, length, timeout);
233  }
234 
235 private:
236  typedef Atomic<NetFeedState::Enum> AtomicState;
237 
238  mutable volatile NetFeedState::Enum state_;
239 
240  NetFeedConsumer* consumer_;
241  NetFeedListener* listener_;
242 
243  NetFeedLink* link_;
244 
245  TimeSpan receiveTimeout_;
246  TimeSpan expirationTime_;
247 
248  NetFeedConnection connection_;
249 
250  NetFeedType::Enum type_;
251  NetFeedRole::Enum role_;
252 
253  NetFeedId id_;
254 
255  NetFeed(const NetFeed&);
256 
257  NetFeed& operator=(const NetFeed&);
258 };
259 
void link(NetFeedLink &link)
Associates the given link with the feed.
Definition: Feed.h:190
NetFeedType::Enum type() const
Type of service (incremental, instrument, etc).
Definition: Feed.h:87
std::string NetFeedId
The feed identifier.
Enum
Defines possible states for the feeds.
Definition: Feed.h:44
NetFeedState::Enum state() const
Indicates current state.
Definition: Feed.h:159
Network feed connection attributes.
UInt32 UInt32
uInt32.
Definition: Fields.h:192
#define ONIXS_CMEMDH_NULLPTR
Definition: Compiler.h:145
Enum
Feed types based on type of market data service.
void role(NetFeedRole::Enum role)
Assigns feed service role.
Definition: Feed.h:105
#define ONIXS_CMEMDH_EXPORTED_CLASS_DECL(typeName)
Definition: Bootstrap.h:35
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
const TimeSpan & expirationTime() const
Life time for the feed.
Definition: Feed.h:129
const NetFeedId & id() const
Identifier associated with feed.
Definition: Feed.h:75
NetFeedConsumer * consumer() const
An instance of data consumer associated with the given feed if available.
Definition: Feed.h:174
NetFeed()
Initializes the instance.
Definition: Feed.h:58
NetFeedRole::Enum role() const
Role in a service (primary, secondary).
Definition: Feed.h:99
Base attributes of market data feed.
Definition: Feed.h:54
Represents time interval.
Definition: Time.h:104
Collection of the events raised by the NetFeed at various stages of its lifetime. ...
Definition: FeedListener.h:31
Defines possible states for the feeds.
Definition: Feed.h:41
void sendMessage(const void *message, size_t length, UInt32 timeout)
Send the given message to the source from which the feed receives data and delivers to the associated...
Definition: Feed.h:228
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:67
Enum
List of known feed roles.
NetFeedConnection & connection()
Connection attributes (overload for modifications).
Definition: Feed.h:111
#define ONIXS_CMEMDH_EXPORTED_STRUCT_DECL(typeName)
Definition: Bootstrap.h:36
void receiveTimeout(UInt32 timeInterval)
Updates time interval between two packets transmitted.
Definition: Feed.h:153
#define ONIXS_CMEMDH_LTWT_EXPORTED
Definition: Bootstrap.h:47
Represents an interface through which the Feed Engine pushes market data received for the feeds...
Definition: FeedConsumer.h:35
void id(const NetFeedId &id)
Assigns identifier.
Definition: Feed.h:81
const TimeSpan & receiveTimeout() const
Maximal time interval between two packets transmitted.
Definition: Feed.h:147
void consumer(NetFeedConsumer &consumer)
Binds the given consumer to the feed.
Definition: Feed.h:180
void expirationTime(UInt32 expirationTime)
Defines life time for the feed in seconds.
Definition: Feed.h:141
void listener(NetFeedListener &listener)
Binds the given listener to the feed.
Definition: Feed.h:165
const NetFeedConnection & connection() const
Connection attributes (read-only access).
Definition: Feed.h:117
void type(NetFeedType::Enum type)
Assigns feed service type.
Definition: Feed.h:93
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68