2 Copyright © 1995-2007, 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 /*****************************************************************************
17 #include <intuition/classes.h>
18 #include <proto/intuition.h>
20 AROS_LH5(struct IClass
*, MakeClass
,
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
),
30 struct IntuitionBase
*, IntuitionBase
, 113, Intuition
)
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
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
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().
51 classID - NULL for private classes otherwise the name/ID of the
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
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
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.
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.
81 *****************************************************************************/
87 EXTENDUWORD(instanceSize
);
89 DEBUG_MAKECLASS(dprintf("MakeClass: ID <%s> SuperID <%s> Super 0x%lx Size 0x%lx Flags 0x%lx\n",
90 classID
? classID
: (UBYTE
*)"NULL",
91 superClassID
? superClassID
: (UBYTE
*)"NULL",
96 /* trust the user ;-) */
97 if (!superClassID
&& !superClassPtr
)
100 /* Workaround for buggy callers: set z flag - Piru */
106 ObtainSemaphoreShared(&GetPrivIBase(IntuitionBase
)->ClassListLock
);
108 /* Does this class already exist? */
109 if (!FindClass(classID
))
111 /* Has the user specified a classPtr? */
114 /* Search for the class... */
115 superClassPtr
= FindClass(superClassID
);
120 /* Allocate memory */
121 iclass
= (Class
*) AllocMem
123 sizeof(Class
), MEMF_PUBLIC
| MEMF_CLEAR
128 /* Initialize fields */
129 iclass
->cl_Super
= superClassPtr
;
130 iclass
->cl_ID
= classID
;
131 iclass
->cl_InstOffset
= superClassPtr
->cl_InstOffset
+
132 superClassPtr
->cl_InstSize
;
133 iclass
->cl_InstSize
= instanceSize
;
134 iclass
->cl_Flags
= flags
;
135 iclass
->cl_ObjectSize
= iclass
->cl_InstOffset
136 + iclass
->cl_InstSize
137 + sizeof(struct _Object
);
139 /* Initialize memory subsystem */
140 iclass
->cl_MemoryPool
= CreatePool
142 MEMF_ANY
| MEMF_CLEAR
| MEMF_SEM_PROTECTED
,
143 32 * iclass
->cl_ObjectSize
, iclass
->cl_ObjectSize
146 if (iclass
->cl_MemoryPool
!= NULL
)
148 /* SuperClass is used one more time now */
149 AROS_ATOMIC_INC(superClassPtr
->cl_SubclassCount
);
153 FreeMem(iclass
, sizeof(Class
));
160 DEBUG_MAKECLASS(dprintf("MakeClass: superclass not found\n"));
165 DEBUG_MAKECLASS(dprintf("MakeClass: already there\n"));
168 ReleaseSemaphore(&GetPrivIBase(IntuitionBase
)->ClassListLock
);
170 DEBUG_MAKECLASS(dprintf("MakeClass: return 0x%lx\n", iclass
));
173 /* Workaround for buggy callers: clear/set z flag - Piru */
174 if (iclass
) REG_SR
&= (ULONG
) ~4;