F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
BufferLogger.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title BufferLogger.hpp
3 // \author bocchino, dinkel, mereweth
4 // \brief Svc Buffer Logger interface
5 //
6 // \copyright
7 // Copyright (C) 2015-2017 California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 #ifndef Svc_BufferLogger_HPP
14 #define Svc_BufferLogger_HPP
15 
17 #include "Os/File.hpp"
18 #include "Fw/Types/String.hpp"
19 #include "Fw/Types/Assert.hpp"
20 #include "Os/Mutex.hpp"
21 #include "Utils/Hash/Hash.hpp"
22 
23 namespace Svc {
24 
25 // Forward declaration for UTs
26  namespace Logging {
27  class CloseFileTester;
28  class SendBuffersTester;
29  class OnOffTester;
30  }
31  namespace Errors {
32  class BufferLoggerTester;
33  }
34 
35 
36  class BufferLogger final :
38  {
39 
40  friend class BufferLoggerTester;
45 
46  private:
47 
48  // ----------------------------------------------------------------------
49  // Types
50  // ----------------------------------------------------------------------
51 
53  class File {
54 
55  friend class BufferLoggerTester;
56  friend class Svc::Logging::CloseFileTester;
57  friend class Svc::Logging::SendBuffersTester;
58  friend class Svc::Logging::OnOffTester;
59  friend class Svc::Errors::BufferLoggerTester;
60 
61  public:
62 
64  struct Mode {
65  typedef enum {
66  CLOSED = 0,
67  OPEN = 1
68  } t;
69  };
70 
71  public:
72 
74  File(
75  BufferLogger& bufferLogger
76  );
77 
79  ~File();
80 
81  public:
82 
84  void init(
85  const char *const prefix,
86  const char *const suffix,
87  const FwSizeType maxSize,
88  const U8 sizeOfSize
89  );
90 
92  void setBaseName(
93  const Fw::StringBase& baseName
94  );
95 
97  void logBuffer(
98  const U8 *const data,
99  const FwSizeType size
100  );
101 
103  void closeAndEmitEvent();
104 
106  bool flush();
107 
108  private:
109 
111  void open();
112 
115  bool writeBuffer(
116  const U8 *const data,
117  const FwSizeType size
118  );
119 
122  bool writeSize(
123  const FwSizeType size
124  );
125 
128  bool writeBytes(
129  const void *const data,
130  const FwSizeType length
131  );
132 
134  void writeHashFile();
135 
137  void close();
138 
139  private:
140 
142  BufferLogger& m_bufferLogger;
143 
145  Fw::String m_prefix;
146 
148  Fw::String m_suffix;
149 
151  Fw::String m_baseName;
152 
154  FwSizeType m_fileCounter;
155 
157  FwSizeType m_maxSize;
158 
160  U8 m_sizeOfSize;
161 
163  Fw::String m_name;
164 
165  // The current mode
166  Mode::t m_mode;
167 
169  Os::File m_osFile;
170 
172  FwSizeType m_bytesWritten;
173 
174  }; // class File
175 
176  public:
177 
178  // ----------------------------------------------------------------------
179  // Construction, initialization, and destruction
180  // ----------------------------------------------------------------------
181 
183  BufferLogger(
184  const char *const compName
185  );
186 
187 
188  // ----------------------------------------------------------------------
189  // Public methods
190  // ----------------------------------------------------------------------
191 
193  void initLog(
194  const char *const logFilePrefix,
195  const char *const logFileSuffix,
196  const FwSizeType maxFileSize,
197  const U8 sizeOfSize
198  );
199 
200  private:
201 
202  // ----------------------------------------------------------------------
203  // Handler implementations for user-defined typed input ports
204  // ----------------------------------------------------------------------
205 
208  void bufferSendIn_handler(
209  const FwIndexType portNum,
210  Fw::Buffer& fwBuffer
211  );
212 
215  void comIn_handler(
216  const FwIndexType portNum,
217  Fw::ComBuffer &data,
218  U32 context
219  );
220 
223  void pingIn_handler(
224  const FwIndexType portNum,
225  U32 key
226  );
227 
230  void schedIn_handler(
231  const FwIndexType portNum,
232  U32 context
233  );
234 
235  private:
236 
237  // ----------------------------------------------------------------------
238  // Command handler implementations
239  // ----------------------------------------------------------------------
240 
243  void BL_OpenFile_cmdHandler(
244  const FwOpcodeType opCode,
245  const U32 cmdSeq,
246  const Fw::CmdStringArg& file
247  );
248 
251  void BL_CloseFile_cmdHandler(
252  const FwOpcodeType opCode,
253  const U32 cmdSeq
254  );
255 
258  void BL_SetLogging_cmdHandler(
259  const FwOpcodeType opCode,
260  const U32 cmdSeq,
262  );
263 
266  void BL_FlushFile_cmdHandler(
267  const FwOpcodeType opCode,
268  const U32 cmdSeq
269  );
270 
271  private:
272 
273  // ----------------------------------------------------------------------
274  // Private instance variables
275  // ----------------------------------------------------------------------
276 
278  BufferLogger_LogState m_state;
279 
281  File m_file;
282 
283  };
284 
285 }
286 
287 #endif
friend class Svc::Errors::BufferLoggerTester
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
void initLog(const char *const logFilePrefix, const char *const logFileSuffix, const FwSizeType maxFileSize, const U8 sizeOfSize)
Set up log file parameters.
friend class Svc::Logging::SendBuffersTester
void init()
Object initializer.
Definition: ObjBase.cpp:26
BufferLogger(const char *const compName)
Create a BufferLogger object.
Auto-generated base for BufferLogger component.
friend class BufferLoggerTester
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:56
friend class Svc::Logging::CloseFileTester
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
friend class Svc::Logging::OnOffTester