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 ***** */
51 #include "morkHandle.h"
59 #include "morkStore.h"
63 #include "orkinStore.h"
66 #ifndef _MORKPORTTABLECURSOR_
67 #include "morkPortTableCursor.h"
70 #ifndef _ORKINPORTTABLECURSOR_
71 #include "orkinPortTableCursor.h"
74 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
77 orkinPortTableCursor:: ~orkinPortTableCursor() // morkHandle destructor does everything
81 /*protected non-poly construction*/
82 orkinPortTableCursor::orkinPortTableCursor(morkEnv
* ev
, // morkUsage is morkUsage_kPool
83 morkHandleFace
* ioFace
, // must not be nil, cookie for this handle
84 morkPortTableCursor
* ioObject
) // must not be nil, object for this handle
85 : morkHandle(ev
, ioFace
, ioObject
,
86 morkMagic_kPortTableCursor
)
88 // do not modify mNode_Derived; leave it equal to morkDerived_kHandle
92 /*static */ orkinPortTableCursor
*
93 orkinPortTableCursor::MakePortTableCursor(morkEnv
* ev
,
94 morkPortTableCursor
* ioObject
)
96 mork_bool isEnv
= ev
->IsEnv();
100 morkHandleFace
* face
= ev
->NewHandle(sizeof(orkinPortTableCursor
));
102 return new(face
) orkinPortTableCursor(ev
, face
, ioObject
);
104 ev
->OutOfMemoryError();
107 return (orkinPortTableCursor
*) 0;
111 orkinPortTableCursor::CanUsePortTableCursor(nsIMdbEnv
* mev
,
112 mork_bool inMutable
, mdb_err
* outErr
) const
115 morkEnv
* ev
= morkEnv::FromMdbEnv(mev
);
118 morkPortTableCursor
* self
= (morkPortTableCursor
*)
119 this->GetGoodHandleObject(ev
, inMutable
, morkMagic_kPortTableCursor
,
120 /*inClosedOkay*/ morkBool_kFalse
);
123 if ( self
->IsPortTableCursor() )
126 self
->NonPortTableCursorTypeError(ev
);
128 *outErr
= ev
->AsErr();
134 // { ===== begin nsIMdbISupports methods =====
135 NS_IMPL_QUERY_INTERFACE0(orkinPortTableCursor
)
138 orkinPortTableCursor::AddRef() // add strong ref with no
140 morkEnv
* ev
= mHandle_Env
;
141 if ( ev
&& ev
->IsEnv() )
142 return this->Handle_AddStrongRef(ev
->AsMdbEnv());
144 return morkEnv_kNonEnvTypeError
;
148 orkinPortTableCursor::Release() // cut strong ref
150 morkEnv
* ev
= mHandle_Env
;
151 if ( ev
&& ev
->IsEnv() )
152 return this->Handle_CutStrongRef(ev
->AsMdbEnv());
154 return morkEnv_kNonEnvTypeError
;
156 // } ===== end nsIMdbObject methods =====
159 // { ===== begin nsIMdbObject methods =====
161 // { ----- begin attribute methods -----
163 orkinPortTableCursor::IsFrozenMdbObject(nsIMdbEnv
* mev
, mdb_bool
* outIsReadonly
)
165 return this->Handle_IsFrozenMdbObject(mev
, outIsReadonly
);
167 // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
168 // } ----- end attribute methods -----
170 // { ----- begin factory methods -----
172 orkinPortTableCursor::GetMdbFactory(nsIMdbEnv
* mev
, nsIMdbFactory
** acqFactory
)
174 return this->Handle_GetMdbFactory(mev
, acqFactory
);
176 // } ----- end factory methods -----
178 // { ----- begin ref counting for well-behaved cyclic graphs -----
180 orkinPortTableCursor::GetWeakRefCount(nsIMdbEnv
* mev
, // weak refs
183 return this->Handle_GetWeakRefCount(mev
, outCount
);
186 orkinPortTableCursor::GetStrongRefCount(nsIMdbEnv
* mev
, // strong refs
189 return this->Handle_GetStrongRefCount(mev
, outCount
);
193 orkinPortTableCursor::AddWeakRef(nsIMdbEnv
* mev
)
195 return this->Handle_AddWeakRef(mev
);
198 orkinPortTableCursor::AddStrongRef(nsIMdbEnv
* mev
)
200 return this->Handle_AddStrongRef(mev
);
204 orkinPortTableCursor::CutWeakRef(nsIMdbEnv
* mev
)
206 return this->Handle_CutWeakRef(mev
);
209 orkinPortTableCursor::CutStrongRef(nsIMdbEnv
* mev
)
211 return this->Handle_CutStrongRef(mev
);
215 orkinPortTableCursor::CloseMdbObject(nsIMdbEnv
* mev
)
217 return this->Handle_CloseMdbObject(mev
);
221 orkinPortTableCursor::IsOpenMdbObject(nsIMdbEnv
* mev
, mdb_bool
* outOpen
)
223 return this->Handle_IsOpenMdbObject(mev
, outOpen
);
225 // } ----- end ref counting -----
227 // } ===== end nsIMdbObject methods =====
229 // { ===== begin nsIMdbCursor methods =====
231 // { ----- begin attribute methods -----
233 orkinPortTableCursor::GetCount(nsIMdbEnv
* mev
, mdb_count
* outCount
)
238 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
241 ev
->StubMethodOnlyError();
242 outErr
= ev
->AsErr();
250 orkinPortTableCursor::GetSeed(nsIMdbEnv
* mev
, mdb_seed
* outSeed
)
255 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
258 ev
->StubMethodOnlyError();
259 outErr
= ev
->AsErr();
267 orkinPortTableCursor::SetPos(nsIMdbEnv
* mev
, mdb_pos inPos
)
272 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
275 ev
->StubMethodOnlyError();
276 outErr
= ev
->AsErr();
282 orkinPortTableCursor::GetPos(nsIMdbEnv
* mev
, mdb_pos
* outPos
)
287 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
290 ev
->StubMethodOnlyError();
291 outErr
= ev
->AsErr();
300 orkinPortTableCursor::SetDoFailOnSeedOutOfSync(nsIMdbEnv
* mev
, mdb_bool inFail
)
305 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
308 ev
->StubMethodOnlyError();
309 outErr
= ev
->AsErr();
315 orkinPortTableCursor::GetDoFailOnSeedOutOfSync(nsIMdbEnv
* mev
, mdb_bool
* outFail
)
320 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
323 ev
->StubMethodOnlyError();
324 outErr
= ev
->AsErr();
330 // } ----- end attribute methods -----
332 // } ===== end nsIMdbCursor methods =====
334 // { ===== begin nsIMdbPortTableCursor methods =====
336 // { ----- begin attribute methods -----
338 orkinPortTableCursor::SetPort(nsIMdbEnv
* mev
, nsIMdbPort
* ioPort
)
343 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
346 ev
->StubMethodOnlyError();
347 outErr
= ev
->AsErr();
353 orkinPortTableCursor::GetPort(nsIMdbEnv
* mev
, nsIMdbPort
** acqPort
)
356 nsIMdbPort
* outPort
= 0;
358 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
361 morkPortTableCursor
* cursor
= (morkPortTableCursor
*) mHandle_Object
;
362 morkStore
* store
= cursor
->mPortTableCursor_Store
;
364 outPort
= store
->AcquireStoreHandle(ev
);
365 outErr
= ev
->AsErr();
373 orkinPortTableCursor::SetRowScope(nsIMdbEnv
* mev
, // sets pos to -1
374 mdb_scope inRowScope
)
378 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
381 morkPortTableCursor
* cursor
= (morkPortTableCursor
*) mHandle_Object
;
382 cursor
->mCursor_Pos
= -1;
384 cursor
->SetRowScope(ev
, inRowScope
);
385 outErr
= ev
->AsErr();
391 orkinPortTableCursor::GetRowScope(nsIMdbEnv
* mev
, mdb_scope
* outRowScope
)
394 mdb_scope rowScope
= 0;
396 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
399 morkPortTableCursor
* cursor
= (morkPortTableCursor
*) mHandle_Object
;
400 rowScope
= cursor
->mPortTableCursor_RowScope
;
401 outErr
= ev
->AsErr();
403 *outRowScope
= rowScope
;
406 // setting row scope to zero iterates over all row scopes in port
409 orkinPortTableCursor::SetTableKind(nsIMdbEnv
* mev
, // sets pos to -1
410 mdb_kind inTableKind
)
414 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
417 morkPortTableCursor
* cursor
= (morkPortTableCursor
*) mHandle_Object
;
418 cursor
->mCursor_Pos
= -1;
420 cursor
->SetTableKind(ev
, inTableKind
);
421 outErr
= ev
->AsErr();
427 orkinPortTableCursor::GetTableKind(nsIMdbEnv
* mev
, mdb_kind
* outTableKind
)
428 // setting table kind to zero iterates over all table kinds in row scope
431 mdb_kind tableKind
= 0;
433 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
436 morkPortTableCursor
* cursor
= (morkPortTableCursor
*) mHandle_Object
;
437 tableKind
= cursor
->mPortTableCursor_TableKind
;
438 outErr
= ev
->AsErr();
440 *outTableKind
= tableKind
;
443 // } ----- end attribute methods -----
445 // { ----- begin table iteration methods -----
447 orkinPortTableCursor::NextTable( // get table at next position in the db
448 nsIMdbEnv
* mev
, // context
449 nsIMdbTable
** acqTable
)
452 nsIMdbTable
* outTable
= 0;
454 this->CanUsePortTableCursor(mev
, /*inMutable*/ morkBool_kFalse
, &outErr
);
457 morkPortTableCursor
* cursor
= (morkPortTableCursor
*) mHandle_Object
;
458 morkTable
* table
= cursor
->NextTable(ev
);
459 if ( table
&& ev
->Good() )
460 outTable
= table
->AcquireTableHandle(ev
);
462 outErr
= ev
->AsErr();
465 *acqTable
= outTable
;
468 // } ----- end table iteration methods -----
470 // } ===== end nsIMdbPortTableCursor methods =====
473 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789