F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
DpCatalog.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title DpCatalog.hpp
3 // \author tcanham
4 // \brief hpp file for DpCatalog component implementation class
5 // ======================================================================
6 
7 #ifndef Svc_DpCatalog_HPP
8 #define Svc_DpCatalog_HPP
9 
12 
15 #include <Fw/Deprecate.hpp>
17 
19 #include <config/DpCatalogCfg.hpp>
20 #include <config/DpCfg.hpp>
21 
22 #define DIRECTORY_DELIMITER "/"
23 
24 namespace Svc {
25 
26 class DpCatalog final : public DpCatalogComponentBase {
27  friend class DpCatalogTester;
28 
29  public:
30  // ----------------------------------------------------------------------
31  // Component construction and destruction
32  // ----------------------------------------------------------------------
33 
36  DpCatalog(const char* const compName
37  );
38 
40  ~DpCatalog() = default;
41 
48  void configure(const Fw::ExternalArray<Fw::FileNameString>& directories,
49  Fw::FileNameString& stateFile,
50  FwEnumStoreType memId,
51  Fw::MemAllocator& allocator);
52 
61  FwSizeType numDirs,
62  Fw::FileNameString& stateFile,
63  FwEnumStoreType memId,
64  Fw::MemAllocator& allocator),
65  "Use configure(const Fw::ExternalArray<Fw::FileNameString>& directories, ...) instead");
66 
67  // @brief clean up component.
68  // Deallocates memory.
69  void shutdown();
70 
71  private:
72  // ----------------------------------------------------------------------
73  // Handler implementations for user-defined typed input ports
74  // ----------------------------------------------------------------------
75 
79  void fileDone_handler(FwIndexType portNum,
80  const Svc::SendFileResponse& resp) override;
81 
85  void pingIn_handler(FwIndexType portNum,
86  U32 key
87  ) override;
88 
92  void addToCat_handler(FwIndexType portNum,
93  const Fw::StringBase& fileName,
94  FwDpPriorityType priority,
95  FwSizeType size
96  ) override;
97 
98  private:
99  // ----------------------------------------------------------------------
100  // Handler implementations for commands
101  // ----------------------------------------------------------------------
102 
106  void BUILD_CATALOG_cmdHandler(FwOpcodeType opCode,
107  U32 cmdSeq
108  ) override;
109 
113  void START_XMIT_CATALOG_cmdHandler(
114  FwOpcodeType opCode,
115  U32 cmdSeq,
116  const Fw::Wait& wait,
117  bool remainActive
118  ) override;
119 
123  void STOP_XMIT_CATALOG_cmdHandler(FwOpcodeType opCode,
124  U32 cmdSeq
125  ) override;
126 
130  void CLEAR_CATALOG_cmdHandler(FwOpcodeType opCode,
131  U32 cmdSeq
132  ) override;
133 
134  // ----------------------------------
135  // Private data structures
136  // ----------------------------------
137 
138  struct DpStateEntry {
139  friend class DpCatalogTester;
140  FwIndexType dir;
141  DpRecord record;
142 
147  static I8 compareEntries(const DpStateEntry& left, const DpStateEntry& right);
148 
149  bool operator==(const DpStateEntry& other) const;
150  bool operator!=(const DpStateEntry& other) const;
151  bool operator>(const DpStateEntry& other) const;
152  bool operator<(const DpStateEntry& other) const;
153  };
154 
155  struct DpDstateFileEntry {
156  bool used;
157  bool visited;
158  DpStateEntry entry;
160  };
161 
162  // ----------------------------------
163  // Private helpers
164  // ----------------------------------
165 
167  enum class ProcessFileStatus {
168  SUCCESS,
169  FAILED,
170  QUIT
171  };
172 
176  FwSizeType determineDirectory(const Fw::String& fullFile);
177 
182  ProcessFileStatus processFile(const Fw::String& fullFile, FwSizeType dir);
183 
187  bool insertEntry(DpStateEntry& entry);
188 
190  void resetCatalog();
191 
193  Fw::CmdResponse fillBinaryTree();
194 
196  void resetStateFileData();
197 
200  void getFileState(DpStateEntry& entry);
201 
203  void pruneAndWriteStateFile();
204 
206  Fw::CmdResponse loadStateFile();
207 
210  void appendFileState(const DpStateEntry& entry);
211 
213  void sendNextEntry();
214 
218  bool findNextEntry(DpStateEntry& entry);
219 
222  bool checkInit();
223 
226  Fw::CmdResponse doCatalogBuild();
227 
230  Fw::CmdResponse doCatalogXmit();
231 
234  void dispatchWaitedResponse(Fw::CmdResponse response);
235 
236  // ----------------------------------
237  // Private data
238  // ----------------------------------
239  bool m_initialized = false;
240 
242  DpStateEntry m_currentXmitEntry;
243  bool m_hasCurrentXmit = false;
244 
245  FwSizeType m_numDpSlots = 0;
246 
247  Fw::FileNameString m_directories[DP_MAX_DIRECTORIES];
248  FwSizeType m_numDirectories = 0;
249  Fw::String m_fileList[DP_MAX_FILES];
250 
251  Fw::FileNameString m_stateFile;
252  DpDstateFileEntry* m_stateFileData = nullptr;
253  FwSizeType m_stateFileEntries = 0;
254 
255  FwSizeType m_memSize = 0;
256  void* m_memPtr = nullptr;
257  FwEnumStoreType m_allocatorId = 0;
258  Fw::MemAllocator* m_allocator = nullptr;
259 
260  bool m_catalogBuilt = false;
261  bool m_xmitInProgress = false;
262  Fw::FileNameString m_currXmitFileName;
263  bool m_xmitCmdWait = false;
264  U64 m_xmitBytes = 0;
265  FwOpcodeType m_xmitOpCode = 0;
266  U32 m_xmitCmdSeq = 0;
267 
268  U32 m_pendingFiles = 0;
269  U64 m_pendingDpBytes = 0;
270 
271  bool m_remainActive = false;
272 };
275 
276 } // namespace Svc
277 
278 #endif
Data structure representing a data product.
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
U32 FwDpPriorityType
The type of a data product priority.
I32 FwEnumStoreType
Auto-generated base for DpCatalog component.
Wait or don&#39;t wait for something.
Definition: WaitEnumAc.hpp:18
static const FwIndexType DP_MAX_DIRECTORIES
int8_t I8
8-bit signed integer
Definition: BasicTypes.h:51
void configure(const Fw::ExternalArray< Fw::FileNameString > &directories, Fw::FileNameString &stateFile, FwEnumStoreType memId, Fw::MemAllocator &allocator)
Configure the DpCatalog.
Definition: DpCatalog.cpp:29
Enum representing a command response.
~DpCatalog()=default
DpCatalog destructor.
static const FwIndexType DP_MAX_FILES
DpCatalog(const char *const compName)
DpCatalog constructor.
Definition: DpCatalog.cpp:25
friend class DpCatalogTester
Definition: DpCatalog.hpp:27
Memory Allocation base class.
DEPRECATED(void configure(Fw::FileNameString directories[DP_MAX_DIRECTORIES], FwSizeType numDirs, Fw::FileNameString &stateFile, FwEnumStoreType memId, Fw::MemAllocator &allocator), "Use configure(const Fw::ExternalArray<Fw::FileNameString>& directories, ...) instead")
Configure the DpCatalog.
PlatformIndexType FwIndexType
Send file response struct.
RateGroupDivider component implementation.
Defines a base class for a memory allocator for classes.