Autodoc headers unified to avoid misinterpretation by the build script.
[cake.git] / rom / intuition / makeclass.c
bloba425a344b76112e0db6e05cfacd003a4d48d805e
1 /*
2 Copyright © 1995-2007, 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
85 Class *iclass = NULL;
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",
92 superClassPtr,
93 instanceSize,
94 flags));
96 /* trust the user ;-) */
97 if (!superClassID && !superClassPtr)
99 #ifdef __MORPHOS__
100 /* Workaround for buggy callers: set z flag - Piru */
101 REG_SR |= 4;
102 #endif
103 return NULL;
106 ObtainSemaphoreShared(&GetPrivIBase(IntuitionBase)->ClassListLock);
108 /* Does this class already exist? */
109 if (!FindClass(classID))
111 /* Has the user specified a classPtr? */
112 if (!superClassPtr)
114 /* Search for the class... */
115 superClassPtr = FindClass(superClassID);
118 if (superClassPtr)
120 /* Allocate memory */
121 iclass = (Class *) AllocMem
123 sizeof(Class), MEMF_PUBLIC | MEMF_CLEAR
126 if (iclass != NULL)
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);
151 else
153 FreeMem(iclass, sizeof(Class));
154 iclass = NULL;
158 else
160 DEBUG_MAKECLASS(dprintf("MakeClass: superclass not found\n"));
163 else
165 DEBUG_MAKECLASS(dprintf("MakeClass: already there\n"));
168 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->ClassListLock);
170 DEBUG_MAKECLASS(dprintf("MakeClass: return 0x%lx\n", iclass));
172 #ifdef __MORPHOS__
173 /* Workaround for buggy callers: clear/set z flag - Piru */
174 if (iclass) REG_SR &= (ULONG) ~4;
175 else REG_SR |= 4;
176 #endif
178 return iclass;
180 AROS_LIBFUNC_EXIT
181 } /* MakeClass() */