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 
15 #include <config/DpCfg.hpp>
16 #include <config/DpCatalogCfg.hpp>
18 
19 namespace Svc {
20 
21  class DpCatalog final :
23  {
24 
25  friend class DpCatalogTester;
26 
27  public:
28 
29  // ----------------------------------------------------------------------
30  // Component construction and destruction
31  // ----------------------------------------------------------------------
32 
35  DpCatalog(
36  const char* const compName
37  );
38 
40  ~DpCatalog();
41 
50  void configure(
52  FwSizeType numDirs,
53  Fw::FileNameString& stateFile,
54  FwEnumStoreType memId,
55  Fw::MemAllocator& allocator
56  );
57 
58  // @brief clean up component.
59  // Deallocates memory.
60  void shutdown();
61 
62  private:
63 
64  // ----------------------------------------------------------------------
65  // Handler implementations for user-defined typed input ports
66  // ----------------------------------------------------------------------
67 
71  void fileDone_handler(
72  FwIndexType portNum,
73  const Svc::SendFileResponse& resp
74  ) override;
75 
79  void pingIn_handler(
80  FwIndexType portNum,
81  U32 key
82  ) override;
83 
84  private:
85 
86  // ----------------------------------------------------------------------
87  // Handler implementations for commands
88  // ----------------------------------------------------------------------
89 
93  void BUILD_CATALOG_cmdHandler(
94  FwOpcodeType opCode,
95  U32 cmdSeq
96  ) override;
97 
101  void START_XMIT_CATALOG_cmdHandler(
102  FwOpcodeType opCode,
103  U32 cmdSeq,
104  Fw::Wait wait
105  ) override;
106 
110  void STOP_XMIT_CATALOG_cmdHandler(
111  FwOpcodeType opCode,
112  U32 cmdSeq
113  ) override;
114 
118  void CLEAR_CATALOG_cmdHandler(
119  FwOpcodeType opCode,
120  U32 cmdSeq
121  ) override;
122 
123 
124  // ----------------------------------
125  // Private data structures
126  // ----------------------------------
127 
128  struct DpStateEntry {
129  friend class DpCatalogTester;
130  FwIndexType dir;
131  DpRecord record;
132  };
133 
134  struct DpDstateFileEntry {
135  bool used;
136  bool visited;
137  DpStateEntry entry;
138  };
139 
141  struct DpBtreeNode {
142  DpStateEntry entry;
143  DpBtreeNode* left;
144  DpBtreeNode* right;
145  };
146 
147  // ----------------------------------
148  // Private helpers
149  // ----------------------------------
150 
154  bool insertEntry(DpStateEntry& entry);
155 
158  void deleteEntry(DpStateEntry& entry);
159 
161  enum CheckStat {
162  CHECK_OK,
163  CHECK_CONT,
164  CHECK_ERROR,
165  };
166 
168  CheckStat checkLeftRight(bool condition, DpBtreeNode* &node, const DpStateEntry& newEntry);
169 
171  void resetBinaryTree();
172 
174  Fw::CmdResponse fillBinaryTree();
175 
177  void resetTreeStack();
178 
180  void resetStateFileData();
181 
184  void getFileState(DpStateEntry& entry);
185 
187  void pruneAndWriteStateFile();
188 
190  Fw::CmdResponse loadStateFile();
191 
194  void appendFileState(const DpStateEntry& entry);
195 
199  bool allocateNode(
200  DpBtreeNode* &newNode,
201  const DpStateEntry& newEntry);
202 
204  void sendNextEntry();
205 
209  DpBtreeNode* findNextTreeNode();
210 
213  bool checkInit();
214 
217  Fw::CmdResponse doCatalogBuild();
218 
221  Fw::CmdResponse doCatalogXmit();
222 
223  // ----------------------------------
224  // Private data
225  // ----------------------------------
226  bool m_initialized;
227 
228  DpBtreeNode* m_dpTree;
229  DpBtreeNode* m_freeListHead;
230  DpBtreeNode* m_freeListFoot;
231  DpBtreeNode** m_traverseStack;
232  DpBtreeNode* m_currentNode;
233  DpBtreeNode* m_currentXmitNode;
234 
235  FwSizeType m_numDpRecords;
236  FwSizeType m_numDpSlots;
237 
238  Fw::FileNameString m_directories[DP_MAX_DIRECTORIES];
239  FwSizeType m_numDirectories;
240  Fw::String m_fileList[DP_MAX_FILES];
241 
242  Fw::FileNameString m_stateFile;
243  DpDstateFileEntry* m_stateFileData;
244  FwSizeType m_stateFileEntries;
245 
246  FwSizeType m_memSize;
247  void* m_memPtr;
248  FwEnumStoreType m_allocatorId;
249  Fw::MemAllocator* m_allocator;
250 
251  bool m_xmitInProgress;
252  FwIndexType m_currStackEntry;
253  Fw::FileNameString m_currXmitFileName;
254  bool m_xmitCmdWait;
255  U64 m_xmitBytes;
256  FwOpcodeType m_xmitOpCode;
257  U32 m_xmitCmdSeq;
258 
259  };
260 
261 }
262 
263 #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:55
static const FwIndexType DP_MAX_FILES
DpCatalog(const char *const compName)
DpCatalog constructor.
Definition: DpCatalog.cpp:24
~DpCatalog()
DpCatalog destructor.
Definition: DpCatalog.cpp:52
friend class DpCatalogTester
Definition: DpCatalog.hpp:25
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