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

Persist.cc

Go to the documentation of this file.
00001 //                            Package   : omniIFR
00002 // Persist.cc                 Created   : 2004/09/05
00003 //                            Author    : Alex Tingle
00004 //
00005 //    Copyright (C) 2004 Alex Tingle.
00006 //
00007 //    This file is part of the omniIFR application.
00008 //
00009 //    omniIFR is free software; you can redistribute it and/or
00010 //    modify it under the terms of the GNU Lesser General Public
00011 //    License as published by the Free Software Foundation; either
00012 //    version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //    omniIFR is distributed in the hope that it will be useful,
00015 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //    Lesser General Public License for more details.
00018 //
00019 //    You should have received a copy of the GNU Lesser General Public
00020 //    License along with this library; if not, write to the Free Software
00021 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 
00024 #include "Persist.h"
00025 
00026 #include "Repository.h"
00027 #include "PersistNode.h"
00028 #include <memory>
00029 
00030 namespace Omniifr {
00031 
00032 
00033 Persist::Persist(int checkpointPeriodSec)
00034 : _ifr(Omniifr::Repository_impl::inst()),
00035   _lock(),
00036   _outstream(NULL),
00037   _checkpointNeeded(true),
00038   _dir("/var/lib/omniifr")
00039 {}
00040 
00041 
00042 Persist::~Persist()
00043 {
00044   if(_outstream)
00045   {
00046     _outstream->close();
00047     delete _outstream;
00048   }
00049 }
00050 
00051 
00052 void Persist::startup()
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 }
00068 
00069 
00070 void Persist::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 }
00081 
00082 
00083 ostream& Persist::outstream()
00084 {
00085   if(!_outstream)
00086   {
00087     string fname =_dir+"/omniifr.db";
00088     _outstream=new ofstream(fname.c_str());
00089   }
00090   return *_outstream;
00091 }
00092 
00093 
00094 } // end namespace Omniifr

Generated on Fri Mar 4 13:03:23 2005 for OmniIFR by  doxygen 1.4.1