Belle II Software  release-08-01-10
SharedMemory.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #ifndef _Belle2_SharedMemory_h
9 #define _Belle2_SharedMemory_h
10 
11 #include <string>
12 
13 namespace Belle2 {
19  class SharedMemory {
20 
21  public:
22  static bool unlink(const std::string& path);
23 
24  // constructors and destructor
25  public:
26  SharedMemory();
27  SharedMemory(const std::string& path, size_t size);
28  SharedMemory(const SharedMemory&);
29  ~SharedMemory();
30 
31  // member functions;
32  public:
33  bool open(const std::string& path, size_t size);
34  bool open();
35  void close();
36  bool unlink();
37  bool seekTo(size_t);
38  bool seekBy(size_t);
39  void* map(size_t, size_t);
40  void* map();
41  bool isOpened();
42  const std::string& getPath() const { return m_path; }
43  size_t size() const { return m_size; }
44  int getfd() const { return m_fd; }
45  bool truncate(size_t size);
46 
47  // operators
48  public:
49  const SharedMemory& operator=(const SharedMemory&);
50 
51  // data members;
52  private:
53  int m_fd;
54  std::string m_path;
55  size_t m_size;
56  void* m_addr;
57 
58  };
59 
61 };
62 
63 #endif
Abstract base class for different kinds of events.