Back to index

lightning-sunbird  0.9+nobinonly
morkObject.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 _MORKOBJECT_
00055 #include "morkObject.h"
00056 #endif
00057 
00058 #ifndef _MORKHANDLE_
00059 #include "morkHandle.h"
00060 #endif
00061 
00062 #include "nsCOMPtr.h"
00063 
00064 
00065 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00066 
00067 NS_IMPL_ISUPPORTS1(morkObject, nsIMdbObject)
00068 
00069 // ````` ````` ````` ````` ````` 
00070 // { ===== begin morkNode interface =====
00071 
00072 /*public virtual*/ void
00073 morkObject::CloseMorkNode(morkEnv* ev) // CloseObject() only if open
00074 {
00075   if ( this->IsOpenNode() )
00076   {
00077     this->MarkClosing();
00078     this->CloseObject(ev);
00079     this->MarkShut();
00080   }
00081 }
00082 
00083 /*public virtual*/
00084 morkObject::~morkObject() // assert CloseObject() executed earlier
00085 {
00086   if (!IsShutNode())
00087     CloseMorkNode(this->mMorkEnv);
00088   MORK_ASSERT(mObject_Handle==0);
00089 }
00090 
00091 /*public non-poly*/
00092 morkObject::morkObject(const morkUsage& inUsage, nsIMdbHeap* ioHeap,
00093   mork_color inBeadColor)
00094 : morkBead(inUsage, ioHeap, inBeadColor)
00095 , mObject_Handle( 0 )
00096 {
00097   mMorkEnv = nsnull;
00098 }
00099 
00100 /*public non-poly*/
00101 morkObject::morkObject(morkEnv* ev,
00102   const morkUsage& inUsage, nsIMdbHeap* ioHeap, 
00103   mork_color inBeadColor, morkHandle* ioHandle)
00104 : morkBead(ev, inUsage, ioHeap, inBeadColor)
00105 , mObject_Handle( 0 )
00106 {
00107   mMorkEnv = ev;
00108   if ( ev->Good() )
00109   {
00110     if ( ioHandle )
00111       morkHandle::SlotWeakHandle(ioHandle, ev, &mObject_Handle);
00112       
00113     if ( ev->Good() )
00114       mNode_Derived = morkDerived_kObject;
00115   }
00116 }
00117 
00118 /*public non-poly*/ void
00119 morkObject::CloseObject(morkEnv* ev) // called by CloseMorkNode();
00120 {
00121   if ( this )
00122   {
00123     if ( this->IsNode() )
00124     {
00125       if ( !this->IsShutNode() )
00126       {
00127         if ( mObject_Handle )
00128           morkHandle::SlotWeakHandle((morkHandle*) 0L, ev, &mObject_Handle);
00129           
00130         mBead_Color = 0; // this->CloseBead(ev);
00131         this->MarkShut();
00132       }
00133     }
00134     else
00135       this->NonNodeError(ev);
00136   }
00137   else
00138     ev->NilPointerError();
00139 }
00140 
00141 // } ===== end morkNode methods =====
00142 // ````` ````` ````` ````` ````` 
00143 
00144 // { ----- begin factory methods -----
00145 NS_IMETHODIMP
00146 morkObject::GetMdbFactory(nsIMdbEnv* mev, nsIMdbFactory** acqFactory)
00147 {
00148   nsresult rv;
00149   nsCOMPtr <nsIMdbObject> obj = do_QueryInterface(mev);
00150   if (obj)
00151     rv = obj->GetMdbFactory(mev, acqFactory);
00152   else
00153     return NS_ERROR_NO_INTERFACE;
00154 
00155   return rv;
00156 } 
00157 // } ----- end factory methods -----
00158 
00159 // { ----- begin ref counting for well-behaved cyclic graphs -----
00160 NS_IMETHODIMP
00161 morkObject::GetWeakRefCount(nsIMdbEnv* mev, // weak refs
00162   mdb_count* outCount)
00163 {
00164   *outCount = WeakRefsOnly();
00165   return NS_OK;
00166 }  
00167 NS_IMETHODIMP
00168 morkObject::GetStrongRefCount(nsIMdbEnv* mev, // strong refs
00169   mdb_count* outCount)
00170 {
00171   *outCount = StrongRefsOnly();
00172   return NS_OK;
00173 }
00174 // ### TODO - clean up this cast, if required
00175 NS_IMETHODIMP
00176 morkObject::AddWeakRef(nsIMdbEnv* mev)
00177 {
00178   return morkNode::AddWeakRef((morkEnv *) mev);
00179 }
00180 NS_IMETHODIMP
00181 morkObject::AddStrongRef(nsIMdbEnv* mev)
00182 {
00183   return morkNode::AddStrongRef((morkEnv *) mev);
00184 }
00185 
00186 NS_IMETHODIMP
00187 morkObject::CutWeakRef(nsIMdbEnv* mev)
00188 {
00189   return morkNode::CutWeakRef((morkEnv *) mev);
00190 }
00191 NS_IMETHODIMP
00192 morkObject::CutStrongRef(nsIMdbEnv* mev)
00193 {
00194   return morkNode::CutStrongRef((morkEnv *) mev);
00195 }
00196 
00197   
00198 NS_IMETHODIMP
00199 morkObject::CloseMdbObject(nsIMdbEnv* mev)
00200 {
00201   return morkNode::CloseMdbObject((morkEnv *) mev);
00202 }
00203 
00204 NS_IMETHODIMP
00205 morkObject::IsOpenMdbObject(nsIMdbEnv* mev, mdb_bool* outOpen)
00206 {
00207   *outOpen = IsOpenNode();
00208   return NS_OK;
00209 }
00210 NS_IMETHODIMP
00211 morkObject::IsFrozenMdbObject(nsIMdbEnv* mev, mdb_bool* outIsReadonly)
00212 {
00213   *outIsReadonly = IsFrozen();
00214   return NS_OK;
00215 }
00216 
00217 //void morkObject::NewNilHandleError(morkEnv* ev) // mObject_Handle is nil
00218 //{
00219 //  ev->NewError("nil mObject_Handle");
00220 //}
00221 
00222 
00223 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789