WvStreams
unicachegen.cc
1/*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 2002 Net Integration Technologies, Inc.
4 *
5 * A UniConf generator that stores keys in memory.
6 */
7#include "uniconf.h"
8#include "unicachegen.h"
9#include "wvmoniker.h"
10#include "wvlinkerhack.h"
11
12WV_LINK(UniCacheGen);
13
14
15// if 'obj' is non-NULL and is a UniConfGen, wrap that; otherwise wrap the
16// given moniker.
17static IUniConfGen *creator(WvStringParm s, IObject *_obj)
18{
19 return new UniCacheGen(wvcreate<IUniConfGen>(s, _obj));
20}
21
22static WvMoniker<IUniConfGen> reg("cache", creator);
23
24
25/***** UniCacheGen *****/
26
27UniCacheGen::UniCacheGen(IUniConfGen *_inner)
28 : log("UniCache", WvLog::Debug1), inner(_inner)
29{
30 if (inner)
31 inner->add_callback(this, wv::bind(&UniCacheGen::deltacallback, this,
32 _1, _2));
33 refreshed_once = false;
34}
35
36
37UniCacheGen::~UniCacheGen()
38{
39 inner->del_callback(this);
40 WVRELEASE(inner);
41}
42
43
45{
46 return inner->isok();
47}
48
49
51{
52 if (!refreshed_once)
53 {
54 bool ret = inner->refresh();
55 loadtree();
56 refreshed_once = true;
57 return ret;
58 }
59 else
60 return false;
61}
62
63
65{
66 inner->commit();
67}
68
69
70void UniCacheGen::loadtree(const UniConfKey &key)
71{
72 UniConfGen::Iter *i = inner->recursiveiterator(key);
73 if (!i) return;
74
75 //assert(false);
76 for (i->rewind(); i->next(); )
77 {
78 WvString value(i->value());
79
80 //fprintf(stderr, "Key: '%s'\n", i->key().cstr());
81 //fprintf(stderr, " Val: '%s'\n", value.cstr());
82
83 if (!!value)
84 UniTempGen::set(i->key(), value);
85 }
86
87 delete i;
88}
89
90
91void UniCacheGen::deltacallback(const UniConfKey &key, WvStringParm value)
92{
93 UniTempGen::set(key, value);
94}
95
97{
98 inner->set(key, value);
99}
100
102{
103 //inner->get(key);
104 inner->flush_buffers(); // update all pending notifications
105 return UniTempGen::get(key);
106}
The basic interface which is included by all other XPLC interfaces and objects.
Definition IObject.h:65
An abstract data container that backs a UniConf tree.
Definition uniconfgen.h:40
virtual void flush_buffers()=0
Flushes any commitment/notification buffers .
virtual bool isok()=0
Determines if the generator is usable and working properly.
virtual bool refresh()=0
Refreshes information about a key recursively.
virtual void commit()=0
Commits any changes.
virtual void del_callback(void *cookie)=0
Removes a callback for change notification.
virtual Iter * recursiveiterator(const UniConfKey &key)=0
Like iterator(), but the returned iterator is recursive, that is, it will return children of the imme...
virtual void set(const UniConfKey &key, WvStringParm value)=0
Stores a string value for a key into the registry.
A UniConf generator that adds a cache layer on top of another generator.
Definition unicachegen.h:27
virtual bool refresh()
Refreshes information about a key recursively.
virtual void commit()
Commits any changes.
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
virtual bool isok()
Determines if the generator is usable and working properly.
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
An abstract iterator over keys and values in a generator.
Definition uniconfgen.h:324
virtual bool next()=0
Seeks to the next element in the sequence.
virtual WvString value() const =0
Returns the value of the current key.
virtual void rewind()=0
Rewinds the iterator.
virtual UniConfKey key() const =0
Returns the current key.
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
Definition uniconfkey.h:39
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
Definition unitempgen.cc:38
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
Definition unitempgen.cc:57
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition wvstring.h:94
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition wvlog.h:57
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
Definition wvmoniker.h:62
WvString is an implementation of a simple and efficient printable-string class.
Definition wvstring.h:330