2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Create a new OOP object
8 #include <exec/lists.h>
9 #include <proto/exec.h>
12 #include <aros/debug.h>
13 #define MD(x) ((struct metadata *)x)
15 /*****************************************************************************
18 #include <proto/oop.h>
20 AROS_LH3(APTR
, OOP_NewObject
,
23 AROS_LHA(struct OOP_IClass
*, classPtr
, A0
),
24 AROS_LHA(UBYTE
*, classID
, A1
),
25 AROS_LHA(struct TagItem
*, tagList
, A2
),
28 struct Library
*, OOPBase
, 5, OOP
)
31 Creates a new object of given class based on the TagItem
35 classPtr - pointer to a class. Use this if the class to
36 create an instance of is private.
37 classID - Public ID of the class to create an instance of.
38 Use this if the class is public.
39 tagList - List of TagItems (creation time attributes),
40 that specifies what initial properties the new
45 Pointer to the new object, or NULL if object creation failed.
48 You should supply one of classPtr and classID, never
49 both. Use NULL for the unspecified one.
61 29-10-95 digulla automatically created from
62 intuition_lib.fd and clib/intuition_protos.h
64 *****************************************************************************/
71 // bug("OOP_NewObject(class=%s, classptr=%p, tags=%p)\n", classID, classPtr, tagList);
72 EnterFunc(bug("OOP_NewObject(classPtr=%p, classID=%s, tagList=%p)\n",
73 classPtr
, ((classID
!= NULL
) ? classID
: (UBYTE
*)"(null)"), tagList
));
75 /* Class list is public, so we must avoid race conditions */
76 ObtainSemaphore(&GetOBase(OOPBase
)->ob_ClassListLock
);
80 /* If a public ID was given, find pointer to class */
83 classPtr
= (OOP_Class
*)FindName((struct List
*)&(GetOBase(OOPBase
)->ob_ClassList
), classID
);
85 MD(classPtr
)->objectcount
++; /* We don't want the class to be freed while we work on it */
89 /* Release lock on list */
90 ReleaseSemaphore(&GetOBase(OOPBase
)->ob_ClassListLock
);
93 ReturnPtr ("OOP_NewObject[No classPtr]", OOP_Object
*, NULL
);
95 /* Create a new instance */
97 D(bug("Creating new instance\n"));
99 p
.mID
= OOP_GetMethodID(IID_Root
, moRoot_New
);
100 p
.attrList
= tagList
;
102 /* print_table(GetOBase(OOPBase)->ob_IIDTable, GetOBase(OOPBase));
104 D(bug("mid=%ld\n", p
.mID
));
106 /* Call the New() method of the specified class */
108 D(bug("OOP_Coercemethod: %p\n", classPtr
->CoerceMethod
));
109 o
= (OOP_Object
*)OOP_CoerceMethod(classPtr
, (OOP_Object
*)classPtr
, (OOP_Msg
)&p
);
112 MD(classPtr
)->objectcount
--; /* Object creation failed, release lock */
114 /* print_table(GetOBase(OOPBase)->ob_IIDTable, GetOBase(OOPBase));
116 ReturnPtr ("OOP_NewObject", OOP_Object
*, o
);
120 } /* OOP_NewObject */