Vector BLF: File.h Source File

Vector BLF

Loading...
Searching...
No Matches
File.h
1// SPDX-FileCopyrightText: 2013-2021 Tobias Lorenz <tobias.lorenz@gmx.net>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6
7#include <Vector/BLF/platform.h>
8
9#include <atomic>
10#include <fstream>
11#include <thread>
12
13#include <Vector/BLF/CompressedFile.h>
14#include <Vector/BLF/FileStatistics.h>
15#include <Vector/BLF/ObjectHeaderBase.h>
16#include <Vector/BLF/ObjectQueue.h>
17#include <Vector/BLF/RestorePoints.h>
18#include <Vector/BLF/UncompressedFile.h>
19
20// UNKNOWN = 0
21#include <Vector/BLF/CanMessage.h> // CAN_MESSAGE = 1
22#include <Vector/BLF/CanErrorFrame.h> // CAN_ERROR = 2
23#include <Vector/BLF/CanOverloadFrame.h> // CAN_OVERLOAD = 3
24#include <Vector/BLF/CanDriverStatistic.h> // CAN_STATISTIC = 4
25#include <Vector/BLF/AppTrigger.h> // APP_TRIGGER = 5
26#include <Vector/BLF/EnvironmentVariable.h> // ENV_INTEGER = 6
27#include <Vector/BLF/EnvironmentVariable.h> // ENV_DOUBLE = 7
28#include <Vector/BLF/EnvironmentVariable.h> // ENV_STRING = 8
29#include <Vector/BLF/EnvironmentVariable.h> // ENV_DATA = 9
30#include <Vector/BLF/LogContainer.h> // LOG_CONTAINER = 10
31#include <Vector/BLF/LinMessage.h> // LIN_MESSAGE = 11
32#include <Vector/BLF/LinCrcError.h> // LIN_CRC_ERROR = 12
33#include <Vector/BLF/LinDlcInfo.h> // LIN_DLC_INFO = 13
34#include <Vector/BLF/LinReceiveError.h> // LIN_RCV_ERROR = 14
35#include <Vector/BLF/LinSendError.h> // LIN_SND_ERROR = 15
36#include <Vector/BLF/LinSlaveTimeout.h> // LIN_SLV_TIMEOUT = 16
37#include <Vector/BLF/LinSchedulerModeChange.h> // LIN_SCHED_MODCH = 17
38#include <Vector/BLF/LinSyncError.h> // LIN_SYN_ERROR = 18
39#include <Vector/BLF/LinBaudrateEvent.h> // LIN_BAUDRATE = 19
40#include <Vector/BLF/LinSleepModeEvent.h> // LIN_SLEEP = 20
41#include <Vector/BLF/LinWakeupEvent.h> // LIN_WAKEUP = 21
42#include <Vector/BLF/MostSpy.h> // MOST_SPY = 22
43#include <Vector/BLF/MostCtrl.h> // MOST_CTRL = 23
44#include <Vector/BLF/MostLightLock.h> // MOST_LIGHTLOCK = 24
45#include <Vector/BLF/MostStatistic.h> // MOST_STATISTIC = 25
46// Reserved26 = 26
47// Reserved27 = 27
48// Reserved28 = 28
49#include <Vector/BLF/FlexRayData.h> // FLEXRAY_DATA = 29
50#include <Vector/BLF/FlexRaySync.h> // FLEXRAY_SYNC = 30
51#include <Vector/BLF/CanDriverError.h> // CAN_DRIVER_ERROR = 31
52#include <Vector/BLF/MostPkt.h> // MOST_PKT = 32
53#include <Vector/BLF/MostPkt2.h> // MOST_PKT2 = 33
54#include <Vector/BLF/MostHwMode.h> // MOST_HWMODE = 34
55#include <Vector/BLF/MostReg.h> // MOST_REG = 35
56#include <Vector/BLF/MostGenReg.h> // MOST_GENREG = 36
57#include <Vector/BLF/MostNetState.h> // MOST_NETSTATE = 37
58#include <Vector/BLF/MostDataLost.h> // MOST_DATALOST = 38
59#include <Vector/BLF/MostTrigger.h> // MOST_TRIGGER = 39
60#include <Vector/BLF/FlexRayV6StartCycleEvent.h> // FLEXRAY_CYCLE = 40
61#include <Vector/BLF/FlexRayV6Message.h> // FLEXRAY_MESSAGE = 41
62#include <Vector/BLF/LinChecksumInfo.h> // LIN_CHECKSUM_INFO = 42
63#include <Vector/BLF/LinSpikeEvent.h> // LIN_SPIKE_EVENT = 43
64#include <Vector/BLF/CanDriverHwSync.h> // CAN_DRIVER_SYNC = 44
65#include <Vector/BLF/FlexRayStatusEvent.h> // FLEXRAY_STATUS = 45
66#include <Vector/BLF/GpsEvent.h> // GPS_EVENT = 46
67#include <Vector/BLF/FlexRayVFrError.h> // FR_ERROR = 47
68#include <Vector/BLF/FlexRayVFrStatus.h> // FR_STATUS = 48
69#include <Vector/BLF/FlexRayVFrStartCycle.h> // FR_STARTCYCLE = 49
70#include <Vector/BLF/FlexRayVFrReceiveMsg.h> // FR_RCVMESSAGE = 50
71#include <Vector/BLF/RealtimeClock.h> // REALTIMECLOCK = 51
72// Reserved52 = 52
73// Reserved53 = 53
74#include <Vector/BLF/LinStatisticEvent.h> // LIN_STATISTIC = 54
75#include <Vector/BLF/J1708Message.h> // J1708_MESSAGE = 55
76#include <Vector/BLF/J1708Message.h> // J1708_VIRTUAL_MSG = 56
77#include <Vector/BLF/LinMessage2.h> // LIN_MESSAGE2 = 57
78#include <Vector/BLF/LinSendError2.h> // LIN_SND_ERROR2 = 58
79#include <Vector/BLF/LinSyncError2.h> // LIN_SYN_ERROR2 = 59
80#include <Vector/BLF/LinCrcError2.h> // LIN_CRC_ERROR2 = 60
81#include <Vector/BLF/LinReceiveError2.h> // LIN_RCV_ERROR2 = 61
82#include <Vector/BLF/LinWakeupEvent2.h> // LIN_WAKEUP2 = 62
83#include <Vector/BLF/LinSpikeEvent2.h> // LIN_SPIKE_EVENT2 = 63
84#include <Vector/BLF/LinLongDomSignalEvent.h> // LIN_LONG_DOM_SIG = 64
85#include <Vector/BLF/AppText.h> // APP_TEXT = 65
86#include <Vector/BLF/FlexRayVFrReceiveMsgEx.h> // FR_RCVMESSAGE_EX = 66
87#include <Vector/BLF/MostStatisticEx.h> // MOST_STATISTICEX = 67
88#include <Vector/BLF/MostTxLight.h> // MOST_TXLIGHT = 68
89#include <Vector/BLF/MostAllocTab.h> // MOST_ALLOCTAB = 69
90#include <Vector/BLF/MostStress.h> // MOST_STRESS = 70
91#include <Vector/BLF/EthernetFrame.h> // ETHERNET_FRAME = 71
92#include <Vector/BLF/SystemVariable.h> // SYS_VARIABLE = 72
93#include <Vector/BLF/CanErrorFrameExt.h> // CAN_ERROR_EXT = 73
94#include <Vector/BLF/CanDriverErrorExt.h> // CAN_DRIVER_ERROR_EXT = 74
95#include <Vector/BLF/LinLongDomSignalEvent2.h> // LIN_LONG_DOM_SIG2 = 75
96#include <Vector/BLF/Most150Message.h> // MOST_150_MESSAGE = 76
97#include <Vector/BLF/Most150Pkt.h> // MOST_150_PKT = 77
98#include <Vector/BLF/MostEthernetPkt.h> // MOST_ETHERNET_PKT = 78
99#include <Vector/BLF/Most150MessageFragment.h> // MOST_150_MESSAGE_FRAGMENT = 79
100#include <Vector/BLF/Most150PktFragment.h> // MOST_150_PKT_FRAGMENT = 80
101#include <Vector/BLF/MostEthernetPktFragment.h> // MOST_ETHERNET_PKT_FRAGMENT = 81
102#include <Vector/BLF/MostSystemEvent.h> // MOST_SYSTEM_EVENT = 82
103#include <Vector/BLF/Most150AllocTab.h> // MOST_150_ALLOCTAB = 83
104#include <Vector/BLF/Most50Message.h> // MOST_50_MESSAGE = 84
105#include <Vector/BLF/Most50Pkt.h> // MOST_50_PKT = 85
106#include <Vector/BLF/CanMessage2.h> // CAN_MESSAGE2 = 86
107#include <Vector/BLF/LinUnexpectedWakeup.h> // LIN_UNEXPECTED_WAKEUP = 87
108#include <Vector/BLF/LinShortOrSlowResponse.h> // LIN_SHORT_OR_SLOW_RESPONSE = 88
109#include <Vector/BLF/LinDisturbanceEvent.h> // LIN_DISTURBANCE_EVENT = 89
110#include <Vector/BLF/SerialEvent.h> // SERIAL_EVENT = 90
111#include <Vector/BLF/DriverOverrun.h> // OVERRUN_ERROR = 91
112#include <Vector/BLF/EventComment.h> // EVENT_COMMENT = 92
113#include <Vector/BLF/WlanFrame.h> // WLAN_FRAME = 93
114#include <Vector/BLF/WlanStatistic.h> // WLAN_STATISTIC = 94
115#include <Vector/BLF/MostEcl.h> // MOST_ECL = 95
116#include <Vector/BLF/GlobalMarker.h> // GLOBAL_MARKER = 96
117#include <Vector/BLF/AfdxFrame.h> // AFDX_FRAME = 97
118#include <Vector/BLF/AfdxStatistic.h> // AFDX_STATISTIC = 98
119#include <Vector/BLF/KLineStatusEvent.h> // KLINE_STATUSEVENT = 99
120#include <Vector/BLF/CanFdMessage.h> // CAN_FD_MESSAGE = 100
121#include <Vector/BLF/CanFdMessage64.h> // CAN_FD_MESSAGE_64 = 101
122#include <Vector/BLF/EthernetRxError.h> // ETHERNET_RX_ERROR = 102
123#include <Vector/BLF/EthernetStatus.h> // ETHERNET_STATUS = 103
124#include <Vector/BLF/CanFdErrorFrame64.h> // CAN_FD_ERROR_64 = 104
125#include <Vector/BLF/LinShortOrSlowResponse2.h> // LIN_SHORT_OR_SLOW_RESPONSE2 = 105
126#include <Vector/BLF/AfdxStatus.h> // AFDX_STATUS = 106
127#include <Vector/BLF/AfdxBusStatistic.h> // AFDX_BUS_STATISTIC = 107
128// Reserved108 = 108
129#include <Vector/BLF/AfdxErrorEvent.h> // AFDX_ERROR_EVENT = 109
130#include <Vector/BLF/A429Error.h> // A429_ERROR = 110
131#include <Vector/BLF/A429Status.h> // A429_STATUS = 111
132#include <Vector/BLF/A429BusStatistic.h> // A429_BUS_STATISTIC = 112
133#include <Vector/BLF/A429Message.h> // A429_MESSAGE = 113
134#include <Vector/BLF/EthernetStatistic.h> // ETHERNET_STATISTIC = 114
135#include <Vector/BLF/RestorePointContainer.h> // Unknown115 = 115
136// Reserved116 = 116
137// Reserved117 = 117
138#include <Vector/BLF/TestStructure.h> // TEST_STRUCTURE = 118
139#include <Vector/BLF/DiagRequestInterpretation.h> // DIAG_REQUEST_INTERPRETATION = 119
140#include <Vector/BLF/EthernetFrameEx.h> // ETHERNET_FRAME_EX = 120
141#include <Vector/BLF/EthernetFrameForwarded.h> // ETHERNET_FRAME_FORWARDED = 121
142#include <Vector/BLF/EthernetErrorEx.h> // ETHERNET_ERROR_EX = 122
143#include <Vector/BLF/EthernetErrorForwarded.h> // ETHERNET_ERROR_FORWARDED = 123
144#include <Vector/BLF/FunctionBus.h> // FUNCTION_BUS = 124
145#include <Vector/BLF/DataLostBegin.h> // DATA_LOST_BEGIN = 125
146#include <Vector/BLF/DataLostEnd.h> // DATA_LOST_END = 126
147#include <Vector/BLF/WaterMarkEvent.h> // WATER_MARK_EVENT = 127
148#include <Vector/BLF/TriggerCondition.h> // TRIGGER_CONDITION = 128
149#include <Vector/BLF/CanSettingChanged.h> // CAN_SETTING_CHANGED = 129
150#include <Vector/BLF/DistributedObjectMember.h> // DISTRIBUTED_OBJECT_MEMBER = 130
151#include <Vector/BLF/AttributeEvent.h> // ATTRIBUTE_EVENT = 131
152
153#include <Vector/BLF/vector_blf_export.h>
154
155namespace Vector {
156namespace BLF {
157
163 class VECTOR_BLF_EXPORT File final {
164 public:
165 File();
166 virtual ~File();
167
171 FileStatistics fileStatistics {};
172
178 uint64_t currentUncompressedFileSize {};
179
185 std::atomic<uint32_t> currentObjectCount {};
186
200 int compressionLevel {1};
201
205 bool writeRestorePoints {true};
206
213 virtual void open(const char * filename, const std::ios_base::openmode mode = std::ios_base::in);
214
221 virtual void open(const std::string & filename, const std::ios_base::openmode mode = std::ios_base::in);
222
228 virtual bool is_open() const;
229
235 virtual bool good() const;
236
242 virtual bool eof() const;
243
254 virtual ObjectHeaderBase * read();
255
266 virtual void write(ObjectHeaderBase * ohb);
267
271 virtual void close();
272
278 virtual uint32_t defaultLogContainerSize() const;
279
285 virtual void setDefaultLogContainerSize(uint32_t defaultLogContainerSize);
286
293 static ObjectHeaderBase * createObject(ObjectType type);
294
295 private:
299 std::ios_base::openmode m_openMode {};
300
301 /* read/write queue */
302
313 ObjectQueue<ObjectHeaderBase> m_readWriteQueue {};
314
315 /* uncompressed file */
316
324 UncompressedFile m_uncompressedFile {};
325
329 std::thread m_uncompressedFileThread {};
330
334 std::exception_ptr m_uncompressedFileThreadException {nullptr};
335
339 std::atomic<bool> m_uncompressedFileThreadRunning {};
340
341 /* compressed file */
342
350 CompressedFile m_compressedFile {};
351
355 std::thread m_compressedFileThread {};
356
360 std::exception_ptr m_compressedFileThreadException {nullptr};
361
365 std::atomic<bool> m_compressedFileThreadRunning {};
366
367 /* internal functions */
368
372 void uncompressedFile2ReadWriteQueue();
373
377 void readWriteQueue2UncompressedFile();
378
382 void compressedFile2UncompressedFile();
383
387 void uncompressedFile2CompressedFile();
388
392 static void uncompressedFileReadThread(File * file);
393
397 static void uncompressedFileWriteThread(File * file);
398
402 static void compressedFileReadThread(File * file);
403
407 static void compressedFileWriteThread(File * file);
408};
409
410}
411}
Vector::BLF::File
Definition File.h:163
Vector::BLF::FileStatistics
Definition FileStatistics.h:104
Vector::BLF::ObjectHeaderBase
Base object header type definition.
Definition ObjectHeaderBase.h:166