F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
16 #include "Svc/BufferLogger/BufferLoggerComponentAc.hpp"
17 #include "Os/File.hpp"
19 #include "Fw/Types/Assert.hpp"
20 #include "Os/Mutex.hpp"
21 #include "Utils/Hash/Hash.hpp"
22 
23 namespace Svc {
24 
25  class BufferLogger :
26  public BufferLoggerComponentBase
27  {
28 
29  PRIVATE:
30 
31  // ----------------------------------------------------------------------
32  // Types
33  // ----------------------------------------------------------------------
34 
36  class File {
37 
38  public:
39 
41  struct Mode {
42  typedef enum {
43  CLOSED = 0,
44  OPEN = 1
45  } t;
46  };
47 
48  public:
49 
51  File(
52  BufferLogger& bufferLogger
53  );
54 
56  ~File(void);
57 
58  public:
59 
61  void init(
62  const char *const prefix,
63  const char *const suffix,
64  const U32 maxSize,
65  const U8 sizeOfSize
66  );
67 
69  void setBaseName(
70  const Fw::EightyCharString& baseName
71  );
72 
74  void logBuffer(
75  const U8 *const data,
76  const U32 size
77  );
78 
80  void closeAndEmitEvent(void);
81 
83  bool flush(void);
84 
85  PRIVATE:
86 
88  void open(void);
89 
92  bool writeBuffer(
93  const U8 *const data,
94  const U32 size
95  );
96 
99  bool writeSize(
100  const U32 size
101  );
102 
105  bool writeBytes(
106  const void *const data,
107  const U32 length
108  );
109 
111  void writeHashFile(void);
112 
114  void close(void);
115 
116  PRIVATE:
117 
119  BufferLogger& bufferLogger;
120 
122  Fw::EightyCharString prefix;
123 
125  Fw::EightyCharString suffix;
126 
128  Fw::EightyCharString baseName;
129 
131  NATIVE_UINT_TYPE fileCounter;
132 
134  U32 maxSize;
135 
137  U8 sizeOfSize;
138 
141 
142  // The current mode
143  Mode::t mode;
144 
146  Os::File osFile;
147 
149  U32 bytesWritten;
150 
151  }; // class File
152 
153  public:
154 
155  // ----------------------------------------------------------------------
156  // Construction, initialization, and destruction
157  // ----------------------------------------------------------------------
158 
160  BufferLogger(
161  const char *const compName
162  );
163 
165  void init(
166  const NATIVE_INT_TYPE queueDepth,
167  const NATIVE_INT_TYPE instance
168  );
169 
170  // ----------------------------------------------------------------------
171  // Public methods
172  // ----------------------------------------------------------------------
173 
175  void initLog(
176  const char *const logFilePrefix,
177  const char *const logFileSuffix,
178  const U32 maxFileSize,
179  const U8 sizeOfSize
180  );
181 
182  PRIVATE:
183 
184  // ----------------------------------------------------------------------
185  // Handler implementations for user-defined typed input ports
186  // ----------------------------------------------------------------------
187 
190  void bufferSendIn_handler(
191  const NATIVE_INT_TYPE portNum,
192  Fw::Buffer& fwBuffer
193  );
194 
197  void comIn_handler(
198  const NATIVE_INT_TYPE portNum,
199  Fw::ComBuffer &data,
200  U32 context
201  );
202 
205  void pingIn_handler(
206  const NATIVE_INT_TYPE portNum,
207  U32 key
208  );
209 
212  void schedIn_handler(
213  const NATIVE_INT_TYPE portNum,
214  NATIVE_UINT_TYPE context
215  );
216 
217  PRIVATE:
218 
219  // ----------------------------------------------------------------------
220  // Command handler implementations
221  // ----------------------------------------------------------------------
222 
225  void BL_OpenFile_cmdHandler(
226  const FwOpcodeType opCode,
227  const U32 cmdSeq,
228  const Fw::CmdStringArg& file
229  );
230 
233  void BL_CloseFile_cmdHandler(
234  const FwOpcodeType opCode,
235  const U32 cmdSeq
236  );
237 
240  void BL_SetLogging_cmdHandler(
241  const FwOpcodeType opCode,
242  const U32 cmdSeq,
243  LogState state
244  );
245 
248  void BL_FlushFile_cmdHandler(
249  const FwOpcodeType opCode,
250  const U32 cmdSeq
251  );
252 
253  PRIVATE:
254 
255  // ----------------------------------------------------------------------
256  // Private instance variables
257  // ----------------------------------------------------------------------
258 
260  LogState m_state;
261 
263  File m_file;
264 
265  };
266 
267 }
268 
269 #endif
Svc::BufferLogger::BufferLogger
BufferLogger(const char *const compName)
Create a BufferLogger object.
Definition: BufferLogger.cpp:22
Svc::BufferLogger::File::Mode::OPEN
@ OPEN
Definition: BufferLogger.hpp:44
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Fw::EightyCharString
Definition: EightyCharString.hpp:10
Svc::BufferLogger::File::Mode::t
t
Definition: BufferLogger.hpp:42
Fw::Buffer
Definition: Buffer.hpp:43
Fw::CmdStringArg
Definition: CmdString.hpp:11
Assert.hpp
Svc::BufferLogger::initLog
void initLog(const char *const logFilePrefix, const char *const logFileSuffix, const U32 maxFileSize, const U8 sizeOfSize)
Set up log file parameters.
Definition: BufferLogger.cpp:45
Svc::BufferLogger
Definition: BufferLogger.hpp:25
EightyCharString.hpp
Hash.hpp
FwOpcodeType
#define FwOpcodeType
Type representation for a command opcode.
Definition: FpConfig.hpp:62
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
Svc::BufferLogger::init
void init(const NATIVE_INT_TYPE queueDepth, const NATIVE_INT_TYPE instance)
Initialize a BufferLogger object.
Definition: BufferLogger.cpp:31
File.hpp
Svc
Definition: ActiveRateGroupImplCfg.hpp:18
Svc::BufferLogger::File::Mode
The file mode.
Definition: BufferLogger.hpp:41
Mutex.hpp
Svc::BufferLogger::File::Mode::CLOSED
@ CLOSED
Definition: BufferLogger.hpp:43
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Fw::ComBuffer
Definition: ComBuffer.hpp:21
Os::File
Definition: File.hpp:11