SDatabase.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_PDATABASE_H_
00014 #define STORAGE_PDATABASE_H_
00015 
00016 #include <support/Atom.h>
00017 #include <support/Locker.h>
00018 #include <support/KeyedVector.h>
00019 
00020 #include <DataMgr.h>
00021 #include <SchemaDatabases.h>
00022 
00023 #if _SUPPORTS_NAMESPACE
00024 namespace palmos {
00025 namespace storage {
00026 using namespace palmos::support;
00027 #endif
00028 
00030 
00054 class SDatabase
00055 {
00056 public:
00057     // --------------------------------------------------------------
00068                         SDatabase();
00069 
00071                         SDatabase(DatabaseID dbID,
00072                                 DmOpenModeType mode, DbShareModeType share);
00073                         
00075 
00076                         SDatabase(const char *dbName, type_code dbCreator,
00077                                 DmOpenModeType mode, DbShareModeType share);
00078                         
00080                         //* @see DmFindDatabaseByTypeCreator() */
00081                         SDatabase(type_code dbType, type_code dbCreator,
00082                                 DmOpenModeType mode, DbShareModeType share);
00083 
00085                         SDatabase(const SDatabase &orig);
00086 
00087                         ~SDatabase();
00088 
00090             SDatabase&  operator=(const SDatabase& o);
00091 
00093             status_t    StatusCheck() const;
00095             bool        IsValid() const;
00096 
00098             status_t    Status() const;
00099 
00101 
00102     // --------------------------------------------------------------
00106 
00108             DmOpenRef   GetOpenRef() const;
00110             DatabaseID  DbID() const;
00111 
00113 
00114 private:
00115     status_t            open_database(DatabaseID dbID, uint16_t attr, DmOpenModeType mode, DbShareModeType share);
00116     
00117     class PrvOpenDbAtom : public virtual SAtom
00118     {
00119         public:
00120                         PrvOpenDbAtom(DatabaseID dbID, uint16_t attr, DmOpenModeType mode, DbShareModeType share, status_t * outResult);
00121             virtual     ~PrvOpenDbAtom();
00122             DatabaseID  m_dbID;
00123             DmOpenRef   m_dbRef;
00124             uint16_t    m_dbAttr;
00125     };
00126 
00127     sptr<PrvOpenDbAtom> m_database;
00128     status_t    m_dbErr;
00129 
00130     typedef DatabaseID dmRefTableKey;
00131     static SLocker s_dmRefTableLock;
00132     static SKeyedVector<dmRefTableKey, wptr<PrvOpenDbAtom> > s_dmRefTable;
00133 };
00134 
00135 #if _SUPPORTS_NAMESPACE
00136 } } // palmos::storage
00137 #endif
00138 
00139 #endif // STORAGE_PDATABASE_H_