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 class TruncateTester;
31 } // namespace Logging
32 namespace Errors {
33 class BufferLoggerTester;
34 }
35 
37  friend class BufferLoggerTester;
43 
44  private:
45  // ----------------------------------------------------------------------
46  // Types
47  // ----------------------------------------------------------------------
48 
50  class File {
51  friend class BufferLoggerTester;
52  friend class Svc::Logging::CloseFileTester;
53  friend class Svc::Logging::SendBuffersTester;
54  friend class Svc::Logging::OnOffTester;
55  friend class Svc::Logging::TruncateTester;
56  friend class Svc::Errors::BufferLoggerTester;
57 
58  public:
60  struct Mode {
61  typedef enum { CLOSED = 0, OPEN = 1 } t;
62  };
63 
64  public:
66  File(BufferLogger& bufferLogger
67  );
68 
70  ~File();
71 
72  public:
74  void init(const char* const prefix,
75  const char* const suffix,
76  const FwSizeType maxSize,
77  const U8 sizeOfSize
78  );
80 
82  void setBaseName(const Fw::ConstStringBase&
83  baseName
84  );
85 
87  void logBuffer(const U8* const data,
88  const FwSizeType size
89  );
90 
92  void closeAndEmitEvent();
93 
95  bool flush();
96 
97  private:
99  void open();
100 
103  bool writeBuffer(const U8* const data,
104  const FwSizeType size
105  );
106 
109  bool writeSize(const FwSizeType size
110  );
111 
114  bool writeBytes(const void* const data,
115  const FwSizeType length
116  );
117 
119  void writeHashFile();
120 
122  void close();
123 
124  private:
126  BufferLogger& m_bufferLogger;
127 
129  Fw::String m_prefix;
130 
132  Fw::String m_suffix;
133 
135  Fw::String m_baseName;
136 
138  FwSizeType m_fileCounter;
139 
141  FwSizeType m_maxSize;
142 
144  U8 m_sizeOfSize;
145 
147  Fw::String m_name;
148 
149  // The current mode
150  Mode::t m_mode;
151 
153  Os::File m_osFile;
154 
156  FwSizeType m_bytesWritten;
157 
159  Utils::Hash m_hash;
160 
161  }; // class File
162 
163  public:
164  // ----------------------------------------------------------------------
165  // Construction, initialization, and destruction
166  // ----------------------------------------------------------------------
167 
169  BufferLogger(const char* const compName
170  );
171 
172  // ----------------------------------------------------------------------
173  // Public methods
174  // ----------------------------------------------------------------------
175 
177  void initLog(
178  const char* const logFilePrefix,
179  const char* const logFileSuffix,
180  const FwSizeType maxFileSize,
181  const U8 sizeOfSize
182  );
183 
184  private:
185  // ----------------------------------------------------------------------
186  // Handler implementations for user-defined typed input ports
187  // ----------------------------------------------------------------------
188 
191  void bufferSendIn_handler(const FwIndexType portNum,
192  Fw::Buffer& fwBuffer);
193 
196  void comIn_handler(const FwIndexType portNum,
197  Fw::ComBuffer& data,
198  U32 context
199  );
200 
203  void pingIn_handler(const FwIndexType portNum,
204  U32 key
205  );
206 
209  void schedIn_handler(const FwIndexType portNum,
210  U32 context
211  );
212 
213  private:
214  // ----------------------------------------------------------------------
215  // Command handler implementations
216  // ----------------------------------------------------------------------
217 
220  void BL_OpenFile_cmdHandler(const FwOpcodeType opCode,
221  const U32 cmdSeq,
222  const Fw::CmdStringArg& file);
223 
226  void BL_CloseFile_cmdHandler(const FwOpcodeType opCode,
227  const U32 cmdSeq
228  );
229 
232  void BL_SetLogging_cmdHandler(const FwOpcodeType opCode,
233  const U32 cmdSeq,
234  const BufferLogger_LogState& state);
235 
238  void BL_FlushFile_cmdHandler(const FwOpcodeType opCode,
239  const U32 cmdSeq
240  );
241 
242  private:
243  // ----------------------------------------------------------------------
244  // Private instance variables
245  // ----------------------------------------------------------------------
246 
248  BufferLogger_LogState m_state;
249 
251  File m_file;
252 };
253 
254 } // namespace Svc
255 
256 #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
A generic interface for creating and comparing hash values.
Definition: Hash.hpp:24
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
friend class Svc::Logging::CloseFileTester
A read-only abstract superclass for StringBase.
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
friend class Svc::Logging::OnOffTester
friend class Svc::Logging::TruncateTester