8 #include "uniretrygen.h"
11 #include "wvstringlist.h"
12 #include "wvlinkerhack.h"
18 #define DPRINTF(format, args...) fprintf(stderr, format ,##args);
20 #define DPRINTF if (0) printf
26 DPRINTF(
"encoded_params = %s\n", encoded_params.cstr());
29 if (params.count() == 0)
33 if (params.count() == 0)
37 time_t retry_interval_ms = retry_interval_ms_str.
num();
38 if (retry_interval_ms < 0)
39 retry_interval_ms = 0;
41 UniRetryGen::ReconnectCallback(),
50 UniRetryGen::UniRetryGen(WvStringParm _moniker,
51 ReconnectCallback _reconnect_callback,
52 time_t _retry_interval_ms)
56 reconnect_callback(_reconnect_callback),
57 retry_interval_ms(_retry_interval_ms),
58 next_reconnect_attempt(wvtime())
60 DPRINTF(
"UniRetryGen::UniRetryGen(%s, %ld)\n",
61 moniker.
cstr(), retry_interval_ms);
67 void UniRetryGen::maybe_reconnect()
71 if (!(wvtime() < next_reconnect_attempt))
77 DPRINTF(
"UniRetryGen::maybe_reconnect: !gen\n");
83 DPRINTF(
"UniRetryGen::maybe_reconnect: gen->isok()\n");
89 if (!!reconnect_callback) reconnect_callback(*
this);
93 DPRINTF(
"UniRetryGen::maybe_reconnect: !gen->isok()\n");
97 next_reconnect_attempt =
98 msecadd(next_reconnect_attempt, retry_interval_ms);
105 void UniRetryGen::maybe_disconnect()
109 DPRINTF(
"UniRetryGen::maybe_disconnect: inner() && !inner()->isok()\n");
111 log(
"Disconnected\n");
117 WVRELEASE(old_inner);
119 next_reconnect_attempt = msecadd(wvtime(), retry_interval_ms);
170 DPRINTF(
"UniRetryGen::get(%s) returns %s\n", key.
printable().
cstr(), result.
cstr());
175 DPRINTF(
"UniRetryGen::get(%s) returns %s because it is root key\n", key.
printable().
cstr(), result.
cstr());
179 DPRINTF(
"UniRetryGen::get(%s): !isok()\n", key.
printable().
cstr());
180 result = WvString::null;
204 DPRINTF(
"UniRetryGen::exists(%s)\n", key.
printable().
cstr());
210 DPRINTF(
"UniRetryGen::exists: returns %s\n", result?
"true":
"false");
214 DPRINTF(
"UniRetryGen::exists: !isok()\n");
void setinner(IUniConfGen *inner)
Rebinds the inner generator and prepares its callback.
A UniConfGen that reconnects to an inner generator specified by a moniker whenever the inner generato...
virtual bool refresh()
Refreshes information about a key recursively.
WvString popstr()
get the first string in the list, or an empty string if the list is empty.
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
virtual bool exists(const UniConfKey &key)
Without fetching its value, returns true if a key exists.
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
WvString printable() const
Returns the canonical string representation of the path.
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
virtual void commit()
Commits any changes.
WvString is an implementation of a simple and efficient printable-string class.
An abstract data container that backs a UniConf tree.
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
virtual bool isok()
Determines if the generator is usable and working properly.
const char * cstr() const
return a (const char *) for this string.
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
virtual bool isok()
Determines if the generator is usable and working properly.
IUniConfGen * inner() const
Returns the inner generator.
virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
virtual bool isok()=0
Determines if the generator is usable and working properly.
virtual bool exists(const UniConfKey &key)
Without fetching its value, returns true if a key exists.
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
virtual bool refresh()
Refreshes information about a key recursively.
This is a WvList of WvStrings, and is a really handy way to parse strings.
virtual void prefetch(const UniConfKey &key, bool recursive)
Indicate that we will eventually be interested in doing get(), haschildren(), or other "get-like" ope...
virtual void commit()
Commits any changes.
void wvtcl_decode(WvList< WvString > &l, WvStringParm _s, const WvStringMask &splitchars=WVTCL_SPLITCHARS, bool do_unescape=true)
split a tcl-style list.
virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
virtual void prefetch(const UniConfKey &key, bool recursive)
Indicate that we will eventually be interested in doing get(), haschildren(), or other "get-like" ope...
virtual Iter * recursiveiterator(const UniConfKey &key)
Like iterator(), but the returned iterator is recursive, that is, it will return children of the imme...
int num() const
Return a stdc++ string with the contents of this string.
virtual Iter * recursiveiterator(const UniConfKey &key)
Like iterator(), but the returned iterator is recursive, that is, it will return children of the imme...
A UniConfGen that delegates all requests to an inner generator.
An abstract iterator over keys and values in a generator.