Added support for zip files.
[cake.git] / rom / oop / newobject.c
blobfce9ba287415d62dc69dc90ae8ed1af43020bcef
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create a new OOP object
6 Lang: english
7 */
8 #include <exec/lists.h>
9 #include <proto/exec.h>
10 #include "intern.h"
11 #include "hash.h"
12 #include <aros/debug.h>
13 #define MD(x) ((struct metadata *)x)
15 /*****************************************************************************
17 NAME */
18 #include <proto/oop.h>
20 AROS_LH3(APTR, OOP_NewObject,
22 /* SYNOPSIS */
23 AROS_LHA(struct OOP_IClass *, classPtr, A0),
24 AROS_LHA(UBYTE *, classID, A1),
25 AROS_LHA(struct TagItem *, tagList, A2),
27 /* LOCATION */
28 struct Library *, OOPBase, 5, OOP)
30 /* FUNCTION
31 Creates a new object of given class based on the TagItem
32 parameters passed.
34 INPUTS
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
41 object should have.
44 RESULT
45 Pointer to the new object, or NULL if object creation failed.
47 NOTES
48 You should supply one of classPtr and classID, never
49 both. Use NULL for the unspecified one.
51 EXAMPLE
53 BUGS
55 SEE ALSO
56 OOP_DisposeObject()
58 INTERNALS
60 HISTORY
61 29-10-95 digulla automatically created from
62 intuition_lib.fd and clib/intuition_protos.h
64 *****************************************************************************/
66 AROS_LIBFUNC_INIT
68 struct pRoot_New p;
69 OOP_Object *o;
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);
78 if (!classPtr)
80 /* If a public ID was given, find pointer to class */
81 if (classID) {
83 classPtr = (OOP_Class *)FindName((struct List *)&(GetOBase(OOPBase)->ob_ClassList), classID);
84 if (classPtr)
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);
92 if (!classPtr)
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);
110 if (!o)
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);
119 AROS_LIBFUNC_EXIT
120 } /* OOP_NewObject */