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 
49  bool fa_setuid(int uid,int gid);
51  bool fa_mkdir(const std::string& path, mode_t mode);
53 
54  bool fa_mkdirp(const std::string& path, mode_t mode);
56  bool fa_link(const std::string& oldpath, const std::string& newpath);
58  bool fa_softlink(const std::string& oldpath, const std::string& newpath);
60 
61  bool fa_copy(const std::string& oldpath, const std::string& newpath, mode_t mode);
63  bool fa_rename(const std::string& oldpath, const std::string& newpath);
65  bool fa_chmod(const std::string& path,mode_t mode);
67  bool fa_stat(const std::string& path, struct stat& st);
69  bool fa_lstat(const std::string& path, struct stat& st);
71  bool fa_fstat(struct stat& st);
73  bool fa_ftruncate(off_t length);
75  off_t fa_fallocate(off_t length);
77  bool fa_readlink(const std::string& path, std::string& linkpath);
79  bool fa_remove(const std::string& path);
81  bool fa_unlink(const std::string& path);
83  bool fa_rmdir(const std::string& path);
85  bool fa_rmdirr(const std::string& path);
87  bool fa_opendir(const std::string& path);
89  bool fa_closedir(void);
91  bool fa_readdir(std::string& name);
93  bool fa_open(const std::string& path, int flags, mode_t mode);
95  bool fa_close(void);
97 
99  bool fa_mkstemp(std::string& path, mode_t mode);
101  off_t fa_lseek(off_t offset, int whence);
103  ssize_t fa_read(void* buf,size_t size);
105  ssize_t fa_write(const void* buf,size_t size);
107  ssize_t fa_pread(void* buf,size_t size,off_t offset);
109  ssize_t fa_pwrite(const void* buf,size_t size,off_t offset);
111  int geterrno() { return errno_; };
113  operator bool(void) { return (file_access_ != NULL); };
115  bool operator!(void) { return (file_access_ == NULL); };
117  static void testtune(void);
118  private:
119  Glib::Mutex lock_;
120  Run* file_access_;
121  int errno_;
122  uid_t uid_;
123  gid_t gid_;
124  public:
126  typedef struct {
127  unsigned int size;
128  unsigned int cmd;
129  } header_t;
130  };
131 
133 
139  public:
141  FileAccessContainer(unsigned int minval, unsigned int maxval);
143  FileAccessContainer(void);
145  ~FileAccessContainer(void);
147 
150  FileAccess* Acquire(void);
152 
154  void Release(FileAccess* fa);
156  void SetMin(unsigned int val);
158  void SetMax(unsigned int val);
159  private:
160  Glib::Mutex lock_;
161  unsigned int min_;
162  unsigned int max_;
163  std::list<FileAccess*> fas_;
164  void KeepRange(void);
165  };
166 
167 } // namespace Arc
168 
169 #endif // __ARC_FILEACCESS_H__
170