Reverted deallocation of existing "new" FD (introduced in r49699). It's
[AROS.git] / rom / oop / intern.h
blob2501631726dd54c6607bd3472ffce603fe8e60f1
1 #ifndef INTERN_H
2 #define INTERN_H
4 /*
5 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc:
9 Lang: english
12 #ifndef EXEC_LISTS_H
13 # include <exec/lists.h>
14 #endif
16 #ifndef EXEC_LIBRARIES_H
17 # include <exec/libraries.h>
18 #endif
20 #ifndef EXEC_SEMAPHORES_H
21 # include <exec/semaphores.h>
22 #endif
24 #ifndef DOS_BPTR_H
25 # include <dos/bptr.h>
26 #endif
28 #ifndef UTILITY_TAGITEM_H
29 # include <utility/tagitem.h>
30 #endif
32 #ifndef OOP_OOP_H
33 # include <oop/oop.h>
34 #endif
37 /* Predeclaration */
38 struct IntOOPBase;
40 #ifndef PRIVATE_H
41 # include "private.h"
42 #endif
44 #define SDEBUG 0
45 #define DEBUG 0
47 #define NUM_METHOD_BITS 10
48 #define METHOD_MASK ((1 << NUM_METHOD_BITS) - 1)
51 /* These are used to index an array in the library base
52 from which we get the IDs for the used interfaces.
55 enum {
56 IDX_IRoot = 0,
57 IDX_IMeta,
58 IDX_IMethod,
59 IDX_IServer,
60 IDX_IProxy,
61 IDX_IInterface,
62 NUM_Indexes
67 /* Used by the internal GetIDs() functions, to get several
68 IDs at a time */
70 struct IDDescr
72 CONST_STRPTR ID;
73 ULONG *Storage;
79 /* defines used to access the interface IDs stored in the library base */
81 #define __IRoot (GetOBase(OOPBase)->ob_InternIDs[IDX_IRoot])
82 #define __IMeta (GetOBase(OOPBase)->ob_InternIDs[IDX_IMeta])
83 #define __IMethod (GetOBase(OOPBase)->ob_InternIDs[IDX_IMethod])
84 #define __IServer (GetOBase(OOPBase)->ob_InternIDs[IDX_IServer])
85 #define __IProxy (GetOBase(OOPBase)->ob_InternIDs[IDX_IProxy])
86 #define __IInterface (GetOBase(OOPBase)->ob_InternIDs[IDX_IInterface])
88 #define GetOBase(lib) ((struct IntOOPBase *)(lib))
90 /*****************
91 ** Prototypes **
92 *****************/
94 BOOL GetIDs(struct IDDescr *idDesr, struct IntOOPBase *OOPBase);
97 /* rootclass.c */
98 BOOL init_rootclass(struct IntOOPBase *OOPBase);
100 /* metaclass.c */
101 BOOL init_basemeta(struct IntOOPBase *OOPBase);
102 BOOL init_ifmetaclass(struct IntOOPBase *OOPBase);
104 /* methodclass.c */
105 OOP_Class *init_methodclass(struct IntOOPBase *OOPBase);
107 /* serverclass.c */
108 OOP_Class *init_serverclass(struct Library *OOPBase);
110 /* proxyclass.c */
111 OOP_Class *init_proxyclass(struct Library *OOPBase);
113 /* interfaceclass.c */
114 OOP_Class *init_interfaceclass(struct Library *OOPBase);
117 OOP_Class *init_hiddmetaclass(struct IntOOPBase *OOPBase);
119 /* support.c */
120 BOOL hasinterface(OOP_Class *cl, CONST_STRPTR interface_id);
121 struct IFMethod *findinterface(OOP_Class *cl, CONST_STRPTR interface_id);
122 struct IFMethod *findmethod(OOP_Class *cl, CONST_STRPTR interface_id, ULONG method_offset);
123 BOOL init_methodbase(CONST_STRPTR interface_id, ULONG methodbase, ULONG *methodbase_ptr, struct IntOOPBase *OOPBase);
124 BOOL init_mi_methodbase(CONST_STRPTR interface_id, ULONG *methodbase_ptr, struct IntOOPBase *OOPBase);
125 VOID release_idbucket(CONST_STRPTR interface_id, struct IntOOPBase *OOPBase);
126 VOID obtain_idbucket(CONST_STRPTR interface_id, struct IntOOPBase *OOPBase);
127 /*****************
128 ** Structures **
129 *****************/
131 /* Bucket for hashtable used to map string interface IDs to
132 ** numeric interface IDs and attrbases.
135 struct iid_bucket
137 struct iid_bucket *next;
138 STRPTR interface_id; /* Not CONST, since it is expected to be freed */
139 ULONG methodbase;
140 ULONG attrbase;
141 ULONG refcount;
147 * Definition of bucket for hashtable used to store
148 * the interfaces (method tables).
149 * InterfaceID must be an IPTR, because it's IPTR in generic struct Bucket
150 * (see hash.h)
153 struct IFBucket
155 struct IFBucket *Next;
156 IPTR InterfaceID;
157 CONST_STRPTR GlobalInterfaceID;
158 struct IFMethod *MethodTable;
159 ULONG NumMethods;
163 /* Definition of an entry in a method table.
164 ** Ie. the method tables are arrays of these.
165 ** One has to store the class for each method
166 ** because we skip unimplemented class calls, and
167 ** therefore a method can go directly to a parent
168 ** class of OCLASS(o)
171 struct IFMethod
173 IPTR (*MethodFunc)();
174 OOP_Class *mClass;
178 /* Message struct used for sending object message structs across
179 ** to another task
181 struct ProxyMsg
183 struct Message pm_Message;
184 OOP_Msg pm_ObjMsg;
185 IPTR pm_RetVal;
186 OOP_Object *pm_Object;
189 /* Listnode that helps keeping track of servers. */
190 struct ServerNode
192 struct Node sn_Node;
193 OOP_Object *sn_Server;
197 /* Instance data of base metaclass and rootclass */
199 struct metadata
201 OOP_Class public; /* public part of class objects */
202 ULONG subclasscount;
203 ULONG objectcount;
204 ULONG instsize;
205 BOOL disptabs_inited;
206 ULONG numinterfaces;
210 #define MD(x) ((struct metadata *)x)
212 #define NUM_BASEMETA_IFS 2
213 struct basemetaobject /* Real instance data of the base meta class */
215 OOP_Class *oclass; /* The meta object's class */
216 struct basemeta_inst
218 struct metadata data;
219 struct IFMethod *iftable[NUM_BASEMETA_IFS]; /* has two interfaces: root and meta */
221 /* The interface tables */
222 struct IFMethod rootif[num_Root_Methods];
223 struct IFMethod metaif[NUMTOTAL_M_Meta];
224 } inst;
227 struct rootclassobject
229 OOP_Class *oclass; /* The rootclass object's class */
230 struct rootinst
232 struct metadata data;
233 struct IFMethod rootif[num_Root_Methods];
234 } inst;
238 /* IFMeta class */
240 struct ifmeta_data
243 /* The hashtable containing the interfaces (method tables) */
244 struct HashTable *iftable;
246 /* A direct pointer into the hashtable, for faster lookup */
247 struct IFBucket **iftab_directptr;
249 /* Used by the hash function. As the above field, it is put
250 ** here for speed
252 ULONG hashmask;
254 /* Number of interfaces in the hashtable */
255 ULONG numinterfaces;
260 struct ifmetaobject
262 OOP_Class *oclass; /* The interface metaclass' class (itself) */
263 struct ifmeta_inst
265 struct metadata base;
266 struct ifmeta_data data;
268 } inst;
273 /*************************
274 ** Library Base struct **
275 *************************/
276 struct IntOOPBase
278 struct Library ob_LibNode;
280 struct SignalSemaphore ob_ClassListLock;
281 struct MinList ob_ClassList;
283 struct SignalSemaphore ob_ServerListLock;
284 struct MinList ob_ServerList;
286 /* rootclass object */
287 struct rootclassobject ob_RootClassObject;
289 /* base metaclass object */
290 struct basemetaobject ob_BaseMetaObject;
292 /* interface metaclass object */
293 struct ifmetaobject ob_IFMetaObject;
295 /* HIDD metaclass */
296 OOP_Class *ob_HIDDMetaClass;
298 /* Store pointers to some usefull classes here */
299 OOP_Class *ob_MethodClass;
300 OOP_Class *ob_ServerClass;
301 OOP_Class *ob_ProxyClass;
302 OOP_Class *ob_InterfaceClass;
304 /* Hashtable containing string interface ID => Numeric interface
305 ** ID mappings. Used by GetMethodID() and GetAttrBase()
307 struct HashTable * ob_IIDTable;
308 struct SignalSemaphore ob_IIDTableLock;
310 /* The currently lowest available numeric interfaceID that
311 ** we can map a new interface string ID onto.
312 ** Used by GetID()
315 ULONG ob_CurrentMethodBase;
316 ULONG ob_CurrentAttrBase;
318 /* An array of the interface IDs used internally. */
319 ULONG ob_InternIDs[NUM_Indexes];
321 /* We use UtilityBase frequently */
322 struct Library *ob_UtilityBase;
324 /* Commonly used method IDs */
325 OOP_MethodID ob_mRoot_Set;
326 OOP_MethodID ob_mRoot_Get;
327 OOP_MethodID ob_M_meta_allocdisptabs;
328 OOP_MethodID ob_M_meta_freedisptabs;
329 OOP_MethodID ob_M_meta_iterateifs;
330 OOP_MethodID ob_M_meta_getifinfo;
331 OOP_MethodID ob_M_meta_findmethod;
334 #define ROOTCLASSPTR (& (OOPBase)->ob_RootClassObject.inst.data.public)
335 #define BASEMETAPTR (& (OOPBase)->ob_BaseMetaObject.inst.data.public)
337 #endif /* INTERN_H */