00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00067 }
00068
00069
00070 void Persist::checkpoint()
00071 {
00072
00073
00074
00075
00076
00077
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 }