Back to index

lightning-sunbird  0.9+nobinonly
orkinFactory.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-  */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _ORKINFACTORY_
00039 #define _ORKINFACTORY_ 1
00040 
00041 #ifndef _MDB_
00042 #include "mdb.h"
00043 #endif
00044 
00045 #ifndef _MORK_
00046 #include "mork.h"
00047 #endif
00048 
00049 #ifndef _MORKNODE_
00050 #include "morkNode.h"
00051 #endif
00052 
00053 #ifndef _MORKHANDLE_
00054 #include "morkHandle.h"
00055 #endif
00056 
00057 #ifndef _MORKFACTORY_
00058 #include "morkFactory.h"
00059 #endif
00060 
00061 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00062 
00063 #define morkMagic_kFactory 0x46616374 /* ascii 'Fact' */
00064 
00065 /*| orkinFactory: 
00066 |*/
00067 class orkinFactory : public morkHandle, public nsIMdbFactory { // nsIMdbObject
00068 
00069 // { ===== begin morkNode interface =====
00070 public: // morkNode virtual methods
00071   // virtual void CloseMorkNode(morkEnv* ev); // morkHandle is fine
00072   virtual ~orkinFactory(); // morkHandle destructor does everything
00073   
00074 protected: // construction is protected (use the static Make() method)
00075   orkinFactory(morkEnv* ev, // note morkUsage is always morkUsage_kPool
00076     morkHandleFace* ioFace,    // must not be nil, cookie for this handle
00077     morkFactory* ioObject); // must not be nil, the object for this handle
00078     
00079   // void CloseHandle(morkEnv* ev); // don't need to specialize closing
00080 
00081 private: // copying is not allowed
00082   orkinFactory(const morkHandle& other);
00083   orkinFactory& operator=(const morkHandle& other);
00084 
00085 // public: // dynamic type identification
00086   // mork_bool IsHandle() const //
00087   // { return IsNode() && mNode_Derived == morkDerived_kHandle; }
00088 // } ===== end morkNode methods =====
00089 
00090 protected: // morkHandle memory management operators
00091   void* operator new(size_t inSize, morkPool& ioPool, morkZone& ioZone, morkEnv* ev) CPP_THROW_NEW
00092   { return ioPool.NewHandle(ev, inSize, &ioZone); }
00093   
00094   void* operator new(size_t inSize, morkPool& ioPool, morkEnv* ev) CPP_THROW_NEW
00095   { return ioPool.NewHandle(ev, inSize, (morkZone*) 0); }
00096   
00097   void* operator new(size_t inSize, morkHandleFace* ioFace) CPP_THROW_NEW
00098   { MORK_USED_1(inSize); return ioFace; }
00099   
00100  
00101 public: // construction:
00102 
00103   static orkinFactory* MakeGlobalFactory();
00104   // instantiate objects using almost no context information.
00105   
00106   static orkinFactory* MakeFactory(morkEnv* ev, morkFactory* ioObject);
00107 
00108 public: // utilities:
00109 
00110   morkEnv* CanUseFactory(nsIMdbEnv* mev, mork_bool inMutable,
00111     mdb_err* outErr) const;
00112     
00113   morkEnv* GetInternalFactoryEnv(mdb_err* outErr);
00114   
00115   mork_bool CanOpenMorkTextFile(morkEnv* ev,
00116     // const mdbYarn* inFirst512Bytes,
00117     nsIMdbFile* ioFile);
00118 
00119 public: // type identification
00120   mork_bool IsOrkinFactory() const
00121   { return mHandle_Magic == morkMagic_kFactory; }
00122 
00123   mork_bool IsOrkinFactoryHandle() const
00124   { return this->IsHandle() && this->IsOrkinFactory(); }
00125   
00126 public:
00127 
00128   NS_DECL_ISUPPORTS
00129 
00130 // { ===== begin nsIMdbObject methods =====
00131 
00132   // { ----- begin attribute methods -----
00133   NS_IMETHOD IsFrozenMdbObject(nsIMdbEnv* ev, mdb_bool* outIsReadonly);
00134   // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
00135   // } ----- end attribute methods -----
00136 
00137   // { ----- begin factory methods -----
00138   NS_IMETHOD GetMdbFactory(nsIMdbEnv* ev, nsIMdbFactory** acqFactory); 
00139   // } ----- end factory methods -----
00140 
00141   // { ----- begin ref counting for well-behaved cyclic graphs -----
00142   NS_IMETHOD GetWeakRefCount(nsIMdbEnv* ev, // weak refs
00143     mdb_count* outCount);  
00144   NS_IMETHOD GetStrongRefCount(nsIMdbEnv* ev, // strong refs
00145     mdb_count* outCount);
00146 
00147   NS_IMETHOD AddWeakRef(nsIMdbEnv* ev);
00148   NS_IMETHOD AddStrongRef(nsIMdbEnv* ev);
00149 
00150   NS_IMETHOD CutWeakRef(nsIMdbEnv* ev);
00151   NS_IMETHOD CutStrongRef(nsIMdbEnv* ev);
00152   
00153   NS_IMETHOD CloseMdbObject(nsIMdbEnv* ev); // called at strong refs zero
00154   NS_IMETHOD IsOpenMdbObject(nsIMdbEnv* ev, mdb_bool* outOpen);
00155   // } ----- end ref counting -----
00156   
00157 // } ===== end nsIMdbObject methods =====
00158 
00159 // { ===== begin nsIMdbFactory methods =====
00160 
00161   // { ----- begin file methods -----
00162   NS_IMETHOD OpenOldFile(nsIMdbEnv* ev, nsIMdbHeap* ioHeap,
00163     const char* inFilePath,
00164     mdb_bool inFrozen, nsIMdbFile** acqFile);
00165   // Choose some subclass of nsIMdbFile to instantiate, in order to read
00166   // (and write if not frozen) the file known by inFilePath.  The file
00167   // returned should be open and ready for use, and presumably positioned
00168   // at the first byte position of the file.  The exact manner in which
00169   // files must be opened is considered a subclass specific detail, and
00170   // other portions or Mork source code don't want to know how it's done.
00171 
00172   NS_IMETHOD CreateNewFile(nsIMdbEnv* ev, nsIMdbHeap* ioHeap,
00173     const char* inFilePath,
00174     nsIMdbFile** acqFile);
00175   // Choose some subclass of nsIMdbFile to instantiate, in order to read
00176   // (and write if not frozen) the file known by inFilePath.  The file
00177   // returned should be created and ready for use, and presumably positioned
00178   // at the first byte position of the file.  The exact manner in which
00179   // files must be opened is considered a subclass specific detail, and
00180   // other portions or Mork source code don't want to know how it's done.
00181   // } ----- end file methods -----
00182 
00183   // { ----- begin env methods -----
00184   NS_IMETHOD MakeEnv(nsIMdbHeap* ioHeap, nsIMdbEnv** acqEnv); // new env
00185   // ioHeap can be nil, causing a MakeHeap() style heap instance to be used
00186   // } ----- end env methods -----
00187 
00188   // { ----- begin heap methods -----
00189   NS_IMETHOD MakeHeap(nsIMdbEnv* ev, nsIMdbHeap** acqHeap); // new heap
00190   // } ----- end heap methods -----
00191 
00192   // { ----- begin compare methods -----
00193   NS_IMETHOD MakeCompare(nsIMdbEnv* ev, nsIMdbCompare** acqCompare); // ASCII
00194   // } ----- end compare methods -----
00195 
00196   // { ----- begin row methods -----
00197   NS_IMETHOD MakeRow(nsIMdbEnv* ev, nsIMdbHeap* ioHeap, nsIMdbRow** acqRow); // new row
00198   // ioHeap can be nil, causing the heap associated with ev to be used
00199   // } ----- end row methods -----
00200   
00201   // { ----- begin port methods -----
00202   NS_IMETHOD CanOpenFilePort(
00203     nsIMdbEnv* ev, // context
00204     // const char* inFilePath, // the file to investigate
00205     // const mdbYarn* inFirst512Bytes,
00206     nsIMdbFile* ioFile, // db abstract file interface
00207     mdb_bool* outCanOpen, // whether OpenFilePort() might succeed
00208     mdbYarn* outFormatVersion); // informal file format description
00209     
00210   NS_IMETHOD OpenFilePort(
00211     nsIMdbEnv* ev, // context
00212     nsIMdbHeap* ioHeap, // can be nil to cause ev's heap attribute to be used
00213     // const char* inFilePath, // the file to open for readonly import
00214     nsIMdbFile* ioFile, // db abstract file interface
00215     const mdbOpenPolicy* inOpenPolicy, // runtime policies for using db
00216     nsIMdbThumb** acqThumb); // acquire thumb for incremental port open
00217   // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
00218   // then call nsIMdbFactory::ThumbToOpenPort() to get the port instance.
00219 
00220   NS_IMETHOD ThumbToOpenPort( // redeeming a completed thumb from OpenFilePort()
00221     nsIMdbEnv* ev, // context
00222     nsIMdbThumb* ioThumb, // thumb from OpenFilePort() with done status
00223     nsIMdbPort** acqPort); // acquire new port object
00224   // } ----- end port methods -----
00225   
00226   // { ----- begin store methods -----
00227   NS_IMETHOD CanOpenFileStore(
00228     nsIMdbEnv* ev, // context
00229     // const char* inFilePath, // the file to investigate
00230     // const mdbYarn* inFirst512Bytes,
00231     nsIMdbFile* ioFile, // db abstract file interface
00232     mdb_bool* outCanOpenAsStore, // whether OpenFileStore() might succeed
00233     mdb_bool* outCanOpenAsPort, // whether OpenFilePort() might succeed
00234     mdbYarn* outFormatVersion); // informal file format description
00235     
00236   NS_IMETHOD OpenFileStore( // open an existing database
00237     nsIMdbEnv* ev, // context
00238     nsIMdbHeap* ioHeap, // can be nil to cause ev's heap attribute to be used
00239     // const char* inFilePath, // the file to open for general db usage
00240     nsIMdbFile* ioFile, // db abstract file interface
00241     const mdbOpenPolicy* inOpenPolicy, // runtime policies for using db
00242     nsIMdbThumb** acqThumb); // acquire thumb for incremental store open
00243   // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
00244   // then call nsIMdbFactory::ThumbToOpenStore() to get the store instance.
00245     
00246   NS_IMETHOD
00247   ThumbToOpenStore( // redeem completed thumb from OpenFileStore()
00248     nsIMdbEnv* ev, // context
00249     nsIMdbThumb* ioThumb, // thumb from OpenFileStore() with done status
00250     nsIMdbStore** acqStore); // acquire new db store object
00251   
00252   NS_IMETHOD CreateNewFileStore( // create a new db with minimal content
00253     nsIMdbEnv* ev, // context
00254     nsIMdbHeap* ioHeap, // can be nil to cause ev's heap attribute to be used
00255     // const char* inFilePath, // name of file which should not yet exist
00256     nsIMdbFile* ioFile, // db abstract file interface
00257     const mdbOpenPolicy* inOpenPolicy, // runtime policies for using db
00258     nsIMdbStore** acqStore); // acquire new db store object
00259   // } ----- end store methods -----
00260 
00261 // } ===== end nsIMdbFactory methods =====
00262 };
00263 
00264 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00265 
00266 #endif /* _ORKINFACTORY_ */