Back to index

lightning-sunbird  0.9+nobinonly
morkThumb.h
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 _MORKTHUMB_
00039 #define _MORKTHUMB_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 #ifndef _MORKNODE_
00046 #include "morkNode.h"
00047 #endif
00048 
00049 #ifndef _MORKOBJECT_
00050 #include "morkObject.h"
00051 #endif
00052 
00053 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00054 
00055 
00056 #define morkThumb_kMagic_OpenFilePort               1 /* factory method */
00057 #define morkThumb_kMagic_OpenFileStore              2 /* factory method */
00058 #define morkThumb_kMagic_ExportToFormat             3 /* port method */
00059 #define morkThumb_kMagic_ImportContent              4 /* store method */
00060 #define morkThumb_kMagic_LargeCommit                5 /* store method */
00061 #define morkThumb_kMagic_SessionCommit              6 /* store method */
00062 #define morkThumb_kMagic_CompressCommit             7 /* store method */
00063 #define morkThumb_kMagic_SearchManyColumns          8 /* table method */
00064 #define morkThumb_kMagic_NewSortColumn              9 /* table metho) */
00065 #define morkThumb_kMagic_NewSortColumnWithCompare  10 /* table method */
00066 #define morkThumb_kMagic_CloneSortColumn           11 /* table method */
00067 #define morkThumb_kMagic_AddIndex                  12 /* table method */
00068 #define morkThumb_kMagic_CutIndex                  13 /* table method */
00069 
00070 #define morkDerived_kThumb     /*i*/ 0x5468 /* ascii 'Th' */
00071 
00072 /*| morkThumb: 
00073 |*/
00074 class morkThumb : public morkObject, public nsIMdbThumb {
00075 
00076 // public: // slots inherited from morkNode (meant to inform only)
00077   // nsIMdbHeap*    mNode_Heap;
00078 
00079   // mork_base      mNode_Base;     // must equal morkBase_kNode
00080   // mork_derived   mNode_Derived;  // depends on specific node subclass
00081   
00082   // mork_access    mNode_Access;   // kOpen, kClosing, kShut, or kDead
00083   // mork_usage     mNode_Usage;    // kHeap, kStack, kMember, kGlobal, kNone
00084   // mork_able      mNode_Mutable;  // can this node be modified?
00085   // mork_load      mNode_Load;     // is this node clean or dirty?
00086   
00087   // mork_uses      mNode_Uses;     // refcount for strong refs
00088   // mork_refs      mNode_Refs;     // refcount for strong refs + weak refs
00089 
00090   // mork_color   mBead_Color;   // ID for this bead
00091   // morkHandle*  mObject_Handle;  // weak ref to handle for this object
00092 
00093 public: // state is public because the entire Mork system is private
00094   NS_DECL_ISUPPORTS_INHERITED
00095 
00096 // { ===== begin nsIMdbThumb methods =====
00097   NS_IMETHOD GetProgress(nsIMdbEnv* ev, mdb_count* outTotal,
00098     mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken);
00099   
00100   NS_IMETHOD DoMore(nsIMdbEnv* ev, mdb_count* outTotal,
00101     mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken);
00102   
00103   NS_IMETHOD CancelAndBreakThumb(nsIMdbEnv* ev);
00104 // } ===== end nsIMdbThumb methods =====
00105 
00106   // might as well include all the return values here:
00107   
00108   mork_magic   mThumb_Magic;   // magic sig different in each thumb type
00109   mork_count   mThumb_Total;
00110   mork_count   mThumb_Current;
00111 
00112   mork_bool    mThumb_Done;
00113   mork_bool    mThumb_Broken;
00114   mork_u2      mThumb_Seed;  // optional seed for u4 alignment padding
00115   
00116   morkStore*   mThumb_Store; // weak ref to created store
00117   nsIMdbFile*  mThumb_File;  // strong ref to file (store, import, export)
00118   morkWriter*  mThumb_Writer;  // strong ref to writer (for commit)
00119   morkBuilder* mThumb_Builder;  // strong ref to builder (for store open)
00120   morkPort*    mThumb_SourcePort;  // strong ref to port for import
00121   
00122   mork_bool    mThumb_DoCollect; // influence whether a collect happens
00123   mork_bool    mThumb_Pad[ 3 ]; // padding for u4 alignment
00124   
00125 // { ===== begin morkNode interface =====
00126 public: // morkNode virtual methods
00127   virtual void CloseMorkNode(morkEnv* ev); // CloseThumb() only if open
00128   virtual ~morkThumb(); // assert that CloseThumb() executed earlier
00129   
00130 public: // morkThumb construction & destruction
00131   morkThumb(morkEnv* ev, const morkUsage& inUsage,
00132     nsIMdbHeap* ioHeap, nsIMdbHeap* ioSlotHeap, mork_magic inMagic);
00133   void CloseThumb(morkEnv* ev); // called by CloseMorkNode();
00134 
00135 private: // copying is not allowed
00136   morkThumb(const morkThumb& other);
00137   morkThumb& operator=(const morkThumb& other);
00138 
00139 public: // dynamic type identification
00140   mork_bool IsThumb() const
00141   { return IsNode() && mNode_Derived == morkDerived_kThumb; }
00142 // } ===== end morkNode methods =====
00143 
00144 public: // typing
00145   static void NonThumbTypeError(morkEnv* ev);
00146   static void UnsupportedThumbMagicError(morkEnv* ev);
00147 
00148   static void NilThumbStoreError(morkEnv* ev);
00149   static void NilThumbFileError(morkEnv* ev);
00150   static void NilThumbWriterError(morkEnv* ev);
00151   static void NilThumbBuilderError(morkEnv* ev);
00152   static void NilThumbSourcePortError(morkEnv* ev);
00153 
00154 public: // 'do more' methods
00155 
00156   void DoMore_OpenFilePort(morkEnv* ev);
00157   void DoMore_OpenFileStore(morkEnv* ev);
00158   void DoMore_ExportToFormat(morkEnv* ev);
00159   void DoMore_ImportContent(morkEnv* ev);
00160   void DoMore_LargeCommit(morkEnv* ev);
00161   void DoMore_SessionCommit(morkEnv* ev);
00162   void DoMore_CompressCommit(morkEnv* ev);
00163   void DoMore_Commit(morkEnv* ev);
00164   void DoMore_SearchManyColumns(morkEnv* ev);
00165   void DoMore_NewSortColumn(morkEnv* ev);
00166   void DoMore_NewSortColumnWithCompare(morkEnv* ev);
00167   void DoMore_CloneSortColumn(morkEnv* ev);
00168   void DoMore_AddIndex(morkEnv* ev);
00169   void DoMore_CutIndex(morkEnv* ev);
00170 
00171 public: // other thumb methods
00172 
00173   morkStore* ThumbToOpenStore(morkEnv* ev);
00174   // for orkinFactory::ThumbToOpenStore() after OpenFileStore()
00175 
00176 public: // assorted thumb constructors
00177 
00178   static morkThumb* Make_OpenFileStore(morkEnv* ev, 
00179     nsIMdbHeap* ioHeap, morkStore* ioStore);
00180 
00181   static morkThumb* Make_CompressCommit(morkEnv* ev, 
00182     nsIMdbHeap* ioHeap, morkStore* ioStore, mork_bool inDoCollect);
00183 
00184   static morkThumb* Make_LargeCommit(morkEnv* ev, 
00185     nsIMdbHeap* ioHeap, morkStore* ioStore);
00186 
00187 // { ===== begin non-poly methods imitating nsIMdbThumb =====
00188   void GetProgress(morkEnv* ev, mdb_count* outTotal,
00189     mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken);
00190   
00191   void DoMore(morkEnv* ev, mdb_count* outTotal,
00192     mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken);
00193   
00194   void CancelAndBreakThumb(morkEnv* ev);
00195 // } ===== end non-poly methods imitating nsIMdbThumb =====
00196 
00197 
00198 
00199 public: // typesafe refcounting inlines calling inherited morkNode methods
00200   static void SlotWeakThumb(morkThumb* me,
00201     morkEnv* ev, morkThumb** ioSlot)
00202   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00203   
00204   static void SlotStrongThumb(morkThumb* me,
00205     morkEnv* ev, morkThumb** ioSlot)
00206   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00207 };
00208 
00209 
00210 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00211 
00212 #endif /* _MORKTHUMB_ */