1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1999
20
* the Initial Developer. All Rights Reserved.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
40
#define _MORKHANDLE_ 1
51
#include "morkDeque.h"
58
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
64
#define morkDerived_kHandle /*i*/ 0x486E /* ascii 'Hn' */
65
#define morkHandle_kTag 0x68416E44 /* ascii 'hAnD' */
69
class morkHandle : public morkNode {
71
// public: // slots inherited from morkNode (meant to inform only)
72
// nsIMdbHeap* mNode_Heap;
74
// mork_base mNode_Base; // must equal morkBase_kNode
75
// mork_derived mNode_Derived; // depends on specific node subclass
77
// mork_access mNode_Access; // kOpen, kClosing, kShut, or kDead
78
// mork_usage mNode_Usage; // kHeap, kStack, kMember, kGlobal, kNone
79
// mork_able mNode_Mutable; // can this node be modified?
80
// mork_load mNode_Load; // is this node clean or dirty?
82
// mork_uses mNode_Uses; // refcount for strong refs
83
// mork_refs mNode_Refs; // refcount for strong refs + weak refs
85
public: // state is public because the entire Mork system is private
87
mork_u4 mHandle_Tag; // must equal morkHandle_kTag
88
morkEnv* mHandle_Env; // pool that allocated this handle
89
morkHandleFace* mHandle_Face; // cookie from pool containing this
90
morkObject* mHandle_Object; // object this handle wraps for MDB API
91
mork_magic mHandle_Magic; // magic sig different in each subclass
93
// { ===== begin morkNode interface =====
94
public: // morkNode virtual methods
95
virtual void CloseMorkNode(morkEnv* ev); // CloseHandle() only if open
96
virtual ~morkHandle(); // assert that CloseHandle() executed earlier
98
public: // morkHandle construction & destruction
99
morkHandle(morkEnv* ev, // note morkUsage is always morkUsage_kPool
100
morkHandleFace* ioFace, // must not be nil, cookie for this handle
101
morkObject* ioObject, // must not be nil, the object for this handle
102
mork_magic inMagic); // magic sig to denote specific subclass
103
void CloseHandle(morkEnv* ev); // called by CloseMorkNode();
105
private: // copying is not allowed
106
morkHandle(const morkHandle& other);
107
morkHandle& operator=(const morkHandle& other);
109
protected: // special case empty construction for morkHandleFrame
110
friend class morkHandleFrame;
113
public: // dynamic type identification
114
mork_bool IsHandle() const
115
{ return IsNode() && mNode_Derived == morkDerived_kHandle; }
116
// } ===== end morkNode methods =====
118
public: // morkHandle memory management operators
119
void* operator new(size_t inSize, morkPool& ioPool, morkZone& ioZone, morkEnv* ev) CPP_THROW_NEW
120
{ return ioPool.NewHandle(ev, inSize, &ioZone); }
122
void* operator new(size_t inSize, morkPool& ioPool, morkEnv* ev) CPP_THROW_NEW
123
{ return ioPool.NewHandle(ev, inSize, (morkZone*) 0); }
125
void* operator new(size_t inSize, morkHandleFace* ioFace) CPP_THROW_NEW
126
{ MORK_USED_1(inSize); return ioFace; }
129
public: // other handle methods
130
mork_bool GoodHandleTag() const
131
{ return mHandle_Tag == morkHandle_kTag; }
133
void NewBadMagicHandleError(morkEnv* ev, mork_magic inMagic) const;
134
void NewDownHandleError(morkEnv* ev) const;
135
void NilFactoryError(morkEnv* ev) const;
136
void NilHandleObjectError(morkEnv* ev) const;
137
void NonNodeObjectError(morkEnv* ev) const;
138
void NonOpenObjectError(morkEnv* ev) const;
140
morkObject* GetGoodHandleObject(morkEnv* ev,
141
mork_bool inMutable, mork_magic inMagicType, mork_bool inClosedOkay) const;
143
public: // interface supporting mdbObject methods
145
morkEnv* CanUseHandle(nsIMdbEnv* mev, mork_bool inMutable,
146
mork_bool inClosedOkay, mdb_err* outErr) const;
148
// { ----- begin mdbObject style methods -----
149
mdb_err Handle_IsFrozenMdbObject(nsIMdbEnv* ev, mdb_bool* outIsReadonly);
151
mdb_err Handle_GetMdbFactory(nsIMdbEnv* ev, nsIMdbFactory** acqFactory);
152
mdb_err Handle_GetWeakRefCount(nsIMdbEnv* ev, mdb_count* outCount);
153
mdb_err Handle_GetStrongRefCount(nsIMdbEnv* ev, mdb_count* outCount);
155
mdb_err Handle_AddWeakRef(nsIMdbEnv* ev);
156
mdb_err Handle_AddStrongRef(nsIMdbEnv* ev);
158
mdb_err Handle_CutWeakRef(nsIMdbEnv* ev);
159
mdb_err Handle_CutStrongRef(nsIMdbEnv* ev);
161
mdb_err Handle_CloseMdbObject(nsIMdbEnv* ev);
162
mdb_err Handle_IsOpenMdbObject(nsIMdbEnv* ev, mdb_bool* outOpen);
163
// } ----- end mdbObject style methods -----
165
public: // typesafe refcounting inlines calling inherited morkNode methods
166
static void SlotWeakHandle(morkHandle* me,
167
morkEnv* ev, morkHandle** ioSlot)
168
{ morkNode::SlotWeakNode((morkNode*) me, ev, (morkNode**) ioSlot); }
170
static void SlotStrongHandle(morkHandle* me,
171
morkEnv* ev, morkHandle** ioSlot)
172
{ morkNode::SlotStrongNode((morkNode*) me, ev, (morkNode**) ioSlot); }
175
#define morkHandleFrame_kPadSlotCount 4
177
/*| morkHandleFrame: an object format used for allocating and maintaining
178
**| instances of morkHandle, with leading slots used to maintain this in a
179
**| linked list, and following slots to provide extra footprint that might
180
**| be needed by any morkHandle subclasses that include very little extra
181
**| space (by virtue of the fact that each morkHandle subclass is expected
182
**| to multiply inherit from another base class that has only abstact methods
183
**| for space overhead related only to some vtable representation).
185
class morkHandleFrame {
187
morkLink mHandleFrame_Link; // list storage without trampling Handle
188
morkHandle mHandleFrame_Handle;
189
mork_ip mHandleFrame_Padding[ morkHandleFrame_kPadSlotCount ];
192
morkHandle* AsHandle() { return &mHandleFrame_Handle; }
194
morkHandleFrame() {} // actually, morkHandleFrame never gets constructed
196
private: // copying is not allowed
197
morkHandleFrame(const morkHandleFrame& other);
198
morkHandleFrame& operator=(const morkHandleFrame& other);
201
#define morkHandleFrame_kHandleOffset \
202
mork_OffsetOf(morkHandleFrame,mHandleFrame_Handle)
204
#define morkHandle_AsHandleFrame(h) ((h)->mHandle_Block , \
205
((morkHandleFrame*) (((mork_u1*)(h)) - morkHandleFrame_kHandleOffset)))
207
//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
209
#endif /* _MORKHANDLE_ */