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/FileSystem.hpp"
19 
20 namespace Svc {
21 
22 class FileManager final : public FileManagerComponentBase {
23  friend class FileManagerTester;
24 
25  public:
26  // ----------------------------------------------------------------------
27  // Construction, initialization, and destruction
28  // ----------------------------------------------------------------------
29 
32  FileManager(const char* const compName
33  );
34 
37  ~FileManager();
38 
39  private:
40  // ----------------------------------------------------------------------
41  // Command handler implementations
42  // ----------------------------------------------------------------------
43 
46  void CreateDirectory_cmdHandler(const FwOpcodeType opCode,
47  const U32 cmdSeq,
48  const Fw::CmdStringArg& dirName
49  ) override;
50 
53  void RemoveFile_cmdHandler(const FwOpcodeType opCode,
54  const U32 cmdSeq,
55  const Fw::CmdStringArg& fileName,
56  const bool ignoreErrors
57  ) override;
58 
61  void MoveFile_cmdHandler(const FwOpcodeType opCode,
62  const U32 cmdSeq,
63  const Fw::CmdStringArg& sourceFileName,
64  const Fw::CmdStringArg& destFileName
65  ) override;
66 
69  void RemoveDirectory_cmdHandler(const FwOpcodeType opCode,
70  const U32 cmdSeq,
71  const Fw::CmdStringArg& dirName
72  ) override;
73 
76  void ShellCommand_cmdHandler(const FwOpcodeType opCode,
77  const U32 cmdSeq,
78  const Fw::CmdStringArg& command,
79  const Fw::CmdStringArg& logFileName
80  ) override;
81 
84  void AppendFile_cmdHandler(const FwOpcodeType opCode,
85  const U32 cmdSeq,
86  const Fw::CmdStringArg& source,
87  const Fw::CmdStringArg& target
88  ) override;
89 
92  void FileSize_cmdHandler(const FwOpcodeType opCode,
93  const U32 cmdSeq,
94  const Fw::CmdStringArg& fileName
95  ) override;
96 
99  void ListDirectory_cmdHandler(const FwOpcodeType opCode,
100  const U32 cmdSeq,
101  const Fw::CmdStringArg& dirName
102  ) override;
103 
107  void CalculateCrc_cmdHandler(FwOpcodeType opCode,
108  U32 cmdSeq,
109  const Fw::CmdStringArg& filename
110  ) override;
111 
114  void pingIn_handler(const FwIndexType portNum,
115  U32 key
116  ) override;
117 
123  void schedIn_handler(const FwIndexType portNum,
124  U32 context
125  ) override;
126 
127  private:
128  // ----------------------------------------------------------------------
129  // Helper methods
130  // ----------------------------------------------------------------------
131 
134  int systemCall(const Fw::CmdStringArg& command,
135  const Fw::CmdStringArg& logFileName
136  ) const;
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 } // end namespace Svc
209 
210 #endif
FwIdType FwOpcodeType
The type of a command opcode.
FileManager(const char *const compName)
Definition: FileManager.cpp:29
Auto-generated base for FileManager component.
friend class FileManagerTester
Definition: FileManager.hpp:23
Directory class.
Definition: Directory.hpp:114
PlatformIndexType FwIndexType
RateGroupDivider component implementation.