Back to index

lightning-sunbird  0.9+nobinonly
orkinFile.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 _ORKINTABLE_
00039 #define _ORKINTABLE_ 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 _MORKFILE_
00058 #include "morkFile.h"
00059 #endif
00060 
00061 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00062 
00063 #define morkMagic_kFile 0x46696C65 /* ascii 'File' */
00064 
00065 /*| orkinFile: 
00066 |*/
00067 class orkinFile : public morkHandle, public nsIMdbFile { // nsIMdbFile
00068 
00069 // { ===== begin morkNode interface =====
00070 public: // morkNode virtual methods
00071   // virtual void CloseMorkNode(morkEnv* ev); // morkHandle is fine
00072   virtual ~orkinFile(); // morkHandle destructor does everything
00073   
00074 protected: // construction is protected (use the static Make() method)
00075   orkinFile(morkEnv* ev, // note morkUsage is always morkUsage_kPool
00076     morkHandleFace* ioFace,    // must not be nil, cookie for this handle
00077     morkFile* 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   orkinFile(const morkHandle& other);
00083   orkinFile& 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 orkinFile* MakeFile(morkEnv* ev, morkFile* ioObject);
00104 
00105 public: // utilities:
00106 
00107   morkEnv* CanUseFile(nsIMdbEnv* mev, mork_bool inMutable,
00108     mdb_err* outErr) const;
00109 
00110 public: // type identification
00111   mork_bool IsOrkinFile() const
00112   { return mHandle_Magic == morkMagic_kFile; }
00113 
00114   mork_bool IsOrkinFileHandle() const
00115   { return this->IsHandle() && this->IsOrkinFile(); }
00116 
00117   NS_DECL_ISUPPORTS
00118 // { ===== begin nsIMdbObject methods =====
00119 
00120   // { ----- begin attribute methods -----
00121   NS_IMETHOD IsFrozenMdbObject(nsIMdbEnv* ev, mdb_bool* outIsReadonly);
00122   // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
00123   // } ----- end attribute methods -----
00124 
00125   // { ----- begin factory methods -----
00126   NS_IMETHOD GetMdbFactory(nsIMdbEnv* ev, nsIMdbFactory** acqFactory); 
00127   // } ----- end factory methods -----
00128 
00129   // { ----- begin ref counting for well-behaved cyclic graphs -----
00130   NS_IMETHOD GetWeakRefCount(nsIMdbEnv* ev, // weak refs
00131     mdb_count* outCount);  
00132   NS_IMETHOD GetStrongRefCount(nsIMdbEnv* ev, // strong refs
00133     mdb_count* outCount);
00134 
00135   NS_IMETHOD AddWeakRef(nsIMdbEnv* ev);
00136   NS_IMETHOD AddStrongRef(nsIMdbEnv* ev);
00137 
00138   NS_IMETHOD CutWeakRef(nsIMdbEnv* ev);
00139   NS_IMETHOD CutStrongRef(nsIMdbEnv* ev);
00140   
00141   NS_IMETHOD CloseMdbObject(nsIMdbEnv* ev); // called at strong refs zero
00142   NS_IMETHOD IsOpenMdbObject(nsIMdbEnv* ev, mdb_bool* outOpen);
00143   // } ----- end ref counting -----
00144   
00145 // } ===== end nsIMdbObject methods =====
00146 
00147 // { ===== begin nsIMdbFile methods =====
00148 
00149   // { ----- begin pos methods -----
00150   NS_IMETHOD Tell(nsIMdbEnv* ev, mdb_pos* outPos);
00151   NS_IMETHOD Seek(nsIMdbEnv* ev, mdb_pos inPos);
00152   NS_IMETHOD Eof(nsIMdbEnv* ev, mdb_pos* outPos);
00153   // } ----- end pos methods -----
00154 
00155   // { ----- begin read methods -----
00156   NS_IMETHOD Read(nsIMdbEnv* ev, void* outBuf, mdb_size inSize,
00157     mdb_size* outActualSize);
00158   NS_IMETHOD Get(nsIMdbEnv* ev, void* outBuf, mdb_size inSize,
00159     mdb_pos inPos, mdb_size* outActualSize);
00160   // } ----- end read methods -----
00161     
00162   // { ----- begin write methods -----
00163   NS_IMETHOD  Write(nsIMdbEnv* ev, const void* inBuf, mdb_size inSize,
00164     mdb_size* outActualSize);
00165   NS_IMETHOD  Put(nsIMdbEnv* ev, const void* inBuf, mdb_size inSize,
00166     mdb_pos inPos, mdb_size* outActualSize);
00167   NS_IMETHOD  Flush(nsIMdbEnv* ev);
00168   // } ----- end attribute methods -----
00169     
00170   // { ----- begin path methods -----
00171   NS_IMETHOD  Path(nsIMdbEnv* ev, mdbYarn* outFilePath);
00172   // } ----- end path methods -----
00173     
00174   // { ----- begin replacement methods -----
00175   NS_IMETHOD  Steal(nsIMdbEnv* ev, nsIMdbFile* ioThief);
00176   NS_IMETHOD  Thief(nsIMdbEnv* ev, nsIMdbFile** acqThief);
00177   // } ----- end replacement methods -----
00178 
00179   // { ----- begin versioning methods -----
00180   NS_IMETHOD BecomeTrunk(nsIMdbEnv* ev);
00181   // If this file is a file version branch created by calling AcquireBud(),
00182   // BecomeTrunk() causes this file's content to replace the original
00183   // file's content, typically by assuming the original file's identity.
00184   // This default implementation of BecomeTrunk() does nothing, and this
00185   // is appropriate behavior for files which are not branches, and is
00186   // also the right behavior for files returned from AcquireBud() which are
00187   // in fact the original file that has been truncated down to zero length.
00188 
00189   NS_IMETHOD AcquireBud(nsIMdbEnv* ev, nsIMdbHeap* ioHeap,
00190     nsIMdbFile** acqBud); // acquired file for new version of content
00191   // AcquireBud() starts a new "branch" version of the file, empty of content,
00192   // so that a new version of the file can be written.  This new file
00193   // can later be told to BecomeTrunk() the original file, so the branch
00194   // created by budding the file will replace the original file.  Some
00195   // file subclasses might initially take the unsafe but expedient
00196   // approach of simply truncating this file down to zero length, and
00197   // then returning the same morkFile pointer as this, with an extra
00198   // reference count increment.  Note that the caller of AcquireBud() is
00199   // expected to eventually call CutStrongRef() on the returned file
00200   // in order to release the strong reference.  High quality versions
00201   // of morkFile subclasses will create entirely new files which later
00202   // are renamed to become the old file, so that better transactional
00203   // behavior is exhibited by the file, so crashes protect old files.
00204   // Note that AcquireBud() is an illegal operation on readonly files.
00205   // } ----- end versioning methods -----
00206 
00207 // } ===== end nsIMdbFile methods =====
00208 };
00209  
00210 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00211 
00212 #endif /* _ORKINTABLE_ */