Go to the documentation of this file.
47 #ifndef CCXX_CONFIG_H_
51 #ifndef CCXX_MISSING_H_
55 #ifndef CCXX_THREAD_H_
59 #ifndef CCXX_EXCEPTION_H_
66 # include <sys/types.h>
71 # include <sys/stat.h>
72 # include <sys/mman.h>
74 # if __BORLANDC__ >= 0x0560
76 # include <sys/stat.h>
87 #include <mach-o/dyld.h>
90 #ifdef CCXX_NAMESPACES
96 #include <sys/types.h>
99 #if !defined(__BORLANDC__) || __BORLANDC__ >= 0x0560
102 typedef void* caddr_t;
134 typedef enum Error Error;
138 accessReadOnly = O_RDONLY,
139 accessWriteOnly= O_WRONLY,
140 accessReadWrite = O_RDWR
142 accessReadOnly = GENERIC_READ,
143 accessWriteOnly = GENERIC_WRITE,
144 accessReadWrite = GENERIC_READ | GENERIC_WRITE
147 typedef enum Access Access;
169 openReadOnly = O_RDONLY,
170 openWriteOnly = O_WRONLY,
171 openReadWrite = O_RDWR,
172 openAppend = O_WRONLY | O_APPEND,
174 openSync = O_RDWR | O_SYNC,
178 openTruncate = O_RDWR | O_TRUNC
180 typedef enum Open Open;
202 #else // defined WIN32
210 typedef enum Attr Attr;
226 mappedRead = accessReadOnly,
227 mappedWrite = accessWriteOnly,
228 mappedReadWrite = accessReadWrite
236 typedef enum Complete Complete;
237 typedef enum Mapping Mapping;
260 #ifdef HAVE_READDIR_R
262 char save_space[
sizeof(
struct dirent) +
PATH_MAX + 1];
264 struct dirent *entry;
267 WIN32_FIND_DATA data, fdata;
272 Dir(
const char *name = NULL);
317 unsigned max, current, prefixpos;
329 virtual bool filter(
const char *file,
struct stat *ino);
339 DirTree(
const char *prefix,
unsigned maxdepth);
436 Error
error(Error errid,
char *errstr = NULL);
445 {
return error(errExtended, err);};
454 {flags.thrown = !enable;};
474 {flags.temp = enable;};
568 Error open(
const char *path);
649 Error open(
const char *path);
679 {
return open(pathname);};
806 void sync(caddr_t address,
size_t len);
816 void update(
size_t offset = 0,
size_t len = 0);
825 void update(caddr_t address,
size_t len);
843 inline caddr_t
fetch(
size_t offset = 0)
844 {
return ((
char *)(fcb.address)) + offset;};
854 caddr_t
fetch(off_t pos,
size_t len);
896 #if defined(HAVE_MACH_DYLD)
898 #elif defined(HAVE_SHL_LOAD)
905 void loader(
const char *filename,
bool resolve);
916 {loader(filename,
true);};
918 DSO(
const char *filename,
bool resolve)
919 {loader(filename, resolve);};
921 DSO(
const char *filename)
923 DSO(
const char *filename,
bool resolve)
947 void *operator[](
const char *)
954 static void dynunload(
void)
987 inline bool isDevice(
const char *path)
999 #ifdef COMMON_STD_EXCEPTION
1001 class DirException :
public IOException
1004 DirException(
const String &str) : IOException(str) {};
1007 class __EXPORT DSOException :
public IOException
1010 DSOException(
const String &str) : IOException(str) {};
1013 class __EXPORT FileException :
public IOException
1016 FileException(
const String &str) : IOException(str) {};
1021 #ifdef CCXX_NAMESPACES
void sync(caddr_t address, size_t len)
Synchronize a segment of memory mapped from a segment fetch.
DSO(const char *filename)
Construct and load a DSO object file.
Definition: file.h:915
Attr
Definition: file.h:196
SharedFile(const char *path)
Open or create a new database file.
Error restart(void)
Restart an existing database; close and re-open.
Definition: file.h:678
virtual Error restart(void)
This method is commonly used to close and re-open an existing database.
Complete
Definition: file.h:230
#define S_IWUSR
Definition: file.h:186
static void setDebug(void)
Install debug handler...
Access
Definition: file.h:136
MappedFile(const char *fname, Access mode)
Open a file for mapping.
RandomFile(const RandomFile &rf)
Default copy constructor.
bool lock(void)
Lock the currently mapped portion of a file.
char * getErrorString(void)
Return current error string.
Definition: file.h:537
caddr_t address
Definition: file.h:152
unsigned count
Definition: file.h:410
Dir(const char *name=NULL)
DSO(const char *filename, bool resolve)
Definition: file.h:918
virtual bool filter(const char *file, struct stat *ino)
Virtual method to filter results.
This class defines a database I/O file service that can be shared by multiple processes.
Definition: file.h:646
caddr_t fetch(off_t pos, size_t len)
Fetch and map a portion of a disk file to a logical memory block.
#define INVALID_HANDLE_VALUE
Definition: serial.h:61
time_t __EXPORT lastModified(const char *path)
#define S_IWGRP
Definition: file.h:188
off_t getPosition(void)
Fetch the current file position marker for this thread.
Error clear(ccxx_size_t length=0, off_t pos=-1)
Clear a lock held from a previous fetch operation without updating.
bool __EXPORT isDir(const char *path)
void update(caddr_t address, size_t len)
Update a mapped region back to disk as specified by address and length.
int HANDLE
Definition: serial.h:60
virtual ~SharedFile()
Close and finish a database file.
Open
Definition: file.h:168
@ errOpenInUse
Definition: file.h:124
Error update(caddr_t address=NULL, ccxx_size_t length=0, off_t position=-1)
Update a portion of a file from physical memory.
RandomFile(const char *name=NULL)
Create an unopened random access file.
MappedFile(const char *fname, Access mode, size_t size)
Create if not exists, and map a file of specified size into memory.
SharedFile(const SharedFile &file)
Create a shared file as a duplicate of an existing shared file.
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
Definition: thread.h:187
DirTree(const char *prefix, unsigned maxdepth)
Construct a directory tree walk starting at the specified prefix.
Error restart(void)
Restart an existing database; close and re-open.
caddr_t fetch(size_t offset=0)
Fetch a pointer to an offset within the memory mapped portion of the disk file.
Definition: file.h:843
bool initial
Definition: file.h:412
bool temp
Definition: file.h:416
__EXPORT AppLog & error(AppLog &sl)
Manipulator for error level.
Definition: applog.h:541
static const char * getFilename(const char *path)
static void dynunload(void)
unsigned perform(const char *prefix)
This is used to step through the filter virtual for an entire subtree, and is used for cases where a ...
bool __EXPORT canAccess(const char *path)
bool operator!()
Definition: file.h:296
Error
Definition: file.h:117
bool __EXPORT canModify(const char *path)
A generic class to walk a hierarchical directory structure.
Definition: file.h:313
#define S_IROTH
Definition: file.h:189
static char * getRealpath(const char *path, char *buffer, size_t size=256)
#define S_IRUSR
Definition: file.h:185
#define S_IWOTH
Definition: file.h:190
void update(size_t offset=0, size_t len=0)
Map a portion of the memory mapped from the file back to the file and do not wait for completion.
virtual ~ThreadFile()
Close and finish a database file.
static bool setPrefix(const char *path)
bool __EXPORT isFile(const char *path)
bool locked
Definition: file.h:155
A low level portable directory class.
Definition: file.h:256
The DSO dynamic loader class is used to load object files.
Definition: file.h:887
#define __EXPORT
Definition: config.h:979
Error error(Error errid, char *errstr=NULL)
Post an error event.
off_t getPosition(void)
Fetch the current file position marker for this thread.
virtual ~MappedFile()
Release a mapped section of memory associated with a file.
#define S_IRGRP
Definition: file.h:187
void close(void)
Close the directory path.
size_t pageAligned(size_t size)
Compute map size to aligned page boundry.
static char * getDirname(const char *path, char *buffer, size_t size=256)
static bool getPrefix(char *path, size_t size=256)
@ errReadIncomplete
Definition: file.h:126
off_t pos
Definition: file.h:154
const char * operator++()
Definition: file.h:286
void setError(bool enable)
Used to enable or disable throwing of exceptions on errors.
Definition: file.h:453
@ errOpenDenied
Definition: file.h:122
virtual ~RandomFile()
Destroy a random access file or it's derived class.
Error append(caddr_t address=NULL, ccxx_size_t length=0)
Add new data to the end of the file.
void sync(void)
Synchronize the contents of the mapped portion of memory with the disk file and wait for completion.
void unlock(void)
Unlock a locked mapped portion of a file.
const char * getError(void)
Retrieve error indicator associated with DSO failure.
Definition: file.h:931
void open(const char *name)
unsigned long pos_t
Definition: file.h:94
DirTree(unsigned maxdepth)
Construct an un-opened directory tree of a known maximum depth.
static const char * getExtension(const char *path)
void open(const char *prefix)
Open a directory tree path.
static bool remove(const char *path)
@ errMapFailed
Definition: file.h:120
size_t ccxx_size_t
Definition: file.h:97
void release(caddr_t address, size_t len)
Release (unmap) a memory segment.
static char * getFilename(const char *path, char *buffer, size_t size=64)
substitute functions which may be missing in target platform libc.
This class allows the creation of a thread context unique "pointer" that can be set and retrieved and...
Definition: thread.h:1708
int fd
Definition: file.h:401
const char * getName(void)
bool initial(void)
This method should be called right after a RandomFile derived object has been created.
@ errOpenFailed
Definition: file.h:123
static bool create(const char *path, Attr attr=attrGroup)
MappedFile(const char *fname, pos_t offset, size_t size, Access mode)
Map a portion or all of a specified file in the specified shared memory access mode.
Error update(caddr_t address=NULL, ccxx_size_t length=0, off_t position=-1)
Update a portion of a file from physical memory.
void * operator[](const char *sym)
Lookup a symbol in the loaded file.
virtual ~DSO()
Detach a DSO object from running memory.
ThreadFile(const char *path)
Open or create a new database file.
void setTemporary(bool enable)
Used to set the temporary attribute for the file.
Definition: file.h:473
#define NAME_MAX
Definition: file.h:111
@ errReadInterrupted
Definition: file.h:125
struct _fcb * next
Definition: file.h:151
bool isValid(void)
See if DSO object is valid.
This class defines a database I/O file service that can be shared by multiple threads.
Definition: file.h:563
Error append(caddr_t address=NULL, ccxx_size_t length=0)
Add new data to the end of the file.
char * getPath(void)
Extract the next full pathname from the directory walk.
Error getErrorNumber(void)
Return current error id.
Definition: file.h:529
bool immediate
Definition: file.h:414
bool thrown
Definition: file.h:411
off_t getCapacity(void)
Get current file capacity.
@ errWriteFailure
Definition: file.h:130
@ errLockFailure
Definition: file.h:131
GNU Common C++ exception model base classes.
Error fetch(caddr_t address=NULL, ccxx_size_t length=0, off_t position=-1)
Fetch a portion of the file into physical memory.
@ errInitFailed
Definition: file.h:121
Error error(char *err)
Post an extended string error message.
Definition: file.h:444
Mapping
Definition: file.h:225
@ completionDelayed
Definition: file.h:232
ccxx_size_t len
Definition: file.h:153
@ completionImmediate
Definition: file.h:231
@ errWriteIncomplete
Definition: file.h:129
Synchronization and threading services.
The purpose of this class is to define a base class for low level random file access that is portable...
Definition: file.h:394
This is a generic and portable string class.
Definition: string.h:81
Error fetch(caddr_t address=NULL, ccxx_size_t length=0, off_t position=-1)
Lock and Fetch a portion of the file into physical memory.
@ errNotOpened
Definition: file.h:119
Error setCompletion(Complete mode)
Used to set file completion modes.
Access access
Definition: file.h:403
@ errReadFailure
Definition: file.h:127
#define PATH_MAX
Definition: file.h:107
virtual Attr initialize(void)
This method is used to initialize a newly created file as indicated by the "initial" flag.
const char * operator++(int)
Definition: file.h:289
Create and map a disk file into memory.
Definition: file.h:745
static DSO * getObject(const char *name)
Find a specific DSO object by filename.
char * pathname
Definition: file.h:407
bool __EXPORT isDevice(const char *path)
@ errWriteInterrupted
Definition: file.h:128