DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
MapFile.hpp
Go to the documentation of this file.
1/*
2 * MapFile.h
3 * OksSystem
4 *
5 * Created by Matthias Wiesmann on 07.01.05.
6 * Copyright 2005 CERN. All rights reserved.
7 *
8 */
9
10#ifndef OKSSYSTEM_MAP_FILE
11#define OKSSYSTEM_MAP_FILE
12
13#include "okssystem/File.hpp"
14
15namespace OksSystem {
16
17 class Descriptor ;
18
26 class MapFile : public File {
27
28 public:
29
30 MapFile(const std::string &file, size_t size, size_t offset, bool read_mode, bool write_mode, mode_t permissions = 0666) ;
31 ~MapFile();
32
33 void zero() const ;
34 void map();
35 void unmap();
36 bool is_mapped() const;
37 bool is_loaded() const throw() ;
38 void *address() const throw() ;
39 size_t memory_size() const throw() ;
40 OksSystem::Descriptor* fd() const throw() ;
42 protected:
43
44 void open_fd();
45 void close_fd();
46 void map_mem();
47 void unmap_mem();
49 void * m_map_address ;
50 size_t m_map_size ;
51 size_t m_map_offset ;
54 bool m_map_read ;
58 private:
59
60 static const char* const MAP_LOAD_MSG ;
61 static const char* const MAP_NOT_LOAD_MSG ;
62 static const char* const PAGE_SIZE_MSG ;
63 static const char* const READ_OR_WRITE_MSG ;
64 static const char* const MAP_NOT_WRITE_MSG ;
66 } ; // MapFile
67
68} // ers
69
70#endif
File descriptor / Socket wrapper.
Wrapper for file operations.
Definition File.hpp:32
mode_t permissions() const
permissions for the file *‍/
Definition File.cpp:500
size_t size() const
size of file *‍/
Definition File.cpp:530
Wrapper for memory map operations.
Definition MapFile.hpp:26
void unmap_mem()
unmaps the file into memory
Definition MapFile.cpp:105
static const char *const MAP_NOT_LOAD_MSG
message pattern - map is not loaded
Definition MapFile.hpp:61
void * m_map_address
the address of the map in memory
Definition MapFile.hpp:49
void zero() const
builds a zeroed file with correct length
Definition MapFile.cpp:120
size_t m_map_offset
offset in the file of the map
Definition MapFile.hpp:51
size_t m_map_size
the size of the map
Definition MapFile.hpp:50
MapFile(const std::string &file, size_t size, size_t offset, bool read_mode, bool write_mode, mode_t permissions=0666)
Definition MapFile.cpp:31
bool is_mapped() const
is the file mopped im memory
Definition MapFile.cpp:181
bool m_map_write
is the map writable
Definition MapFile.hpp:55
void unmap()
unmaps the file
Definition MapFile.cpp:152
static const char *const MAP_LOAD_MSG
message pattern - map is loaded
Definition MapFile.hpp:60
static const char *const READ_OR_WRITE_MSG
message pattern - map mode is neither read nor write
Definition MapFile.hpp:63
Descriptor * m_map_descriptor
internal file descriptor
Definition MapFile.hpp:52
bool m_is_mapped
is the file mapped in memory
Definition MapFile.hpp:56
bool is_loaded() const
is the map loaded in memory
Definition MapFile.cpp:157
static const char *const PAGE_SIZE_MSG
message pattern - illegal page size
Definition MapFile.hpp:62
OksSystem::Descriptor * fd() const
the file descriptor. This method returns a valid pointer only if called after map().
Definition MapFile.cpp:185
void open_fd()
opens the file descriptor for the map
Definition MapFile.cpp:60
void close_fd()
closes the file descriptor for the map
Definition MapFile.cpp:70
size_t memory_size() const
the size of the map
Definition MapFile.cpp:175
void map_mem()
maps the file into memory
Definition MapFile.cpp:81
bool m_map_read
is the map readable
Definition MapFile.hpp:54
void map()
maps the file in memory
Definition MapFile.cpp:141
mode_t m_map_permission
permissions associated with the file
Definition MapFile.hpp:53
static const char *const MAP_NOT_WRITE_MSG
message pattern - map is not writable
Definition MapFile.hpp:64
void * address() const
the address of the memory mapped file
Definition MapFile.cpp:167
double offset