Catalog.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00013 #ifndef _SUPPORT_CATALOG_H
00014 #define _SUPPORT_CATALOG_H
00015 
00021 #include <storage/DatumGeneratorInt.h>
00022 #include <storage/IndexedIterable.h>
00023 #include <storage/MetaDataNode.h>
00024 
00025 #include <support/Context.h>
00026 #include <support/ICatalog.h>
00027 #include <support/KeyedVector.h>
00028 #include <support/Locker.h>
00029 #include <support/Node.h>
00030 #include <support/String.h>
00031 #include <support/Value.h>
00032 
00033 
00034 #if _SUPPORTS_NAMESPACE
00035 namespace palmos {
00036 namespace support {
00037 #endif
00038 
00043 // Temporary compatibility
00044 typedef SNode SCatalog;
00045 
00046 class SWalkHelper
00047 {
00048 public:
00049     status_t    HelperWalk(SString* path, uint32_t flags, SValue* node);
00050     
00051     virtual sptr<INode>     HelperAttributesCatalog() const;
00052     virtual status_t        HelperLookupEntry(const SString& entry, uint32_t flags, SValue* node) = 0;
00053     virtual sptr<ICatalog>  HelperCreateCatalog(SString* name, status_t* err);
00054     virtual sptr<IDatum>    HelperCreateDatum(SString* name, uint32_t flags, status_t* err);
00055 };
00056 
00057 class BGenericCatalog : public BnCatalog, public BMetaDataNode, public BnIterable
00058 {
00059 public:
00060     BGenericCatalog();
00061     BGenericCatalog(const SContext& context);
00062 
00063     // Deal with multiple interfaces
00064     inline const SContext& Context() const { return BnCatalog::Context(); }
00065     virtual SValue Inspect(const sptr<IBinder>& caller, const SValue& which, uint32_t flags);
00066     
00067     // Stub these out for ICatalog (call to BMetaDataNode implementation).
00068     virtual sptr<INode> CreateNode(SString* name, status_t* err);
00069     virtual sptr<IDatum> CreateDatum(SString* name, uint32_t flags, status_t* err);
00070 
00071 protected:
00072     virtual ~BGenericCatalog();
00073 };
00074 
00075 class BIndexedCatalog : public BnCatalog, public BMetaDataNode, public BIndexedIterable
00076 {
00077 public:
00078     BIndexedCatalog();
00079     BIndexedCatalog(const SContext& context);
00080     
00081     // Deal with multiple interfaces
00082     inline const SContext& Context() const { return BnCatalog::Context(); }
00083     virtual SValue Inspect(const sptr<IBinder>& caller, const SValue& which, uint32_t flags);
00084 
00086     virtual lock_status_t           Lock() const;
00087     virtual void                    Unlock() const;
00088 
00090     virtual status_t                EntryAtLocked(  const sptr<IndexedIterator>& it, size_t index,
00091                                                     uint32_t flags, SValue* key, SValue* entry);
00093     virtual status_t                EntryAtLocked(size_t index, uint32_t flags, SValue* key, SValue* entry) = 0;
00094 
00095     // Stub these out for ICatalog (call to BMetaDataNode implementation).
00096     virtual sptr<INode> CreateNode(SString* name, status_t* err);
00097     virtual sptr<IDatum> CreateDatum(SString* name, uint32_t flags, status_t* err);
00098 
00099 protected:
00100     virtual ~BIndexedCatalog();
00101 
00103     void EntryAddedAt(uint32_t index);
00104     void EntryRemovedAt(uint32_t index);
00105 };
00106 
00107 class BMetaDataCatalog : public BIndexedCatalog
00108 {
00109 public:
00110     BMetaDataCatalog(const SContext& context);
00111 
00112     // Implement BGenericNode attributes.
00113     virtual status_t            LookupMetaEntry(const SString& entry, uint32_t flags, SValue* node);
00114     virtual status_t            CreateMetaEntry(const SString& name, const SValue& initialValue, sptr<IDatum>* outDatum = NULL);
00115     virtual status_t            RemoveMetaEntry(const SString& name);
00116     virtual status_t            RenameMetaEntry(const SString& old_name, const SString& new_name);
00117     virtual status_t            MetaEntryAtLocked(ssize_t index, uint32_t flags, SValue* key, SValue* entry);
00118     virtual size_t              CountMetaEntriesLocked() const;
00119 
00120 protected:
00121     virtual ~BMetaDataCatalog();
00122     
00123 private:
00124     SKeyedVector<SString, SValue>*  m_attrs;
00125 };
00126 
00127 class BCatalog : public BMetaDataCatalog, public SDatumGeneratorInt
00128 {
00129 public:
00130     BCatalog();
00131     BCatalog(const SContext& context);
00132 
00133     virtual void InitAtom();
00134 
00136     virtual lock_status_t           Lock() const;
00137     virtual void                    Unlock() const;
00138 
00139     virtual status_t AddEntry(const SString& name, const SValue& entry);
00140     virtual status_t RemoveEntry(const SString& name);
00141     virtual status_t RenameEntry(const SString& entry, const SString& name);
00142     
00143     virtual sptr<INode> CreateNode(SString* name, status_t* err);
00144     virtual sptr<IDatum> CreateDatum(SString* name, uint32_t flags, status_t* err);
00145     
00147     virtual status_t EntryAtLocked(size_t index, uint32_t flags, SValue* key, SValue* entry);
00149     virtual size_t  CountEntriesLocked() const;
00151     virtual status_t LookupEntry(const SString& entry, uint32_t flags, SValue* node);
00153     virtual SValue ValueAtLocked(size_t index) const;
00155     virtual status_t StoreValueAtLocked(size_t index, const SValue& value);
00156 
00157     virtual ssize_t AddEntryLocked(const SString& name, const SValue& entry, sptr<IBinder>* outEntry, bool* replaced);
00158 
00159 protected:
00161     virtual sptr<INode> InstantiateNodeLocked(const SString &name, status_t *err);
00162     
00164     virtual void OnEntryCreated(const SString &name, const sptr<IBinder> &entry);
00165     virtual void OnEntryModified(const SString &name, const sptr<IBinder> &entry);
00166     virtual void OnEntryRenamed(const SString &old_name, const SString &new_name, const sptr<IBinder> &entry);
00167     virtual void OnEntryRemoved(const SString &name);
00168     
00169     virtual ~BCatalog();
00170 
00171 private:
00172     bool has_entry_l(const SString& name);
00173     
00174     SKeyedVector<SString, SValue> m_entries;
00175 };
00176 
00179 #if _SUPPORTS_NAMESPACE
00180 } } // namespace palmos::support
00181 #endif
00182 
00183 #endif // _SUPPORT_CATALOG_H
00184