ARC SDK
FileAccess.h
1 #ifndef __ARC_FILEACCESS_H__
2 #define __ARC_FILEACCESS_H__
3 
4 #include <string>
5 #include <list>
6 
7 #include <unistd.h>
8 #include <sys/stat.h>
9 #include <sys/types.h>
10 
11 #include <glibmm.h>
12 
13 #ifdef WIN32
14 #ifndef uid_t
15 #define uid_t int
16 #endif
17 #ifndef gid_t
18 #define gid_t int
19 #endif
20 #endif
21 
22 namespace Arc {
23 
24  class Run;
25 
27 
35  class FileAccess {
36  public:
38  FileAccess(void);
40  ~FileAccess(void);
42  static FileAccess* Acquire(void);
44  static void Release(FileAccess* fa);
46  bool ping(void);
48 
53  bool fa_setuid(int uid,int gid);
55 
58  bool fa_mkdir(const std::string& path, mode_t mode);
60 
65  bool fa_mkdirp(const std::string& path, mode_t mode);
67 
70  bool fa_link(const std::string& oldpath, const std::string& newpath);
72 
75  bool fa_softlink(const std::string& oldpath, const std::string& newpath);
77 
82  bool fa_copy(const std::string& oldpath, const std::string& newpath, mode_t mode);
84 
87  bool fa_rename(const std::string& oldpath, const std::string& newpath);
89 
92  bool fa_chmod(const std::string& path,mode_t mode);
94 
97  bool fa_stat(const std::string& path, struct stat& st);
99 
102  bool fa_lstat(const std::string& path, struct stat& st);
104 
107  bool fa_fstat(struct stat& st);
109 
112  bool fa_ftruncate(off_t length);
114 
117  off_t fa_fallocate(off_t length);
119 
122  bool fa_readlink(const std::string& path, std::string& linkpath);
124 
127  bool fa_remove(const std::string& path);
129 
132  bool fa_unlink(const std::string& path);
134 
137  bool fa_rmdir(const std::string& path);
139 
142  bool fa_rmdirr(const std::string& path);
144 
149  bool fa_opendir(const std::string& path);
151 
154  bool fa_closedir(void);
156 
159  bool fa_readdir(std::string& name);
161 
164  bool fa_open(const std::string& path, int flags, mode_t mode);
166 
169  bool fa_close(void);
171 
177  bool fa_mkstemp(std::string& path, mode_t mode);
179 
182  off_t fa_lseek(off_t offset, int whence);
184 
187  ssize_t fa_read(void* buf,size_t size);
189 
192  ssize_t fa_write(const void* buf,size_t size);
194 
197  ssize_t fa_pread(void* buf,size_t size,off_t offset);
199 
202  ssize_t fa_pwrite(const void* buf,size_t size,off_t offset);
204  int geterrno() { return errno_; };
206  operator bool(void) { return (file_access_ != NULL); };
208  bool operator!(void) { return (file_access_ == NULL); };
210  static void testtune(void);
211  private:
212  Glib::Mutex lock_;
213  Run* file_access_;
214  int errno_;
215  uid_t uid_;
216  gid_t gid_;
217  public:
219  typedef struct {
220  unsigned int size;
221  unsigned int cmd;
222  } header_t;
223  };
224 
226 
232  public:
234  FileAccessContainer(unsigned int minval, unsigned int maxval);
236  FileAccessContainer(void);
238  ~FileAccessContainer(void);
240 
243  FileAccess* Acquire(void);
245 
247  void Release(FileAccess* fa);
249  void SetMin(unsigned int val);
251  void SetMax(unsigned int val);
252  private:
253  Glib::Mutex lock_;
254  unsigned int min_;
255  unsigned int max_;
256  std::list<FileAccess*> fas_;
257  void KeepRange(void);
258  };
259 
260 } // namespace Arc
261 
262 #endif // __ARC_FILEACCESS_H__
263