Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / db / mork / src / orkinThumb.cpp
blob4816c0e0cfc5ddbfd00e4bc5332f6f9cdaa34b88
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
13 * License.
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.
22 * Contributor(s):
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 ***** */
38 #ifndef _MDB_
39 #include "mdb.h"
40 #endif
42 #ifndef _MORK_
43 #include "mork.h"
44 #endif
46 #ifndef _MORKNODE_
47 #include "morkNode.h"
48 #endif
50 #ifndef _MORKHANDLE_
51 #include "morkHandle.h"
52 #endif
54 #ifndef _MORKTHUMB_
55 #include "morkThumb.h"
56 #endif
58 #ifndef _MORKENV_
59 #include "morkEnv.h"
60 #endif
62 #ifndef _ORKINTHUMB_
63 #include "orkinThumb.h"
64 #endif
66 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
68 /* public virtual*/
69 orkinThumb:: ~orkinThumb() // morkHandle destructor does everything
73 /*protected non-poly construction*/
74 orkinThumb::orkinThumb(morkEnv* ev, // morkUsage is morkUsage_kPool
75 morkHandleFace* ioFace, // must not be nil, cookie for this handle
76 morkThumb* ioObject) // must not be nil, the object for this handle
77 : morkHandle(ev, ioFace, ioObject, morkMagic_kThumb)
79 // do not modify mNode_Derived; leave it equal to morkDerived_kHandle
83 /*static */ orkinThumb*
84 orkinThumb::MakeThumb(morkEnv* ev, morkThumb* ioObject)
86 mork_bool isEnv = ev->IsEnv();
87 MORK_ASSERT(isEnv);
88 if ( isEnv )
90 morkHandleFace* face = ev->NewHandle(sizeof(orkinThumb));
91 if ( face )
92 return new(face) orkinThumb(ev, face, ioObject);
93 else
94 ev->OutOfMemoryError();
97 return (orkinThumb*) 0;
100 morkEnv*
101 orkinThumb::CanUseThumb(nsIMdbEnv* mev,
102 mork_bool inMutable, mdb_err* outErr) const
104 morkEnv* outEnv = 0;
105 morkEnv* ev = morkEnv::FromMdbEnv(mev);
106 if ( ev )
108 morkThumb* self = (morkThumb*)
109 this->GetGoodHandleObject(ev, inMutable, morkMagic_kThumb,
110 /*inClosedOkay*/ morkBool_kFalse);
111 if ( self )
113 if ( self->IsThumb() )
114 outEnv = ev;
115 else
116 self->NonThumbTypeError(ev);
118 *outErr = ev->AsErr();
120 MORK_ASSERT(outEnv);
121 return outEnv;
125 // { ===== begin nsIMdbISupports methods =====
126 NS_IMPL_QUERY_INTERFACE1(orkinThumb, nsIMdbThumb)
128 /*virtual*/ nsrefcnt
129 orkinThumb::AddRef() // add strong ref with no
131 morkEnv* ev = mHandle_Env;
132 if ( ev && ev->IsEnv() )
133 return this->Handle_AddStrongRef(ev->AsMdbEnv());
134 else
135 return morkEnv_kNonEnvTypeError;
138 /*virtual*/ nsrefcnt
139 orkinThumb::Release() // cut strong ref
141 morkEnv* ev = mHandle_Env;
142 if ( ev && ev->IsEnv() )
143 return this->Handle_CutStrongRef(ev->AsMdbEnv());
144 else
145 return morkEnv_kNonEnvTypeError;
147 // } ===== end nsIMdbObject methods =====
150 // { ===== begin nsIMdbObject methods =====
152 // { ----- begin attribute methods -----
153 /*virtual*/ mdb_err
154 orkinThumb::IsFrozenMdbObject(nsIMdbEnv* mev, mdb_bool* outIsReadonly)
156 return this->Handle_IsFrozenMdbObject(mev, outIsReadonly);
158 // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
159 // } ----- end attribute methods -----
161 // { ----- begin factory methods -----
162 /*virtual*/ mdb_err
163 orkinThumb::GetMdbFactory(nsIMdbEnv* mev, nsIMdbFactory** acqFactory)
165 return this->Handle_GetMdbFactory(mev, acqFactory);
167 // } ----- end factory methods -----
169 // { ----- begin ref counting for well-behaved cyclic graphs -----
170 /*virtual*/ mdb_err
171 orkinThumb::GetWeakRefCount(nsIMdbEnv* mev, // weak refs
172 mdb_count* outCount)
174 return this->Handle_GetWeakRefCount(mev, outCount);
176 /*virtual*/ mdb_err
177 orkinThumb::GetStrongRefCount(nsIMdbEnv* mev, // strong refs
178 mdb_count* outCount)
180 return this->Handle_GetStrongRefCount(mev, outCount);
183 /*virtual*/ mdb_err
184 orkinThumb::AddWeakRef(nsIMdbEnv* mev)
186 return this->Handle_AddWeakRef(mev);
188 /*virtual*/ mdb_err
189 orkinThumb::AddStrongRef(nsIMdbEnv* mev)
191 return this->Handle_AddStrongRef(mev);
194 /*virtual*/ mdb_err
195 orkinThumb::CutWeakRef(nsIMdbEnv* mev)
197 return this->Handle_CutWeakRef(mev);
199 /*virtual*/ mdb_err
200 orkinThumb::CutStrongRef(nsIMdbEnv* mev)
202 return this->Handle_CutStrongRef(mev);
205 /*virtual*/ mdb_err
206 orkinThumb::CloseMdbObject(nsIMdbEnv* mev)
208 return this->Handle_CloseMdbObject(mev);
211 /*virtual*/ mdb_err
212 orkinThumb::IsOpenMdbObject(nsIMdbEnv* mev, mdb_bool* outOpen)
214 return this->Handle_IsOpenMdbObject(mev, outOpen);
216 // } ----- end ref counting -----
218 // } ===== end nsIMdbObject methods =====
221 // { ===== begin nsIMdbThumb methods =====
222 /*virtual*/ mdb_err
223 orkinThumb::GetProgress(nsIMdbEnv* mev, mdb_count* outTotal,
224 mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken)
226 mdb_err outErr = 0;
227 morkEnv* ev = this->CanUseThumb(mev, /*inMutable*/ morkBool_kFalse, &outErr);
228 if ( ev )
230 ((morkThumb*) mHandle_Object)->GetProgress(ev, outTotal,
231 outCurrent, outDone, outBroken);
232 outErr = ev->AsErr();
234 return outErr;
237 /*virtual*/ mdb_err
238 orkinThumb::DoMore(nsIMdbEnv* mev, mdb_count* outTotal,
239 mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken)
241 mdb_err outErr = 0;
242 morkEnv* ev = this->CanUseThumb(mev, /*inMutable*/ morkBool_kFalse, &outErr);
243 if ( ev )
245 morkThumb* thumb = (morkThumb*) mHandle_Object;
246 thumb->DoMore(ev, outTotal, outCurrent, outDone, outBroken);
247 outErr = ev->AsErr();
249 return outErr;
252 /*virtual*/ mdb_err
253 orkinThumb::CancelAndBreakThumb(nsIMdbEnv* mev)
255 mdb_err outErr = 0;
256 morkEnv* ev = this->CanUseThumb(mev, /*inMutable*/ morkBool_kFalse, &outErr);
257 if ( ev )
259 morkThumb* thumb = (morkThumb*) mHandle_Object;
260 thumb->mThumb_Done = morkBool_kTrue;
261 thumb->mThumb_Broken = morkBool_kTrue;
262 thumb->CloseMorkNode(ev); // should I close this here?
263 outErr = ev->AsErr();
265 return outErr;
267 // } ===== end nsIMdbThumb methods =====
269 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789