DatumGeneratorInt.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_DATUMGENERATORINT_H
00014 #define _STORAGE_DATUMGENERATORINT_H
00015 
00021 #include <storage/StreamDatum.h>
00022 
00023 #include <support/KeyedVector.h>
00024 
00025 #if _SUPPORTS_NAMESPACE
00026 namespace palmos {
00027 namespace storage {
00028 #endif
00029 
00034 // ==========================================================================
00035 // ==========================================================================
00036 
00038 
00055 class SDatumGeneratorInt : public virtual SAtom
00056 {
00057 public:
00058     // --------------------------------------------------------------
00062                                     SDatumGeneratorInt(uint32_t mode = IDatum::READ_WRITE);
00063                                     SDatumGeneratorInt(const SContext& context, uint32_t mode = IDatum::READ_WRITE);
00064 protected:
00065     virtual                         ~SDatumGeneratorInt();
00066 public:
00067 
00069 
00075     virtual lock_status_t           Lock() const;
00076 
00078     virtual void                    Unlock() const;
00079 
00081 
00082     //  ------------------------------------------------------------------
00086 
00088 
00091             sptr<IDatum>            DatumAtLocked(size_t index);
00092 
00094 
00095             void                    UpdateDatumIndicesLocked(size_t index, ssize_t delta);
00096 
00098 
00099     //  ------------------------------------------------------------------
00103 
00105 
00108             void                    SetValueAtLocked(size_t index, const SValue& value);
00109 
00111     virtual uint32_t                ValueTypeAtLocked(size_t index) const;
00113     virtual status_t                StoreValueTypeAtLocked(size_t index, uint32_t type);
00115     virtual off_t                   SizeAtLocked(size_t index) const;
00117     virtual status_t                StoreSizeAtLocked(size_t index, off_t size);
00119     virtual SValue                  ValueAtLocked(size_t index) const = 0;
00121     virtual status_t                StoreValueAtLocked(size_t index, const SValue& value) = 0;
00122 
00124     virtual void                    ReportChangeAtLocked(size_t index, const sptr<IBinder>& editor, uint32_t changes, off_t start=-1, off_t length=-1);
00125 
00127 
00128     //  ------------------------------------------------------------------
00132 
00134     virtual const void*             StartReadingAtLocked(   size_t index, off_t position,
00135                                                             ssize_t* inoutSize, uint32_t flags) const;
00137     virtual void                    FinishReadingAtLocked(  size_t index, const void* data) const;
00139     virtual void*                   StartWritingAtLocked(   size_t index, off_t position,
00140                                                             ssize_t* inoutSize, uint32_t flags);
00142     virtual void                    FinishWritingAtLocked(  size_t index, void* data);
00143 
00145 
00146     //  ------------------------------------------------------------------
00149 
00150     class IndexedDatum;
00151 
00153 
00155     virtual sptr<IndexedDatum>      NewDatumLocked(size_t index, uint32_t mode);
00156 
00158 
00159 private:
00160                                     SDatumGeneratorInt(const SDatumGeneratorInt&);
00161             SDatumGeneratorInt& operator=(const SDatumGeneratorInt&);
00162 
00163     friend class IndexedDatum;
00164 
00165     const   SContext                m_context;
00166     const   uint32_t                m_mode;
00167 
00168     mutable SLocker                 m_lock;
00169             SKeyedVector<size_t, wptr<IndexedDatum> >*  m_datums;
00170     mutable SValue                  m_tmpValue;
00171             size_t                  m_writeLen;
00172 };
00173 
00174 // --------------------------------------------------------------------------
00175 
00177 
00180 class SDatumGeneratorInt::IndexedDatum : public BStreamDatum
00181 {
00182     // --------------------------------------------------------------
00186 public:
00187                                     IndexedDatum(const SContext& context, const sptr<SDatumGeneratorInt>& owner, size_t index, uint32_t mode);
00188 protected:
00189     virtual                         ~IndexedDatum();
00191     virtual status_t                FinishAtom(const void* id);
00193     virtual bool                    HoldRefForLink(const SValue& binding, uint32_t flags);
00194 public:
00195 
00197     virtual lock_status_t           Lock() const;
00199     virtual void                    Unlock() const;
00200 
00202 
00203     // --------------------------------------------------------------
00207 
00208     virtual uint32_t                ValueTypeLocked() const;
00209     virtual status_t                StoreValueTypeLocked(uint32_t type);
00210     virtual off_t                   SizeLocked() const;
00211     virtual status_t                StoreSizeLocked(off_t size);
00212     virtual SValue                  ValueLocked() const;
00213     virtual status_t                StoreValueLocked(const SValue& value);
00214     virtual void                    ReportChangeLocked(const sptr<IBinder>& editor, uint32_t changes, off_t start=-1, off_t length=-1);
00215     virtual const void*             StartReadingLocked( const sptr<Stream>& stream, off_t position,
00216                                                         ssize_t* inoutSize, uint32_t flags) const;
00217     virtual void                    FinishReadingLocked(const sptr<Stream>& stream, const void* data) const;
00218     virtual void*                   StartWritingLocked( const sptr<Stream>& stream, off_t position,
00219                                                         ssize_t* inoutSize, uint32_t flags);
00220     virtual void                    FinishWritingLocked(const sptr<Stream>& stream, void* data);
00221 
00222             const sptr<SDatumGeneratorInt>  m_owner;
00223             ssize_t                 m_index;
00224 };
00225 
00226 // ==========================================================================
00227 // ==========================================================================
00228 
00231 #if _SUPPORTS_NAMESPACE
00232 } } // namespace palmos::storage
00233 #endif
00234 
00235 #endif // _STORAGE_DATUMGENERATORINT_H