Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

Omniifr::Persist Class Reference

Responsible for reading & writing the persistancy database. More...

#include <Persist.h>

Collaboration diagram for Omniifr::Persist:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Persist (int checkpointPeriodSec)
 ~Persist ()
void setdir (const char *dir)
 Sets the directory used for persistency database files.
void startup ()
 Called by the Repository, when initial setup is complete.
void checkpoint ()
 [?? FUTURE:] Called by the checkpointing thread, and also when Omniifr_Ifr_checkpoint() receives SIGUSR2.
ostream & outstream ()
 Obtains an open output stream.

Private Attributes

Repository_impl_ifr
omni_mutex _lock
ofstream * _outstream
bool _checkpointNeeded
string _dir

Friends

class WriteLock

Classes

class  WriteLock
 Obtains an output stream to the active persistancy file, and locks it for exclusive access. More...

Detailed Description

Responsible for reading & writing the persistancy database.

Definition at line 48 of file Persist.h.


Constructor & Destructor Documentation

Omniifr::Persist::Persist int  checkpointPeriodSec  ) 
 

Definition at line 33 of file Persist.cc.

00034 : _ifr(Omniifr::Repository_impl::inst()),
00035   _lock(),
00036   _outstream(NULL),
00037   _checkpointNeeded(true),
00038   _dir("/var/lib/omniifr")
00039 {}

Omniifr::Persist::~Persist  ) 
 

Definition at line 42 of file Persist.cc.

References _outstream.

00043 {
00044   if(_outstream)
00045   {
00046     _outstream->close();
00047     delete _outstream;
00048   }
00049 }


Member Function Documentation

void Omniifr::Persist::checkpoint  ) 
 

[?? FUTURE:] Called by the checkpointing thread, and also when Omniifr_Ifr_checkpoint() receives SIGUSR2.

Writes the entire contents of the repository to a clean database file.

Definition at line 70 of file Persist.cc.

References _ifr, Omniifr::Repository_impl::output(), and outstream().

Referenced by Omniifr_Ifr_checkpoint().

00071 {
00072   // ?? This is a dummy implementation.
00073   // The real implementation should move aside the current database file
00074   // before replacing it with a new one. See the very robust (if a bit cruddy)
00075   // implementation in omniEvents.
00076   // ?? Furthermore, this is currently called from a signal handler - it would
00077   // be safer for that call to be replaced by a condition_variable wakeup.
00078   _ifr.output(outstream());
00079   outstream()<<flush;
00080 }

ostream & Omniifr::Persist::outstream  ) 
 

Obtains an open output stream.

Definition at line 83 of file Persist.cc.

References _dir, and _outstream.

Referenced by checkpoint().

00084 {
00085   if(!_outstream)
00086   {
00087     string fname =_dir+"/omniifr.db";
00088     _outstream=new ofstream(fname.c_str());
00089   }
00090   return *_outstream;
00091 }

void Omniifr::Persist::setdir const char *  dir  )  [inline]
 

Sets the directory used for persistency database files.

Definition at line 55 of file Persist.h.

References _dir.

00055 { _dir=dir; }

void Omniifr::Persist::startup  ) 
 

Called by the Repository, when initial setup is complete.

Reincarnates the repository contents (if there is a database file from which to read) and [?? FUTURE:] starts the checkpointing thread.

Definition at line 52 of file Persist.cc.

References _dir, _ifr, _outstream, and Omniifr::Repository_impl::reincarnate().

Referenced by Omniifr::Repository_impl::init().

00053 {
00054   assert(_outstream==NULL);
00055   {
00056     string fname =_dir+"/omniifr.db";
00057     ifstream instream(fname.c_str());
00058     if(instream)
00059     {
00060       auto_ptr<PersistNode> savedState( new PersistNode(instream) );
00061       instream.close();
00062       _ifr.reincarnate(*savedState);
00063     }
00064   }
00065   
00066   // ?? START UP CHECKPOINTING HERE
00067 }


Friends And Related Function Documentation

friend class WriteLock [friend]
 

Definition at line 86 of file Persist.h.


Member Data Documentation

bool Omniifr::Persist::_checkpointNeeded [private]
 

Definition at line 92 of file Persist.h.

Referenced by Omniifr::Persist::WriteLock::~WriteLock().

string Omniifr::Persist::_dir [private]
 

Definition at line 93 of file Persist.h.

Referenced by outstream(), setdir(), and startup().

Repository_impl& Omniifr::Persist::_ifr [private]
 

Definition at line 89 of file Persist.h.

Referenced by checkpoint(), and startup().

omni_mutex Omniifr::Persist::_lock [private]
 

Definition at line 90 of file Persist.h.

ofstream* Omniifr::Persist::_outstream [private]
 

Definition at line 91 of file Persist.h.

Referenced by outstream(), startup(), and ~Persist().


The documentation for this class was generated from the following files:
Generated on Fri Mar 4 13:04:05 2005 for OmniIFR by  doxygen 1.4.1