All Classes Namespaces Functions Variables Typedefs Enumerations Pages
file.h
1 /* Copyright (C) 2009 Markus Friedrich
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact:
18  * friedrich.at.gc@googlemail.com
19  *
20  */
21 
22 #ifndef _HDF5SERIE_FILE_H_
23 #define _HDF5SERIE_FILE_H_
24 
25 #include <hdf5serie/group.h>
26 #include <boost/filesystem.hpp>
27 #include <boost/date_time/posix_time/posix_time_types.hpp>
28 
29 namespace boost {
30  namespace interprocess {
31 #ifdef _WIN32
32  class windows_shared_memory;
33 #else
34  class shared_memory_object;
35 #endif
36  class mapped_region;
37  class interprocess_mutex;
38  class interprocess_condition;
39  }
40 }
41 
42 namespace H5 {
43 
44  class Dataset;
45 
46  class File : public GroupBase {
47  friend class Dataset;
48  friend class GroupBase;
49  public:
50  enum FileAccess {
51  read,
52  write
53  };
54  File(const boost::filesystem::path &filename, FileAccess type_);
55  ~File();
56  void reopenAsSWMR();
57  static void reopenAllFilesAsSWMR();
58  static int getDefaultCompression() { return defaultCompression; }
59  static void setDefaultCompression(int comp) { defaultCompression=comp; }
60  static int getDefaultChunkSize() { return defaultChunkSize; }
61  static void setDefaultChunkSize(int chunk) { defaultChunkSize=chunk; }
62  void refresh();
63  void flush();
64 
65  void requestWriterFlush();
66  bool waitForWriterFlush();
67 
68  void flushIfRequested();
69  static void flushAllFiles();
70  static void flushAllFilesIfRequested();
71  void refreshAfterWriterFlush();
72  static void refreshAllFiles();
73  static void refreshFilesAfterWriterFlush(const std::set<H5::File*> &files);
74  static void refreshAllFilesAfterWriterFlush();
75 
76  struct IPC {
77  boost::filesystem::path filename; // the filename of this IPC
78  std::string interprocessName; // the name of this IPC
79 #ifdef _WIN32
80  std::shared_ptr<boost::interprocess::windows_shared_memory> shm; // shared memory used for this IPC
81 #else
82  std::shared_ptr<boost::interprocess::shared_memory_object> shm; // shared memory used for this IPC
83 #endif
84  std::shared_ptr<boost::interprocess::mapped_region> shmmap; // mapping of shared memory to real memory
85  bool *flushVar; // true if flush by the writer is requested (lies in shared memory)
86  boost::interprocess::interprocess_mutex *mutex; // mutex for access of flushVar and cond (lies in shared memory)
87  boost::interprocess::interprocess_condition *cond; // condition to notify readers (lies in shared memory)
88  boost::posix_time::ptime flushRequestTime; // the time of the flush request (only used on reader side)
89  };
90  protected:
91  FileAccess type;
92  bool isSWMR;
93  void close();
94  void open();
95  static int defaultCompression;
96  static int defaultChunkSize;
97 
98  static std::set<File*> writerFiles;
99  static std::set<File*> readerFiles;
100  std::string interprocessName;
101  IPC ipc;
102  void addFileToNotifyOnRefresh(const boost::filesystem::path &filename);
103  std::vector<IPC> ipcAdd;
104  };
105 }
106 
107 #endif
Definition: file.h:76
Definition: group.h:30
Definition: interface.h:249
Definition: file.h:46

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML