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 
17 #include <config/DpCatalogCfg.hpp>
18 #include <config/DpCfg.hpp>
19 
20 #define DIRECTORY_DELIMITER "/"
21 
22 namespace Svc {
23 
24 class DpCatalog final : public DpCatalogComponentBase {
25  friend class DpCatalogTester;
26 
27  public:
28  // ----------------------------------------------------------------------
29  // Component construction and destruction
30  // ----------------------------------------------------------------------
31 
34  DpCatalog(const char* const compName
35  );
36 
38  ~DpCatalog() = default;
39 
49  FwSizeType numDirs,
50  Fw::FileNameString& stateFile,
51  FwEnumStoreType memId,
52  Fw::MemAllocator& allocator);
53 
54  // @brief clean up component.
55  // Deallocates memory.
56  void shutdown();
57 
58  private:
59  // ----------------------------------------------------------------------
60  // Handler implementations for user-defined typed input ports
61  // ----------------------------------------------------------------------
62 
66  void fileDone_handler(FwIndexType portNum,
67  const Svc::SendFileResponse& resp) override;
68 
72  void pingIn_handler(FwIndexType portNum,
73  U32 key
74  ) override;
75 
79  void addToCat_handler(FwIndexType portNum,
80  const Fw::StringBase& fileName,
81  FwDpPriorityType priority,
82  FwSizeType size
83  ) override;
84 
85  private:
86  // ----------------------------------------------------------------------
87  // Handler implementations for commands
88  // ----------------------------------------------------------------------
89 
93  void BUILD_CATALOG_cmdHandler(FwOpcodeType opCode,
94  U32 cmdSeq
95  ) override;
96 
100  void START_XMIT_CATALOG_cmdHandler(
101  FwOpcodeType opCode,
102  U32 cmdSeq,
103  Fw::Wait wait,
104  bool remainActive
105  ) override;
106 
110  void STOP_XMIT_CATALOG_cmdHandler(FwOpcodeType opCode,
111  U32 cmdSeq
112  ) override;
113 
117  void CLEAR_CATALOG_cmdHandler(FwOpcodeType opCode,
118  U32 cmdSeq
119  ) override;
120 
121  // ----------------------------------
122  // Private data structures
123  // ----------------------------------
124 
125  struct DpStateEntry {
126  friend class DpCatalogTester;
127  FwIndexType dir;
128  DpRecord record;
129 
134  static int compareEntries(const DpStateEntry& left, const DpStateEntry& right);
135 
136  bool operator==(const DpStateEntry& other) const;
137  bool operator!=(const DpStateEntry& other) const;
138  bool operator>(const DpStateEntry& other) const;
139  bool operator<(const DpStateEntry& other) const;
140  };
141 
142  struct DpDstateFileEntry {
143  bool used;
144  bool visited;
145  DpStateEntry entry;
147  };
148 
149  // ----------------------------------
150  // Private helpers
151  // ----------------------------------
152 
156  FwSizeType determineDirectory(Fw::String fullFile);
157 
162  int processFile(Fw::String fullFile, FwSizeType dir);
163 
167  bool insertEntry(DpStateEntry& entry);
168 
170  void resetCatalog();
171 
173  Fw::CmdResponse fillBinaryTree();
174 
176  void resetStateFileData();
177 
180  void getFileState(DpStateEntry& entry);
181 
183  void pruneAndWriteStateFile();
184 
186  Fw::CmdResponse loadStateFile();
187 
190  void appendFileState(const DpStateEntry& entry);
191 
193  void sendNextEntry();
194 
198  bool findNextEntry(DpStateEntry& entry);
199 
202  bool checkInit();
203 
206  Fw::CmdResponse doCatalogBuild();
207 
210  Fw::CmdResponse doCatalogXmit();
211 
214  void dispatchWaitedResponse(Fw::CmdResponse response);
215 
216  // ----------------------------------
217  // Private data
218  // ----------------------------------
219  bool m_initialized = false;
220 
222  DpStateEntry m_currentXmitEntry;
223  bool m_hasCurrentXmit = false;
224 
225  FwSizeType m_numDpSlots = 0;
226 
227  Fw::FileNameString m_directories[DP_MAX_DIRECTORIES];
228  FwSizeType m_numDirectories = 0;
229  Fw::String m_fileList[DP_MAX_FILES];
230 
231  Fw::FileNameString m_stateFile;
232  DpDstateFileEntry* m_stateFileData = nullptr;
233  FwSizeType m_stateFileEntries = 0;
234 
235  FwSizeType m_memSize = 0;
236  void* m_memPtr = nullptr;
237  FwEnumStoreType m_allocatorId = 0;
238  Fw::MemAllocator* m_allocator = nullptr;
239 
240  bool m_catalogBuilt = false;
241  bool m_xmitInProgress = false;
242  Fw::FileNameString m_currXmitFileName;
243  bool m_xmitCmdWait = false;
244  U64 m_xmitBytes = 0;
245  FwOpcodeType m_xmitOpCode = 0;
246  U32 m_xmitCmdSeq = 0;
247 
248  U32 m_pendingFiles = 0;
249  U64 m_pendingDpBytes = 0;
250 
251  bool m_remainActive = false;
252 };
255 
256 } // namespace Svc
257 
258 #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.
~DpCatalog()=default
DpCatalog destructor.
void configure(Fw::FileNameString directories[DP_MAX_DIRECTORIES], FwSizeType numDirs, Fw::FileNameString &stateFile, FwEnumStoreType memId, Fw::MemAllocator &allocator)
Configure the DpCatalog.
Definition: DpCatalog.cpp:29
static const FwIndexType DP_MAX_FILES
DpCatalog(const char *const compName)
DpCatalog constructor.
Definition: DpCatalog.cpp:25
friend class DpCatalogTester
Definition: DpCatalog.hpp:25
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