DatumLord.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_DATUMLORD_H
00014 #define _SUPPORT_DATUMLORD_H
00015 
00021 #include <storage/GenericDatum.h>
00022 
00023 #include <support/KeyedVector.h>
00024 #include <support/Locker.h>
00025 #include <support/MemoryStore.h>
00026 
00032 class SDatumLord : public virtual SAtom
00033 {
00034 public:
00035                         SDatumLord();
00036                         ~SDatumLord();
00037     virtual void        InitAtom();
00038     
00039     status_t    RequestDatum(const SValue &key, sptr<IDatum> *result);
00040 
00041 protected:
00042     virtual status_t    GetValue(const SValue &key, SValue *value) = 0;
00043     virtual status_t    SetValue(const SValue &key, const SValue &value) = 0;
00044 
00045 private:
00046             SDatumLord(const SDatumLord &);
00047     
00048 // ADS doesn't even closely follow the C++ standard, so we make this public so it can
00049 // compile.  But don't use it outside this class, when we get a real compiler, this will
00050 // be fixed.
00051 // "d:\source\rome\platform\headers\PDK\support\DatumLord.h", line 30: Error: C3032E: 'SDatumLord::Datum' is a non-public member
00052 public:
00053     class Datum : public BGenericDatum
00054     {
00055     public:
00056                         Datum(const sptr<SDatumLord> &owner, const SValue &key);
00057         virtual         ~Datum();
00058         virtual void    InitAtom();
00059 
00060         // IDatum
00061         virtual uint32_t ValueType() const;
00062         virtual void SetValueType(uint32_t type);
00063         virtual off_t Size() const;
00064         virtual void SetSize(off_t size);
00065         virtual SValue Value() const;
00066         virtual void SetValue(const SValue& value);
00067         virtual sptr<IBinder> Open(uint32_t mode, const sptr<IBinder>& editor, uint32_t newType);
00068         
00069         void StorageDone();
00070         
00071     private:
00072         sptr<SDatumLord> m_owner;
00073         const SValue m_key;
00074 
00075         SLocker m_lock;
00076         wptr<IStorage> m_storage;
00077 
00078         // these are used by the Storage 'cuz it keeps a direct pointer to data...
00079         SLocker m_storageLock;
00080         SValue m_storageValue;
00081     };
00082 
00083 private:
00084     class Storage : public BValueStorage
00085     {
00086     public:
00087                 Storage(SValue* value, SLocker* lock, const sptr<Datum>& owner);
00088         virtual ~Storage();
00089     private:
00090         sptr<Datum> m_owner;
00091     };
00092 
00093     friend class Datum;
00094     
00095     SLocker m_lock;
00096     SKeyedVector<SValue, wptr<IDatum> > m_data;
00097 };
00098 
00101 #endif // _SUPPORT_DATUMLORD_H