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 run_internalInterfaceHandler() override;
186 
187  private:
188  // ----------------------------------------------------------------------
189  // Variables
190  // ----------------------------------------------------------------------
191 
194  U32 commandCount;
195 
198  U32 errorCount;
199 
202  Fw::FileNameString m_sandboxDir;
203 
206  bool m_sandboxConfigured;
207 
208  // ----------------------------------------------------------------------
209  // Directory listing state machine variables
210  // ----------------------------------------------------------------------
211  // The FileManager uses an asynchronous state machine to process
212  // directory listings through Rate Group 2. This prevents event
213  // flooding and ensures bounded execution time by processing
214  // FILES_PER_RATE_TICK directory entries per rate tick.
215 
217  enum ListDirectoryState {
218  IDLE,
219  LISTING_IN_PROGRESS
220  };
221 
223  ListDirectoryState m_listState;
224 
226  Os::Directory m_currentDir;
227 
229  Fw::String m_currentDirName;
230 
232  U32 m_totalEntries;
233 
235  FwOpcodeType m_currentOpCode;
236 
238  U32 m_currentCmdSeq;
239 
240  std::atomic<bool> m_runQueued;
241 
242  // ----------------------------------------------------------------------
243  // Data product generation state machine variables
244  // ----------------------------------------------------------------------
245  // Files are packaged into data products one chunk at a time, paced by
246  // the rate group in the same way as directory listing. This keeps the
247  // work bounded per tick and lets the command succeed regardless of how
248  // large the buffers allocated to data products are.
249 
251  enum GenerateDpState {
252  DP_IDLE,
253  DP_IN_PROGRESS
254  };
255 
257  GenerateDpState m_dpState;
258 
260  Os::File m_dpFile;
261 
263  Fw::String m_dpFileName;
264 
266  FwSizeType m_dpFileSize;
267 
269  U64 m_dpOffset;
270 
272  U32 m_dpChunkSize;
273 
275  U64 m_dpEndOffset;
276 
278  FwDpPriorityType m_dpPriority;
279 
281  U32 m_dpChunkCount;
282 
284  FwOpcodeType m_dpOpCode;
285 
287  U32 m_dpCmdSeq;
288 
292 
294  void processDpChunks(U32 chunkLimit);
295 
297  void finishDpGeneration();
298 };
299 
300 } // end namespace Svc
301 
302 #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.
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.