1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1999
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 #define _ORKINTABLE_ 1
54 #include "morkHandle.h"
61 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
63 #define morkMagic_kFile 0x46696C65 /* ascii 'File' */
67 class orkinFile
: public morkHandle
, public nsIMdbFile
{ // nsIMdbFile
69 // { ===== begin morkNode interface =====
70 public: // morkNode virtual methods
71 // virtual void CloseMorkNode(morkEnv* ev); // morkHandle is fine
72 virtual ~orkinFile(); // morkHandle destructor does everything
74 protected: // construction is protected (use the static Make() method)
75 orkinFile(morkEnv
* ev
, // note morkUsage is always morkUsage_kPool
76 morkHandleFace
* ioFace
, // must not be nil, cookie for this handle
77 morkFile
* ioObject
); // must not be nil, the object for this handle
79 // void CloseHandle(morkEnv* ev); // don't need to specialize closing
81 private: // copying is not allowed
82 orkinFile(const morkHandle
& other
);
83 orkinFile
& operator=(const morkHandle
& other
);
85 // public: // dynamic type identification
86 // mork_bool IsHandle() const //
87 // { return IsNode() && mNode_Derived == morkDerived_kHandle; }
88 // } ===== end morkNode methods =====
90 protected: // morkHandle memory management operators
91 void* operator new(size_t inSize
, morkPool
& ioPool
, morkZone
& ioZone
, morkEnv
* ev
) CPP_THROW_NEW
92 { return ioPool
.NewHandle(ev
, inSize
, &ioZone
); }
94 void* operator new(size_t inSize
, morkPool
& ioPool
, morkEnv
* ev
) CPP_THROW_NEW
95 { return ioPool
.NewHandle(ev
, inSize
, (morkZone
*) 0); }
97 void* operator new(size_t inSize
, morkHandleFace
* ioFace
) CPP_THROW_NEW
98 { MORK_USED_1(inSize
); return ioFace
; }
101 public: // construction:
103 static orkinFile
* MakeFile(morkEnv
* ev
, morkFile
* ioObject
);
105 public: // utilities:
107 morkEnv
* CanUseFile(nsIMdbEnv
* mev
, mork_bool inMutable
,
108 mdb_err
* outErr
) const;
110 public: // type identification
111 mork_bool
IsOrkinFile() const
112 { return mHandle_Magic
== morkMagic_kFile
; }
114 mork_bool
IsOrkinFileHandle() const
115 { return this->IsHandle() && this->IsOrkinFile(); }
118 // { ===== begin nsIMdbObject methods =====
120 // { ----- begin attribute methods -----
121 NS_IMETHOD
IsFrozenMdbObject(nsIMdbEnv
* ev
, mdb_bool
* outIsReadonly
);
122 // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
123 // } ----- end attribute methods -----
125 // { ----- begin factory methods -----
126 NS_IMETHOD
GetMdbFactory(nsIMdbEnv
* ev
, nsIMdbFactory
** acqFactory
);
127 // } ----- end factory methods -----
129 // { ----- begin ref counting for well-behaved cyclic graphs -----
130 NS_IMETHOD
GetWeakRefCount(nsIMdbEnv
* ev
, // weak refs
131 mdb_count
* outCount
);
132 NS_IMETHOD
GetStrongRefCount(nsIMdbEnv
* ev
, // strong refs
133 mdb_count
* outCount
);
135 NS_IMETHOD
AddWeakRef(nsIMdbEnv
* ev
);
136 NS_IMETHOD
AddStrongRef(nsIMdbEnv
* ev
);
138 NS_IMETHOD
CutWeakRef(nsIMdbEnv
* ev
);
139 NS_IMETHOD
CutStrongRef(nsIMdbEnv
* ev
);
141 NS_IMETHOD
CloseMdbObject(nsIMdbEnv
* ev
); // called at strong refs zero
142 NS_IMETHOD
IsOpenMdbObject(nsIMdbEnv
* ev
, mdb_bool
* outOpen
);
143 // } ----- end ref counting -----
145 // } ===== end nsIMdbObject methods =====
147 // { ===== begin nsIMdbFile methods =====
149 // { ----- begin pos methods -----
150 NS_IMETHOD
Tell(nsIMdbEnv
* ev
, mdb_pos
* outPos
);
151 NS_IMETHOD
Seek(nsIMdbEnv
* ev
, mdb_pos inPos
);
152 NS_IMETHOD
Eof(nsIMdbEnv
* ev
, mdb_pos
* outPos
);
153 // } ----- end pos methods -----
155 // { ----- begin read methods -----
156 NS_IMETHOD
Read(nsIMdbEnv
* ev
, void* outBuf
, mdb_size inSize
,
157 mdb_size
* outActualSize
);
158 NS_IMETHOD
Get(nsIMdbEnv
* ev
, void* outBuf
, mdb_size inSize
,
159 mdb_pos inPos
, mdb_size
* outActualSize
);
160 // } ----- end read methods -----
162 // { ----- begin write methods -----
163 NS_IMETHOD
Write(nsIMdbEnv
* ev
, const void* inBuf
, mdb_size inSize
,
164 mdb_size
* outActualSize
);
165 NS_IMETHOD
Put(nsIMdbEnv
* ev
, const void* inBuf
, mdb_size inSize
,
166 mdb_pos inPos
, mdb_size
* outActualSize
);
167 NS_IMETHOD
Flush(nsIMdbEnv
* ev
);
168 // } ----- end attribute methods -----
170 // { ----- begin path methods -----
171 NS_IMETHOD
Path(nsIMdbEnv
* ev
, mdbYarn
* outFilePath
);
172 // } ----- end path methods -----
174 // { ----- begin replacement methods -----
175 NS_IMETHOD
Steal(nsIMdbEnv
* ev
, nsIMdbFile
* ioThief
);
176 NS_IMETHOD
Thief(nsIMdbEnv
* ev
, nsIMdbFile
** acqThief
);
177 // } ----- end replacement methods -----
179 // { ----- begin versioning methods -----
180 NS_IMETHOD
BecomeTrunk(nsIMdbEnv
* ev
);
181 // If this file is a file version branch created by calling AcquireBud(),
182 // BecomeTrunk() causes this file's content to replace the original
183 // file's content, typically by assuming the original file's identity.
184 // This default implementation of BecomeTrunk() does nothing, and this
185 // is appropriate behavior for files which are not branches, and is
186 // also the right behavior for files returned from AcquireBud() which are
187 // in fact the original file that has been truncated down to zero length.
189 NS_IMETHOD
AcquireBud(nsIMdbEnv
* ev
, nsIMdbHeap
* ioHeap
,
190 nsIMdbFile
** acqBud
); // acquired file for new version of content
191 // AcquireBud() starts a new "branch" version of the file, empty of content,
192 // so that a new version of the file can be written. This new file
193 // can later be told to BecomeTrunk() the original file, so the branch
194 // created by budding the file will replace the original file. Some
195 // file subclasses might initially take the unsafe but expedient
196 // approach of simply truncating this file down to zero length, and
197 // then returning the same morkFile pointer as this, with an extra
198 // reference count increment. Note that the caller of AcquireBud() is
199 // expected to eventually call CutStrongRef() on the returned file
200 // in order to release the strong reference. High quality versions
201 // of morkFile subclasses will create entirely new files which later
202 // are renamed to become the old file, so that better transactional
203 // behavior is exhibited by the file, so crashes protect old files.
204 // Note that AcquireBud() is an illegal operation on readonly files.
205 // } ----- end versioning methods -----
207 // } ===== end nsIMdbFile methods =====
210 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
212 #endif /* _ORKINTABLE_ */