OnixS C++ Eurex T7 Market and Reference Data (EMDI, MDI, RDI, EOBI) Handlers  16.0.1
API documentation
Replay.h
Go to the documentation of this file.
1 // Copyright 2005-2012 Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
4 // and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable ONIXS Software
7 // Services Agreement (the Agreement) and Customer end user license agreements granting
8 // a non-assignable, non-transferable and non-exclusive license to use the software
9 // for it's own data processing purposes under the terms defined in the Agreement.
10 //
11 // Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
12 // of this source code or associated reference material to any other location for further reproduction
13 // or redistribution, and any amendments to this copyright notice, are expressly prohibited.
14 //
15 // Any reproduction or redistribution for sale or hiring of the Software not in accordance with
16 // the terms of the Agreement is a violation of copyright law.
17 //
18 
19 #pragma once
20 
21 #include <string>
22 #include <vector>
23 
26 
27 namespace OnixS
28 {
29  namespace Eurex
30  {
31  namespace MarketData
32  {
33  namespace Implementation { struct PcapPeplayHelper; }
34 
35  /// @typedef FilesList
36  /// Ordered list of files to be replayed.
37  typedef std::vector<std::string> FilesList;
38 
39  /// Listening interface for log replay-related events.
40  class ONIXS_EUREX_EMDI_API ReplayListener
41  {
42  public:
43  /// Is called once error occurs while replaying.
44  virtual void onReplayError (const std::string& errorDescription) = 0;
45 
46  /// Is called once the replay is finished
47  virtual void onReplayFinished() = 0;
48 
49  protected:
50  /// Deletion is not supposed
51  /// through interface of this class.
52  virtual ~ReplayListener();
53  };
54 
55  /// Logging options.
56  struct ONIXS_EUREX_EMDI_API ReplayMode
57  {
58  enum Enum
59  {
60  /// The packets are replayed with constant delay, defined by ReplayOptions::packetReplayDelay
61  /// Timestamps from the replayed file are ignored
62  /// ReplayOptions::playSpeedMultiplier is ignored
63  ConstantPacketReplayDelay = 1,
64 
65  /// The packets are replayed with delays as it come from the replayed file.
66  /// FinalDelay = LogFileDelay * ReplayOptions::playSpeedMultiplier + ReplayOptions::packetReplayDelay
67  NaturalPacketReplayDelay = 2
68  };
69  };
70 
71  /// Gathers files which are stored in a given folder.
72  void ONIXS_EUREX_EMDI_API gatherFiles(FilesList* gatheredFiles, const std::string& root, const std::string& extension);
73 
74  /// Gathers log files which are stored in a given folder.
75  inline
76  void gatherLogs(FilesList* gatheredLogs, const std::string& root)
77  {
78  gatherFiles(gatheredLogs, root, ".log");
79  }
80 
81  /// Defines params which affect replay.
83  {
84  /// List of files to be replayed.
85  /// Must be stored in 'oldest to recent' order.
86  FilesList logs;
87 
88  /// Instance to notify about replay events.
90 
91  /// Specifies the time delay (milliseconds) between replayed packets.
92  ///
93  /// @note Ability to control replay rate. The default value is 0 milliseconds.
94  unsigned int packetReplayDelay;
95 
96  /// Replay multiplier. Used only in ReplayMode::NaturalPacketReplayDelay
97  /// The default value is 1
99 
100  /// Replay mode. The default value is ReplayMode::ConstantPacketReplayDelay
102 
103  /// Initializes instance with default values.
105  : listener(defaultReplayListener())
106  , packetReplayDelay(0)
107  , playSpeedMultiplier(1)
108  , replayMode(ReplayMode::ConstantPacketReplayDelay)
109  {
110  }
111 
112  /// Initializes with all the files which are available and stored in a given folder.
113  explicit
114  ReplayOptions (const std::string& filesRoot, const std::string& filesExtention = ".log")
115  : listener(defaultReplayListener())
116  , packetReplayDelay(0)
117  , playSpeedMultiplier(1)
118  , replayMode(ReplayMode::ConstantPacketReplayDelay)
119  {
120  gatherFiles(&logs, filesRoot, filesExtention);
121  }
122 
123  private:
124  ONIXS_EUREX_EMDI_API static ReplayListener* defaultReplayListener();
125  };
126 
127  /// Set the `ReplayOptions` to run the replay at maximal speed.
128  struct ONIXS_EUREX_EMDI_API NoDelayReplay : public ReplayOptions
129  {
130  /// Initializes with all the files which are available and stored in a given folder.
131  explicit NoDelayReplay(const std::string& filesRoot, const std::string& filesExtention = ".log");
132 
133  /// Initializes instance with default values.
134  NoDelayReplay();
135  };
136 
137  /// Set the `ReplayOptions` to run the replay with the original speed.
138  struct ONIXS_EUREX_EMDI_API OriginalDelayReplay : public ReplayOptions
139  {
140  /// Initializes with all the files which are available and stored in a given folder.
141  explicit OriginalDelayReplay(const std::string& filesRoot, const std::string& filesExtention = ".log");
142 
143  /// Initializes instance with default values.
144  OriginalDelayReplay();
145  };
146 
147  /// Set the `ReplayOptions` to replay the data two times faster than recorded.
148  struct ONIXS_EUREX_EMDI_API X2SpeedReplay : public ReplayOptions
149  {
150  /// Initializes with all the files which are available and stored in a given folder.
151  explicit X2SpeedReplay(const std::string& filesRoot, const std::string& filesExtention = ".log");
152 
153  /// Initializes instance with default values.
154  X2SpeedReplay();
155  };
156 
157 
158  inline
159  NoDelayReplay::NoDelayReplay(const std::string& filesRoot, const std::string& filesExtention)
160  : ReplayOptions(filesRoot, filesExtention)
161  {
163  packetReplayDelay = 0;
165  }
166 
167  inline
169  {
171  packetReplayDelay = 0;
173  }
174 
175  inline
176  OriginalDelayReplay::OriginalDelayReplay(const std::string& filesRoot, const std::string& filesExtention)
177  : ReplayOptions(filesRoot, filesExtention)
178  {
180  packetReplayDelay = 0;
182  }
183 
184  inline
186  {
188  packetReplayDelay = 0;
190  }
191 
192  inline
193  X2SpeedReplay::X2SpeedReplay (const std::string& filesRoot, const std::string& filesExtention)
194  : ReplayOptions(filesRoot, filesExtention)
195  {
197  packetReplayDelay = 0;
199  }
200 
201  inline
203  {
205  packetReplayDelay = 0;
207  }
208  }
209  }
210 }
Set the ReplayOptions to run the replay at maximal speed.
Definition: Replay.h:128
X2SpeedReplay()
Initializes instance with default values.
Definition: Replay.h:202
OriginalDelayReplay()
Initializes instance with default values.
Definition: Replay.h:185
NoDelayReplay()
Initializes instance with default values.
Definition: Replay.h:168
void gatherFiles(FilesList *gatheredFiles, const std::string &root, const std::string &extension)
Gathers files which are stored in a given folder.
Definition: Defines.h:30
ReplayMode::Enum replayMode
Replay mode. The default value is ReplayMode::ConstantPacketReplayDelay.
Definition: Replay.h:101
Defines params which affect replay.
Definition: Replay.h:82
Set the ReplayOptions to replay the data two times faster than recorded.
Definition: Replay.h:148
std::vector< std::string > FilesList
Definition: Replay.h:37
ReplayOptions(const std::string &filesRoot, const std::string &filesExtention=".log")
Initializes with all the files which are available and stored in a given folder.
Definition: Replay.h:114
ReplayOptions()
Initializes instance with default values.
Definition: Replay.h:104
ReplayListener * listener
Instance to notify about replay events.
Definition: Replay.h:89
Listening interface for log replay-related events.
Definition: Replay.h:40
void gatherLogs(FilesList *gatheredLogs, const std::string &root)
Gathers log files which are stored in a given folder.
Definition: Replay.h:76
Set the ReplayOptions to run the replay with the original speed.
Definition: Replay.h:138