Back to index

lightning-sunbird  0.9+nobinonly
orkinPortTableCursor.cpp
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 _MDB_
00039 #include "mdb.h"
00040 #endif
00041 
00042 #ifndef _MORK_
00043 #include "mork.h"
00044 #endif
00045 
00046 #ifndef _MORKNODE_
00047 #include "morkNode.h"
00048 #endif
00049 
00050 #ifndef _MORKHANDLE_
00051 #include "morkHandle.h"
00052 #endif
00053 
00054 #ifndef _MORKENV_
00055 #include "morkEnv.h"
00056 #endif
00057 
00058 #ifndef _MORKSTORE_
00059 #include "morkStore.h"
00060 #endif
00061 
00062 #ifndef _ORKINSTORE_
00063 #include "orkinStore.h"
00064 #endif
00065 
00066 #ifndef _MORKPORTTABLECURSOR_
00067 #include "morkPortTableCursor.h"
00068 #endif
00069 
00070 #ifndef _ORKINPORTTABLECURSOR_
00071 #include "orkinPortTableCursor.h"
00072 #endif
00073 
00074 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00075 
00076 /* public virtual*/
00077 orkinPortTableCursor:: ~orkinPortTableCursor() // morkHandle destructor does everything
00078 {
00079 }
00080 
00081 /*protected non-poly construction*/
00082 orkinPortTableCursor::orkinPortTableCursor(morkEnv* ev, // morkUsage is morkUsage_kPool
00083     morkHandleFace* ioFace,    // must not be nil, cookie for this handle
00084     morkPortTableCursor* ioObject)  // must not be nil, object for this handle
00085 : morkHandle(ev, ioFace, ioObject,
00086   morkMagic_kPortTableCursor)
00087 {
00088   // do not modify mNode_Derived; leave it equal to morkDerived_kHandle
00089 }
00090 
00091 
00092 /*static */ orkinPortTableCursor*
00093 orkinPortTableCursor::MakePortTableCursor(morkEnv* ev,
00094    morkPortTableCursor* ioObject)
00095 {
00096   mork_bool isEnv = ev->IsEnv();
00097   MORK_ASSERT(isEnv);
00098   if ( isEnv )
00099   {
00100     morkHandleFace* face = ev->NewHandle(sizeof(orkinPortTableCursor));
00101     if ( face )
00102       return new(face) orkinPortTableCursor(ev, face, ioObject);
00103     else
00104       ev->OutOfMemoryError();
00105   }
00106     
00107   return (orkinPortTableCursor*) 0;
00108 }
00109 
00110 morkEnv*
00111 orkinPortTableCursor::CanUsePortTableCursor(nsIMdbEnv* mev,
00112   mork_bool inMutable, mdb_err* outErr) const
00113 {
00114   morkEnv* outEnv = 0;
00115   morkEnv* ev = morkEnv::FromMdbEnv(mev);
00116   if ( ev )
00117   {
00118     morkPortTableCursor* self = (morkPortTableCursor*)
00119       this->GetGoodHandleObject(ev, inMutable, morkMagic_kPortTableCursor,
00120         /*inClosedOkay*/ morkBool_kFalse);
00121     if ( self )
00122     {
00123       if ( self->IsPortTableCursor() )
00124         outEnv = ev;
00125       else
00126         self->NonPortTableCursorTypeError(ev);
00127     }
00128     *outErr = ev->AsErr();
00129   }
00130   MORK_ASSERT(outEnv);
00131   return outEnv;
00132 }
00133 
00134 // { ===== begin nsIMdbISupports methods =====
00135 NS_IMPL_QUERY_INTERFACE0(orkinPortTableCursor)
00136 
00137 /*virtual*/ nsrefcnt
00138 orkinPortTableCursor::AddRef() // add strong ref with no
00139 {
00140   morkEnv* ev = mHandle_Env;
00141   if ( ev && ev->IsEnv() )
00142     return this->Handle_AddStrongRef(ev->AsMdbEnv());
00143   else
00144     return morkEnv_kNonEnvTypeError;
00145 }
00146 
00147 /*virtual*/ nsrefcnt
00148 orkinPortTableCursor::Release() // cut strong ref
00149 {
00150   morkEnv* ev = mHandle_Env;
00151   if ( ev && ev->IsEnv() )
00152     return this->Handle_CutStrongRef(ev->AsMdbEnv());
00153   else
00154     return morkEnv_kNonEnvTypeError;
00155 }
00156 // } ===== end nsIMdbObject methods =====
00157 
00158 
00159 // { ===== begin nsIMdbObject methods =====
00160 
00161 // { ----- begin attribute methods -----
00162 /*virtual*/ mdb_err
00163 orkinPortTableCursor::IsFrozenMdbObject(nsIMdbEnv* mev, mdb_bool* outIsReadonly)
00164 {
00165   return this->Handle_IsFrozenMdbObject(mev, outIsReadonly);
00166 }
00167 // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
00168 // } ----- end attribute methods -----
00169 
00170 // { ----- begin factory methods -----
00171 /*virtual*/ mdb_err
00172 orkinPortTableCursor::GetMdbFactory(nsIMdbEnv* mev, nsIMdbFactory** acqFactory)
00173 {
00174   return this->Handle_GetMdbFactory(mev, acqFactory);
00175 } 
00176 // } ----- end factory methods -----
00177 
00178 // { ----- begin ref counting for well-behaved cyclic graphs -----
00179 /*virtual*/ mdb_err
00180 orkinPortTableCursor::GetWeakRefCount(nsIMdbEnv* mev, // weak refs
00181   mdb_count* outCount)
00182 {
00183   return this->Handle_GetWeakRefCount(mev, outCount);
00184 }  
00185 /*virtual*/ mdb_err
00186 orkinPortTableCursor::GetStrongRefCount(nsIMdbEnv* mev, // strong refs
00187   mdb_count* outCount)
00188 {
00189   return this->Handle_GetStrongRefCount(mev, outCount);
00190 }
00191 
00192 /*virtual*/ mdb_err
00193 orkinPortTableCursor::AddWeakRef(nsIMdbEnv* mev)
00194 {
00195   return this->Handle_AddWeakRef(mev);
00196 }
00197 /*virtual*/ mdb_err
00198 orkinPortTableCursor::AddStrongRef(nsIMdbEnv* mev)
00199 {
00200   return this->Handle_AddStrongRef(mev);
00201 }
00202 
00203 /*virtual*/ mdb_err
00204 orkinPortTableCursor::CutWeakRef(nsIMdbEnv* mev)
00205 {
00206   return this->Handle_CutWeakRef(mev);
00207 }
00208 /*virtual*/ mdb_err
00209 orkinPortTableCursor::CutStrongRef(nsIMdbEnv* mev)
00210 {
00211   return this->Handle_CutStrongRef(mev);
00212 }
00213 
00214 /*virtual*/ mdb_err
00215 orkinPortTableCursor::CloseMdbObject(nsIMdbEnv* mev)
00216 {
00217   return this->Handle_CloseMdbObject(mev);
00218 }
00219 
00220 /*virtual*/ mdb_err
00221 orkinPortTableCursor::IsOpenMdbObject(nsIMdbEnv* mev, mdb_bool* outOpen)
00222 {
00223   return this->Handle_IsOpenMdbObject(mev, outOpen);
00224 }
00225 // } ----- end ref counting -----
00226 
00227 // } ===== end nsIMdbObject methods =====
00228 
00229 // { ===== begin nsIMdbCursor methods =====
00230 
00231 // { ----- begin attribute methods -----
00232 /*virtual*/ mdb_err
00233 orkinPortTableCursor::GetCount(nsIMdbEnv* mev, mdb_count* outCount)
00234 {
00235   mdb_err outErr = 0;
00236   mdb_count count = 0;
00237   morkEnv* ev =
00238     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00239   if ( ev )
00240   {
00241     ev->StubMethodOnlyError();
00242     outErr = ev->AsErr();
00243   }
00244   if ( outCount )
00245     *outCount = count;
00246   return outErr;
00247 }
00248 
00249 /*virtual*/ mdb_err
00250 orkinPortTableCursor::GetSeed(nsIMdbEnv* mev, mdb_seed* outSeed)
00251 {
00252   mdb_err outErr = 0;
00253   mdb_seed seed = 0;
00254   morkEnv* ev =
00255     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00256   if ( ev )
00257   {
00258     ev->StubMethodOnlyError();
00259     outErr = ev->AsErr();
00260   }
00261   if ( outSeed )
00262     *outSeed = seed;
00263   return outErr;
00264 }
00265 
00266 /*virtual*/ mdb_err
00267 orkinPortTableCursor::SetPos(nsIMdbEnv* mev, mdb_pos inPos)
00268 {
00269   MORK_USED_1(inPos);
00270   mdb_err outErr = 0;
00271   morkEnv* ev =
00272     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00273   if ( ev )
00274   {
00275     ev->StubMethodOnlyError();
00276     outErr = ev->AsErr();
00277   }
00278   return outErr;
00279 }
00280 
00281 /*virtual*/ mdb_err
00282 orkinPortTableCursor::GetPos(nsIMdbEnv* mev, mdb_pos* outPos)
00283 {
00284   mdb_err outErr = 0;
00285   mdb_pos pos = 0;
00286   morkEnv* ev =
00287     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00288   if ( ev )
00289   {
00290     ev->StubMethodOnlyError();
00291     outErr = ev->AsErr();
00292   }
00293   if ( outPos )
00294     *outPos = pos;
00295     
00296   return outErr;
00297 }
00298 
00299 /*virtual*/ mdb_err
00300 orkinPortTableCursor::SetDoFailOnSeedOutOfSync(nsIMdbEnv* mev, mdb_bool inFail)
00301 {
00302   MORK_USED_1(inFail);
00303   mdb_err outErr = 0;
00304   morkEnv* ev =
00305     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00306   if ( ev )
00307   {
00308     ev->StubMethodOnlyError();
00309     outErr = ev->AsErr();
00310   }
00311   return outErr;
00312 }
00313 
00314 /*virtual*/ mdb_err
00315 orkinPortTableCursor::GetDoFailOnSeedOutOfSync(nsIMdbEnv* mev, mdb_bool* outFail)
00316 {
00317   mdb_err outErr = 0;
00318   mdb_bool fail = 0;
00319   morkEnv* ev =
00320     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00321   if ( ev )
00322   {
00323     ev->StubMethodOnlyError();
00324     outErr = ev->AsErr();
00325   }
00326   if ( outFail )
00327     *outFail = fail;
00328   return outErr;
00329 }
00330 // } ----- end attribute methods -----
00331 
00332 // } ===== end nsIMdbCursor methods =====
00333 
00334 // { ===== begin nsIMdbPortTableCursor methods =====
00335 
00336 // { ----- begin attribute methods -----
00337 /*virtual*/ mdb_err
00338 orkinPortTableCursor::SetPort(nsIMdbEnv* mev, nsIMdbPort* ioPort)
00339 {
00340   MORK_USED_1(ioPort);
00341   mdb_err outErr = 0;
00342   morkEnv* ev =
00343     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00344   if ( ev )
00345   {
00346     ev->StubMethodOnlyError();
00347     outErr = ev->AsErr();
00348   }
00349   return outErr;
00350 }
00351 
00352 /*virtual*/ mdb_err
00353 orkinPortTableCursor::GetPort(nsIMdbEnv* mev, nsIMdbPort** acqPort)
00354 {
00355   mdb_err outErr = 0;
00356   nsIMdbPort* outPort = 0;
00357   morkEnv* ev =
00358     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00359   if ( ev )
00360   {
00361     morkPortTableCursor* cursor = (morkPortTableCursor*) mHandle_Object;
00362     morkStore* store = cursor->mPortTableCursor_Store;
00363     if ( store )
00364       outPort = store->AcquireStoreHandle(ev);
00365     outErr = ev->AsErr();
00366   }
00367   if ( acqPort )
00368     *acqPort = outPort;
00369   return outErr;
00370 }
00371 
00372 /*virtual*/ mdb_err
00373 orkinPortTableCursor::SetRowScope(nsIMdbEnv* mev, // sets pos to -1
00374   mdb_scope inRowScope)
00375 {
00376   mdb_err outErr = 0;
00377   morkEnv* ev =
00378     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00379   if ( ev )
00380   {
00381     morkPortTableCursor* cursor = (morkPortTableCursor*) mHandle_Object;
00382     cursor->mCursor_Pos = -1;
00383     
00384     cursor->SetRowScope(ev, inRowScope);
00385     outErr = ev->AsErr();
00386   }
00387   return outErr;
00388 }
00389 
00390 /*virtual*/ mdb_err
00391 orkinPortTableCursor::GetRowScope(nsIMdbEnv* mev, mdb_scope* outRowScope)
00392 {
00393   mdb_err outErr = 0;
00394   mdb_scope rowScope = 0;
00395   morkEnv* ev =
00396     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00397   if ( ev )
00398   {
00399     morkPortTableCursor* cursor = (morkPortTableCursor*) mHandle_Object;
00400     rowScope = cursor->mPortTableCursor_RowScope;
00401     outErr = ev->AsErr();
00402   }
00403   *outRowScope = rowScope;
00404   return outErr;
00405 }
00406 // setting row scope to zero iterates over all row scopes in port
00407   
00408 /*virtual*/ mdb_err
00409 orkinPortTableCursor::SetTableKind(nsIMdbEnv* mev, // sets pos to -1
00410   mdb_kind inTableKind)
00411 {
00412   mdb_err outErr = 0;
00413   morkEnv* ev =
00414     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00415   if ( ev )
00416   {
00417     morkPortTableCursor* cursor = (morkPortTableCursor*) mHandle_Object;
00418     cursor->mCursor_Pos = -1;
00419     
00420     cursor->SetTableKind(ev, inTableKind);
00421     outErr = ev->AsErr();
00422   }
00423   return outErr;
00424 }
00425 
00426 /*virtual*/ mdb_err
00427 orkinPortTableCursor::GetTableKind(nsIMdbEnv* mev, mdb_kind* outTableKind)
00428 // setting table kind to zero iterates over all table kinds in row scope
00429 {
00430   mdb_err outErr = 0;
00431   mdb_kind tableKind = 0;
00432   morkEnv* ev =
00433     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00434   if ( ev )
00435   {
00436     morkPortTableCursor* cursor = (morkPortTableCursor*) mHandle_Object;
00437     tableKind = cursor->mPortTableCursor_TableKind;
00438     outErr = ev->AsErr();
00439   }
00440   *outTableKind = tableKind;
00441   return outErr;
00442 }
00443 // } ----- end attribute methods -----
00444 
00445 // { ----- begin table iteration methods -----
00446 /*virtual*/ mdb_err
00447 orkinPortTableCursor::NextTable( // get table at next position in the db
00448   nsIMdbEnv* mev, // context
00449   nsIMdbTable** acqTable)
00450 {
00451   mdb_err outErr = 0;
00452   nsIMdbTable* outTable = 0;
00453   morkEnv* ev =
00454     this->CanUsePortTableCursor(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00455   if ( ev )
00456   {
00457     morkPortTableCursor* cursor = (morkPortTableCursor*) mHandle_Object;
00458     morkTable* table = cursor->NextTable(ev);
00459     if ( table && ev->Good() )
00460       outTable = table->AcquireTableHandle(ev);
00461         
00462     outErr = ev->AsErr();
00463   }
00464   if ( acqTable )
00465     *acqTable = outTable;
00466   return outErr;
00467 }
00468 // } ----- end table iteration methods -----
00469 
00470 // } ===== end nsIMdbPortTableCursor methods =====
00471 
00472 
00473 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789