Call CloseDevice() before DeleteIORequest(), and don't call
[AROS.git] / rom / oop / rootclass.c
blobfe1df840c0f60d2eb1ed86dff36bee11ad34a679
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: OOP rootclass
6 Lang: english
7 */
9 #include <proto/exec.h>
10 #include <proto/oop.h>
11 #include <proto/utility.h>
12 #include <exec/memory.h>
13 #include <oop/oop.h>
14 #include <string.h>
16 #include "intern.h"
17 #include "private.h"
18 #include "basemetaclass.h"
20 #undef SDEBUG
21 #undef DEBUG
22 #define SDEBUG 0
23 #define DEBUG 0
24 #include <aros/debug.h>
26 /*****************************************************************************************
28 NAME
29 --background_root--
31 LOCATION
32 Root
34 NOTES
35 Root class is the base class of all classes.
36 One can create new baseclasses, but all classes must implement the root interface.
38 *****************************************************************************************/
40 /*****************************************************************************************
42 NAME
43 moRoot_New
45 SYNOPSIS
46 See OOP_NewObject() doc.
48 FUNCTION
49 Creates a new object of some class. Class users should use OOP_NewObject() to
50 create an object.
52 *****************************************************************************************/
54 /*****************************************************************************************
56 NAME
57 moRoot_Dispose
59 SYNOPSIS
60 See OOP_DisposeObject() doc.
62 FUNCTION
63 Used internally to dispose of an object previously
64 created using the moRoot_New method.
66 *****************************************************************************************/
68 /*****************************************************************************************
70 NAME
71 moRoot_Set
73 SYNOPSIS
74 OOP_SetAttrs() (OOP_Object *object, struct TagItem *attrs);
76 FUNCTION
77 Set an attribute of an object.
79 *****************************************************************************************/
81 /*****************************************************************************************
83 NAME
84 moRoot_Get
86 SYNOPSIS
87 OOP_GetAttr(OOP_Object *object, ULONG attrID, IPTR *storage);
89 FUNCTION
90 Get the value for an object attribute.
91 The attribute value will be stored in *storage.
93 EXAMPLE
95 ULONG num_members;
97 OOP_GetAttr(list, aList_NumMembers, &num_members);
99 *****************************************************************************************/
101 /************************
102 ** Rootclass methods **
103 ************************/
105 /************
106 ** New() **
107 ************/
108 OOP_Object *root_new(OOP_Class *root_cl, OOP_Class *cl, struct pRoot_New *param)
110 struct _OOP_Object *o;
112 EnterFunc(bug("Root::New(cl=%s, param = %p)\n",
113 cl->ClassNode.ln_Name, param));
115 /* Allocate memory for the object */
116 D(bug("Object size: %ld\n", MD(cl)->public.InstOffset + MD(cl)->instsize + sizeof (struct _OOP_Object)));
117 o = AllocVec(MD(cl)->public.InstOffset + MD(cl)->instsize + sizeof (struct _OOP_Object), MEMF_ANY|MEMF_CLEAR);
118 if (o)
120 D(bug("Mem allocated: %p\n", o));
121 o->o_Class = (OOP_Class *)cl;
123 /* Class has one more object */
124 MD(cl)->objectcount ++;
126 ReturnPtr ("Root::New", OOP_Object *, OOP_BASEOBJECT(o) );
129 ReturnPtr ("Root::New", OOP_Object *, NULL);
132 /****************
133 ** Dispose() **
134 ****************/
135 static VOID root_dispose(OOP_Class *root_cl, OOP_Object *o, OOP_Msg msg)
137 EnterFunc(bug("Root::Dispose(o=%p, oclass=%s)\n", o, _OOP_OBJECT(o)->o_Class->ClassNode.ln_Name));
139 MD(OOP_OCLASS(o))->objectcount --;
140 D(bug("Object mem: %p, size: %ld\n", _OOP_OBJECT(o), ((ULONG *)_OOP_OBJECT(o))[-1] ));
142 /* Free object's memory */
143 FreeVec(_OOP_OBJECT(o));
145 ReturnVoid("Root::Dispose");
148 static VOID root_get(OOP_Class *root_cl, OOP_Object *p, struct pRoot_Get *msg)
150 *msg->storage = 0UL;
151 D(bug("!!! Get() METHOD REACHED ROOTCLASS !!!\n"));
152 return;
155 /**********************
156 ** init_rootclass() **
157 **********************/
158 BOOL init_rootclass(struct IntOOPBase *OOPBase)
161 struct rootclassobject *rco;
162 OOP_Class *rootclass;
164 BOOL success;
165 ULONG mbase = 0UL;
167 EnterFunc(bug("init_rootclass()\n"));
169 rco = &(OOPBase->ob_RootClassObject);
170 rootclass = &(rco->inst.data.public);
172 /* Its class is the metaobject */
173 rco->oclass = &(OOPBase->ob_BaseMetaObject.inst.data.public);
175 rco->inst.data.public.ClassNode.ln_Name = CLID_Root;
176 rco->inst.data.public.OOPBasePtr = OOPBase;
177 rco->inst.data.public.InstOffset = 0;
178 rco->inst.data.public.UserData = (APTR)OOPBase;
180 rco->inst.data.public.cl_DoSuperMethod = basemeta_dosupermethod;
181 rco->inst.data.public.cl_CoerceMethod = basemeta_coercemethod;
182 rco->inst.data.public.cl_DoMethod = basemeta_domethod;
184 D(bug("Root stuff: dosupermethod %p, coeremethod %p, domethod %p\n",
185 basemeta_dosupermethod, basemeta_coercemethod, basemeta_domethod));
187 rco->inst.data.public.superclass = NULL;
188 rco->inst.data.subclasscount = 0UL;
189 rco->inst.data.objectcount = 0UL;
190 rco->inst.data.instsize = 0UL;
191 rco->inst.data.numinterfaces = 1UL;
193 /* Initialize methodtable */
195 rco->inst.rootif[moRoot_New].MethodFunc = (IPTR (*)())root_new;
196 rco->inst.rootif[moRoot_New].mClass = rootclass;
198 rco->inst.rootif[moRoot_Dispose].MethodFunc = (IPTR (*)())root_dispose;
199 rco->inst.rootif[moRoot_Dispose].mClass = rootclass;
201 rco->inst.rootif[moRoot_Get].MethodFunc = (IPTR (*)())root_get;
202 rco->inst.rootif[moRoot_Get].mClass = rootclass;
204 /* Important: IID_Root interface ID MUST be the first one
205 initialized, so that it gets the value 0UL. This is
206 because it's used as rootclass both for IFMeta and HIDDMeta classes
209 success = init_mi_methodbase(IID_Root, &mbase, OOPBase);
210 if (success)
212 /* Make it public */
213 OOP_AddClass(rootclass);
216 ReturnBool ("init_rootclass", success);
219 /* Below is rootclass DoMethod and CoerceMethod. They are hardly useful,
220 cause you would never create an object of rootclass
224 #define ROOT_CALLMETHOD(cl, o, m) \
226 register struct IFMethod *ifm; \
227 ifm = &(RI(cl)->rootif[msg->MethodID]); \
228 return ifm->MethodFunc(ifm->mClass, o, msg); \
231 #define RI(cl) ((struct rootinst *)cl)
233 static IPTR root_domethod(OOP_Object *o, OOP_Msg msg)
235 register Class *cl;
236 cl = OCLASS(o);
238 ROOT_CALLMETHOD(cl, o, msg);
241 static IPTR root_coercemethod(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
243 ROOT_CALLMETHOD(cl, o, msg);