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 
14 namespace Arc {
15 
16  class Run;
17 
19 
27  class FileAccess {
28  public:
30  FileAccess(void);
32  ~FileAccess(void);
34  static FileAccess* Acquire(void);
36  static void Release(FileAccess* fa);
38  bool ping(void);
40 
45  bool fa_setuid(int uid,int gid);
47 
50  bool fa_mkdir(const std::string& path, mode_t mode);
52 
57  bool fa_mkdirp(const std::string& path, mode_t mode);
59 
62  bool fa_link(const std::string& oldpath, const std::string& newpath);
64 
67  bool fa_softlink(const std::string& oldpath, const std::string& newpath);
69 
74  bool fa_copy(const std::string& oldpath, const std::string& newpath, mode_t mode);
76 
79  bool fa_rename(const std::string& oldpath, const std::string& newpath);
81 
84  bool fa_chmod(const std::string& path,mode_t mode);
86 
89  bool fa_stat(const std::string& path, struct stat& st);
91 
94  bool fa_lstat(const std::string& path, struct stat& st);
96 
99  bool fa_fstat(struct stat& st);
101 
104  bool fa_ftruncate(off_t length);
106 
109  off_t fa_fallocate(off_t length);
111 
114  bool fa_readlink(const std::string& path, std::string& linkpath);
116 
119  bool fa_remove(const std::string& path);
121 
124  bool fa_unlink(const std::string& path);
126 
129  bool fa_rmdir(const std::string& path);
131 
134  bool fa_rmdirr(const std::string& path);
136 
141  bool fa_opendir(const std::string& path);
143 
146  bool fa_closedir(void);
148 
151  bool fa_readdir(std::string& name);
153 
156  bool fa_open(const std::string& path, int flags, mode_t mode);
158 
161  bool fa_close(void);
163 
169  bool fa_mkstemp(std::string& path, mode_t mode);
171 
174  off_t fa_lseek(off_t offset, int whence);
176 
179  ssize_t fa_read(void* buf,size_t size);
181 
184  ssize_t fa_write(const void* buf,size_t size);
186 
189  ssize_t fa_pread(void* buf,size_t size,off_t offset);
191 
194  ssize_t fa_pwrite(const void* buf,size_t size,off_t offset);
196  int geterrno() { return errno_; };
198  operator bool(void) { return (file_access_ != NULL); };
200  bool operator!(void) { return (file_access_ == NULL); };
202  static void testtune(void);
203  private:
204  Glib::Mutex lock_;
205  Run* file_access_;
206  int errno_;
207  uid_t uid_;
208  gid_t gid_;
209  public:
211  typedef struct {
212  unsigned int size;
213  unsigned int cmd;
214  } header_t;
215  };
216 
218 
224  public:
226  FileAccessContainer(unsigned int minval, unsigned int maxval);
228  FileAccessContainer(void);
230  ~FileAccessContainer(void);
232 
235  FileAccess* Acquire(void);
237 
239  void Release(FileAccess* fa);
241  void SetMin(unsigned int val);
243  void SetMax(unsigned int val);
244  private:
245  Glib::Mutex lock_;
246  unsigned int min_;
247  unsigned int max_;
248  std::list<FileAccess*> fas_;
249  void KeepRange(void);
250  };
251 
252 } // namespace Arc
253 
254 #endif // __ARC_FILEACCESS_H__
255 
ssize_t fa_read(void *buf, size_t size)
Read from open file.
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
bool fa_lstat(const std::string &path, struct stat &st)
Stat symbolic link or file.
bool fa_open(const std::string &path, int flags, mode_t mode)
Open file. Only one file may be open at a time.
ssize_t fa_pread(void *buf, size_t size, off_t offset)
Read from open file at specified offset.
bool fa_rmdir(const std::string &path)
Remove directory (if empty).
bool fa_close(void)
Close open file.
static void testtune(void)
Special method for using in unit tests.
bool fa_mkstemp(std::string &path, mode_t mode)
Open new temporary file for writing.
off_t fa_lseek(off_t offset, int whence)
Change current position in open file.
FileAccess(void)
New FileAccess object.
void Release(FileAccess *fa)
Returns object into container.
bool ping(void)
Check if communication with proxy works.
bool fa_readlink(const std::string &path, std::string &linkpath)
Read content of symbolic link.
FileAccess * Acquire(void)
Get object from container.
~FileAccessContainer(void)
Destroys container and all stored objects.
bool fa_chmod(const std::string &path, mode_t mode)
Change mode of filesystem object.
static FileAccess * Acquire(void)
Constructor which takes already existing object from global cache.
static void Release(FileAccess *fa)
Destructor which returns object into global cache.
bool fa_link(const std::string &oldpath, const std::string &newpath)
Create hard link.
bool fa_readdir(std::string &name)
Read relative name of object in open directory.
bool fa_rename(const std::string &oldpath, const std::string &newpath)
Rename file.
bool fa_unlink(const std::string &path)
Remove file.
ssize_t fa_pwrite(const void *buf, size_t size, off_t offset)
Write to open file at specified offset.
bool fa_mkdirp(const std::string &path, mode_t mode)
Make a directory and assign it specified mode.
bool fa_setuid(int uid, int gid)
Modify user uid and gid.
bool operator!(void)
Returns true if this instance is not in useful condition.
Definition: FileAccess.h:200
Container for shared FileAccess objects.
Definition: FileAccess.h:223
FileAccessContainer(void)
Creates container with number of stored objects between 1 and 10.
~FileAccess(void)
Shuts down any spawned executable.
int geterrno()
Get errno of last operation. Every operation resets errno.
Definition: FileAccess.h:196
bool fa_ftruncate(off_t length)
Truncate open file.
bool fa_rmdirr(const std::string &path)
Remove directory recursively.
bool fa_fstat(struct stat &st)
Stat open file.
void SetMin(unsigned int val)
Adjust minimal number of stored objects.
Defines interface for accessing filesystems.
Definition: FileAccess.h:27
void SetMax(unsigned int val)
Adjust maximal number of stored objects.
bool fa_stat(const std::string &path, struct stat &st)
Stat file.
bool fa_softlink(const std::string &oldpath, const std::string &newpath)
Create symbolic (aka soft) link.
bool fa_copy(const std::string &oldpath, const std::string &newpath, mode_t mode)
Copy file to new location.
bool fa_remove(const std::string &path)
Remove file system object.
bool fa_closedir(void)
Close open directory.
ssize_t fa_write(const void *buf, size_t size)
Write to open file.
Internal struct used for communication between processes.
Definition: FileAccess.h:211
bool fa_mkdir(const std::string &path, mode_t mode)
Make a directory and assign it specified mode.
bool fa_opendir(const std::string &path)
Open directory.
This class runs an external executable.
Definition: Run.h:19
off_t fa_fallocate(off_t length)
Allocate disk space for open file.