1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef _MDB_
7 # include "mdb.h"
8 #endif
9
10 #ifndef _MORK_
11 # include "mork.h"
12 #endif
13
14 #ifndef _MORKNODE_
15 # include "morkNode.h"
16 #endif
17
18 #ifndef _MORKENV_
19 # include "morkEnv.h"
20 #endif
21
22 #ifndef _MORKOBJECT_
23 # include "morkObject.h"
24 #endif
25
26 #ifndef _MORKHANDLE_
27 # include "morkHandle.h"
28 #endif
29
30 #include "nsCOMPtr.h"
31
32 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
33
NS_IMPL_ISUPPORTS(morkObject,nsIMdbObject)34 NS_IMPL_ISUPPORTS(morkObject, nsIMdbObject)
35
36 // ````` ````` ````` ````` `````
37 // { ===== begin morkNode interface =====
38
39 /*public virtual*/ void morkObject::CloseMorkNode(
40 morkEnv* ev) // CloseObject() only if open
41 {
42 if (this->IsOpenNode()) {
43 this->MarkClosing();
44 this->CloseObject(ev);
45 this->MarkShut();
46 }
47 }
48
49 /*public virtual*/
~morkObject()50 morkObject::~morkObject() // assert CloseObject() executed earlier
51 {
52 if (!IsShutNode()) CloseMorkNode(this->mMorkEnv);
53 MORK_ASSERT(mObject_Handle == 0);
54 }
55
56 /*public non-poly*/
morkObject(const morkUsage & inUsage,nsIMdbHeap * ioHeap,mork_color inBeadColor)57 morkObject::morkObject(const morkUsage& inUsage, nsIMdbHeap* ioHeap,
58 mork_color inBeadColor)
59 : morkBead(inUsage, ioHeap, inBeadColor), mObject_Handle(0) {
60 mMorkEnv = nullptr;
61 }
62
63 /*public non-poly*/
morkObject(morkEnv * ev,const morkUsage & inUsage,nsIMdbHeap * ioHeap,mork_color inBeadColor,morkHandle * ioHandle)64 morkObject::morkObject(morkEnv* ev, const morkUsage& inUsage,
65 nsIMdbHeap* ioHeap, mork_color inBeadColor,
66 morkHandle* ioHandle)
67 : morkBead(ev, inUsage, ioHeap, inBeadColor), mObject_Handle(0) {
68 mMorkEnv = ev;
69 if (ev->Good()) {
70 if (ioHandle) morkHandle::SlotWeakHandle(ioHandle, ev, &mObject_Handle);
71
72 if (ev->Good()) mNode_Derived = morkDerived_kObject;
73 }
74 }
75
CloseObject(morkEnv * ev)76 /*public non-poly*/ void morkObject::CloseObject(
77 morkEnv* ev) // called by CloseMorkNode();
78 {
79 if (this->IsNode()) {
80 if (!this->IsShutNode()) {
81 if (mObject_Handle)
82 morkHandle::SlotWeakHandle((morkHandle*)0L, ev, &mObject_Handle);
83
84 mBead_Color = 0; // this->CloseBead(ev);
85 this->MarkShut();
86 }
87 } else
88 this->NonNodeError(ev);
89 }
90
91 // } ===== end morkNode methods =====
92 // ````` ````` ````` ````` `````
93
94 // { ----- begin factory methods -----
95 NS_IMETHODIMP
GetMdbFactory(nsIMdbEnv * mev,nsIMdbFactory ** acqFactory)96 morkObject::GetMdbFactory(nsIMdbEnv* mev, nsIMdbFactory** acqFactory) {
97 nsresult rv;
98 nsCOMPtr<nsIMdbObject> obj = do_QueryInterface(mev);
99 if (obj)
100 rv = obj->GetMdbFactory(mev, acqFactory);
101 else
102 return NS_ERROR_NO_INTERFACE;
103
104 return rv;
105 }
106 // } ----- end factory methods -----
107
108 // { ----- begin ref counting for well-behaved cyclic graphs -----
109 NS_IMETHODIMP
GetWeakRefCount(nsIMdbEnv * mev,mdb_count * outCount)110 morkObject::GetWeakRefCount(nsIMdbEnv* mev, // weak refs
111 mdb_count* outCount) {
112 *outCount = WeakRefsOnly();
113 return NS_OK;
114 }
115 NS_IMETHODIMP
GetStrongRefCount(nsIMdbEnv * mev,mdb_count * outCount)116 morkObject::GetStrongRefCount(nsIMdbEnv* mev, // strong refs
117 mdb_count* outCount) {
118 *outCount = StrongRefsOnly();
119 return NS_OK;
120 }
121 // ### TODO - clean up this cast, if required
122 NS_IMETHODIMP
AddWeakRef(nsIMdbEnv * mev)123 morkObject::AddWeakRef(nsIMdbEnv* mev) {
124 // XXX Casting mork_refs to nsresult
125 return static_cast<nsresult>(morkNode::AddWeakRef((morkEnv*)mev));
126 }
127
128 #ifndef _MSC_VER
NS_IMETHODIMP_(mork_uses)129 NS_IMETHODIMP_(mork_uses)
130 morkObject::AddStrongRef(morkEnv* mev) { return morkNode::AddStrongRef(mev); }
131 #endif
132
NS_IMETHODIMP_(mork_uses)133 NS_IMETHODIMP_(mork_uses)
134 morkObject::AddStrongRef(nsIMdbEnv* mev) {
135 return morkNode::AddStrongRef((morkEnv*)mev);
136 }
137
138 NS_IMETHODIMP
CutWeakRef(nsIMdbEnv * mev)139 morkObject::CutWeakRef(nsIMdbEnv* mev) {
140 // XXX Casting mork_refs to nsresult
141 return static_cast<nsresult>(morkNode::CutWeakRef((morkEnv*)mev));
142 }
143
144 #ifndef _MSC_VER
NS_IMETHODIMP_(mork_uses)145 NS_IMETHODIMP_(mork_uses)
146 morkObject::CutStrongRef(morkEnv* mev) { return morkNode::CutStrongRef(mev); }
147 #endif
148
149 NS_IMETHODIMP
CutStrongRef(nsIMdbEnv * mev)150 morkObject::CutStrongRef(nsIMdbEnv* mev) {
151 // XXX Casting mork_refs to nsresult
152 return static_cast<nsresult>(morkNode::CutStrongRef((morkEnv*)mev));
153 }
154
155 NS_IMETHODIMP
CloseMdbObject(nsIMdbEnv * mev)156 morkObject::CloseMdbObject(nsIMdbEnv* mev) {
157 return morkNode::CloseMdbObject((morkEnv*)mev);
158 }
159
160 NS_IMETHODIMP
IsOpenMdbObject(nsIMdbEnv * mev,mdb_bool * outOpen)161 morkObject::IsOpenMdbObject(nsIMdbEnv* mev, mdb_bool* outOpen) {
162 *outOpen = IsOpenNode();
163 return NS_OK;
164 }
165 NS_IMETHODIMP
IsFrozenMdbObject(nsIMdbEnv * mev,mdb_bool * outIsReadonly)166 morkObject::IsFrozenMdbObject(nsIMdbEnv* mev, mdb_bool* outIsReadonly) {
167 *outIsReadonly = IsFrozen();
168 return NS_OK;
169 }
170
171 // void morkObject::NewNilHandleError(morkEnv* ev) // mObject_Handle is nil
172 //{
173 // ev->NewError("nil mObject_Handle");
174 //}
175
176 // 456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
177