Back to index

lightning-sunbird  0.9+nobinonly
morkObject.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 _MORKOBJECT_
00039 #define _MORKOBJECT_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 #ifndef _MORKNODE_
00046 #include "morkNode.h"
00047 #endif
00048 
00049 #ifndef _MORKBEAD_
00050 #include "morkBead.h"
00051 #endif
00052 
00053 #ifndef _MORKCONFIG_
00054 #include "morkConfig.h"
00055 #endif
00056 
00057 #ifndef _ORKINHEAP_
00058 #include "orkinHeap.h"
00059 #endif
00060 
00061 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00062 
00063 #define morkDerived_kObject   /*i*/ 0x6F42 /* ascii 'oB' */
00064 
00065 /*| morkObject: subclass of morkNode that adds knowledge of db suite factory
00066 **| and containing port to those objects that are exposed as instances of
00067 **| nsIMdbObject in the public interface.
00068 |*/
00069 class morkObject : public morkBead, public nsIMdbObject { 
00070 
00071 // public: // slots inherited from morkNode (meant to inform only)
00072   // nsIMdbHeap*    mNode_Heap;
00073 
00074   // mork_base      mNode_Base;     // must equal morkBase_kNode
00075   // mork_derived   mNode_Derived;  // depends on specific node subclass
00076   
00077   // mork_access    mNode_Access;   // kOpen, kClosing, kShut, or kDead
00078   // mork_usage     mNode_Usage;    // kHeap, kStack, kMember, kGlobal, kNone
00079   // mork_able      mNode_Mutable;  // can this node be modified?
00080   // mork_load      mNode_Load;     // is this node clean or dirty?
00081   
00082   // mork_uses      mNode_Uses;     // refcount for strong refs
00083   // mork_refs      mNode_Refs;     // refcount for strong refs + weak refs
00084 
00085   // mork_color      mBead_Color;   // ID for this bead
00086   
00087 public: // state is public because the entire Mork system is private
00088 
00089   morkHandle*      mObject_Handle;   // weak ref to handle for this object
00090 
00091   morkEnv * mMorkEnv; // weak ref to environment this object created in.
00092 // { ===== begin morkNode interface =====
00093 public: // morkNode virtual methods
00094   virtual void CloseMorkNode(morkEnv* ev); // CloseObject() only if open
00095   virtual ~morkObject(); // assert that CloseObject() executed earlier
00096 #ifdef MORK_DEBUG_HEAP_STATS
00097   void operator delete(void* ioAddress, size_t size)
00098   { 
00099     mork_u4* array = (mork_u4*) ioAddress;
00100     array -= 3;
00101     orkinHeap *heap = (orkinHeap *) *array;
00102     if (heap)
00103       heap->Free(nsnull, ioAddress);
00104   }
00105 #endif
00106 
00107   NS_DECL_ISUPPORTS
00108 
00109     // { ----- begin attribute methods -----
00110   NS_IMETHOD IsFrozenMdbObject(nsIMdbEnv* ev, mdb_bool* outIsReadonly);
00111   // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
00112   // } ----- end attribute methods -----
00113 
00114   // { ----- begin factory methods -----
00115   NS_IMETHOD GetMdbFactory(nsIMdbEnv* ev, nsIMdbFactory** acqFactory); 
00116   // } ----- end factory methods -----
00117 
00118   // { ----- begin ref counting for well-behaved cyclic graphs -----
00119   NS_IMETHOD GetWeakRefCount(nsIMdbEnv* ev, // weak refs
00120     mdb_count* outCount);  
00121   NS_IMETHOD GetStrongRefCount(nsIMdbEnv* ev, // strong refs
00122     mdb_count* outCount);
00123 
00124   NS_IMETHOD AddWeakRef(nsIMdbEnv* ev);
00125   NS_IMETHOD AddStrongRef(nsIMdbEnv* ev);
00126 
00127   NS_IMETHOD CutWeakRef(nsIMdbEnv* ev);
00128   NS_IMETHOD CutStrongRef(nsIMdbEnv* ev);
00129   
00130   NS_IMETHOD CloseMdbObject(nsIMdbEnv* ev); // called at strong refs zero
00131   NS_IMETHOD IsOpenMdbObject(nsIMdbEnv* ev, mdb_bool* outOpen);
00132   // } ----- end ref counting -----
00133   
00134 
00135 protected: // special case construction of first env without preceding env
00136   morkObject(const morkUsage& inUsage, nsIMdbHeap* ioHeap,
00137     mork_color inBeadColor);
00138   
00139 public: // morkEnv construction & destruction
00140   morkObject(morkEnv* ev, const morkUsage& inUsage, nsIMdbHeap* ioHeap, 
00141      mork_color inBeadColor, morkHandle* ioHandle); // ioHandle can be nil
00142   void CloseObject(morkEnv* ev); // called by CloseMorkNode();
00143 
00144 private: // copying is not allowed
00145   morkObject(const morkObject& other);
00146   morkObject& operator=(const morkObject& other);
00147 
00148 public: // dynamic type identification
00149   mork_bool IsObject() const
00150   { return IsNode() && mNode_Derived == morkDerived_kObject; }
00151 // } ===== end morkNode methods =====
00152 
00153   // void NewNilHandleError(morkEnv* ev); // mObject_Handle is nil
00154   
00155 public: // typesafe refcounting inlines calling inherited morkNode methods
00156   static void SlotWeakObject(morkObject* me,
00157     morkEnv* ev, morkObject** ioSlot)
00158   { morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00159   
00160   static void SlotStrongObject(morkObject* me,
00161     morkEnv* ev, morkObject** ioSlot)
00162   { morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
00163 };
00164 
00165 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00166 
00167 #endif /* _MORKOBJECT_ */