WvStreams
|
Creates a UniConf tree that mirrors some point in the Linux filesystem, with restrictions. More...
#include <unifilesystemgen.h>
Public Types | |
typedef ::UniListIter | ListIter |
An iterator over a constant list of keys (see below) | |
Public Member Functions | |
UniFileSystemGen (WvStringParm _dir, mode_t _mode) | |
virtual WvString | get (const UniConfKey &key) |
Fetches a string value for a key from the registry. | |
virtual void | set (const UniConfKey &key, WvStringParm value) |
Stores a string value for a key into the registry. | |
virtual void | setv (const UniConfPairList &pairs) |
Stores multiple key-value pairs into the registry. | |
virtual void | flush_buffers () |
Flushes any commitment/notification buffers . | |
virtual Iter * | iterator (const UniConfKey &key) |
Returns an iterator over the children of the specified key. | |
virtual void | add_callback (void *cookie, const UniConfGenCallback &callback) |
Adds a callback for change notification. | |
virtual void | del_callback (void *cookie) |
Removes a callback for change notification. | |
void | dispatch_delta (const UniConfKey &key, WvStringParm value) |
Immediately sends notification that a key has possibly changed. | |
void | hold_delta () |
Pauses notifications until matched with a call to unhold_delta(). | |
void | unhold_delta () |
Resumes notifications when each hold_delta() has been matched. | |
void | clear_delta () |
Clears the list of pending notifications without sending them. | |
void | flush_delta () |
Flushes the list of pending notifications by sending them. | |
void | delta (const UniConfKey &key, WvStringParm value) |
Call this when a key's value or children have possibly changed. | |
virtual bool | isok () |
Determines if the generator is usable and working properly. | |
virtual void | commit () |
Commits any changes. | |
virtual bool | refresh () |
Refreshes information about a key recursively. | |
virtual void | prefetch (const UniConfKey &key, bool recursive) |
Indicate that we will eventually be interested in doing get(), haschildren(), or other "get-like" operations on a particular key or tree of keys. | |
virtual bool | exists (const UniConfKey &key) |
Without fetching its value, returns true if a key exists. | |
virtual int | str2int (WvStringParm s, int defvalue) const |
Converts a string to an integer. | |
virtual bool | haschildren (const UniConfKey &key) |
Returns true if a key has children. | |
virtual Iter * | recursiveiterator (const UniConfKey &key) |
Like iterator(), but the returned iterator is recursive, that is, it will return children of the immediate children, not just the immediate children themselves. | |
virtual unsigned int | addRef ()=0 |
Indicate you are using this object. | |
virtual unsigned int | release ()=0 |
Indicate that you are finished using this object. | |
virtual IObject * | getInterface (const UUID &)=0 |
Returns the requested XPLC interface. | |
virtual IWeakRef * | getWeakRef ()=0 |
Return a weak reference to this object. | |
Protected Member Functions | |
void | setv_naive (const UniConfPairList &pairs) |
Creates a UniConf tree that mirrors some point in the Linux filesystem, with restrictions.
The root of the point to be mirrored is a directory name. Additionally, the mode for creation of all files and directories must be given.
UniConf keys are mapped to filesystem paths in the obvious way (delimit and precede the list of names with "/", then append to the path for the point being mirrored).
Keys corresponding to regular files have value equal to the content of that file (plus a terminating NUL). Keys whose corresponding pathname does not exist have value equal to the null string. Keys corresponding to things other than regular files have value equal to the empty string, unless their last segment is "." or "..", in which case they have value equal to the null string.
Due to these definitions, the UniFileSystemGen violates the UniConfGen semantics in that it is not possible for a key to have simultaneously a non-empty value and children and it is not possible for a key named "." or ".." to exist. Any set operation that by the UniConfGen semantics would cause either of those things to be true will instead do nothing. These shortcomings are permanent.
If an unrecoverable error occurs during set, it will fail, but will possibly still have an effect. If an unrecoverable error occurs during get, it will return the null string. If an unrecoverable error occurs during iterator(), it will return a NULL pointer.
Presently, callbacks are never triggered.
Files containing embedded NUL characters don't currently work quite right because WvString can't deal with them. They'll stop at the first NUL.
Definition at line 41 of file unifilesystemgen.h.
WvString UniFileSystemGen::get | ( | const UniConfKey & | key | ) | [virtual] |
Fetches a string value for a key from the registry.
If the key doesn't exist, the return value has .isnull() == true.
Implements UniConfGen.
Definition at line 43 of file unifilesystemgen.cc.
References WvErrorBase::geterr(), WvFdStream::getrfd(), WvBufBase< unsigned char >::getstr(), WvFdStream::isok(), and WvStream::read().
Referenced by UniFileSystemGenIter::value().
void UniFileSystemGen::set | ( | const UniConfKey & | key, |
WvStringParm | value | ||
) | [virtual] |
Stores a string value for a key into the registry.
If the value is WvString::null, the key is deleted.
Implements UniConfGen.
Definition at line 77 of file unifilesystemgen.cc.
References WvFastString::isnull(), UniConfKey::removelast(), and WvStream::write().
void UniFileSystemGen::setv | ( | const UniConfPairList & | pairs | ) | [virtual] |
Stores multiple key-value pairs into the registry.
If the value is WvString::null, the key is deleted.
Implements UniConfGen.
Definition at line 97 of file unifilesystemgen.cc.
virtual void UniFileSystemGen::flush_buffers | ( | ) | [inline, virtual] |
Flushes any commitment/notification buffers .
The default implementation always returns true. NOTE: This method should be 'protected'
Implements UniConfGen.
Definition at line 48 of file unifilesystemgen.h.
UniConfGen::Iter * UniFileSystemGen::iterator | ( | const UniConfKey & | key | ) | [virtual] |
Returns an iterator over the children of the specified key.
May return NULL or an empty iterator if the key has no children.
The caller takes ownership of the returned iterator and is responsible for deleting it when finished.
Implements UniConfGen.
Definition at line 133 of file unifilesystemgen.cc.
void UniConfGen::add_callback | ( | void * | cookie, |
const UniConfGenCallback & | callback | ||
) | [virtual, inherited] |
Adds a callback for change notification.
Must *not* be reimplemented by subclasses of UniConfGen.
Implements IUniConfGen.
Definition at line 158 of file uniconfgen.cc.
Referenced by UniConfRoot::UniConfRoot().
void UniConfGen::del_callback | ( | void * | cookie | ) | [virtual, inherited] |
Removes a callback for change notification.
Implements IUniConfGen.
Definition at line 165 of file uniconfgen.cc.
Referenced by UniConfRoot::~UniConfRoot().
void UniConfGen::dispatch_delta | ( | const UniConfKey & | key, |
WvStringParm | value | ||
) | [inherited] |
Immediately sends notification that a key has possibly changed.
Takes care of the details of invoking the callback.
Note: You probably want to be using delta() instead.
Definition at line 71 of file uniconfgen.cc.
Referenced by UniConfGen::delta(), and UniConfGen::flush_delta().
void UniConfGen::hold_delta | ( | ) | [inherited] |
Pauses notifications until matched with a call to unhold_delta().
While paused, notification events are placed into a pending list. Redundant notifications may be discarded.
Use this to safeguard non-reentrant code.
Definition at line 32 of file uniconfgen.cc.
Referenced by UniTransactionGen::commit(), UniMountGen::commit(), UniConfGen::delta(), UniConfGen::haschildren(), UniMountGen::mountgen(), UniIniGen::refresh(), UniTransactionGen::refresh(), UniMountGen::refresh(), UniTempGen::set(), UniClientGen::set(), UniTransactionGen::set(), UniClientGen::setv(), UniTransactionGen::setv(), and UniMountGen::unmount().
void UniConfGen::unhold_delta | ( | ) | [inherited] |
Resumes notifications when each hold_delta() has been matched.
On resumption, dispatches all pending notifications except those that were destined to watches that were removed.
Use this to safeguard non-reentrant code.
Definition at line 38 of file uniconfgen.cc.
References UniConfGen::flush_delta().
Referenced by UniTransactionGen::commit(), UniMountGen::commit(), UniConfGen::delta(), UniConfGen::haschildren(), UniMountGen::mountgen(), UniIniGen::refresh(), UniTransactionGen::refresh(), UniMountGen::refresh(), UniTempGen::set(), UniClientGen::set(), UniTransactionGen::set(), UniClientGen::setv(), UniTransactionGen::setv(), and UniMountGen::unmount().
void UniConfGen::clear_delta | ( | ) | [inherited] |
Clears the list of pending notifications without sending them.
Does not affect the hold nesting count.
Definition at line 47 of file uniconfgen.cc.
void UniConfGen::flush_delta | ( | ) | [inherited] |
Flushes the list of pending notifications by sending them.
Does not affect the hold nesting count.
Definition at line 53 of file uniconfgen.cc.
References UniConfGen::dispatch_delta().
Referenced by UniConfGen::unhold_delta().
void UniConfGen::delta | ( | const UniConfKey & | key, |
WvStringParm | value | ||
) | [inherited] |
Call this when a key's value or children have possibly changed.
If the hold nesting count is 0, the notification is sent immediately. Otherwise it is added to a pending list for later.
Definition at line 77 of file uniconfgen.cc.
References UniConfGen::dispatch_delta(), UniConfGen::hold_delta(), and UniConfGen::unhold_delta().
Referenced by UniTransactionGen::cancel_changes(), UniTransactionGen::cancel_values(), UniTransactionGen::create_value(), UniTransactionGen::deletion_simulator(), UniTransactionGen::deletion_simulator2(), UniTransactionGen::deletion_visitor(), UniListGen::gencallback(), UniFilterGen::gencallback(), UniTransactionGen::gencallback(), UniMountGen::mountgen(), UniTempGen::set(), UniRegistryGen::set(), UniPStoreGen::set(), and UniMountGen::unmount().
bool UniConfGen::isok | ( | ) | [virtual, inherited] |
Determines if the generator is usable and working properly.
The default implementation always returns true.
Implements IUniConfGen.
Reimplemented in UniTransactionGen, UniRetryGen, UniFilterGen, UniReplicateGen, UniPStoreGen, UniClientGen, UniUnwrapGen, UniListGen, UniCacheGen, and UniRegistryGen.
Definition at line 152 of file uniconfgen.cc.
virtual void UniConfGen::commit | ( | ) | [inline, virtual, inherited] |
Commits any changes.
The default implementation does nothing.
Implements IUniConfGen.
Reimplemented in UniMountGen, UniTransactionGen, UniRetryGen, UniReplicateGen, UniClientGen, UniFilterGen, UniSecureGen, UniIniGen, UniUnwrapGen, UniCacheGen, UniListGen, UniTempGen, UniSlowGen, and UniBachelorGen.
Definition at line 280 of file uniconfgen.h.
virtual bool UniConfGen::refresh | ( | ) | [inline, virtual, inherited] |
Refreshes information about a key recursively.
May discard uncommitted data.
The default implementation always returns true.
Implements IUniConfGen.
Reimplemented in UniMountGen, UniTransactionGen, UniRetryGen, UniReplicateGen, UniClientGen, UniFilterGen, UniSecureGen, UniIniGen, UniUnwrapGen, UniCacheGen, UniListGen, UniTempGen, UniSlowGen, and UniBachelorGen.
Definition at line 281 of file uniconfgen.h.
virtual void UniConfGen::prefetch | ( | const UniConfKey & | key, |
bool | recursive | ||
) | [inline, virtual, inherited] |
Indicate that we will eventually be interested in doing get(), haschildren(), or other "get-like" operations on a particular key or tree of keys.
The generator may be able to speed up these operations by, say, caching them in advance.
This function is not allowed to do blocking operations. It is allowed to do nothing at all, however, and then get() might block later.
Implements IUniConfGen.
Reimplemented in UniRetryGen, UniFilterGen, and UniUnwrapGen.
Definition at line 282 of file uniconfgen.h.
bool UniConfGen::exists | ( | const UniConfKey & | key | ) | [virtual, inherited] |
Without fetching its value, returns true if a key exists.
This is provided because it is often more efficient to test existance than to actually retrieve the value.
The default implementation returns !get(key).isnull().
Implements IUniConfGen.
Reimplemented in UniMountGen, UniRetryGen, UniFilterGen, UniPStoreGen, UniUnwrapGen, UniSecureGen, UniListGen, UniRegistryGen, UniFastRegetGen, and UniSlowGen.
Definition at line 120 of file uniconfgen.cc.
int UniConfGen::str2int | ( | WvStringParm | s, |
int | defvalue | ||
) | const [virtual, inherited] |
Converts a string to an integer.
If the string is null or not recognized, return defvalue.
This is here to support the common str2int(get(key)).
The default implementation recognizes the booleans 'true', 'yes', 'on' and 'enabled' as 1, and 'false', 'no', 'off' and 'disabled' as 0.
Implements IUniConfGen.
Definition at line 126 of file uniconfgen.cc.
References WvFastString::cstr(), and WvFastString::isnull().
bool UniConfGen::haschildren | ( | const UniConfKey & | key | ) | [virtual, inherited] |
Returns true if a key has children.
This is provided because it is often more efficient to test existance than to actually retrieve the keys.
The default implementation uses the iterator returned by iterator() to test whether the child has any keys. Subclasses are strongly encouraged to provide a better implementation.
Implements IUniConfGen.
Reimplemented in UniMountGen, UniRetryGen, UniFilterGen, UniClientGen, UniPStoreGen, UniUnwrapGen, UniSecureGen, UniListGen, UniRegistryGen, UniFastRegetGen, UniWvConfGen, UniSlowGen, UniTempGen, and UniNullGen.
Definition at line 101 of file uniconfgen.cc.
References UniConfGen::hold_delta(), UniConfGen::iterator(), UniConfGen::Iter::next(), UniConfGen::Iter::rewind(), and UniConfGen::unhold_delta().
UniConfGen::Iter * UniConfGen::recursiveiterator | ( | const UniConfKey & | key | ) | [virtual, inherited] |
Like iterator(), but the returned iterator is recursive, that is, it will return children of the immediate children, not just the immediate children themselves.
May return NULL if the key has no immediate children (since that means there are also no indirect children).
Note that UniConfGen::recursiveiterator() is a default implementation that just calls iterator() recursively, so it'll work in any derived class without you overriding this function. However, you might want to do it anyway if it would be more efficient in your particular case.
Implements IUniConfGen.
Reimplemented in UniMountGen, UniRetryGen, UniFilterGen, UniClientGen, UniAutoMountGen, UniUnwrapGen, UniSecureGen, and UniSlowGen.
Definition at line 260 of file uniconfgen.cc.
virtual unsigned int IObject::addRef | ( | ) | [pure virtual, inherited] |
Indicate you are using this object.
This increases the reference count of the object by one. Usually, when the reference count reaches zero, the object is freed automatically.
This called a "strong reference", because they will prevent the object from being destroyed. They should thus be used carefully, as they control the lifetime of the object. For example, you do not need to call addRef() on object passed as parameters, unless you intend on keeping them.
addRef() is often called automatically for you in XPLC, but you'll have to call release() by hand sometimes unless you use xplc_ptr.
Referenced by WvIStreamList::execute(), IObjectImplInternal::getInterface(), StaticServiceHandler::getObject(), WeakRef::getObject(), WvIStreamList::post_select(), WvQtStreamClone::WvQtStreamClone(), and WvSSLStream::WvSSLStream().
virtual unsigned int IObject::release | ( | ) | [pure virtual, inherited] |
Indicate that you are finished using this object.
This decreases the reference count of the object by one. Usually, when the reference count reaches zero, the object is freed automatically.
You will usually need to manually release() any object given to you by any other XPLC function, unless you give the object to someone else who will call release.
If you use xplc_ptr, it will do this for you.
Referenced by WvIStreamList::execute(), mutate(), NewMoniker::resolve(), and MonikerService::resolve().
virtual IObject* IObject::getInterface | ( | const UUID & | ) | [pure virtual, inherited] |
Returns the requested XPLC interface.
Will return NULL if the interface is not supported. The returned interface has been addRef()ed, so you will need to release() it when done. Note that the interface returned may be a pointer to the same object or a different one - that's none of your business. Asking for the IObject interface should always return the same pointer for a given logical object, so this can be used for comparison by identity.
You should probably use the convenient mutate() and get() functions instead of this, or use an xplc_ptr, which mutates the object for you.
Referenced by mutate().
virtual IWeakRef* IObject::getWeakRef | ( | ) | [pure virtual, inherited] |