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(const Fw::ConstStringBase&
80  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 
156  Utils::Hash m_hash;
157 
158  }; // class File
159 
160  public:
161  // ----------------------------------------------------------------------
162  // Construction, initialization, and destruction
163  // ----------------------------------------------------------------------
164 
166  BufferLogger(const char* const compName
167  );
168 
169  // ----------------------------------------------------------------------
170  // Public methods
171  // ----------------------------------------------------------------------
172 
174  void initLog(
175  const char* const logFilePrefix,
176  const char* const logFileSuffix,
177  const FwSizeType maxFileSize,
178  const U8 sizeOfSize
179  );
180 
181  private:
182  // ----------------------------------------------------------------------
183  // Handler implementations for user-defined typed input ports
184  // ----------------------------------------------------------------------
185 
188  void bufferSendIn_handler(const FwIndexType portNum,
189  Fw::Buffer& fwBuffer);
190 
193  void comIn_handler(const FwIndexType portNum,
194  Fw::ComBuffer& data,
195  U32 context
196  );
197 
200  void pingIn_handler(const FwIndexType portNum,
201  U32 key
202  );
203 
206  void schedIn_handler(const FwIndexType portNum,
207  U32 context
208  );
209 
210  private:
211  // ----------------------------------------------------------------------
212  // Command handler implementations
213  // ----------------------------------------------------------------------
214 
217  void BL_OpenFile_cmdHandler(const FwOpcodeType opCode,
218  const U32 cmdSeq,
219  const Fw::CmdStringArg& file);
220 
223  void BL_CloseFile_cmdHandler(const FwOpcodeType opCode,
224  const U32 cmdSeq
225  );
226 
229  void BL_SetLogging_cmdHandler(const FwOpcodeType opCode,
230  const U32 cmdSeq,
231  const BufferLogger_LogState& state);
232 
235  void BL_FlushFile_cmdHandler(const FwOpcodeType opCode,
236  const U32 cmdSeq
237  );
238 
239  private:
240  // ----------------------------------------------------------------------
241  // Private instance variables
242  // ----------------------------------------------------------------------
243 
245  BufferLogger_LogState m_state;
246 
248  File m_file;
249 };
250 
251 } // namespace Svc
252 
253 #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