diff --git a/core-writer/include/H5WriteModule.hpp b/core-writer/include/H5WriteModule.hpp new file mode 100644 index 0000000..989d9b1 --- /dev/null +++ b/core-writer/include/H5WriteModule.hpp @@ -0,0 +1,32 @@ +#ifndef H5WRITERMODULE_H +#define H5WRITERMODULE_H + +#include +#include "RingBuffer.hpp" +#include "ZmqReceiver.hpp" +#include "H5Format.hpp" + +class H5WriteModule { + typedef std::unordered_map header_map; + + RingBuffer& ring_buffer_; + const header_map& header_values_; + const H5Format& format_; + std::atomic_bool is_writing_; + std::thread writing_thread_; + +protected: + void write_thread(); + +public: + H5WriteModule( + RingBuffer& ring_buffer, + const header_map& header_values, + const H5Format& format); + + void start_writing(); + void stop_writing(); +}; + + +#endif //H5WRITERMODULE_H diff --git a/core-writer/src/module/H5WriteModule.cpp b/core-writer/src/module/H5WriteModule.cpp new file mode 100644 index 0000000..773e1da --- /dev/null +++ b/core-writer/src/module/H5WriteModule.cpp @@ -0,0 +1,32 @@ +#include "H5WriteModule.hpp" +#include + +using namespace std; + +H5WriteModule::H5WriteModule( + RingBuffer& ring_buffer, + const header_map& header_values, + const H5Format& format) : + ring_buffer_(ring_buffer), + header_values_(header_values), + format_(format), + is_writing_(false) +{ +} + +void H5WriteModule::stop_writing() +{ + #ifdef DEBUG_OUTPUT + using namespace date; + using namespace chrono; + cout << "[" << system_clock::now() << "]"; + cout << "[H5WriteModule::stop_writing]"; + cout << " Disable writing." << endl; + #endif + + is_writing_ = false; + + if (writing_thread_.joinable()) { + writing_thread_.join(); + } +}