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 namespace Svc {
20 
21 class DpCatalog final : public DpCatalogComponentBase {
22  friend class DpCatalogTester;
23 
24  public:
25  // ----------------------------------------------------------------------
26  // Component construction and destruction
27  // ----------------------------------------------------------------------
28 
31  DpCatalog(const char* const compName
32  );
33 
35  ~DpCatalog();
36 
46  FwSizeType numDirs,
47  Fw::FileNameString& stateFile,
48  FwEnumStoreType memId,
49  Fw::MemAllocator& allocator);
50 
51  // @brief clean up component.
52  // Deallocates memory.
53  void shutdown();
54 
55  private:
56  // ----------------------------------------------------------------------
57  // Handler implementations for user-defined typed input ports
58  // ----------------------------------------------------------------------
59 
63  void fileDone_handler(FwIndexType portNum,
64  const Svc::SendFileResponse& resp) override;
65 
69  void pingIn_handler(FwIndexType portNum,
70  U32 key
71  ) override;
72 
73  private:
74  // ----------------------------------------------------------------------
75  // Handler implementations for commands
76  // ----------------------------------------------------------------------
77 
81  void BUILD_CATALOG_cmdHandler(FwOpcodeType opCode,
82  U32 cmdSeq
83  ) override;
84 
88  void START_XMIT_CATALOG_cmdHandler(
89  FwOpcodeType opCode,
90  U32 cmdSeq,
91  Fw::Wait wait
92  ) override;
93 
97  void STOP_XMIT_CATALOG_cmdHandler(FwOpcodeType opCode,
98  U32 cmdSeq
99  ) override;
100 
104  void CLEAR_CATALOG_cmdHandler(FwOpcodeType opCode,
105  U32 cmdSeq
106  ) override;
107 
108  // ----------------------------------
109  // Private data structures
110  // ----------------------------------
111 
112  struct DpStateEntry {
113  friend class DpCatalogTester;
114  FwIndexType dir;
115  DpRecord record;
116  };
117 
118  struct DpDstateFileEntry {
119  bool used;
120  bool visited;
121  DpStateEntry entry;
123  };
124 
126  struct DpBtreeNode {
127  DpStateEntry entry;
128  DpBtreeNode* left;
129  DpBtreeNode* right;
130  };
131 
132  // ----------------------------------
133  // Private helpers
134  // ----------------------------------
135 
139  bool insertEntry(DpStateEntry& entry);
140 
143  void deleteEntry(DpStateEntry& entry);
144 
146  enum CheckStat {
147  CHECK_OK,
148  CHECK_CONT,
149  CHECK_ERROR,
150  };
151 
153  CheckStat checkLeftRight(bool condition, DpBtreeNode*& node, const DpStateEntry& newEntry);
154 
156  void resetBinaryTree();
157 
159  Fw::CmdResponse fillBinaryTree();
160 
162  void resetTreeStack();
163 
165  void resetStateFileData();
166 
169  void getFileState(DpStateEntry& entry);
170 
172  void pruneAndWriteStateFile();
173 
175  Fw::CmdResponse loadStateFile();
176 
179  void appendFileState(const DpStateEntry& entry);
180 
184  bool allocateNode(DpBtreeNode*& newNode, const DpStateEntry& newEntry);
185 
187  void sendNextEntry();
188 
192  DpBtreeNode* findNextTreeNode();
193 
196  bool checkInit();
197 
200  Fw::CmdResponse doCatalogBuild();
201 
204  Fw::CmdResponse doCatalogXmit();
205 
206  // ----------------------------------
207  // Private data
208  // ----------------------------------
209  bool m_initialized;
210 
211  DpBtreeNode* m_dpTree;
212  DpBtreeNode* m_freeListHead;
213  DpBtreeNode* m_freeListFoot;
214  DpBtreeNode** m_traverseStack;
215  DpBtreeNode* m_currentNode;
216  DpBtreeNode* m_currentXmitNode;
217 
218  FwSizeType m_numDpRecords;
219  FwSizeType m_numDpSlots;
220 
221  Fw::FileNameString m_directories[DP_MAX_DIRECTORIES];
222  FwSizeType m_numDirectories;
223  Fw::String m_fileList[DP_MAX_FILES];
224 
225  Fw::FileNameString m_stateFile;
226  DpDstateFileEntry* m_stateFileData;
227  FwSizeType m_stateFileEntries;
228 
229  FwSizeType m_memSize;
230  void* m_memPtr;
231  FwEnumStoreType m_allocatorId;
232  Fw::MemAllocator* m_allocator;
233 
234  bool m_xmitInProgress;
235  FwIndexType m_currStackEntry;
236  Fw::FileNameString m_currXmitFileName;
237  bool m_xmitCmdWait;
238  U64 m_xmitBytes;
239  FwOpcodeType m_xmitOpCode;
240  U32 m_xmitCmdSeq;
241 };
242 
243 } // namespace Svc
244 
245 #endif
Data structure representing a data product.
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
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:49
static const FwIndexType DP_MAX_FILES
DpCatalog(const char *const compName)
DpCatalog constructor.
Definition: DpCatalog.cpp:23
~DpCatalog()
DpCatalog destructor.
Definition: DpCatalog.cpp:47
friend class DpCatalogTester
Definition: DpCatalog.hpp:22
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:180