2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
6 Initialize a BOOPSI class.
9 #include <exec/lists.h>
10 #include <exec/memory.h>
11 #include <proto/exec.h>
12 #include "intuition_intern.h"
14 #define MAX_PUDDLE_SIZE (16 * 1024) /* Maximum puddle size */
16 /*****************************************************************************
19 #include <intuition/classes.h>
20 #include <proto/intuition.h>
22 AROS_LH5(struct IClass
*, MakeClass
,
25 AROS_LHA(ClassID
, classID
, A0
),
26 AROS_LHA(ClassID
, superClassID
, A1
),
27 AROS_LHA(struct IClass
*, superClassPtr
, A2
),
28 AROS_LHA(ULONG
, instanceSize
, D0
),
29 AROS_LHA(ULONG
, flags
, D1
),
32 struct IntuitionBase
*, IntuitionBase
, 113, Intuition
)
35 Only for class implementators.
37 This function creates a new public BOOPSI class. The SuperClass
38 should be another BOOPSI class; all BOOPSI classes are subclasses
41 SuperClasses can by private or public. You can specify a name/ID
42 for the class if you want it to become a public class. For public
43 classes, you must call AddClass() afterwards to make it public
46 The return value contains a pointer to the IClass structure of your
47 class. You must specify your dispatcher in cl_Dispatcher. You can
48 also store shared data in cl_UserData.
50 To get rid of the class, you must call FreeClass().
53 classID - NULL for private classes otherwise the name/ID of the
55 superClassID - Name/ID of a public SuperClass. NULL is you don't
56 want to use a public SuperClass or if you have the pointer
58 superClassPtr - Pointer to the SuperClass. If this is non-NULL,
59 then superClassID is ignored.
60 instanceSize - The amount of memory which your objects need (in
61 addition to the memory which is needed by the SuperClass(es))
62 flags - For future extensions. To maintain comaptibility, use 0
66 Pointer to the new class or NULL if
67 - There wasn't enough memory
68 - The superclass couldn't be found
69 - There already is a class with the same name/ID.
72 No copy is made of classID. So make sure the lifetime of the contents
73 of classID is at least the same as the lifetime of the class itself.
83 *****************************************************************************/
89 EXTENDUWORD(instanceSize
);
91 DEBUG_MAKECLASS(dprintf("MakeClass: ID <%s> SuperID <%s> Super 0x%lx Size 0x%lx Flags 0x%lx\n",
92 classID
? classID
: (UBYTE
*)"NULL",
93 superClassID
? superClassID
: (UBYTE
*)"NULL",
98 /* trust the user ;-) */
99 if (!superClassID
&& !superClassPtr
)
102 /* Workaround for buggy callers: set z flag - Piru */
108 ObtainSemaphoreShared(&GetPrivIBase(IntuitionBase
)->ClassListLock
);
110 /* Does this class already exist? */
111 if (!FindClass(classID
))
113 /* Has the user specified a classPtr? */
116 /* Search for the class... */
117 superClassPtr
= FindClass(superClassID
);
122 /* Allocate memory */
123 iclass
= (Class
*) AllocMem
125 sizeof(Class
), MEMF_PUBLIC
| MEMF_CLEAR
132 /* Initialize fields */
133 iclass
->cl_Super
= superClassPtr
;
134 iclass
->cl_ID
= classID
;
135 iclass
->cl_InstOffset
= superClassPtr
->cl_InstOffset
+
136 superClassPtr
->cl_InstSize
;
137 iclass
->cl_InstSize
= instanceSize
;
138 iclass
->cl_Flags
= flags
;
139 iclass
->cl_ObjectSize
= iclass
->cl_InstOffset
140 + iclass
->cl_InstSize
141 + sizeof(struct _Object
);
143 /* Try to limit the puddle to MAX_PUDDLE_SIZE.
144 * This comes in to play, for example, with
145 * picture.library, where 32 instances of the
146 * picture class is a whopping 280K.
148 perpuddle
= MAX_PUDDLE_SIZE
/ iclass
->cl_ObjectSize
;
154 /* Initialize memory subsystem */
155 iclass
->cl_MemoryPool
= CreatePool
157 MEMF_ANY
| MEMF_CLEAR
| MEMF_SEM_PROTECTED
,
158 perpuddle
* iclass
->cl_ObjectSize
, iclass
->cl_ObjectSize
161 if (iclass
->cl_MemoryPool
!= NULL
)
163 /* SuperClass is used one more time now */
164 AROS_ATOMIC_INC(superClassPtr
->cl_SubclassCount
);
168 FreeMem(iclass
, sizeof(Class
));
175 DEBUG_MAKECLASS(dprintf("MakeClass: superclass not found\n"));
180 DEBUG_MAKECLASS(dprintf("MakeClass: already there\n"));
183 ReleaseSemaphore(&GetPrivIBase(IntuitionBase
)->ClassListLock
);
185 DEBUG_MAKECLASS(dprintf("MakeClass: return 0x%lx\n", iclass
));
188 /* Workaround for buggy callers: clear/set z flag - Piru */
189 if (iclass
) REG_SR
&= (ULONG
) ~4;