blob: 96025b0108705b28ed57cdf9c6b2a8e149e47b17 [file] [log] [blame]
Tim Yao10e5d9b2020-12-30 17:38:10 -08001#ifndef __IPCBUFFER_H
2#define __IPCBUFFER_H
3
4#include <boost/interprocess/managed_shared_memory.hpp>
5
6using namespace boost::interprocess;
7
8class IpcBuffer
9{
10public:
11 IpcBuffer(const char *name, size_t capacity);
12 ~IpcBuffer();
13
14 size_t size() const { return size_; }
15 size_t capacity() const { return capacity_; }
16 size_t write(const uint8_t *data, size_t bytes);
17 size_t read(uint8_t *data, size_t bytes);
18 void write_nb(const uint8_t *data, size_t bytes);
19 void get_write_position(uint64_t& time, uint64_t& position);
20 void reset();
21 uint8_t *start_ptr();
22 const char *name();
23
24private:
25 // Note: members can be access from different process
26 // only keep information which are common to all processes
27 // addresses must be mapped during runtime
28 size_t begin_index_, end_index_, size_, capacity_;
29 managed_shared_memory::handle_t handle_;
30 std::string name_;
31 bool blocking_;
32 interprocess_mutex wr_position_mutex_;
33 uint64_t wr_position_;
34 uint64_t wr_time_;
35};
36
37#endif