GNU CommonC++
Public Member Functions | List of all members
ost::SharedFile Class Reference

This class defines a database I/O file service that can be shared by multiple processes. More...

#include <file.h>

Inheritance diagram for ost::SharedFile:
ost::RandomFile ost::Mutex ost::File

Public Member Functions

 SharedFile (const char *path)
 Open or create a new database file.
 
 SharedFile (const SharedFile &file)
 Create a shared file as a duplicate of an existing shared file.
 
virtual ~SharedFile ()
 Close and finish a database file.
 
Error restart (void)
 Restart an existing database; close and re-open.
 
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.
 
Error update (char *address=NULL, ccxx_size_t length=0, off_t position=-1)
 Update a portion of a file from physical memory.
 
Error clear (ccxx_size_t length=0, off_t pos=-1)
 Clear a lock held from a previous fetch operation without updating.
 
Error append (char *address=NULL, ccxx_size_t length=0)
 Add new data to the end of the file.
 
off_t getPosition (void)
 Fetch the current file position marker for this thread.
 
bool operator++ (void)
 
bool operator-- (void)
 
- Public Member Functions inherited from ost::RandomFile
virtual ~RandomFile ()
 Destroy a random access file or it's derived class.
 
bool initial (void)
 This method should be called right after a RandomFile derived object has been created.
 
off_t getCapacity (void)
 Get current file capacity.
 
virtual Error restart (void)
 This method is commonly used to close and re-open an existing database.
 
Error getErrorNumber (void)
 Return current error id.
 
char * getErrorString (void)
 Return current error string.
 
bool operator! (void)
 

Additional Inherited Members

- Public Types inherited from ost::File
enum  Error {
  errSuccess = 0 , errNotOpened , errMapFailed , errInitFailed ,
  errOpenDenied , errOpenFailed , errOpenInUse , errReadInterrupted ,
  errReadIncomplete , errReadFailure , errWriteInterrupted , errWriteIncomplete ,
  errWriteFailure , errLockFailure , errExtended
}
 
enum  Access { accessReadOnly = O_RDONLY , accessWriteOnly = O_WRONLY , accessReadWrite = O_RDWR }
 
enum  Open {
  openReadOnly = O_RDONLY , openWriteOnly = O_WRONLY , openReadWrite = O_RDWR , openAppend = O_WRONLY | O_APPEND ,
  openSync = O_RDWR , openTruncate = O_RDWR | O_TRUNC
}
 
enum  Attr { attrInvalid = 0 , attrPrivate = 0400 | 0200 , attrGroup = attrPrivate | 0040 | 0020 , attrPublic = attrGroup | 0004 | 0002 }
 
enum  Mapping { mappedRead = accessReadOnly , mappedWrite = accessWriteOnly , mappedReadWrite = accessReadWrite }
 
enum  Complete { completionImmediate , completionDelayed , completionDeferred }
 
typedef enum Error Error
 
typedef enum Access Access
 
typedef enum Open Open
 
typedef enum Attr Attr
 
typedef enum Complete Complete
 
typedef enum Mapping Mapping
 
- Static Public Member Functions inherited from ost::File
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 inherited from ost::File
typedef struct ost::File::_fcb fcb_t
 
enum  Error {
  errSuccess = 0 , errNotOpened , errMapFailed , errInitFailed ,
  errOpenDenied , errOpenFailed , errOpenInUse , errReadInterrupted ,
  errReadIncomplete , errReadFailure , errWriteInterrupted , errWriteIncomplete ,
  errWriteFailure , errLockFailure , errExtended
}
 
enum  Access { accessReadOnly = O_RDONLY , accessWriteOnly = O_WRONLY , accessReadWrite = O_RDWR }
 
enum  Open {
  openReadOnly = O_RDONLY , openWriteOnly = O_WRONLY , openReadWrite = O_RDWR , openAppend = O_WRONLY | O_APPEND ,
  openSync = O_RDWR , openTruncate = O_RDWR | O_TRUNC
}
 
enum  Attr { attrInvalid = 0 , attrPrivate = 0400 | 0200 , attrGroup = attrPrivate | 0040 | 0020 , attrPublic = attrGroup | 0004 | 0002 }
 
enum  Mapping { mappedRead = accessReadOnly , mappedWrite = accessWriteOnly , mappedReadWrite = accessReadWrite }
 
enum  Complete { completionImmediate , completionDelayed , completionDeferred }
 
typedef enum Error Error
 
typedef enum Access Access
 
typedef enum Open Open
 
typedef enum Attr Attr
 
typedef enum Complete Complete
 
typedef enum Mapping Mapping
 
- Protected Member Functions inherited from ost::RandomFile
 RandomFile (const char *name=NULL)
 Create an unopened random access file.
 
 RandomFile (const RandomFile &rf)
 Default copy constructor.
 
Error error (Error errid, char *errstr=NULL)
 Post an error event.
 
Error error (char *err)
 Post an extended string error message.
 
void setError (bool enable)
 Used to enable or disable throwing of exceptions on errors.
 
Error setCompletion (Complete mode)
 Used to set file completion modes.
 
void setTemporary (bool enable)
 Used to set the temporary attribute for the file.
 
virtual Attr initialize (void)
 This method is used to initialize a newly created file as indicated by the "initial" flag.
 
void final (void)
 Close the file.
 
- Protected Member Functions inherited from ost::Mutex
 Mutex (const char *name=NULL)
 The mutex is always initialized as a recursive entity.
 
virtual ~Mutex ()
 Destroying the mutex removes any system resources associated with it.
 
void nameMutex (const char *name)
 Enable setting of mutex name for deadlock debug.
 
void enterMutex (void)
 Entering a Mutex locks the mutex for the current thread.
 
void enter (void)
 Future abi will use enter/leave/test members.
 
void leave (void)
 Future abi will use enter/leave/test members.
 
bool test (void)
 Future abi will use enter/leave/test members.
 
bool tryEnterMutex (void)
 Tries to lock the mutex for the current thread.
 
void leaveMutex (void)
 Leaving a mutex frees that mutex for use by another thread.
 
- Static Protected Member Functions inherited from ost::Mutex
static void setDebug (bool mode)
 Enable or disable deadlock debugging.
 
- Static Protected Member Functions inherited from ost::File
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 Attributes inherited from ost::RandomFile
int fd
 
Access access
 
char * pathname
 
struct { 
 
   unsigned   count: 16 
 
   bool   thrown: 1 
 
   bool   initial: 1 
 
   bool   immediate: 1 
 
   bool   temp: 1 
 
flags 
 

Detailed Description

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.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m

This class defines a database I/O file service that can be shared by multiple processes.

Constructor & Destructor Documentation

◆ SharedFile() [1/2]

ost::SharedFile::SharedFile ( const char *  path)

Open or create a new database file.

You should also use Initial.

Parameters
pathpathname of database to open.

◆ SharedFile() [2/2]

ost::SharedFile::SharedFile ( const SharedFile file)

Create a shared file as a duplicate of an existing shared file.

Parameters
fileoriginal file.

◆ ~SharedFile()

virtual ost::SharedFile::~SharedFile ( )
virtual

Close and finish a database file.

Member Function Documentation

◆ append()

Error ost::SharedFile::append ( char *  address = NULL,
ccxx_size_t  length = 0 
)

Add new data to the end of the file.

Locks file during append.

Parameters
addressaddress to use, or NULL if same as last I/O.
lengthlength to use, or 0 if same as last I/O.

◆ clear()

Error ost::SharedFile::clear ( ccxx_size_t  length = 0,
off_t  pos = -1 
)

Clear a lock held from a previous fetch operation without updating.

Returns
errSuccess on success.
Parameters
lengthlength to use, or 0 if same as last I/O.
posfile position to use or -1 if same as last I/O.

◆ fetch()

Error ost::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.

Returns
errSuccess on success.
Parameters
addressaddress to use, or NULL if same as last I/O.
lengthlength to use, or 0 if same as last I/O.
positionfile position to use -1 if same as last I/O.

◆ getPosition()

off_t ost::SharedFile::getPosition ( void  )

Fetch the current file position marker for this thread.

Returns
file position offset.

◆ operator++()

bool ost::SharedFile::operator++ ( void  )

◆ operator--()

bool ost::SharedFile::operator-- ( void  )

◆ restart()

Error ost::SharedFile::restart ( void  )
inlinevirtual

Restart an existing database; close and re-open.

Returns
errSuccess if successful.

Reimplemented from ost::RandomFile.

◆ update()

Error ost::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.

Returns
errSuccess on success.
Parameters
addressaddress to use, or NULL if same as last I/O.
lengthlength to use, or 0 if same as last I/O.
positionfile position to use or -1 if same as last I/O.

The documentation for this class was generated from the following file: