F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
FileManager.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title FileManager.hpp
3 // \author bocchino
4 // \brief hpp file for FileManager component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 #ifndef Svc_FileManager_HPP
14 #define Svc_FileManager_HPP
15 
16 #include <atomic>
17 #include "Os/File.hpp"
18 #include "Os/FileSystem.hpp"
20 #include "config/FileManagerConfig.hpp"
21 
22 namespace Svc {
23 
24 class FileManager final : public FileManagerComponentBase {
25  friend class FileManagerTester;
26 
27  public:
28  // ----------------------------------------------------------------------
29  // Construction, initialization, and destruction
30  // ----------------------------------------------------------------------
31 
34  FileManager(const char* const compName
35  );
36 
39  ~FileManager();
40 
41  private:
42  // ----------------------------------------------------------------------
43  // Command handler implementations
44  // ----------------------------------------------------------------------
45 
48  void CreateDirectory_cmdHandler(const FwOpcodeType opCode,
49  const U32 cmdSeq,
50  const Fw::CmdStringArg& dirName
51  ) override;
52 
55  void RemoveFile_cmdHandler(const FwOpcodeType opCode,
56  const U32 cmdSeq,
57  const Fw::CmdStringArg& fileName,
58  const bool ignoreErrors
59  ) override;
60 
63  void MoveFile_cmdHandler(const FwOpcodeType opCode,
64  const U32 cmdSeq,
65  const Fw::CmdStringArg& sourceFileName,
66  const Fw::CmdStringArg& destFileName
67  ) override;
68 
71  void RemoveDirectory_cmdHandler(const FwOpcodeType opCode,
72  const U32 cmdSeq,
73  const Fw::CmdStringArg& dirName
74  ) override;
75 
78  void AppendFile_cmdHandler(const FwOpcodeType opCode,
79  const U32 cmdSeq,
80  const Fw::CmdStringArg& source,
81  const Fw::CmdStringArg& target
82  ) override;
83 
86  void FileSize_cmdHandler(const FwOpcodeType opCode,
87  const U32 cmdSeq,
88  const Fw::CmdStringArg& fileName
89  ) override;
90 
93  void ListDirectory_cmdHandler(const FwOpcodeType opCode,
94  const U32 cmdSeq,
95  const Fw::CmdStringArg& dirName
96  ) override;
97 
101  void CalculateCrc_cmdHandler(FwOpcodeType opCode,
102  U32 cmdSeq,
103  const Fw::CmdStringArg& filename
104  ) override;
105 
108  void GenerateDp_cmdHandler(FwOpcodeType opCode,
109  U32 cmdSeq,
110  const Fw::CmdStringArg& fileName,
111  U32 chunkSize,
112  U64 beginOffset,
113  U64 endOffset,
114  U32 priority,
115  const FileManager_GenerateDpMode& mode
116  ) override;
117 
120  void pingIn_handler(const FwIndexType portNum,
121  U32 key
122  ) override;
123 
129  void schedIn_handler(const FwIndexType portNum,
130  U32 context
131  ) override;
132 
133  private:
134  // ----------------------------------------------------------------------
135  // Helper methods
136  // ----------------------------------------------------------------------
137 
140  void emitTelemetry(const Os::FileSystem::Status status
141  );
142 
145  void sendCommandResponse(const FwOpcodeType opCode,
146  const U32 cmdSeq,
147  const Os::FileSystem::Status status
148  );
149 
150  private:
151  // ----------------------------------------------------------------------
152  // Handler implementations for user-defined internal interfaces
153  // ----------------------------------------------------------------------
154 
158  void run_internalInterfaceHandler() override;
159 
160  private:
161  // ----------------------------------------------------------------------
162  // Variables
163  // ----------------------------------------------------------------------
164 
167  U32 commandCount;
168 
171  U32 errorCount;
172 
173  // ----------------------------------------------------------------------
174  // Directory listing state machine variables
175  // ----------------------------------------------------------------------
176  // The FileManager uses an asynchronous state machine to process
177  // directory listings through Rate Group 2. This prevents event
178  // flooding and ensures bounded execution time by processing one
179  // directory entry per rate tick (0.5Hz).
180 
182  enum ListDirectoryState {
183  IDLE,
184  LISTING_IN_PROGRESS
185  };
186 
188  ListDirectoryState m_listState;
189 
191  Os::Directory m_currentDir;
192 
194  Fw::String m_currentDirName;
195 
197  U32 m_totalEntries;
198 
200  FwOpcodeType m_currentOpCode;
201 
203  U32 m_currentCmdSeq;
204 
205  std::atomic<bool> m_runQueued;
206 
207  // ----------------------------------------------------------------------
208  // Data product generation state machine variables
209  // ----------------------------------------------------------------------
210  // Files are packaged into data products one chunk at a time, paced by
211  // the rate group in the same way as directory listing. This keeps the
212  // work bounded per tick and lets the command succeed regardless of how
213  // large the buffers allocated to data products are.
214 
216  enum GenerateDpState {
217  DP_IDLE,
218  DP_IN_PROGRESS
219  };
220 
222  GenerateDpState m_dpState;
223 
225  Os::File m_dpFile;
226 
228  Fw::String m_dpFileName;
229 
231  FwSizeType m_dpFileSize;
232 
234  U64 m_dpOffset;
235 
237  U32 m_dpChunkSize;
238 
240  U64 m_dpEndOffset;
241 
243  FwDpPriorityType m_dpPriority;
244 
246  U32 m_dpChunkCount;
247 
249  FwOpcodeType m_dpOpCode;
250 
252  U32 m_dpCmdSeq;
253 
257 
259  void processDpChunks(U32 chunkLimit);
260 
262  void finishDpGeneration();
263 };
264 
265 } // end namespace Svc
266 
267 #endif
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
U32 FwDpPriorityType
The type of a data product priority.
FileManager(const char *const compName)
Definition: FileManager.cpp:29
Auto-generated base for FileManager component.
friend class FileManagerTester
Definition: FileManager.hpp:25
static constexpr U32 GENERATE_DP_MAX_CHUNK_SIZE
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
Directory class.
Definition: Directory.hpp:116
How the chunks of a file are emitted.
PlatformIndexType FwIndexType
RateGroupDivider component implementation.