WvStreams
uniretrygen.h
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 2002 Net Integration Technologies, Inc.
00004  * 
00005  * A UniConfGen that reconnects to an inner generator whenever the inner
00006  * generator is no longer OK.
00007  */
00008 #ifndef __UNIRETRYGEN_H
00009 #define __UNIRETRYGEN_H
00010 
00011 #include "unifiltergen.h"
00012 #include "wvtimeutils.h"
00013 #include "wvlog.h"
00014 
00041 class UniRetryGen : public UniFilterGen
00042 {
00043 public:
00044 
00045     typedef wv::function<void(UniRetryGen&)> ReconnectCallback;
00046     
00047 private:
00048 
00049     WvLog log;
00050 
00051     WvString moniker;
00052 
00053     ReconnectCallback reconnect_callback; 
00054 
00055     time_t retry_interval_ms;
00056     WvTime next_reconnect_attempt;
00057     
00058     void maybe_disconnect();
00059     void maybe_reconnect();
00060 
00061 public:
00062 
00063     UniRetryGen(WvStringParm _moniker,
00064             ReconnectCallback _reconect_callback = ReconnectCallback(),
00065             time_t _retry_internal_ms = 5000);
00066 
00067     /***** Overridden methods *****/
00068 
00069     virtual void commit();
00070     virtual bool refresh();
00071     virtual void prefetch(const UniConfKey &key, bool recursive);
00072     virtual void flush_buffers() { }
00073     virtual WvString get(const UniConfKey &key);
00074     virtual void set(const UniConfKey &key, WvStringParm value);
00075     virtual bool exists(const UniConfKey &key);
00076     virtual bool haschildren(const UniConfKey &key);
00077     virtual bool isok();
00078     virtual Iter *iterator(const UniConfKey &key);
00079     virtual Iter *recursiveiterator(const UniConfKey &key);
00080 };
00081 
00082 #endif //__UNIRETRYGEN_H