Don't get OOPBase in this ugly way.
[tangerine.git] / rom / intuition / makeclass.c
bloba8cf494a53064c9b643d617bb658e9bc6d2f4833
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
6 Initialize a BOOPSI class.
7 */
9 #include <exec/lists.h>
10 #include <exec/memory.h>
11 #include <proto/exec.h>
12 #include "intuition_intern.h"
14 /*****************************************************************************
16 NAME */
17 #include <intuition/classes.h>
18 #include <proto/intuition.h>
20 AROS_LH5(struct IClass *, MakeClass,
22 /* SYNOPSIS */
23 AROS_LHA(ClassID, classID, A0),
24 AROS_LHA(ClassID, superClassID, A1),
25 AROS_LHA(struct IClass *, superClassPtr, A2),
26 AROS_LHA(ULONG, instanceSize, D0),
27 AROS_LHA(ULONG, flags, D1),
29 /* LOCATION */
30 struct IntuitionBase *, IntuitionBase, 113, Intuition)
32 /* FUNCTION
33 Only for class implementators.
35 This function creates a new public BOOPSI class. The SuperClass
36 should be another BOOPSI class; all BOOPSI classes are subclasses
37 of the ROOTCLASS.
39 SuperClasses can by private or public. You can specify a name/ID
40 for the class if you want it to become a public class. For public
41 classes, you must call AddClass() afterwards to make it public
42 accessible.
44 The return value contains a pointer to the IClass structure of your
45 class. You must specify your dispatcher in cl_Dispatcher. You can
46 also store shared data in cl_UserData.
48 To get rid of the class, you must call FreeClass().
50 INPUTS
51 classID - NULL for private classes otherwise the name/ID of the
52 public class.
53 superClassID - Name/ID of a public SuperClass. NULL is you don't
54 want to use a public SuperClass or if you have the pointer
55 your SuperClass.
56 superClassPtr - Pointer to the SuperClass. If this is non-NULL,
57 then superClassID is ignored.
58 instanceSize - The amount of memory which your objects need (in
59 addition to the memory which is needed by the SuperClass(es))
60 flags - For future extensions. To maintain comaptibility, use 0
61 for now.
63 RESULT
64 Pointer to the new class or NULL if
65 - There wasn't enough memory
66 - The superclass couldn't be found
67 - There already is a class with the same name/ID.
69 NOTES
70 No copy is made of classID. So make sure the lifetime of the contents
71 of classID is at least the same as the lifetime of the class itself.
73 EXAMPLE
75 BUGS
77 SEE ALSO
79 INTERNALS
81 *****************************************************************************/
83 AROS_LIBFUNC_INIT
84 AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
86 Class *iclass = NULL;
88 EXTENDUWORD(instanceSize);
90 DEBUG_MAKECLASS(dprintf("MakeClass: ID <%s> SuperID <%s> Super 0x%lx Size 0x%lx Flags 0x%lx\n",
91 classID ? classID : (UBYTE*)"NULL",
92 superClassID ? superClassID : (UBYTE*)"NULL",
93 superClassPtr,
94 instanceSize,
95 flags));
97 /* trust the user ;-) */
98 if (!superClassID && !superClassPtr)
100 #ifdef __MORPHOS__
101 /* Workaround for buggy callers: set z flag - Piru */
102 REG_SR |= 4;
103 #endif
104 return NULL;
107 ObtainSemaphoreShared(&GetPrivIBase(IntuitionBase)->ClassListLock);
109 /* Does this class already exist? */
110 if (!FindClass(classID))
112 /* Has the user specified a classPtr? */
113 if (!superClassPtr)
115 /* Search for the class... */
116 superClassPtr = FindClass(superClassID);
119 if (superClassPtr)
121 /* Allocate memory */
122 iclass = (Class *) AllocMem
124 sizeof(Class), MEMF_PUBLIC | MEMF_CLEAR
127 if (iclass != NULL)
129 /* Initialize fields */
130 iclass->cl_Super = superClassPtr;
131 iclass->cl_ID = classID;
132 iclass->cl_InstOffset = superClassPtr->cl_InstOffset +
133 superClassPtr->cl_InstSize;
134 iclass->cl_InstSize = instanceSize;
135 iclass->cl_Flags = flags;
136 iclass->cl_ObjectSize = iclass->cl_InstOffset
137 + iclass->cl_InstSize
138 + sizeof(struct _Object);
140 /* Initialize memory subsystem */
141 iclass->cl_MemoryPool = CreatePool
143 MEMF_ANY | MEMF_CLEAR | MEMF_SEM_PROTECTED,
144 32 * iclass->cl_ObjectSize, iclass->cl_ObjectSize
147 if (iclass->cl_MemoryPool != NULL)
149 /* SuperClass is used one more time now */
150 AROS_ATOMIC_INC(superClassPtr->cl_SubclassCount);
152 else
154 FreeMem(iclass, sizeof(Class));
155 iclass = NULL;
159 else
161 DEBUG_MAKECLASS(dprintf("MakeClass: superclass not found\n"));
164 else
166 DEBUG_MAKECLASS(dprintf("MakeClass: already there\n"));
169 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->ClassListLock);
171 DEBUG_MAKECLASS(dprintf("MakeClass: return 0x%lx\n", iclass));
173 #ifdef __MORPHOS__
174 /* Workaround for buggy callers: clear/set z flag - Piru */
175 if (iclass) REG_SR &= (ULONG) ~4;
176 else REG_SR |= 4;
177 #endif
179 return iclass;
181 AROS_LIBFUNC_EXIT
182 } /* MakeClass() */