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 FlushFileTester;
29 class SendBuffersTester;
30 class OnOffTester;
31 class TruncateTester;
32 } // namespace Logging
33 namespace Errors {
34 class BufferLoggerTester;
35 }
36 
38  friend class BufferLoggerTester;
45 
46  private:
47  // ----------------------------------------------------------------------
48  // Types
49  // ----------------------------------------------------------------------
50 
52  class File {
53  friend class BufferLoggerTester;
54  friend class Svc::Logging::CloseFileTester;
55  friend class Svc::Logging::SendBuffersTester;
56  friend class Svc::Logging::OnOffTester;
57  friend class Svc::Logging::TruncateTester;
58  friend class Svc::Errors::BufferLoggerTester;
59 
60  public:
62  struct Mode {
63  typedef enum { CLOSED = 0, OPEN = 1 } t;
64  };
65 
66  public:
68  File(BufferLogger& bufferLogger
69  );
70 
72  ~File();
73 
74  public:
76  void init(const char* const prefix,
77  const char* const suffix,
78  const FwSizeType maxSize,
79  const U8 sizeOfSize
80  );
82 
84  void setBaseName(const Fw::ConstStringBase&
85  baseName
86  );
87 
89  void logBuffer(const U8* const data,
90  const FwSizeType size
91  );
92 
94  void closeAndEmitEvent();
95 
97  bool flush();
98 
99  private:
101  void open();
102 
105  bool writeBuffer(const U8* const data,
106  const FwSizeType size
107  );
108 
111  bool writeSize(const FwSizeType size
112  );
113 
116  bool writeBytes(const void* const data,
117  const FwSizeType length
118  );
119 
121  void writeHashFile();
122 
124  void close();
125 
126  private:
128  BufferLogger& m_bufferLogger;
129 
131  Fw::String m_prefix;
132 
134  Fw::String m_suffix;
135 
137  Fw::String m_baseName;
138 
140  FwSizeType m_fileCounter;
141 
143  FwSizeType m_maxSize;
144 
146  U8 m_sizeOfSize;
147 
149  Fw::String m_name;
150 
151  // The current mode
152  Mode::t m_mode;
153 
155  Os::File m_osFile;
156 
158  FwSizeType m_bytesWritten;
159 
161  Utils::Hash m_hash;
162 
163  }; // class File
164 
165  public:
166  // ----------------------------------------------------------------------
167  // Construction, initialization, and destruction
168  // ----------------------------------------------------------------------
169 
171  BufferLogger(const char* const compName
172  );
173 
174  // ----------------------------------------------------------------------
175  // Public methods
176  // ----------------------------------------------------------------------
177 
179  void initLog(
180  const char* const logFilePrefix,
181  const char* const logFileSuffix,
182  const FwSizeType maxFileSize,
183  const U8 sizeOfSize
184  );
185 
186  private:
187  // ----------------------------------------------------------------------
188  // Handler implementations for user-defined typed input ports
189  // ----------------------------------------------------------------------
190 
193  void bufferSendIn_handler(const FwIndexType portNum,
194  Fw::Buffer& fwBuffer);
195 
198  void comIn_handler(const FwIndexType portNum,
199  Fw::ComBuffer& data,
200  U32 context
201  );
202 
205  void pingIn_handler(const FwIndexType portNum,
206  U32 key
207  );
208 
209  private:
210  // ----------------------------------------------------------------------
211  // Command handler implementations
212  // ----------------------------------------------------------------------
213 
216  void BL_OpenFile_cmdHandler(const FwOpcodeType opCode,
217  const U32 cmdSeq,
218  const Fw::CmdStringArg& file);
219 
222  void BL_CloseFile_cmdHandler(const FwOpcodeType opCode,
223  const U32 cmdSeq
224  );
225 
228  void BL_SetLogging_cmdHandler(const FwOpcodeType opCode,
229  const U32 cmdSeq,
230  const BufferLogger_LogState& state);
231 
234  void BL_FlushFile_cmdHandler(const FwOpcodeType opCode,
235  const U32 cmdSeq
236  );
237 
238  private:
239  // ----------------------------------------------------------------------
240  // Private instance variables
241  // ----------------------------------------------------------------------
242 
244  BufferLogger_LogState m_state;
245 
247  File m_file;
248 };
249 
250 } // namespace Svc
251 
252 #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
friend class Svc::Logging::FlushFileTester
A read-only abstract superclass for StringBase.
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
friend class Svc::Logging::OnOffTester
friend class Svc::Logging::TruncateTester