All Classes Namespaces Functions 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 #include <boost/shared_ptr.hpp>
29 
30 namespace boost {
31  namespace interprocess {
32 #ifdef _WIN32
33  class windows_shared_memory;
34 #else
35  class shared_memory_object;
36 #endif
37  class mapped_region;
38  class interprocess_mutex;
39  class interprocess_condition;
40  }
41 }
42 
43 namespace H5 {
44 
45  class Dataset;
46 
47  class File : public GroupBase {
48  friend class Dataset;
49  friend class GroupBase;
50  public:
51  enum FileAccess {
52  read,
53  write
54  };
55  File(const boost::filesystem::path &filename, FileAccess type_);
56  ~File();
57  void reopenAsSWMR();
58  static void reopenAllFilesAsSWMR();
59  static int getDefaultCompression() { return defaultCompression; }
60  static void setDefaultCompression(int comp) { defaultCompression=comp; }
61  static int getDefaultChunkSize() { return defaultChunkSize; }
62  static void setDefaultChunkSize(int chunk) { defaultChunkSize=chunk; }
63  void refresh();
64  void flush();
65 
66  void requestWriterFlush();
67  bool waitForWriterFlush();
68 
69  void flushIfRequested();
70  static void flushAllFiles();
71  static void flushAllFilesIfRequested();
72  void refreshAfterWriterFlush();
73  static void refreshAllFiles();
74  static void refreshFilesAfterWriterFlush(const std::set<H5::File*> &files);
75  static void refreshAllFilesAfterWriterFlush();
76 
77  struct IPC {
78  boost::filesystem::path filename; // the filename of this IPC
79  std::string interprocessName; // the name of this IPC
80 #ifdef _WIN32
81  boost::shared_ptr<boost::interprocess::windows_shared_memory> shm; // shared memory used for this IPC
82 #else
83  boost::shared_ptr<boost::interprocess::shared_memory_object> shm; // shared memory used for this IPC
84 #endif
85  boost::shared_ptr<boost::interprocess::mapped_region> shmmap; // mapping of shared memory to real memory
86  bool *flushVar; // true if flush by the writer is requested (lies in shared memory)
87  boost::interprocess::interprocess_mutex *mutex; // mutex for access of flushVar and cond (lies in shared memory)
88  boost::interprocess::interprocess_condition *cond; // condition to notify readers (lies in shared memory)
89  boost::posix_time::ptime flushRequestTime; // the time of the flush request (only used on reader side)
90  };
91  protected:
92  FileAccess type;
93  bool isSWMR;
94  void close();
95  void open();
96  static int defaultCompression;
97  static int defaultChunkSize;
98 
99  static std::set<File*> writerFiles;
100  static std::set<File*> readerFiles;
101  std::string interprocessName;
102  IPC ipc;
103  void addFileToNotifyOnRefresh(const boost::filesystem::path &filename);
104  std::vector<IPC> ipcAdd;
105  };
106 }
107 
108 #endif
Definition: file.h:77
Definition: group.h:30
Definition: interface.h:238
Definition: file.h:47

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML