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>
18 #include "Os/File.hpp"
19 #include "Os/FileSystem.hpp"
21 #include "config/FileManagerConfig.hpp"
22 
23 namespace Svc {
24 
25 class FileManager final : public FileManagerComponentBase {
26  friend class FileManagerTester;
27 
28  public:
29  // ----------------------------------------------------------------------
30  // Construction, initialization, and destruction
31  // ----------------------------------------------------------------------
32 
35  FileManager(const char* const compName
36  );
37 
40  ~FileManager();
41 
51  void configure(const char* sandboxDir);
52 
53  private:
54  // ----------------------------------------------------------------------
55  // Command handler implementations
56  // ----------------------------------------------------------------------
57 
60  void CreateDirectory_cmdHandler(const FwOpcodeType opCode,
61  const U32 cmdSeq,
62  const Fw::CmdStringArg& dirName
63  ) override;
64 
67  void RemoveFile_cmdHandler(const FwOpcodeType opCode,
68  const U32 cmdSeq,
69  const Fw::CmdStringArg& fileName,
70  const bool ignoreErrors
71  ) override;
72 
75  void MoveFile_cmdHandler(const FwOpcodeType opCode,
76  const U32 cmdSeq,
77  const Fw::CmdStringArg& sourceFileName,
78  const Fw::CmdStringArg& destFileName
79  ) override;
80 
83  void RemoveDirectory_cmdHandler(const FwOpcodeType opCode,
84  const U32 cmdSeq,
85  const Fw::CmdStringArg& dirName
86  ) override;
87 
90  void AppendFile_cmdHandler(const FwOpcodeType opCode,
91  const U32 cmdSeq,
92  const Fw::CmdStringArg& source,
93  const Fw::CmdStringArg& target
94  ) override;
95 
98  void FileSize_cmdHandler(const FwOpcodeType opCode,
99  const U32 cmdSeq,
100  const Fw::CmdStringArg& fileName
101  ) override;
102 
105  void ListDirectory_cmdHandler(const FwOpcodeType opCode,
106  const U32 cmdSeq,
107  const Fw::CmdStringArg& dirName
108  ) override;
109 
113  void CalculateCrc_cmdHandler(FwOpcodeType opCode,
114  U32 cmdSeq,
115  const Fw::CmdStringArg& filename
116  ) override;
117 
120  void GenerateDp_cmdHandler(FwOpcodeType opCode,
121  U32 cmdSeq,
122  const Fw::CmdStringArg& fileName,
123  U32 chunkSize,
124  U64 beginOffset,
125  U64 endOffset,
126  U32 priority,
127  const FileManager_GenerateDpMode& mode
128  ) override;
129 
132  void pingIn_handler(const FwIndexType portNum,
133  U32 key
134  ) override;
135 
141  void schedIn_handler(const FwIndexType portNum,
142  U32 context
143  ) override;
144 
145  private:
146  // ----------------------------------------------------------------------
147  // Helper methods
148  // ----------------------------------------------------------------------
149 
152  void emitTelemetry(const Os::FileSystem::Status status
153  );
154 
157  void sendCommandResponse(const FwOpcodeType opCode,
158  const U32 cmdSeq,
159  const Os::FileSystem::Status status
160  );
161 
171  bool resolveInSandbox(const Fw::CmdStringArg& path,
172  Fw::FileNameString& resolved,
173  const FwOpcodeType opCode,
174  const U32 cmdSeq
175  );
176 
177  private:
178  // ----------------------------------------------------------------------
179  // Handler implementations for user-defined internal interfaces
180  // ----------------------------------------------------------------------
181 
185  void schedInInternal_internalInterfaceHandler() override;
186 
188  void schedInInternal_overflowHook() override;
189 
190  private:
191  // ----------------------------------------------------------------------
192  // Variables
193  // ----------------------------------------------------------------------
194 
197  U32 commandCount;
198 
201  U32 errorCount;
202 
205  Fw::FileNameString m_sandboxDir;
206 
209  bool m_sandboxConfigured;
210 
211  // ----------------------------------------------------------------------
212  // Directory listing state machine variables
213  // ----------------------------------------------------------------------
214  // The FileManager uses an asynchronous state machine to process
215  // directory listings through Rate Group 2. This prevents event
216  // flooding and ensures bounded execution time by processing
217  // FILES_PER_RATE_TICK directory entries per rate tick.
218 
220  enum ListDirectoryState {
221  IDLE,
222  LISTING_IN_PROGRESS
223  };
224 
226  ListDirectoryState m_listState;
227 
229  Os::Directory m_currentDir;
230 
232  Fw::String m_currentDirName;
233 
235  U32 m_totalEntries;
236 
238  FwOpcodeType m_currentOpCode;
239 
241  U32 m_currentCmdSeq;
242 
243  std::atomic<bool> m_schedInQueued;
244 
245  // ----------------------------------------------------------------------
246  // Data product generation state machine variables
247  // ----------------------------------------------------------------------
248  // Files are packaged into data products one chunk at a time, paced by
249  // the rate group in the same way as directory listing. This keeps the
250  // work bounded per tick and lets the command succeed regardless of how
251  // large the buffers allocated to data products are.
252 
254  enum GenerateDpState {
255  DP_IDLE,
256  DP_IN_PROGRESS
257  };
258 
260  GenerateDpState m_dpState;
261 
263  Os::File m_dpFile;
264 
266  Fw::String m_dpFileName;
267 
269  FwSizeType m_dpFileSize;
270 
272  U64 m_dpOffset;
273 
275  U32 m_dpChunkSize;
276 
278  U64 m_dpEndOffset;
279 
281  FwDpPriorityType m_dpPriority;
282 
284  U32 m_dpChunkCount;
285 
287  FwOpcodeType m_dpOpCode;
288 
290  U32 m_dpCmdSeq;
291 
295 
297  void processDpChunks(U32 chunkLimit);
298 
300  void finishDpGeneration();
301 };
302 
303 } // end namespace Svc
304 
305 #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:31
Auto-generated base for FileManager component.
const char *const sandboxDir
void configure(const char *sandboxDir)
Definition: FileManager.cpp:56
friend class FileManagerTester
Definition: FileManager.hpp:26
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.