Back to index

lightning-sunbird  0.9+nobinonly
orkinThumb.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 _MORKTHUMB_
00055 #include "morkThumb.h"
00056 #endif
00057 
00058 #ifndef _MORKENV_
00059 #include "morkEnv.h"
00060 #endif
00061 
00062 #ifndef _ORKINTHUMB_
00063 #include "orkinThumb.h"
00064 #endif
00065 
00066 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00067 
00068 /* public virtual*/
00069 orkinThumb:: ~orkinThumb() // morkHandle destructor does everything
00070 {
00071 }
00072 
00073 /*protected non-poly construction*/
00074 orkinThumb::orkinThumb(morkEnv* ev, // morkUsage is morkUsage_kPool
00075     morkHandleFace* ioFace,    // must not be nil, cookie for this handle
00076     morkThumb* ioObject)  // must not be nil, the object for this handle
00077 : morkHandle(ev, ioFace, ioObject, morkMagic_kThumb)
00078 {
00079   // do not modify mNode_Derived; leave it equal to morkDerived_kHandle
00080 }
00081 
00082 
00083 /*static */ orkinThumb*
00084 orkinThumb::MakeThumb(morkEnv* ev, morkThumb* ioObject)
00085 {
00086   mork_bool isEnv = ev->IsEnv();
00087   MORK_ASSERT(isEnv);
00088   if ( isEnv )
00089   {
00090     morkHandleFace* face = ev->NewHandle(sizeof(orkinThumb));
00091     if ( face )
00092       return new(face) orkinThumb(ev, face, ioObject);
00093     else
00094       ev->OutOfMemoryError();
00095   }
00096     
00097   return (orkinThumb*) 0;
00098 }
00099 
00100 morkEnv*
00101 orkinThumb::CanUseThumb(nsIMdbEnv* mev,
00102   mork_bool inMutable, mdb_err* outErr) const
00103 {
00104   morkEnv* outEnv = 0;
00105   morkEnv* ev = morkEnv::FromMdbEnv(mev);
00106   if ( ev )
00107   {
00108     morkThumb* self = (morkThumb*)
00109       this->GetGoodHandleObject(ev, inMutable, morkMagic_kThumb,
00110         /*inClosedOkay*/ morkBool_kFalse);
00111     if ( self )
00112     {
00113       if ( self->IsThumb() )
00114         outEnv = ev;
00115       else
00116         self->NonThumbTypeError(ev);
00117     }
00118     *outErr = ev->AsErr();
00119   }
00120   MORK_ASSERT(outEnv);
00121   return outEnv;
00122 }
00123 
00124 
00125 // { ===== begin nsIMdbISupports methods =====
00126 NS_IMPL_QUERY_INTERFACE1(orkinThumb, nsIMdbThumb)
00127 
00128 /*virtual*/ nsrefcnt
00129 orkinThumb::AddRef() // add strong ref with no
00130 {
00131   morkEnv* ev = mHandle_Env;
00132   if ( ev && ev->IsEnv() )
00133     return this->Handle_AddStrongRef(ev->AsMdbEnv());
00134   else
00135     return morkEnv_kNonEnvTypeError;
00136 }
00137 
00138 /*virtual*/ nsrefcnt
00139 orkinThumb::Release() // cut strong ref
00140 {
00141   morkEnv* ev = mHandle_Env;
00142   if ( ev && ev->IsEnv() )
00143     return this->Handle_CutStrongRef(ev->AsMdbEnv());
00144   else
00145     return morkEnv_kNonEnvTypeError;
00146 }
00147 // } ===== end nsIMdbObject methods =====
00148 
00149 
00150 // { ===== begin nsIMdbObject methods =====
00151 
00152 // { ----- begin attribute methods -----
00153 /*virtual*/ mdb_err
00154 orkinThumb::IsFrozenMdbObject(nsIMdbEnv* mev, mdb_bool* outIsReadonly)
00155 {
00156   return this->Handle_IsFrozenMdbObject(mev, outIsReadonly);
00157 }
00158 // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
00159 // } ----- end attribute methods -----
00160 
00161 // { ----- begin factory methods -----
00162 /*virtual*/ mdb_err
00163 orkinThumb::GetMdbFactory(nsIMdbEnv* mev, nsIMdbFactory** acqFactory)
00164 {
00165   return this->Handle_GetMdbFactory(mev, acqFactory);
00166 } 
00167 // } ----- end factory methods -----
00168 
00169 // { ----- begin ref counting for well-behaved cyclic graphs -----
00170 /*virtual*/ mdb_err
00171 orkinThumb::GetWeakRefCount(nsIMdbEnv* mev, // weak refs
00172   mdb_count* outCount)
00173 {
00174   return this->Handle_GetWeakRefCount(mev, outCount);
00175 }  
00176 /*virtual*/ mdb_err
00177 orkinThumb::GetStrongRefCount(nsIMdbEnv* mev, // strong refs
00178   mdb_count* outCount)
00179 {
00180   return this->Handle_GetStrongRefCount(mev, outCount);
00181 }
00182 
00183 /*virtual*/ mdb_err
00184 orkinThumb::AddWeakRef(nsIMdbEnv* mev)
00185 {
00186   return this->Handle_AddWeakRef(mev);
00187 }
00188 /*virtual*/ mdb_err
00189 orkinThumb::AddStrongRef(nsIMdbEnv* mev)
00190 {
00191   return this->Handle_AddStrongRef(mev);
00192 }
00193 
00194 /*virtual*/ mdb_err
00195 orkinThumb::CutWeakRef(nsIMdbEnv* mev)
00196 {
00197   return this->Handle_CutWeakRef(mev);
00198 }
00199 /*virtual*/ mdb_err
00200 orkinThumb::CutStrongRef(nsIMdbEnv* mev)
00201 {
00202   return this->Handle_CutStrongRef(mev);
00203 }
00204 
00205 /*virtual*/ mdb_err
00206 orkinThumb::CloseMdbObject(nsIMdbEnv* mev)
00207 {
00208   return this->Handle_CloseMdbObject(mev);
00209 }
00210 
00211 /*virtual*/ mdb_err
00212 orkinThumb::IsOpenMdbObject(nsIMdbEnv* mev, mdb_bool* outOpen)
00213 {
00214   return this->Handle_IsOpenMdbObject(mev, outOpen);
00215 }
00216 // } ----- end ref counting -----
00217 
00218 // } ===== end nsIMdbObject methods =====
00219 
00220 
00221 // { ===== begin nsIMdbThumb methods =====
00222 /*virtual*/ mdb_err
00223 orkinThumb::GetProgress(nsIMdbEnv* mev, mdb_count* outTotal,
00224   mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken)
00225 {
00226   mdb_err outErr = 0;
00227   morkEnv* ev = this->CanUseThumb(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00228   if ( ev )
00229   {
00230     ((morkThumb*) mHandle_Object)->GetProgress(ev, outTotal,
00231       outCurrent, outDone, outBroken);
00232     outErr = ev->AsErr();
00233   }
00234   return outErr;
00235 }
00236 
00237 /*virtual*/ mdb_err
00238 orkinThumb::DoMore(nsIMdbEnv* mev, mdb_count* outTotal,
00239   mdb_count* outCurrent, mdb_bool* outDone, mdb_bool* outBroken)
00240 {
00241   mdb_err outErr = 0;
00242   morkEnv* ev = this->CanUseThumb(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00243   if ( ev )
00244   {
00245     morkThumb* thumb = (morkThumb*) mHandle_Object;
00246     thumb->DoMore(ev, outTotal, outCurrent, outDone, outBroken);
00247     outErr = ev->AsErr();
00248   }
00249   return outErr;
00250 }
00251 
00252 /*virtual*/ mdb_err
00253 orkinThumb::CancelAndBreakThumb(nsIMdbEnv* mev)
00254 {
00255   mdb_err outErr = 0;
00256   morkEnv* ev = this->CanUseThumb(mev, /*inMutable*/ morkBool_kFalse, &outErr);
00257   if ( ev )
00258   {
00259     morkThumb* thumb = (morkThumb*) mHandle_Object;
00260     thumb->mThumb_Done = morkBool_kTrue;
00261     thumb->mThumb_Broken = morkBool_kTrue;
00262     thumb->CloseMorkNode(ev); // should I close this here?
00263     outErr = ev->AsErr();
00264   }
00265   return outErr;
00266 }
00267 // } ===== end nsIMdbThumb methods =====
00268 
00269 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789