CARMA C++
MemoryMappedFile.h
Go to the documentation of this file.
1 
2 #ifndef CARMA_UI_RTD_MEMORYMAPPEDFILE_H_
3 #define CARMA_UI_RTD_MEMORYMAPPEDFILE_H_
4 
18 #include <sys/mman.h>
19 #include <iostream>
20 #include <string>
21 
22 
23 
24 
25 namespace carma {
26  namespace ui {
27  namespace rtd {
28 
29 
30 struct MapfileHeader;
31 
36 
74 public:
78  enum Protection_t {
79  NoAccess = PROT_NONE,
80  Read = PROT_READ,
81  Write = PROT_WRITE,
82  Exec = PROT_EXEC
83  };
84 
95  MemoryMappedFile(const char* map_file_name,
96  size_t client_size,
97  bool reuse,
98  Protection_t p_mask = Protection_t (Read | Write),
99  bool persistent = true);
108  MemoryMappedFile(const std::string& map_file_name,
109  size_t client_size,
110  bool reuse,
111  Protection_t p_mask = Protection_t (Read | Write),
112  bool persistent = true);
113 
119  bool lockRead();
123  bool lockWrite();
127  bool unlock();
131  void* getClientArea();
135  const char* getFileName();
139  int getFileDescriptor() const;
140 
141 private:
142  void init(const char* map_file_name,
143  size_t client_size,
144  bool reuse,
145  Protection_t p_mask = Protection_t (Read | Write),
146  bool persistent = true);
147  MapfileHeader* header;
148  void* client_data;
149  char* file_name;
150  int fd;
151  bool realFile;
152  bool debug;
153 };
154 
155 
156 
157 }}} // End namespace carma::ui::rtd
158 
159 
160 #endif // _MEMORYMAPPEDFILE_H_
161 
162 
163 
bool unlock()
Unlock the file.
Exceptions for MemoryMappedFile&#39;s.
Protection_t
File protection flags.
Memory Mapped file is a class that provides a C++ interface to the mmap(2) system call...
MemoryMappedFile(const char *map_file_name, size_t client_size, bool reuse, Protection_t p_mask=Protection_t(Read|Write), bool persistent=true)
bool lockRead()
Lock the file for read access.
void * getClientArea()
Get a pointer to the start of the data area.
int getFileDescriptor() const
Get the file descriptor.
bool lockWrite()
Lock the file for write access.
const char * getFileName()
Get the filename.