UCommon
Public Member Functions
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:
Inheritance graph
[legend]
Collaboration diagram for ost::SharedFile:
Collaboration graph
[legend]

Public Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from ost::RandomFile
Error error (Error errid, char *errstr=NULL)
 Post an error event. More...
 
Error error (char *err)
 Post an extended string error message. More...
 
void final (void)
 Close the file.
 
virtual Attr initialize (void)
 This method is used to initialize a newly created file as indicated by the "initial" flag. More...
 
 RandomFile (const char *name=NULL)
 Create an unopened random access file.
 
 RandomFile (const RandomFile &rf)
 Default copy constructor.
 
Error setCompletion (Complete mode)
 Used to set file completion modes. More...
 
void setError (bool enable)
 Used to enable or disable throwing of exceptions on errors. More...
 
void setTemporary (bool enable)
 Used to set the temporary attribute for the file. More...
 
- Protected Attributes inherited from ost::RandomFile
Access access
 
int fd
 
struct {
   unsigned   count: 16
 
   bool   immediate: 1
 
   bool   initial: 1
 
   bool   temp: 1
 
   bool   thrown: 1
 
flags
 
char * pathname
 

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.

Definition at line 563 of file file.h.

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.

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.

◆ restart()

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

Restart an existing database; close and re-open.

Returns
errSuccess if successful.

Reimplemented from ost::RandomFile.

Definition at line 596 of file file.h.

◆ 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: