Bayonne2 / Common C++ 2 Framework
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Related Functions
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 SharedFile:
Inheritance graph
[legend]
Collaboration diagram for SharedFile:
Collaboration graph
[legend]

Public Types

 
typedef enum Error  Error
 
enum   Access { accessReadOnly = O_RDONLY, accessWriteOnly = O_WRONLY, accessReadWrite = O_RDWR }
 
typedef enum Access  Access
 
enum   Open {
  openReadOnly = O_RDONLY, openWriteOnly = O_WRONLY, openReadWrite = O_RDWR, openAppend = O_WRONLY | O_APPEND,
  openSync = O_RDWR, openTruncate = O_RDWR | O_TRUNC
}
 
typedef enum Open  Open
 
enum   Attr { attrInvalid = 0, attrPrivate = 0400 | 0200, attrGroup = attrPrivate | 0040 | 0020, attrPublic = attrGroup | 0004 | 0002 }
 
typedef enum Attr  Attr
 
enum   Mapping { mappedRead = accessReadOnly, mappedWrite = accessWriteOnly, mappedReadWrite = accessReadWrite }
 
typedef enum Mapping  Mapping
 
 
typedef enum Complete  Complete
 

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...
 
  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...
 
  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
 
 
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

 

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)
 

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 648 of file file.h.

Member Typedef Documentation

typedef enum Access File::Access
inherited

Definition at line 150 of file file.h.

typedef enum Attr File::Attr
inherited

Definition at line 213 of file file.h.

typedef enum Complete File::Complete
inherited

Definition at line 239 of file file.h.

typedef enum Error File::Error
inherited

Definition at line 137 of file file.h.

typedef struct File::_fcb File::fcb_t
protectedinherited
typedef enum Mapping File::Mapping
inherited

Definition at line 240 of file file.h.

typedef enum Open File::Open
inherited

Definition at line 183 of file file.h.

Member Enumeration Documentation

inherited
Enumerator
accessReadOnly 
accessWriteOnly 
accessReadWrite 

Definition at line 139 of file file.h.

enum File::Attr
inherited
Enumerator
attrInvalid 
attrPrivate 
attrGroup 
attrPublic 

Definition at line 199 of file file.h.

inherited
Enumerator
completionImmediate 
completionDelayed 
completionDeferred 

Definition at line 233 of file file.h.

inherited
Enumerator
errSuccess 
errNotOpened 
errMapFailed 
errInitFailed 
errOpenDenied 
errOpenFailed 
errOpenInUse 
errReadInterrupted 
errReadIncomplete 
errReadFailure 
errWriteInterrupted 
errWriteIncomplete 
errWriteFailure 
errLockFailure 
errExtended 

Definition at line 120 of file file.h.

inherited
Enumerator
mappedRead 
mappedWrite 
mappedReadWrite 

Definition at line 228 of file file.h.

enum File::Open
inherited
Enumerator
openReadOnly 
openWriteOnly 
openReadWrite 
openAppend 
openSync 
openTruncate 

Definition at line 171 of file file.h.

Constructor & Destructor Documentation

SharedFile::SharedFile ( const char *  path )

Open or create a new database file.

You should also use Initial.

Parameters
path pathname of database to open.
SharedFile::SharedFile ( const SharedFilefile )

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

Parameters
file original file.
virtual SharedFile::~SharedFile ( )
virtual

Close and finish a database file.

Member Function Documentation

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

Add new data to the end of the file.

Locks file during append.

Parameters
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.

Returns
errSuccess on success.
Parameters
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.
void Mutex::enter ( void  )
inlineinherited

Future abi will use enter/leave/test members.

Definition at line 263 of file thread.h.

void Mutex::enterMutex ( void  )
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.

See Also
leaveMutex
Error RandomFile::error ( Error  errid,
char *  errstr = NULL 
)
protectedinherited

Post an error event.

Returns
error code.
Parameters
errid error code.
errstr error message string.
Error RandomFile::error ( char *  err )
inlineprotectedinherited

Post an extended string error message.

Returns
errExtended.
Parameters
err error string.

Definition at line 447 of file file.h.

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.

Returns
errSuccess on success.
Parameters
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.
void RandomFile::final ( void  )
protectedinherited

Close the file.

off_t RandomFile::getCapacity ( void  )
inherited

Get current file capacity.

Returns
total file size.
static char* File::getDirname ( const char *  path,
char *  buffer,
size_t  size = 256 
)
staticinherited
Error RandomFile::getErrorNumber ( void  )
inlineinherited

Return current error id.

Returns
last error identifier set.

Definition at line 532 of file file.h.

char* RandomFile::getErrorString ( void  )
inlineinherited

Return current error string.

Returns
last error string set.

Definition at line 540 of file file.h.

static const char* File::getExtension ( const char *  path )
staticinherited
static const char* File::getFilename ( const char *  path )
staticinherited
static char* File::getFilename ( const char *  path,
char *  buffer,
size_t  size = 64 
)
staticinherited
off_t SharedFile::getPosition ( void  )

Fetch the current file position marker for this thread.

Returns
file position offset.
static char* File::getRealpath ( const char *  path,
char *  buffer,
size_t  size = 256 
)
staticinherited
bool RandomFile::initial ( void  )
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.

Returns
true if file had to be initialized.
virtual Attr RandomFile::initialize ( void  )
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.

Returns
access, or attrInvalid if should be removed.
void Mutex::leave ( void  )
inlineinherited

Future abi will use enter/leave/test members.

Definition at line 269 of file thread.h.

void Mutex::leaveMutex ( void  )
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.

See Also
enterMutex
void Mutex::nameMutex ( const char *  name )
inlineinherited

Enable setting of mutex name for deadlock debug.

Parameters
name for mutex.

Definition at line 248 of file thread.h.

Error SharedFile::open ( const char *  path )
private
bool RandomFile::operator! ( void  )
inherited
bool SharedFile::operator++ ( void  )
bool SharedFile::operator-- ( void  )
Error SharedFile::restart ( void  )
inlinevirtual

Restart an existing database; close and re-open.

Returns
errSuccess if successful.

Reimplemented from RandomFile.

Definition at line 681 of file file.h.

Error RandomFile::setCompletion ( Complete  mode )
protectedinherited

Used to set file completion modes.

Returns
errSuccess if okay.
Parameters
mode completion mode.
Todo:
implement in win32
static void Mutex::setDebug ( bool  mode )
inlinestaticinherited

Enable or disable deadlock debugging.

Parameters
mode debug mode.

Definition at line 240 of file thread.h.

void RandomFile::setError ( bool  enable )
inlineprotectedinherited

Used to enable or disable throwing of exceptions on errors.

Parameters
enable true if errors will be thrown.

Definition at line 456 of file file.h.

void RandomFile::setTemporary ( bool  enable )
inlineprotectedinherited

Used to set the temporary attribute for the file.

Temporary files are automatically deleted when closed.

Parameters
enable true for marking as temporary.

Definition at line 476 of file file.h.

bool Mutex::test ( void  )
inlineinherited

Future abi will use enter/leave/test members.

Returns
true if entered.

Definition at line 277 of file thread.h.

bool Mutex::tryEnterMutex ( void  )
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.

Returns
true if locking the mutex was succesful otherwise false
See Also
enterMutex
leaveMutex
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.

Returns
errSuccess on success.
Parameters
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.

Friends And Related Function Documentation

bool __EXPORT canAccess ( const char *  path )
related
bool __EXPORT canModify ( const char *  path )
related
bool __EXPORT isDevice ( const char *  path )
related
bool __EXPORT isDir ( const char *  path )
related
bool __EXPORT isFile ( const char *  path )
related
time_t __EXPORT lastAccessed ( const char *  path )
related
time_t __EXPORT lastModified ( const char *  path )
related

Field Documentation

Access RandomFile::access
protectedinherited

Definition at line 406 of file file.h.

unsigned RandomFile::count
inherited

Definition at line 413 of file file.h.

fcb_t SharedFile::fcb
private

Definition at line 651 of file file.h.

int RandomFile::fd
protectedinherited

Definition at line 404 of file file.h.

struct { ... } RandomFile::flags
bool RandomFile::immediate
inherited

Definition at line 417 of file file.h.

bool RandomFile::initial
inherited

Definition at line 415 of file file.h.

char* RandomFile::pathname
protectedinherited

Definition at line 410 of file file.h.

bool RandomFile::temp
inherited

Definition at line 419 of file file.h.

bool RandomFile::thrown
inherited

Definition at line 414 of file file.h.


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

Generated on Dec 21, 2017 for commoncpp2-1.8.1, ccrtp-1.7.2, libzrtpcpp-2.3.4, ccscript3-1.1.7, ccaudio2-1.0.0 and bayonne2-2.3.2 (after installation in /usr/local/) by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /