WvStreams
uniretrygen.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 2002 Net Integration Technologies, Inc.
4  *
5  * A UniConfGen that reconnects to an inner generator whenever the inner
6  * generator is no longer OK.
7  */
8 #ifndef __UNIRETRYGEN_H
9 #define __UNIRETRYGEN_H
10 
11 #include "unifiltergen.h"
12 #include "wvtimeutils.h"
13 #include "wvlog.h"
14 
41 class UniRetryGen : public UniFilterGen
42 {
43 public:
44 
45  typedef wv::function<void(UniRetryGen&)> ReconnectCallback;
46 
47 private:
48 
49  WvLog log;
50 
51  WvString moniker;
52 
53  ReconnectCallback reconnect_callback;
54 
55  time_t retry_interval_ms;
56  WvTime next_reconnect_attempt;
57 
58  void maybe_disconnect();
59  void maybe_reconnect();
60 
61 public:
62 
63  UniRetryGen(WvStringParm _moniker,
64  ReconnectCallback _reconect_callback = ReconnectCallback(),
65  time_t _retry_internal_ms = 5000);
66 
67  /***** Overridden methods *****/
68 
69  virtual void commit();
70  virtual bool refresh();
71  virtual void prefetch(const UniConfKey &key, bool recursive);
72  virtual void flush_buffers() { }
73  virtual WvString get(const UniConfKey &key);
74  virtual void set(const UniConfKey &key, WvStringParm value);
75  virtual bool exists(const UniConfKey &key);
76  virtual bool haschildren(const UniConfKey &key);
77  virtual bool isok();
78  virtual Iter *iterator(const UniConfKey &key);
79  virtual Iter *recursiveiterator(const UniConfKey &key);
80 };
81 
82 #endif //__UNIRETRYGEN_H