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 
16 #include "Fw/Types/Assert.hpp"
17 #include "Fw/Types/String.hpp"
18 #include "Os/File.hpp"
19 #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 } // namespace Logging
31 namespace Errors {
32 class BufferLoggerTester;
33 }
34 
36  friend class BufferLoggerTester;
41 
42  private:
43  // ----------------------------------------------------------------------
44  // Types
45  // ----------------------------------------------------------------------
46 
48  class File {
49  friend class BufferLoggerTester;
50  friend class Svc::Logging::CloseFileTester;
51  friend class Svc::Logging::SendBuffersTester;
52  friend class Svc::Logging::OnOffTester;
53  friend class Svc::Errors::BufferLoggerTester;
54 
55  public:
57  struct Mode {
58  typedef enum { CLOSED = 0, OPEN = 1 } t;
59  };
60 
61  public:
63  File(BufferLogger& bufferLogger
64  );
65 
67  ~File();
68 
69  public:
71  void init(const char* const prefix,
72  const char* const suffix,
73  const FwSizeType maxSize,
74  const U8 sizeOfSize
75  );
77 
79  void setBaseName(
80  const Fw::StringBase& baseName
81  );
82 
84  void logBuffer(const U8* const data,
85  const FwSizeType size
86  );
87 
89  void closeAndEmitEvent();
90 
92  bool flush();
93 
94  private:
96  void open();
97 
100  bool writeBuffer(const U8* const data,
101  const FwSizeType size
102  );
103 
106  bool writeSize(const FwSizeType size
107  );
108 
111  bool writeBytes(const void* const data,
112  const FwSizeType length
113  );
114 
116  void writeHashFile();
117 
119  void close();
120 
121  private:
123  BufferLogger& m_bufferLogger;
124 
126  Fw::String m_prefix;
127 
129  Fw::String m_suffix;
130 
132  Fw::String m_baseName;
133 
135  FwSizeType m_fileCounter;
136 
138  FwSizeType m_maxSize;
139 
141  U8 m_sizeOfSize;
142 
144  Fw::String m_name;
145 
146  // The current mode
147  Mode::t m_mode;
148 
150  Os::File m_osFile;
151 
153  FwSizeType m_bytesWritten;
154 
155  }; // class File
156 
157  public:
158  // ----------------------------------------------------------------------
159  // Construction, initialization, and destruction
160  // ----------------------------------------------------------------------
161 
163  BufferLogger(const char* const compName
164  );
165 
166  // ----------------------------------------------------------------------
167  // Public methods
168  // ----------------------------------------------------------------------
169 
171  void initLog(
172  const char* const logFilePrefix,
173  const char* const logFileSuffix,
174  const FwSizeType maxFileSize,
175  const U8 sizeOfSize
176  );
177 
178  private:
179  // ----------------------------------------------------------------------
180  // Handler implementations for user-defined typed input ports
181  // ----------------------------------------------------------------------
182 
185  void bufferSendIn_handler(const FwIndexType portNum,
186  Fw::Buffer& fwBuffer);
187 
190  void comIn_handler(const FwIndexType portNum,
191  Fw::ComBuffer& data,
192  U32 context
193  );
194 
197  void pingIn_handler(const FwIndexType portNum,
198  U32 key
199  );
200 
203  void schedIn_handler(const FwIndexType portNum,
204  U32 context
205  );
206 
207  private:
208  // ----------------------------------------------------------------------
209  // Command handler implementations
210  // ----------------------------------------------------------------------
211 
214  void BL_OpenFile_cmdHandler(const FwOpcodeType opCode,
215  const U32 cmdSeq,
216  const Fw::CmdStringArg& file);
217 
220  void BL_CloseFile_cmdHandler(const FwOpcodeType opCode,
221  const U32 cmdSeq
222  );
223 
226  void BL_SetLogging_cmdHandler(const FwOpcodeType opCode,
227  const U32 cmdSeq,
228  BufferLogger_LogState state);
229 
232  void BL_FlushFile_cmdHandler(const FwOpcodeType opCode,
233  const U32 cmdSeq
234  );
235 
236  private:
237  // ----------------------------------------------------------------------
238  // Private instance variables
239  // ----------------------------------------------------------------------
240 
242  BufferLogger_LogState m_state;
243 
245  File m_file;
246 };
247 
248 } // namespace Svc
249 
250 #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:24
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:53
friend class Svc::Logging::CloseFileTester
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
friend class Svc::Logging::OnOffTester