WvStreams
unislowgen.cc
1 /*
2  * Worldvisions Weaver Software:
3  * Copyright (C) 2002 Net Integration Technologies, Inc.
4  *
5  * A UniConfGen that makes everything slow. See unislowgen.h.
6  */
7 #include "unislowgen.h"
8 #include "wvmoniker.h"
9 #ifndef _MSC_VER // FIXME:WLACH Is unistd even needed here?!
10 #include <unistd.h>
11 #endif
12 
13 static IUniConfGen *creator(WvStringParm s, IObject *_obj)
14 {
15  return new UniSlowGen(wvcreate<IUniConfGen>(s, _obj));
16 }
17 
18 static WvMoniker<IUniConfGen> reg("slow", creator);
19 
20 
21 UniSlowGen::UniSlowGen(IUniConfGen *inner) : UniFilterGen(inner)
22 {
23  slowcount = 0;
24 }
25 
26 
27 UniSlowGen::~UniSlowGen()
28 {
29  fprintf(stderr, "%p: UniSlowGen: ran a total of %d slow operations.\n",
30  this, how_slow());
31 }
32 
33 
35 {
36  be_slow("commit()");
38 }
39 
40 
42 {
43  be_slow("refresh()");
44  return UniFilterGen::refresh();
45 }
46 
47 
49 {
50  be_slow("get(%s)", key);
51  return UniFilterGen::get(key);
52 }
53 
54 
56 {
57  be_slow("exists(%s)", key);
58  return UniFilterGen::exists(key);
59 }
60 
61 
63 {
64  be_slow("haschildren(%s)", key);
65  return UniFilterGen::haschildren(key);
66 }
67 
68 
70 {
71  be_slow("iterator(%s)", key);
72  return UniFilterGen::iterator(key);
73 }
74 
75 
77 {
78  be_slow("recursiveiterator(%s)", key);
80 }
81 
82 
83 void UniSlowGen::be_slow(WvStringParm what)
84 {
85  fprintf(stderr, "%p: UniSlowGen: slow operation: %s\n",
86  this, what.cstr());
87  // sleep(1);
88  slowcount++;
89 }
90 
91 
UniSlowGen::get
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
Definition: unislowgen.cc:48
UniSlowGen::haschildren
virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
Definition: unislowgen.cc:62
UniFilterGen::get
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
Definition: unifiltergen.cc:76
UniFilterGen::iterator
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
Definition: unifiltergen.cc:137
UniSlowGen::iterator
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
Definition: unislowgen.cc:69
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
IUniConfGen
An abstract data container that backs a UniConf tree.
Definition: uniconfgen.h:39
UniSlowGen::exists
virtual bool exists(const UniConfKey &key)
Without fetching its value, returns true if a key exists.
Definition: unislowgen.cc:55
UniConfKey
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
Definition: uniconfkey.h:38
WvMoniker
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
Definition: wvmoniker.h:61
UniSlowGen::refresh
virtual bool refresh()
Refreshes information about a key recursively.
Definition: unislowgen.cc:41
IObject
Definition: IObject.h:65
UniSlowGen
A UniConfGen that counts all "potentially synchronous" (ie.
Definition: unislowgen.h:27
UniSlowGen::commit
virtual void commit()
Commits any changes.
Definition: unislowgen.cc:34
UniFilterGen::exists
virtual bool exists(const UniConfKey &key)
Without fetching its value, returns true if a key exists.
Definition: unifiltergen.cc:108
UniFilterGen::refresh
virtual bool refresh()
Refreshes information about a key recursively.
Definition: unifiltergen.cc:59
UniFilterGen::commit
virtual void commit()
Commits any changes.
Definition: unifiltergen.cc:52
UniFilterGen::haschildren
virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
Definition: unifiltergen.cc:118
UniSlowGen::recursiveiterator
virtual Iter * recursiveiterator(const UniConfKey &key)
Like iterator(), but the returned iterator is recursive, that is, it will return children of the imme...
Definition: unislowgen.cc:76
UniFilterGen::recursiveiterator
virtual Iter * recursiveiterator(const UniConfKey &key)
Like iterator(), but the returned iterator is recursive, that is, it will return children of the imme...
Definition: unifiltergen.cc:147
UniFilterGen
A UniConfGen that delegates all requests to an inner generator.
Definition: unifiltergen.h:17
UniConfGen::Iter
An abstract iterator over keys and values in a generator.
Definition: uniconfgen.h:323