Bayonne2 / Common C++ 2 Framework
|
This class defines a database I/O file service that can be shared by multiple processes. More...
#include <file.h>
Public Member Functions | |
SharedFile (const char *path) | |
Open or create a new database file. More... | |
SharedFile (const SharedFile &file) | |
Create a shared file as a duplicate of an existing shared file. More... | |
virtual | ~SharedFile () |
Close and finish a database file. More... | |
Error | restart (void) |
Restart an existing database; close and re-open. More... | |
Error | fetch (char *address=NULL, ccxx_size_t length=0, off_t position=-1) |
Lock and Fetch a portion of the file into physical memory. More... | |
Error | update (char *address=NULL, ccxx_size_t length=0, off_t position=-1) |
Update a portion of a file from physical memory. More... | |
Error | clear (ccxx_size_t length=0, off_t pos=-1) |
Clear a lock held from a previous fetch operation without updating. More... | |
Error | append (char *address=NULL, ccxx_size_t length=0) |
Add new data to the end of the file. More... | |
off_t | getPosition (void) |
Fetch the current file position marker for this thread. More... | |
bool | operator++ (void) |
bool | operator-- (void) |
bool | initial (void) |
This method should be called right after a RandomFile derived object has been created. More... | |
off_t | getCapacity (void) |
Get current file capacity. More... | |
Error | getErrorNumber (void) |
Return current error id. More... | |
char * | getErrorString (void) |
Return current error string. More... | |
bool | operator! (void) |
Static Public Member Functions | |
static const char * | getExtension (const char *path) |
static const char * | getFilename (const char *path) |
static char * | getFilename (const char *path, char *buffer, size_t size=64) |
static char * | getDirname (const char *path, char *buffer, size_t size=256) |
static char * | getRealpath (const char *path, char *buffer, size_t size=256) |
Protected Types | |
typedef struct File::_fcb | fcb_t |
Protected Member Functions | |
Error | error (Error errid, char *errstr=NULL) |
Post an error event. More... | |
Error | error (char *err) |
Post an extended string error message. More... | |
void | setError (bool enable) |
Used to enable or disable throwing of exceptions on errors. More... | |
Error | setCompletion (Complete mode) |
Used to set file completion modes. More... | |
void | setTemporary (bool enable) |
Used to set the temporary attribute for the file. More... | |
virtual Attr | initialize (void) |
This method is used to initialize a newly created file as indicated by the "initial" flag. More... | |
void | final (void) |
Close the file. More... | |
void | nameMutex (const char *name) |
Enable setting of mutex name for deadlock debug. More... | |
void | enterMutex (void) |
Entering a Mutex locks the mutex for the current thread. More... | |
void | enter (void) |
Future abi will use enter/leave/test members. More... | |
void | leave (void) |
Future abi will use enter/leave/test members. More... | |
bool | test (void) |
Future abi will use enter/leave/test members. More... | |
bool | tryEnterMutex (void) |
Tries to lock the mutex for the current thread. More... | |
void | leaveMutex (void) |
Leaving a mutex frees that mutex for use by another thread. More... | |
Static Protected Member Functions | |
static void | setDebug (bool mode) |
Enable or disable deadlock debugging. More... | |
Protected Attributes | |
int | fd |
Access | access |
char * | pathname |
struct { | |
unsigned count: 16 | |
bool thrown: 1 | |
bool initial: 1 | |
bool immediate: 1 | |
bool temp: 1 | |
} | flags |
Private Member Functions | |
Error | open (const char *path) |
Private Attributes | |
fcb_t | fcb |
Related Functions | |
(Note that these are not member functions.) | |
bool __EXPORT | isDir (const char *path) |
bool __EXPORT | isFile (const char *path) |
bool __EXPORT | isDevice (const char *path) |
bool __EXPORT | canAccess (const char *path) |
bool __EXPORT | canModify (const char *path) |
time_t __EXPORT | lastModified (const char *path) |
time_t __EXPORT | lastAccessed (const char *path) |
This class defines a database I/O file service that can be shared by multiple processes.
Each thread should access a dup of the database object, and mutex locks can be used to preserve transaction integrety if multiple threads are used.
SharedFile is used when a database may be shared between multiple processes. SharedFile automatically applies low level byte-range "file locks", and provides an interface to fetch and release byte-range locked portions of a file.
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
protectedinherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
SharedFile::SharedFile | ( | const char * | path | ) |
Open or create a new database file.
You should also use Initial.
path | pathname of database to open. |
SharedFile::SharedFile | ( | const SharedFile & | file | ) |
Create a shared file as a duplicate of an existing shared file.
file | original file. |
|
virtual |
Close and finish a database file.
Error SharedFile::append | ( | char * | address = NULL , |
ccxx_size_t | length = 0 |
||
) |
Add new data to the end of the file.
Locks file during append.
address | address to use, or NULL if same as last I/O. |
length | length to use, or 0 if same as last I/O. |
Error SharedFile::clear | ( | ccxx_size_t | length = 0 , |
off_t | pos = -1 |
||
) |
Clear a lock held from a previous fetch operation without updating.
length | length to use, or 0 if same as last I/O. |
pos | file position to use or -1 if same as last I/O. |
|
inlineinherited |
|
inherited |
Entering a Mutex locks the mutex for the current thread.
This also can be done using the ENTER_CRITICAL macro or by using the ++ operator on a mutex.
Post an error event.
errid | error code. |
errstr | error message string. |
|
inlineprotectedinherited |
Error SharedFile::fetch | ( | char * | address = NULL , |
ccxx_size_t | length = 0 , |
||
off_t | position = -1 |
||
) |
Lock and Fetch a portion of the file into physical memory.
This can use state information to fetch the current record multiple times.
address | address to use, or NULL if same as last I/O. |
length | length to use, or 0 if same as last I/O. |
position | file position to use -1 if same as last I/O. |
|
protectedinherited |
Close the file.
|
inherited |
Get current file capacity.
|
staticinherited |
|
inlineinherited |
|
inlineinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
off_t SharedFile::getPosition | ( | void | ) |
Fetch the current file position marker for this thread.
|
staticinherited |
|
inherited |
This method should be called right after a RandomFile derived object has been created.
This method will invoke initialize if the object is newly created, and set file access permissions appropriately.
|
protectedvirtualinherited |
This method is used to initialize a newly created file as indicated by the "initial" flag.
This method also returns the file access permissions that should be associated with the file. This method should never be called directly, but is instead used to impliment the "Initial" method. Typically one would use this to build an empty database shell when a previously empty database file is created.
|
inlineinherited |
|
inherited |
Leaving a mutex frees that mutex for use by another thread.
If the mutex has been entered (invoked) multiple times (recursivily) by the same thread, then it will need to be exited the same number of instances before it is free for re-use. This operation can also be done using the LEAVE_CRITICAL macro or by the – operator on a mutex.
|
inlineinherited |
|
private |
|
inherited |
bool SharedFile::operator++ | ( | void | ) |
bool SharedFile::operator-- | ( | void | ) |
|
inlinevirtual |
Restart an existing database; close and re-open.
Reimplemented from RandomFile.
Used to set file completion modes.
mode | completion mode. |
|
inlinestaticinherited |
|
inlineprotectedinherited |
|
inlineprotectedinherited |
|
inlineinherited |
|
inherited |
Tries to lock the mutex for the current thread.
Behaves like enterMutex , except that it doesn't block the calling thread if the mutex is already locked by another thread.
Error SharedFile::update | ( | char * | address = NULL , |
ccxx_size_t | length = 0 , |
||
off_t | position = -1 |
||
) |
Update a portion of a file from physical memory.
This can use state information to commit the last read record. The current lock is also cleared.
address | address to use, or NULL if same as last I/O. |
length | length to use, or 0 if same as last I/O. |
position | file position to use or -1 if same as last I/O. |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
struct { ... } RandomFile::flags |