F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
FileWorker.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title FileWorker.hpp
3 // \author racheljt
4 // \brief hpp file for FileWorker component implementation class
5 // ======================================================================
6 
7 #ifndef Svc_FileWorker_HPP
8 #define Svc_FileWorker_HPP
9 
10 #include <atomic>
11 #include "Fw/Types/BasicTypes.hpp"
13 #include "Fw/Types/StringUtils.hpp"
14 #include "Os/File.hpp"
15 #include "Os/FileSystem.hpp"
16 #include "Os/Mutex.hpp"
19 #include "Utils/CRCChecker.hpp"
20 #include "Utils/Hash/Hash.hpp"
21 
22 namespace Svc {
23 
25  friend class FileWorkerTester;
26 
27  public:
28  // ----------------------------------------------------------------------
29  // Component construction and destruction
30  // ----------------------------------------------------------------------
31 
33  FileWorker(const char* const compName
34  );
35 
37  ~FileWorker();
38 
41  void configure(U64 chunkSize);
42 
43  private:
44  static constexpr U64 BLOCK_SIZE_BYTES = 4096;
45  static constexpr U32 TIMEOUT_MS = 1000000;
46  static constexpr U32 MAX_LOOP_ITERATIONS = 32;
47 
48  Svc::FileWorkerState m_state;
49  std::atomic<bool> m_abort;
50  U64 m_chunkSize;
51 
52  // ----------------------------------------------------------------------
53  // Handler implementations for typed input ports
54  // ----------------------------------------------------------------------
55 
57  void cancelIn_handler(FwIndexType portNum
58  ) override;
59 
61  void readIn_handler(FwIndexType portNum,
62  const Fw::StringBase& path,
63  Fw::Buffer& buffer) override;
64 
66  void verifyIn_handler(FwIndexType portNum,
67  const Fw::StringBase& path,
68  U32 crc) override;
69 
71  void writeIn_handler(FwIndexType portNum,
72  const Fw::StringBase& path,
73  Fw::Buffer& buffer,
74  FwSizeType offsetBytes,
75  bool append) override;
76 
77  // ----------------------------------------------------------------------
78  // Helper functions
79  // ----------------------------------------------------------------------
80 
81  Svc::FileWorkerStatus readBufferFromFile(Fw::Buffer& buffer, const char* const fileName);
82  Svc::FileWorkerReadStatus readFile(Fw::Buffer& buffer,
83  FwSizeType size,
84  Os::File& file,
85  const Fw::LogStringArg& fileNameStr);
86  Svc::FileWorkerReadStatus readFileBytes(Fw::Buffer& buffer, FwSizeType size, Os::File& file, FwSizeType& bytesRead);
87 
88  bool getHash(const char* const hashFileName,
89  Utils::Hash& hash,
90  Utils::HashBuffer& hashBuffer,
91  const U8* const data,
92  const FwSizeType size);
94  static bool pathFitsWithHashExtension(const Fw::StringBase& path);
95  bool writeBufferToFile(Fw::Buffer& buffer, const char* fileName, FwSizeType offset, bool append);
96  void writeBufferHashToFile(Fw::Buffer& buffer, const char* fileName, FwSizeType offset, bool append);
97  FwSizeType writeToFile(const U8* data, FwSizeType size, Os::File& file, const char* fileName);
98 };
99 
100 } // namespace Svc
101 
102 #endif
PlatformSizeType FwSizeType
friend class FileWorkerTester
Definition: FileWorker.hpp:25
A generic interface for creating and comparing hash values.
Definition: Hash.hpp:24
~FileWorker()
Destroy FileWorker object.
Definition: FileWorker.cpp:26
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
PlatformIndexType FwIndexType
void configure(U64 chunkSize)
Definition: FileWorker.cpp:21
C++ header for working with basic fprime types.
A container class for holding a hash buffer.
Definition: HashBuffer.hpp:26
FileWorker(const char *const compName)
Construct FileWorker object.
Definition: FileWorker.cpp:15
RateGroupDivider component implementation.
FileWorkerReadStatus
Auto-generated base for FileWorker component.