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 
14 
16 #include <config/DpCatalogCfg.hpp>
17 #include <config/DpCfg.hpp>
18 
19 #define DIRECTORY_DELIMITER "/"
20 
21 namespace Svc {
22 
23 class DpCatalog final : public DpCatalogComponentBase {
24  friend class DpCatalogTester;
25 
26  public:
27  // ----------------------------------------------------------------------
28  // Component construction and destruction
29  // ----------------------------------------------------------------------
30 
33  DpCatalog(const char* const compName
34  );
35 
37  ~DpCatalog();
38 
48  FwSizeType numDirs,
49  Fw::FileNameString& stateFile,
50  FwEnumStoreType memId,
51  Fw::MemAllocator& allocator);
52 
53  // @brief clean up component.
54  // Deallocates memory.
55  void shutdown();
56 
57  private:
58  // ----------------------------------------------------------------------
59  // Handler implementations for user-defined typed input ports
60  // ----------------------------------------------------------------------
61 
65  void fileDone_handler(FwIndexType portNum,
66  const Svc::SendFileResponse& resp) override;
67 
71  void pingIn_handler(FwIndexType portNum,
72  U32 key
73  ) override;
74 
78  void addToCat_handler(FwIndexType portNum,
79  const Fw::StringBase& fileName,
80  FwDpPriorityType priority,
81  FwSizeType size
82  ) override;
83 
84  private:
85  // ----------------------------------------------------------------------
86  // Handler implementations for commands
87  // ----------------------------------------------------------------------
88 
92  void BUILD_CATALOG_cmdHandler(FwOpcodeType opCode,
93  U32 cmdSeq
94  ) override;
95 
99  void START_XMIT_CATALOG_cmdHandler(
100  FwOpcodeType opCode,
101  U32 cmdSeq,
102  Fw::Wait wait,
103  bool remainActive
104  ) override;
105 
109  void STOP_XMIT_CATALOG_cmdHandler(FwOpcodeType opCode,
110  U32 cmdSeq
111  ) override;
112 
116  void CLEAR_CATALOG_cmdHandler(FwOpcodeType opCode,
117  U32 cmdSeq
118  ) override;
119 
120  // ----------------------------------
121  // Private data structures
122  // ----------------------------------
123 
124  struct DpStateEntry {
125  friend class DpCatalogTester;
126  FwIndexType dir;
127  DpRecord record;
128 
133  static int compareEntries(const DpStateEntry& left, const DpStateEntry& right);
134 
135  bool operator==(const DpStateEntry& other) const;
136  bool operator!=(const DpStateEntry& other) const;
137  bool operator>(const DpStateEntry& other) const;
138  bool operator<(const DpStateEntry& other) const;
139  };
140 
141  struct DpDstateFileEntry {
142  bool used;
143  bool visited;
144  DpStateEntry entry;
146  };
147 
149  struct DpBtreeNode {
150  DpStateEntry entry;
151  DpBtreeNode* left;
152  DpBtreeNode* right;
153  DpBtreeNode* parent;
154  };
155 
156  // ----------------------------------
157  // Private helpers
158  // ----------------------------------
159 
163  FwSizeType determineDirectory(Fw::String fullFile);
164 
169  int processFile(Fw::String fullFile, FwSizeType dir);
170 
174  DpCatalog::DpBtreeNode* insertEntry(DpStateEntry& entry);
175 
177  enum CheckStat {
178  CHECK_OK,
179  CHECK_CONT,
180  CHECK_ERROR,
181  };
182 
184  CheckStat checkLeftRight(bool condition, DpBtreeNode*& node, const DpStateEntry& newEntry);
185 
187  void resetBinaryTree();
188 
190  Fw::CmdResponse fillBinaryTree();
191 
193  void resetStateFileData();
194 
197  void getFileState(DpStateEntry& entry);
198 
200  void pruneAndWriteStateFile();
201 
203  Fw::CmdResponse loadStateFile();
204 
207  void appendFileState(const DpStateEntry& entry);
208 
213  bool allocateNode(DpBtreeNode*& newNode, const DpStateEntry& newEntry);
214 
217  void deallocateNode(DpBtreeNode* node);
218 
220  void sendNextEntry();
221 
225  DpBtreeNode* findNextTreeNode();
226 
229  bool checkInit();
230 
233  Fw::CmdResponse doCatalogBuild();
234 
237  Fw::CmdResponse doCatalogXmit();
238 
241  void dispatchWaitedResponse(Fw::CmdResponse response);
242 
243  // ----------------------------------
244  // Private data
245  // ----------------------------------
246  bool m_initialized;
247 
248  DpBtreeNode* m_dpTree;
249  DpBtreeNode* m_freeListHead;
250  DpBtreeNode* m_currentNode;
251  DpBtreeNode* m_currentXmitNode;
252 
253  FwSizeType m_numDpSlots;
254 
255  Fw::FileNameString m_directories[DP_MAX_DIRECTORIES];
256  FwSizeType m_numDirectories;
257  Fw::String m_fileList[DP_MAX_FILES];
258 
259  Fw::FileNameString m_stateFile;
260  DpDstateFileEntry* m_stateFileData;
261  FwSizeType m_stateFileEntries;
262 
263  FwSizeType m_memSize;
264  void* m_memPtr;
265  FwEnumStoreType m_allocatorId;
266  Fw::MemAllocator* m_allocator;
267 
268  bool m_catalogBuilt;
269  bool m_xmitInProgress;
270  Fw::FileNameString m_currXmitFileName;
271  bool m_xmitCmdWait;
272  U64 m_xmitBytes;
273  FwOpcodeType m_xmitOpCode;
274  U32 m_xmitCmdSeq;
275 
276  U32 m_pendingFiles;
277  U64 m_pendingDpBytes;
278 
279  bool m_remainActive;
280 };
283 
284 } // namespace Svc
285 
286 #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:17
static const FwIndexType DP_MAX_DIRECTORIES
Enum representing a command response.
void configure(Fw::FileNameString directories[DP_MAX_DIRECTORIES], FwSizeType numDirs, Fw::FileNameString &stateFile, FwEnumStoreType memId, Fw::MemAllocator &allocator)
Configure the DpCatalog.
Definition: DpCatalog.cpp:51
static const FwIndexType DP_MAX_FILES
DpCatalog(const char *const compName)
DpCatalog constructor.
Definition: DpCatalog.cpp:24
~DpCatalog()
DpCatalog destructor.
Definition: DpCatalog.cpp:49
friend class DpCatalogTester
Definition: DpCatalog.hpp:24
Memory Allocation base class.
PlatformIndexType FwIndexType
Send file response struct.
RateGroupDivider component implementation.
Defines a base class for a memory allocator for classes.
#define U64(C)
Definition: sha.h:181