DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
ipcqueue.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // DISPLACE: DYNAMIC INDIVIDUAL VESSEL-BASED SPATIAL PLANNING
3 // AND EFFORT DISPLACEMENT
4 // Copyright (c) 2012-2019 Francois Bastardie <fba@aqua.dtu.dk>
5 
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // --------------------------------------------------------------------------
20 
21 
22 #ifndef IPCQUEUE_H
23 #define IPCQUEUE_H
24 
25 #include <commons_global.h>
26 #include <ipcmsgtypes.h>
27 #include <boost/interprocess/containers/list.hpp>
28 #include <boost/interprocess/managed_shared_memory.hpp>
29 #include <boost/interprocess/allocators/allocator.hpp>
30 #include <boost/interprocess/sync/interprocess_mutex.hpp>
31 #include <boost/interprocess/sync/interprocess_condition.hpp>
32 #include <boost/interprocess/containers/list.hpp>
33 #include <boost/interprocess/containers/string.hpp>
34 #include <cstddef>
35 
40 {
41 public:
42  IpcQueue();
43  ~IpcQueue();
44 
45  bool push(IpcMessageTypes type, void *buffer, size_t len);
46  IpcMessageTypes pickOrWait(void *buffer, size_t maxlen, size_t *len);
47 
48  static void forceCleanup();
49 private:
50  bool empty() const;
51  bool full() const;
52  size_t space_available() const;
53  bool push (char byte);
54  char pop();
55 
56  struct MessageManager {
57  boost::interprocess::interprocess_mutex mutex;
58  boost::interprocess::interprocess_condition cond_notempty;
59  boost::interprocess::interprocess_condition cond_notfull;
60 
61  static const size_t BufferSize = 512*1024;
62 
63  char buffer[BufferSize];
64  int head;
65  int tail;
66  int size;
67 
68  MessageManager()
69  : mutex(),
70  cond_notempty(),
71  cond_notfull(),
72  head(0), tail(0),
73  size(BufferSize)
74  {
75 
76  }
77  };
78 
79  static const size_t SharedMemorySize;
80  static const char *SharedListName;
81 
82  boost::interprocess::shared_memory_object shmobj;
83  boost::interprocess::mapped_region mapreg;
84 
85 // boost::interprocess::managed_shared_memory sharedMemory;
86 // boost::interprocess::managed_heap_memory::handle_t sharedHandle;
87  MessageManager *mManager;
88 };
89 
90 #endif // IPCQUEUE_H
IpcMessageTypes
Definition: ipcmsgtypes.h:47
implements a CircularBuffer to be used in a boost::interprocess::managed_heap_memory
Definition: ipcqueue.h:39
#define COMMONSSHARED_EXPORT
Definition: commons_global.h:23