Vector BLF
File.h
1 /*
2  * Copyright (C) 2013 Tobias Lorenz.
3  * Contact: tobias.lorenz@gmx.net
4  *
5  * This file is part of Tobias Lorenz's Toolkit.
6  *
7  * Commercial License Usage
8  * Licensees holding valid commercial licenses may use this file in
9  * accordance with the commercial license agreement provided with the
10  * Software or, alternatively, in accordance with the terms contained in
11  * a written agreement between you and Tobias Lorenz.
12  *
13  * GNU General Public License 3.0 Usage
14  * Alternatively, this file may be used under the terms of the GNU
15  * General Public License version 3.0 as published by the Free Software
16  * Foundation and appearing in the file LICENSE.GPL included in the
17  * packaging of this file. Please review the following information to
18  * ensure the GNU General Public License version 3.0 requirements will be
19  * met: http://www.gnu.org/copyleft/gpl.html.
20  */
21 
22 #pragma once
23 
24 #include <Vector/BLF/platform.h>
25 
26 #include <atomic>
27 #include <fstream>
28 #include <thread>
29 
30 #include <Vector/BLF/CompressedFile.h>
31 #include <Vector/BLF/FileStatistics.h>
32 #include <Vector/BLF/ObjectHeaderBase.h>
33 #include <Vector/BLF/ObjectQueue.h>
34 #include <Vector/BLF/UncompressedFile.h>
35 #include <Vector/BLF/VectorTypes.h>
36 
37 // UNKNOWN = 0
38 #include <Vector/BLF/CanMessage.h> // CAN_MESSAGE = 1
39 #include <Vector/BLF/CanErrorFrame.h> // CAN_ERROR = 2
40 #include <Vector/BLF/CanOverloadFrame.h> // CAN_OVERLOAD = 3
41 #include <Vector/BLF/CanDriverStatistic.h> // CAN_STATISTIC = 4
42 #include <Vector/BLF/AppTrigger.h> // APP_TRIGGER = 5
43 #include <Vector/BLF/EnvironmentVariable.h> // ENV_INTEGER = 6
44 #include <Vector/BLF/EnvironmentVariable.h> // ENV_DOUBLE = 7
45 #include <Vector/BLF/EnvironmentVariable.h> // ENV_STRING = 8
46 #include <Vector/BLF/EnvironmentVariable.h> // ENV_DATA = 9
47 #include <Vector/BLF/LogContainer.h> // LOG_CONTAINER = 10
48 #include <Vector/BLF/LinMessage.h> // LIN_MESSAGE = 11
49 #include <Vector/BLF/LinCrcError.h> // LIN_CRC_ERROR = 12
50 #include <Vector/BLF/LinDlcInfo.h> // LIN_DLC_INFO = 13
51 #include <Vector/BLF/LinReceiveError.h> // LIN_RCV_ERROR = 14
52 #include <Vector/BLF/LinSendError.h> // LIN_SND_ERROR = 15
53 #include <Vector/BLF/LinSlaveTimeout.h> // LIN_SLV_TIMEOUT = 16
54 #include <Vector/BLF/LinSchedulerModeChange.h> // LIN_SCHED_MODCH = 17
55 #include <Vector/BLF/LinSyncError.h> // LIN_SYN_ERROR = 18
56 #include <Vector/BLF/LinBaudrateEvent.h> // LIN_BAUDRATE = 19
57 #include <Vector/BLF/LinSleepModeEvent.h> // LIN_SLEEP = 20
58 #include <Vector/BLF/LinWakeupEvent.h> // LIN_WAKEUP = 21
59 #include <Vector/BLF/MostSpy.h> // MOST_SPY = 22
60 #include <Vector/BLF/MostCtrl.h> // MOST_CTRL = 23
61 #include <Vector/BLF/MostLightLock.h> // MOST_LIGHTLOCK = 24
62 #include <Vector/BLF/MostStatistic.h> // MOST_STATISTIC = 25
63 // Reserved26 = 26
64 // Reserved27 = 27
65 // Reserved28 = 28
66 #include <Vector/BLF/FlexRayData.h> // FLEXRAY_DATA = 29
67 #include <Vector/BLF/FlexRaySync.h> // FLEXRAY_SYNC = 30
68 #include <Vector/BLF/CanDriverError.h> // CAN_DRIVER_ERROR = 31
69 #include <Vector/BLF/MostPkt.h> // MOST_PKT = 32
70 #include <Vector/BLF/MostPkt2.h> // MOST_PKT2 = 33
71 #include <Vector/BLF/MostHwMode.h> // MOST_HWMODE = 34
72 #include <Vector/BLF/MostReg.h> // MOST_REG = 35
73 #include <Vector/BLF/MostGenReg.h> // MOST_GENREG = 36
74 #include <Vector/BLF/MostNetState.h> // MOST_NETSTATE = 37
75 #include <Vector/BLF/MostDataLost.h> // MOST_DATALOST = 38
76 #include <Vector/BLF/MostTrigger.h> // MOST_TRIGGER = 39
77 #include <Vector/BLF/FlexRayV6StartCycleEvent.h> // FLEXRAY_CYCLE = 40
78 #include <Vector/BLF/FlexRayV6Message.h> // FLEXRAY_MESSAGE = 41
79 #include <Vector/BLF/LinChecksumInfo.h> // LIN_CHECKSUM_INFO = 42
80 #include <Vector/BLF/LinSpikeEvent.h> // LIN_SPIKE_EVENT = 43
81 #include <Vector/BLF/CanDriverHwSync.h> // CAN_DRIVER_SYNC = 44
82 #include <Vector/BLF/FlexRayStatusEvent.h> // FLEXRAY_STATUS = 45
83 #include <Vector/BLF/GpsEvent.h> // GPS_EVENT = 46
84 #include <Vector/BLF/FlexRayVFrError.h> // FR_ERROR = 47
85 #include <Vector/BLF/FlexRayVFrStatus.h> // FR_STATUS = 48
86 #include <Vector/BLF/FlexRayVFrStartCycle.h> // FR_STARTCYCLE = 49
87 #include <Vector/BLF/FlexRayVFrReceiveMsg.h> // FR_RCVMESSAGE = 50
88 #include <Vector/BLF/RealtimeClock.h> // REALTIMECLOCK = 51
89 // Reserved52 = 52
90 // Reserved53 = 53
91 #include <Vector/BLF/LinStatisticEvent.h> // LIN_STATISTIC = 54
92 #include <Vector/BLF/J1708Message.h> // J1708_MESSAGE = 55
93 #include <Vector/BLF/J1708Message.h> // J1708_VIRTUAL_MSG = 56
94 #include <Vector/BLF/LinMessage2.h> // LIN_MESSAGE2 = 57
95 #include <Vector/BLF/LinSendError2.h> // LIN_SND_ERROR2 = 58
96 #include <Vector/BLF/LinSyncError2.h> // LIN_SYN_ERROR2 = 59
97 #include <Vector/BLF/LinCrcError2.h> // LIN_CRC_ERROR2 = 60
98 #include <Vector/BLF/LinReceiveError2.h> // LIN_RCV_ERROR2 = 61
99 #include <Vector/BLF/LinWakeupEvent2.h> // LIN_WAKEUP2 = 62
100 #include <Vector/BLF/LinSpikeEvent2.h> // LIN_SPIKE_EVENT2 = 63
101 #include <Vector/BLF/LinLongDomSignalEvent.h> // LIN_LONG_DOM_SIG = 64
102 #include <Vector/BLF/AppText.h> // APP_TEXT = 65
103 #include <Vector/BLF/FlexRayVFrReceiveMsgEx.h> // FR_RCVMESSAGE_EX = 66
104 #include <Vector/BLF/MostStatisticEx.h> // MOST_STATISTICEX = 67
105 #include <Vector/BLF/MostTxLight.h> // MOST_TXLIGHT = 68
106 #include <Vector/BLF/MostAllocTab.h> // MOST_ALLOCTAB = 69
107 #include <Vector/BLF/MostStress.h> // MOST_STRESS = 70
108 #include <Vector/BLF/EthernetFrame.h> // ETHERNET_FRAME = 71
109 #include <Vector/BLF/SystemVariable.h> // SYS_VARIABLE = 72
110 #include <Vector/BLF/CanErrorFrameExt.h> // CAN_ERROR_EXT = 73
111 #include <Vector/BLF/CanDriverErrorExt.h> // CAN_DRIVER_ERROR_EXT = 74
112 #include <Vector/BLF/LinLongDomSignalEvent2.h> // LIN_LONG_DOM_SIG2 = 75
113 #include <Vector/BLF/Most150Message.h> // MOST_150_MESSAGE = 76
114 #include <Vector/BLF/Most150Pkt.h> // MOST_150_PKT = 77
115 #include <Vector/BLF/MostEthernetPkt.h> // MOST_ETHERNET_PKT = 78
116 #include <Vector/BLF/Most150MessageFragment.h> // MOST_150_MESSAGE_FRAGMENT = 79
117 #include <Vector/BLF/Most150PktFragment.h> // MOST_150_PKT_FRAGMENT = 80
118 #include <Vector/BLF/MostEthernetPktFragment.h> // MOST_ETHERNET_PKT_FRAGMENT = 81
119 #include <Vector/BLF/MostSystemEvent.h> // MOST_SYSTEM_EVENT = 82
120 #include <Vector/BLF/Most150AllocTab.h> // MOST_150_ALLOCTAB = 83
121 #include <Vector/BLF/Most50Message.h> // MOST_50_MESSAGE = 84
122 #include <Vector/BLF/Most50Pkt.h> // MOST_50_PKT = 85
123 #include <Vector/BLF/CanMessage2.h> // CAN_MESSAGE2 = 86
124 #include <Vector/BLF/LinUnexpectedWakeup.h> // LIN_UNEXPECTED_WAKEUP = 87
125 #include <Vector/BLF/LinShortOrSlowResponse.h> // LIN_SHORT_OR_SLOW_RESPONSE = 88
126 #include <Vector/BLF/LinDisturbanceEvent.h> // LIN_DISTURBANCE_EVENT = 89
127 #include <Vector/BLF/SerialEvent.h> // SERIAL_EVENT = 90
128 #include <Vector/BLF/DriverOverrun.h> // OVERRUN_ERROR = 91
129 #include <Vector/BLF/EventComment.h> // EVENT_COMMENT = 92
130 #include <Vector/BLF/WlanFrame.h> // WLAN_FRAME = 93
131 #include <Vector/BLF/WlanStatistic.h> // WLAN_STATISTIC = 94
132 #include <Vector/BLF/MostEcl.h> // MOST_ECL = 95
133 #include <Vector/BLF/GlobalMarker.h> // GLOBAL_MARKER = 96
134 #include <Vector/BLF/AfdxFrame.h> // AFDX_FRAME = 97
135 #include <Vector/BLF/AfdxStatistic.h> // AFDX_STATISTIC = 98
136 #include <Vector/BLF/KLineStatusEvent.h> // KLINE_STATUSEVENT = 99
137 #include <Vector/BLF/CanFdMessage.h> // CAN_FD_MESSAGE = 100
138 #include <Vector/BLF/CanFdMessage64.h> // CAN_FD_MESSAGE_64 = 101
139 #include <Vector/BLF/EthernetRxError.h> // ETHERNET_RX_ERROR = 102
140 #include <Vector/BLF/EthernetStatus.h> // ETHERNET_STATUS = 103
141 #include <Vector/BLF/CanFdErrorFrame64.h> // CAN_FD_ERROR_64 = 104
142 #include <Vector/BLF/LinShortOrSlowResponse2.h> // LIN_SHORT_OR_SLOW_RESPONSE2 = 105
143 #include <Vector/BLF/AfdxStatus.h> // AFDX_STATUS = 106
144 #include <Vector/BLF/AfdxBusStatistic.h> // AFDX_BUS_STATISTIC = 107
145 // Reserved108 = 108
146 #include <Vector/BLF/AfdxErrorEvent.h> // AFDX_ERROR_EVENT = 109
147 #include <Vector/BLF/A429Error.h> // A429_ERROR = 110
148 #include <Vector/BLF/A429Status.h> // A429_STATUS = 111
149 #include <Vector/BLF/A429BusStatistic.h> // A429_BUS_STATISTIC = 112
150 #include <Vector/BLF/A429Message.h> // A429_MESSAGE = 113
151 #include <Vector/BLF/EthernetStatistic.h> // ETHERNET_STATISTIC = 114
152 #include <Vector/BLF/Unknown115.h> // Unknown115 = 115
153 // Reserved116 = 116
154 // Reserved117 = 117
155 #include <Vector/BLF/TestStructure.h> // TEST_STRUCTURE = 118
156 #include <Vector/BLF/DiagRequestInterpretation.h> // DIAG_REQUEST_INTERPRETATION = 119
157 #include <Vector/BLF/EthernetFrameEx.h> // ETHERNET_FRAME_EX = 120
158 #include <Vector/BLF/EthernetFrameForwarded.h> // ETHERNET_FRAME_FORWARDED = 121
159 #include <Vector/BLF/EthernetErrorEx.h> // ETHERNET_ERROR_EX = 122
160 #include <Vector/BLF/EthernetErrorForwarded.h> // ETHERNET_ERROR_FORWARDED = 123
161 #include <Vector/BLF/FunctionBus.h> // FUNCTION_BUS = 124
162 #include <Vector/BLF/DataLostBegin.h> // DATA_LOST_BEGIN = 125
163 #include <Vector/BLF/DataLostEnd.h> // DATA_LOST_END = 126
164 #include <Vector/BLF/WaterMarkEvent.h> // WATER_MARK_EVENT = 127
165 #include <Vector/BLF/TriggerCondition.h> // TRIGGER_CONDITION = 128
166 
167 #include <Vector/BLF/vector_blf_export.h>
168 
169 namespace Vector {
170 namespace BLF {
171 
177 class VECTOR_BLF_EXPORT File final {
178  public:
179  File();
180  virtual ~File();
181 
185  FileStatistics fileStatistics {};
186 
192  ULONGLONG currentUncompressedFileSize {};
193 
199  std::atomic<DWORD> currentObjectCount {};
200 
204  int compressionLevel {6};
205 
209  bool writeUnknown115 {true};
210 
217  virtual void open(const char * filename, const std::ios_base::openmode mode = std::ios_base::in);
218 
225  virtual void open(const std::string & filename, const std::ios_base::openmode mode = std::ios_base::in);
226 
232  virtual bool is_open() const;
233 
239  virtual bool good() const;
240 
246  virtual bool eof() const;
247 
258  virtual ObjectHeaderBase * read();
259 
270  virtual void write(ObjectHeaderBase * ohb);
271 
275  virtual void close();
276 
282  virtual DWORD defaultLogContainerSize() const;
283 
289  virtual void setDefaultLogContainerSize(DWORD defaultLogContainerSize);
290 
297  static ObjectHeaderBase * createObject(ObjectType type);
298 
299  private:
303  std::ios_base::openmode m_openMode {};
304 
305  /* read/write queue */
306 
317  ObjectQueue<ObjectHeaderBase> m_readWriteQueue {};
318 
319  /* uncompressed file */
320 
328  UncompressedFile m_uncompressedFile {};
329 
333  std::thread m_uncompressedFileThread {};
334 
338  std::atomic<bool> m_uncompressedFileThreadRunning {};
339 
340  /* compressed file */
341 
349  CompressedFile m_compressedFile {};
350 
354  std::thread m_compressedFileThread {};
355 
359  std::atomic<bool> m_compressedFileThreadRunning {};
360 
361  /* internal functions */
362 
366  void uncompressedFile2ReadWriteQueue();
367 
371  void readWriteQueue2UncompressedFile();
372 
376  void compressedFile2UncompressedFile();
377 
381  void uncompressedFile2CompressedFile();
382 
386  static void uncompressedFileReadThread(File * file);
387 
391  static void uncompressedFileWriteThread(File * file);
392 
396  static void compressedFileReadThread(File * file);
397 
401  static void compressedFileWriteThread(File * file);
402 };
403 
404 }
405 }
Definition: File.h:177
Definition: FileStatistics.h:79
Base object header type definition.
Definition: ObjectHeaderBase.h:179