Back to index

lightning-sunbird  0.9+nobinonly
morkThumb.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 _MORKENV_
00051 #include "morkEnv.h"
00052 #endif
00053 
00054 #ifndef _MORKTHUMB_
00055 #include "morkThumb.h"
00056 #endif
00057 
00058 #ifndef _ORKINTHUMB_
00059 #include "orkinThumb.h"
00060 #endif
00061 
00062 #ifndef _MORKSTORE_
00063 #include "morkStore.h"
00064 #endif
00065 
00066 // #ifndef _MORKFILE_
00067 // #include "morkFile.h"
00068 // #endif
00069 
00070 #ifndef _MORKWRITER_
00071 #include "morkWriter.h"
00072 #endif
00073 
00074 #ifndef _MORKPARSER_
00075 #include "morkParser.h"
00076 #endif
00077 
00078 #ifndef _MORKBUILDER_
00079 #include "morkBuilder.h"
00080 #endif
00081 
00082 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00083 
00084 // ````` ````` ````` ````` ````` 
00085 // { ===== begin morkNode interface =====
00086 
00087 /*public virtual*/ void
00088 morkThumb::CloseMorkNode(morkEnv* ev) // CloseThumb() only if open
00089 {
00090   if ( this->IsOpenNode() )
00091   {
00092     this->MarkClosing();
00093     this->CloseThumb(ev);
00094     this->MarkShut();
00095   }
00096 }
00097 
00098 /*public virtual*/
00099 morkThumb::~morkThumb() // assert CloseThumb() executed earlier
00100 {
00101   CloseMorkNode(mMorkEnv);
00102   MORK_ASSERT(mThumb_Magic==0);
00103   MORK_ASSERT(mThumb_Store==0);
00104   MORK_ASSERT(mThumb_File==0);
00105 }
00106 
00107 /*public non-poly*/
00108 morkThumb::morkThumb(morkEnv* ev,
00109   const morkUsage& inUsage, nsIMdbHeap* ioHeap,
00110   nsIMdbHeap* ioSlotHeap, mork_magic inMagic)
00111 : morkObject(ev, inUsage, ioHeap, morkColor_kNone, (morkHandle*) 0)
00112 , mThumb_Magic( 0 )
00113 , mThumb_Total( 0 )
00114 , mThumb_Current( 0 )
00115 
00116 , mThumb_Done( morkBool_kFalse )
00117 , mThumb_Broken( morkBool_kFalse )
00118 , mThumb_Seed( 0 )
00119 
00120 , mThumb_Store( 0 )
00121 , mThumb_File( 0 )
00122 , mThumb_Writer( 0 )
00123 , mThumb_Builder( 0 )
00124 , mThumb_SourcePort( 0 )
00125 
00126 , mThumb_DoCollect( morkBool_kFalse )
00127 {
00128   if ( ev->Good() )
00129   {
00130     if ( ioSlotHeap )
00131     {
00132       mThumb_Magic = inMagic;
00133       mNode_Derived = morkDerived_kThumb;
00134     }
00135     else
00136       ev->NilPointerError();
00137   }
00138 }
00139 
00140 NS_IMPL_ISUPPORTS_INHERITED1(morkThumb, morkObject, nsIMdbThumb)
00141 
00142 /*public non-poly*/ void
00143 morkThumb::CloseThumb(morkEnv* ev) // called by CloseMorkNode();
00144 {
00145   if ( this )
00146   {
00147     if ( this->IsNode() )
00148     {
00149       mThumb_Magic = 0;
00150       if ( mThumb_Builder && mThumb_Store )
00151         mThumb_Store->ForgetBuilder(ev);
00152       morkBuilder::SlotStrongBuilder((morkBuilder*) 0, ev, &mThumb_Builder);
00153       
00154       morkWriter::SlotStrongWriter((morkWriter*) 0, ev, &mThumb_Writer);
00155       nsIMdbFile_SlotStrongFile((nsIMdbFile*) 0, ev, &mThumb_File);
00156       morkStore::SlotStrongStore((morkStore*) 0, ev, &mThumb_Store);
00157       morkStore::SlotStrongPort((morkPort*) 0, ev, &mThumb_SourcePort);
00158       this->MarkShut();
00159     }
00160     else
00161       this->NonNodeError(ev);
00162   }
00163   else
00164     ev->NilPointerError();
00165 }
00166 
00167 // } ===== end morkNode methods =====
00168 // ````` ````` ````` ````` ````` 
00169 
00170 // { ===== begin nsIMdbThumb methods =====
00171 NS_IMETHODIMP
00172 morkThumb::GetProgress(nsIMdbEnv* mev, mdb_count* outTotal,
00173   mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken)
00174 {
00175   mdb_err outErr = 0;
00176   morkEnv* ev = morkEnv::FromMdbEnv(mev);
00177   if ( ev )
00178   {
00179     GetProgress(ev, outTotal, outCurrent, outDone, outBroken);
00180     outErr = ev->AsErr();
00181   }
00182   return outErr;
00183 }
00184 
00185 NS_IMETHODIMP
00186 morkThumb::DoMore(nsIMdbEnv* mev, mdb_count* outTotal,
00187   mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken)
00188 {
00189   mdb_err outErr = 0;
00190   morkEnv* ev = morkEnv::FromMdbEnv(mev);
00191   if ( ev )
00192   {
00193     DoMore(ev, outTotal, outCurrent, outDone, outBroken);
00194     outErr = ev->AsErr();
00195   }
00196   return outErr;
00197 }
00198 
00199 NS_IMETHODIMP
00200 morkThumb::CancelAndBreakThumb(nsIMdbEnv* mev)
00201 {
00202   mdb_err outErr = 0;
00203   morkEnv* ev = morkEnv::FromMdbEnv(mev);
00204   if ( ev )
00205   {
00206     mThumb_Done = morkBool_kTrue;
00207     mThumb_Broken = morkBool_kTrue;
00208     CloseMorkNode(ev); // should I close this here?
00209     outErr = ev->AsErr();
00210   }
00211   return outErr;
00212 }
00213 // } ===== end nsIMdbThumb methods =====
00214 
00215 /*static*/ void morkThumb::NonThumbTypeError(morkEnv* ev)
00216 {
00217   ev->NewError("non morkThumb");
00218 }
00219 
00220 /*static*/ void morkThumb::UnsupportedThumbMagicError(morkEnv* ev)
00221 {
00222   ev->NewError("unsupported mThumb_Magic");
00223 }
00224 
00225 /*static*/ void morkThumb::NilThumbStoreError(morkEnv* ev)
00226 {
00227   ev->NewError("nil mThumb_Store");
00228 }
00229 
00230 /*static*/ void morkThumb::NilThumbFileError(morkEnv* ev)
00231 {
00232   ev->NewError("nil mThumb_File");
00233 }
00234 
00235 /*static*/ void morkThumb::NilThumbWriterError(morkEnv* ev)
00236 {
00237   ev->NewError("nil mThumb_Writer");
00238 }
00239 
00240 /*static*/ void morkThumb::NilThumbBuilderError(morkEnv* ev)
00241 {
00242   ev->NewError("nil mThumb_Builder");
00243 }
00244 
00245 /*static*/ void morkThumb::NilThumbSourcePortError(morkEnv* ev)
00246 {
00247   ev->NewError("nil mThumb_SourcePort");
00248 }
00249 
00250 /*static*/ morkThumb*
00251 morkThumb::Make_OpenFileStore(morkEnv* ev, nsIMdbHeap* ioHeap, 
00252   morkStore* ioStore)
00253 {
00254   morkThumb* outThumb = 0;
00255   if ( ioHeap && ioStore )
00256   {
00257     nsIMdbFile* file = ioStore->mStore_File;
00258     if ( file )
00259     {
00260       mork_pos fileEof = 0;
00261       file->Eof(ev->AsMdbEnv(), &fileEof);
00262       if ( ev->Good() )
00263       {
00264         outThumb = new(*ioHeap, ev)
00265           morkThumb(ev, morkUsage::kHeap, ioHeap, ioHeap,
00266             morkThumb_kMagic_OpenFileStore);
00267             
00268         if ( outThumb )
00269         {
00270           morkBuilder* builder = ioStore->LazyGetBuilder(ev);
00271           if ( builder )
00272           {
00273             outThumb->mThumb_Total = (mork_count) fileEof;
00274             morkStore::SlotStrongStore(ioStore, ev, &outThumb->mThumb_Store);
00275             morkBuilder::SlotStrongBuilder(builder, ev,
00276               &outThumb->mThumb_Builder);
00277           }
00278         }
00279       }
00280     }
00281     else
00282       ioStore->NilStoreFileError(ev);
00283   }
00284   else
00285     ev->NilPointerError();
00286     
00287   return outThumb;
00288 }
00289 
00290 
00291 /*static*/ morkThumb*
00292 morkThumb::Make_LargeCommit(morkEnv* ev, 
00293   nsIMdbHeap* ioHeap, morkStore* ioStore)
00294 {
00295   morkThumb* outThumb = 0;
00296   if ( ioHeap && ioStore )
00297   {
00298     nsIMdbFile* file = ioStore->mStore_File;
00299     if ( file )
00300     {
00301       outThumb = new(*ioHeap, ev)
00302         morkThumb(ev, morkUsage::kHeap, ioHeap, ioHeap,
00303           morkThumb_kMagic_LargeCommit);
00304           
00305       if ( outThumb )
00306       {
00307         morkWriter* writer = new(*ioHeap, ev)
00308           morkWriter(ev, morkUsage::kHeap, ioHeap, ioStore, file, ioHeap);
00309         if ( writer )
00310         {
00311           writer->mWriter_CommitGroupIdentity =
00312             ++ioStore->mStore_CommitGroupIdentity;
00313           writer->mWriter_NeedDirtyAll = morkBool_kFalse;
00314           outThumb->mThumb_DoCollect = morkBool_kFalse;
00315           morkStore::SlotStrongStore(ioStore, ev, &outThumb->mThumb_Store);
00316           
00317           nsIMdbFile_SlotStrongFile(file, ev, &outThumb->mThumb_File);
00318           
00319           outThumb->mThumb_Writer = writer; // pass writer ownership to thumb
00320         }
00321       }
00322     }
00323     else
00324       ioStore->NilStoreFileError(ev);
00325   }
00326   else
00327     ev->NilPointerError();
00328     
00329   return outThumb;
00330 }
00331 
00332 /*static*/ morkThumb*
00333 morkThumb::Make_CompressCommit(morkEnv* ev, 
00334   nsIMdbHeap* ioHeap, morkStore* ioStore, mork_bool inDoCollect)
00335 {
00336   morkThumb* outThumb = 0;
00337   if ( ioHeap && ioStore )
00338   {
00339     nsIMdbFile* file = ioStore->mStore_File;
00340     if ( file )
00341     {
00342       outThumb = new(*ioHeap, ev)
00343         morkThumb(ev, morkUsage::kHeap, ioHeap, ioHeap,
00344           morkThumb_kMagic_CompressCommit);
00345           
00346       if ( outThumb )
00347       {
00348         morkWriter* writer = new(*ioHeap, ev)
00349           morkWriter(ev, morkUsage::kHeap, ioHeap, ioStore, file, ioHeap);
00350         if ( writer )
00351         {
00352           writer->mWriter_NeedDirtyAll = morkBool_kTrue;
00353           outThumb->mThumb_DoCollect = inDoCollect;
00354           morkStore::SlotStrongStore(ioStore, ev, &outThumb->mThumb_Store);
00355           nsIMdbFile_SlotStrongFile(file, ev, &outThumb->mThumb_File);
00356           outThumb->mThumb_Writer = writer; // pass writer ownership to thumb
00357           
00358           // cope with fact that parsed transaction groups are going away:
00359           ioStore->mStore_FirstCommitGroupPos = 0;
00360           ioStore->mStore_SecondCommitGroupPos = 0;
00361         }
00362       }
00363     }
00364     else
00365       ioStore->NilStoreFileError(ev);
00366   }
00367   else
00368     ev->NilPointerError();
00369     
00370   return outThumb;
00371 }
00372 
00373 // { ===== begin non-poly methods imitating nsIMdbThumb =====
00374 void morkThumb::GetProgress(morkEnv* ev, mdb_count* outTotal,
00375   mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken)
00376 {
00377   MORK_USED_1(ev);
00378   if ( outTotal )
00379     *outTotal = mThumb_Total;
00380   if ( outCurrent )
00381     *outCurrent = mThumb_Current;
00382   if ( outDone )
00383     *outDone = mThumb_Done;
00384   if ( outBroken )
00385     *outBroken = mThumb_Broken;
00386 }
00387 
00388 void morkThumb::DoMore(morkEnv* ev, mdb_count* outTotal,
00389   mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken)
00390 {
00391   if ( !mThumb_Done && !mThumb_Broken )
00392   {
00393     switch ( mThumb_Magic )
00394     {
00395       case morkThumb_kMagic_OpenFilePort: // 1 /* factory method */
00396         this->DoMore_OpenFilePort(ev); break;
00397 
00398       case morkThumb_kMagic_OpenFileStore: // 2 /* factory method */
00399         this->DoMore_OpenFileStore(ev); break;
00400 
00401       case morkThumb_kMagic_ExportToFormat: // 3 /* port method */
00402         this->DoMore_ExportToFormat(ev); break;
00403 
00404       case morkThumb_kMagic_ImportContent: // 4 /* store method */
00405         this->DoMore_ImportContent(ev); break;
00406 
00407       case morkThumb_kMagic_LargeCommit: // 5 /* store method */
00408         this->DoMore_LargeCommit(ev); break;
00409 
00410       case morkThumb_kMagic_SessionCommit: // 6 /* store method */
00411         this->DoMore_SessionCommit(ev); break;
00412 
00413       case morkThumb_kMagic_CompressCommit: // 7 /* store method */
00414         this->DoMore_CompressCommit(ev); break;
00415 
00416       case morkThumb_kMagic_SearchManyColumns: // 8 /* table method */
00417         this->DoMore_SearchManyColumns(ev); break;
00418 
00419       case morkThumb_kMagic_NewSortColumn: // 9 /* table metho) */
00420         this->DoMore_NewSortColumn(ev); break;
00421 
00422       case morkThumb_kMagic_NewSortColumnWithCompare: // 10 /* table method */
00423         this->DoMore_NewSortColumnWithCompare(ev); break;
00424 
00425       case morkThumb_kMagic_CloneSortColumn: // 11 /* table method */
00426         this->DoMore_CloneSortColumn(ev); break;
00427 
00428       case morkThumb_kMagic_AddIndex: // 12 /* table method */
00429         this->DoMore_AddIndex(ev); break;
00430 
00431       case morkThumb_kMagic_CutIndex: // 13 /* table method */
00432         this->DoMore_CutIndex(ev); break;
00433 
00434       default:
00435         this->UnsupportedThumbMagicError(ev);
00436         break;
00437     }
00438   }
00439   if ( outTotal )
00440     *outTotal = mThumb_Total;
00441   if ( outCurrent )
00442     *outCurrent = mThumb_Current;
00443   if ( outDone )
00444     *outDone = mThumb_Done;
00445   if ( outBroken )
00446     *outBroken = mThumb_Broken;
00447 }
00448 
00449 void morkThumb::CancelAndBreakThumb(morkEnv* ev)
00450 {
00451   MORK_USED_1(ev);
00452   mThumb_Broken = morkBool_kTrue;
00453 }
00454 
00455 // } ===== end non-poly methods imitating nsIMdbThumb =====
00456 
00457 morkStore*
00458 morkThumb::ThumbToOpenStore(morkEnv* ev)
00459 // for orkinFactory::ThumbToOpenStore() after OpenFileStore()
00460 {
00461   MORK_USED_1(ev);
00462   return mThumb_Store;
00463 }
00464 
00465 void morkThumb::DoMore_OpenFilePort(morkEnv* ev)
00466 {
00467   this->UnsupportedThumbMagicError(ev);
00468 }
00469 
00470 void morkThumb::DoMore_OpenFileStore(morkEnv* ev)
00471 {
00472   morkBuilder* builder = mThumb_Builder;
00473   if ( builder )
00474   {
00475     mork_pos pos = 0;
00476     builder->ParseMore(ev, &pos, &mThumb_Done, &mThumb_Broken);
00477     // mThumb_Total = builder->mBuilder_TotalCount;
00478     // mThumb_Current = builder->mBuilder_DoneCount;
00479     mThumb_Current = (mork_count) pos;
00480   }
00481   else
00482   {
00483     this->NilThumbBuilderError(ev);
00484     mThumb_Broken = morkBool_kTrue;
00485     mThumb_Done = morkBool_kTrue;
00486   }
00487 }
00488 
00489 void morkThumb::DoMore_ExportToFormat(morkEnv* ev)
00490 {
00491   this->UnsupportedThumbMagicError(ev);
00492 }
00493 
00494 void morkThumb::DoMore_ImportContent(morkEnv* ev)
00495 {
00496   this->UnsupportedThumbMagicError(ev);
00497 }
00498 
00499 void morkThumb::DoMore_LargeCommit(morkEnv* ev)
00500 {
00501   this->DoMore_Commit(ev);
00502 }
00503 
00504 void morkThumb::DoMore_SessionCommit(morkEnv* ev)
00505 {
00506   this->DoMore_Commit(ev);
00507 }
00508 
00509 void morkThumb::DoMore_Commit(morkEnv* ev)
00510 {
00511   morkWriter* writer = mThumb_Writer;
00512   if ( writer )
00513   {
00514     writer->WriteMore(ev);
00515     mThumb_Total = writer->mWriter_TotalCount;
00516     mThumb_Current = writer->mWriter_DoneCount;
00517     mThumb_Done = ( ev->Bad() || writer->IsWritingDone() );
00518     mThumb_Broken = ev->Bad();
00519   }
00520   else
00521   {
00522     this->NilThumbWriterError(ev);
00523     mThumb_Broken = morkBool_kTrue;
00524     mThumb_Done = morkBool_kTrue;
00525   }
00526 }
00527 
00528 void morkThumb::DoMore_CompressCommit(morkEnv* ev)
00529 {
00530   this->DoMore_Commit(ev);
00531 }
00532 
00533 void morkThumb::DoMore_SearchManyColumns(morkEnv* ev)
00534 {
00535   this->UnsupportedThumbMagicError(ev);
00536 }
00537 
00538 void morkThumb::DoMore_NewSortColumn(morkEnv* ev)
00539 {
00540   this->UnsupportedThumbMagicError(ev);
00541 }
00542 
00543 void morkThumb::DoMore_NewSortColumnWithCompare(morkEnv* ev)
00544 {
00545   this->UnsupportedThumbMagicError(ev);
00546 }
00547 
00548 void morkThumb::DoMore_CloneSortColumn(morkEnv* ev)
00549 {
00550   this->UnsupportedThumbMagicError(ev);
00551 }
00552 
00553 void morkThumb::DoMore_AddIndex(morkEnv* ev)
00554 {
00555   this->UnsupportedThumbMagicError(ev);
00556 }
00557 
00558 void morkThumb::DoMore_CutIndex(morkEnv* ev)
00559 {
00560   this->UnsupportedThumbMagicError(ev);
00561 }
00562 
00563 
00564 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789