IndexedTableNode.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 _STORAGE_INDEXEDTABLENODE_H
00014 #define _STORAGE_INDEXEDTABLENODE_H
00015 
00021 #include <storage/IndexedDataNode.h>
00022 
00023 #include <support/ITable.h>
00024 
00025 #if _SUPPORTS_NAMESPACE
00026 namespace palmos {
00027 namespace storage {
00028 #endif
00029 
00034 
00035 
00062 class BIndexedTableNode : public BMetaDataNode, public BIndexedIterable, public BnTable
00063 {
00064 public:
00065     // --------------------------------------------------------------
00069                                     BIndexedTableNode(uint32_t mode = IDatum::READ_WRITE);
00070                                     BIndexedTableNode(const SContext& context, uint32_t mode = IDatum::READ_WRITE);
00071 protected:
00072     virtual                         ~BIndexedTableNode();
00073 public:
00074 
00076     virtual lock_status_t           Lock() const;
00078     virtual void                    Unlock() const;
00080     inline  SContext                Context() { return BMetaDataNode::Context(); }
00082     virtual SValue                  Inspect(const sptr<IBinder>& caller, const SValue& which, uint32_t flags);
00083 
00085 
00086     // --------------------------------------------------------------
00090 
00092     virtual status_t                LookupEntry(const SString& entry, uint32_t flags, SValue* node);
00094     virtual status_t                EntryAtLocked(const sptr<IndexedIterator>& it, size_t index, uint32_t flags, SValue* key, SValue* entry);
00096 
00097             status_t                FetchEntryAtLocked(const sptr<IndexedIterator>& it, size_t rowIndex, uint32_t flags, SValue* entry);
00099 
00102             status_t                FetchValueAtLocked(size_t row, const sptr<BIndexedDataNode>& rowNode, size_t column, uint32_t flags, SValue* entry);
00103 
00105 
00106     // --------------------------------------------------------------
00109 
00111     virtual SValue                  ColumnNames() const;
00113     virtual SValue                  Schema() const;
00115     virtual status_t                CreateRow(SString* inoutName, const SValue& columns, uint32_t flags = 0, sptr<INode>* createdRow = NULL);
00117     virtual status_t                RemoveRow(const sptr<INode>& row);
00119     virtual status_t                AddColumn(const SString& name, uint32_t type, size_t maxSize, uint32_t flags, const SValue& extras);
00121     virtual status_t                RemoveColumn(const SString& name);
00122 
00123     // --------------------------------------------------------------
00127 
00129 
00133     virtual void                    SetMimeType(const SString& value);
00134 
00136             SString                 EntryMimeTypeLocked() const;
00137 
00139             status_t                StoreEntryMimeTypeLocked(const SString& mimeType);
00140 
00142     virtual void                    CreateSelectionLocked(SValue* inoutSelection, SValue* outCookie) const;
00143 
00145 
00146     // --------------------------------------------------------------
00151 
00153 
00154     virtual ssize_t                 EntryIndexOfLocked(const SString& entry) const = 0;
00156 
00158     virtual SString                 EntryNameAtLocked(size_t index) const = 0;
00160     virtual size_t                  CountEntriesLocked() const = 0;
00161 
00163 
00164     virtual ssize_t                 ColumnIndexOfLocked(const SString& entry) const = 0;
00166 
00168     virtual SString                 ColumnNameAtLocked(size_t index) const = 0;
00169 
00171     virtual size_t                  CountColumnsLocked() const = 0;
00172 
00174 
00175     //  ------------------------------------------------------------------
00179 
00181 
00184             sptr<BIndexedDataNode>  NodeAtLocked(size_t index);
00185 
00187 
00189             sptr<BIndexedDataNode>  ActiveNodeAtLocked(size_t index);
00190 
00192 
00193             void                    UpdateEntryIndicesLocked(size_t index, ssize_t delta);
00194 
00196 
00197             void                    UpdateColumnIndicesLocked(size_t index, ssize_t delta);
00198 
00200 
00201     //  ------------------------------------------------------------------
00205 
00207 
00210             void                    SetValueAtLocked(size_t row, size_t col, const SValue& value);
00211 
00213     virtual uint32_t                ValueTypeAtLocked(size_t row, size_t col) const;
00215     virtual status_t                StoreValueTypeAtLocked(size_t row, size_t col, uint32_t type);
00217     virtual off_t                   SizeAtLocked(size_t row, size_t col) const;
00219     virtual status_t                StoreSizeAtLocked(size_t row, size_t col, off_t size);
00221     virtual SValue                  ValueAtLocked(size_t row, size_t col) const = 0;
00223     virtual status_t                StoreValueAtLocked(size_t row, size_t col, const SValue& value) = 0;
00224 
00226 
00227     virtual void                    ReportChangeAtLocked(size_t row, size_t col, const sptr<IBinder>& editor, uint32_t changes, off_t start=-1, off_t length=-1);
00228 
00230 
00231     //  ------------------------------------------------------------------
00235 
00237     virtual const void*             StartReadingAtLocked(   size_t row, size_t col, off_t position,
00238                                                             ssize_t* inoutSize, uint32_t flags) const;
00240     virtual void                    FinishReadingAtLocked(  size_t row, size_t col, const void* data) const;
00242     virtual void*                   StartWritingAtLocked(   size_t row, size_t col, off_t position,
00243                                                             ssize_t* inoutSize, uint32_t flags);
00245     virtual void                    FinishWritingAtLocked(  size_t row, size_t col, void* data);
00246 
00248 
00249     //  ------------------------------------------------------------------
00252 
00253     class RowNode;
00254 
00256 
00258     virtual sptr<RowNode>           NewRowNodeLocked(size_t index, uint32_t mode);
00259 
00261 
00262 private:
00263                                     BIndexedTableNode(const BIndexedTableNode&);
00264             BIndexedTableNode&              operator=(const BIndexedTableNode&);
00265 
00266     friend class RowNode;
00267 
00268     const   uint32_t                m_mode;
00269             SString                 m_entryMimeType;
00270             SKeyedVector<size_t, wptr<RowNode> >*   m_nodes;
00271     mutable SValue                  m_tmpValue;
00272             size_t                  m_writeLen;
00273 };
00274 
00275 // --------------------------------------------------------------------------
00276 
00278 
00281 class BIndexedTableNode::RowNode : public BIndexedDataNode
00282 {
00283 public:
00284     // --------------------------------------------------------------
00288                                     RowNode(const SContext& context, const sptr<BIndexedTableNode>& owner, size_t rowIndex, uint32_t mode);
00289 protected:
00290     virtual                         ~RowNode();
00292     virtual status_t                FinishAtom(const void* id);
00294     virtual bool                    HoldRefForLink(const SValue& binding, uint32_t flags);
00295 public:
00296 
00298     virtual lock_status_t           Lock() const;
00300     virtual void                    Unlock() const;
00301 
00303 
00304     // --------------------------------------------------------------
00309 
00311     virtual SString                 MimeTypeLocked() const;
00313     virtual status_t                StoreMimeTypeLocked(const SString& value);
00315     virtual size_t                  CountEntriesLocked() const;
00317     virtual ssize_t                 EntryIndexOfLocked(const SString& entry) const;
00319     virtual SString                 EntryNameAtLocked(size_t index) const;
00321     virtual uint32_t                ValueTypeAtLocked(size_t index) const;
00323     virtual status_t                StoreValueTypeAtLocked(size_t index, uint32_t type);
00325     virtual off_t                   SizeAtLocked(size_t index) const;
00327     virtual status_t                StoreSizeAtLocked(size_t index, off_t size);
00329     virtual SValue                  ValueAtLocked(size_t index) const;
00331     virtual status_t                StoreValueAtLocked(size_t index, const SValue& value);
00333     virtual void                    ReportChangeAtLocked(size_t index, const sptr<IBinder>& editor, uint32_t changes, off_t start=-1, off_t length=-1);
00335     virtual const void*             StartReadingAtLocked(   size_t index, off_t position,
00336                                                             ssize_t* inoutSize, uint32_t flags) const;
00338     virtual void                    FinishReadingAtLocked(  size_t index, const void* data) const;
00340     virtual void*                   StartWritingAtLocked(   size_t index, off_t position,
00341                                                             ssize_t* inoutSize, uint32_t flags);
00343     virtual void                    FinishWritingAtLocked(  size_t index, void* data);
00344 
00346 
00347             const sptr<BIndexedTableNode>   m_owner;
00348             ssize_t                 m_index;
00349 
00350 private:
00351                                     RowNode(const RowNode&);
00352             RowNode&                operator=(const RowNode&);
00353 };
00354 
00355 // ==========================================================================
00356 // ==========================================================================
00357 
00360 #if _SUPPORTS_NAMESPACE
00361 } } // namespace palmos::storage
00362 #endif
00363 
00364 #endif // _STORAGE_INDEXEDTABLENODE_H