binutils 2.32 courtesy of NicJA.
[AROS.git] / rom / intuition / newobjecta.c
blob36edc6d5338b1e197e842eb05798303d70919228
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
6 Create a new BOOPSI object.
7 */
9 #include <exec/lists.h>
10 #include <intuition/classes.h>
11 #include <proto/exec.h>
12 #include <proto/alib.h>
13 #include <proto/utility.h>
14 #include "intuition_intern.h"
16 /*****************************************************************************
18 NAME */
19 #include <intuition/classusr.h>
20 #include <proto/intuition.h>
22 AROS_LH3(APTR, NewObjectA,
24 /* SYNOPSIS */
25 AROS_LHA(struct IClass *, classPtr, A0),
26 AROS_LHA(UBYTE *, classID, A1),
27 AROS_LHA(struct TagItem *, tagList, A2),
29 /* LOCATION */
30 struct IntuitionBase *, IntuitionBase, 106, Intuition)
32 /* FUNCTION
33 Use this function to create BOOPSI objects (BOOPSI stands for
34 "Basic Object Oriented Programming System for Intuition").
36 You may specify a class either by its name (if it's a public class)
37 or by a pointer to its definition (if it's a private class). If
38 classPtr is NULL, classID is used.
40 INPUTS
41 classPtr - Pointer to a private class (or a public class if you
42 happen to have a pointer to it)
43 classID - Name of a public class
44 tagList - Initial attributes. Read the documentation of the class
45 carefully to find out which attributes must or can be specified
46 here.
48 RESULT
49 A BOOPSI object which can be manipulated with general functions and
50 which must be disposed of with DisposeObject() later.
52 NOTES
53 This function sends OM_NEW to the dispatcher of the class.
55 EXAMPLE
57 BUGS
59 SEE ALSO
60 DisposeObject(), SetAttrsA(), GetAttr(), MakeClass(),
61 "Basic Object-Oriented Programming System for Intuition" and
62 "Boopsi Class Reference" Document.
64 *****************************************************************************/
66 AROS_LIBFUNC_INIT
68 Object *object;
69 struct opSet method;
71 DEBUG_NEWOBJECT
73 dprintf("NewObject[%x]: Class 0x%lx <%s> TagList 0x%lx\n",
74 &method, /* some unique id to see matching debug info */
75 classPtr,
76 classID ?
77 classID :
78 (classPtr->cl_ID ? classPtr->cl_ID : (ClassID)"NULL"),
79 tagList);
82 EnterFunc(bug("intuition::NewObjectA()\n"));
84 DEBUG_NEWOBJECT
86 if (tagList)
88 struct Library *UtilityBase =
89 GetPrivIBase(IntuitionBase)->UtilityBase;
90 struct TagItem *state = tagList;
91 struct TagItem *tag;
93 while (tag = NextTagItem(&state))
95 dprintf("\t%08lx %08lx\n", tag->ti_Tag, tag->ti_Data);
100 ObtainSemaphoreShared (&GetPrivIBase(IntuitionBase)->ClassListLock);
102 /* No classPtr ? */
103 if (!classPtr)
104 classPtr = FindClass (classID);
106 /* Make sure the class doesn't go away while we create the object */
107 if (classPtr)
109 AROS_ATOMIC_INC(classPtr->cl_ObjectCount);
112 ReleaseSemaphore (&GetPrivIBase(IntuitionBase)->ClassListLock);
114 if (!classPtr)
115 return (NULL); /* Nothing found */
117 D(bug("classPtr: %p\n", classPtr));
119 /* Try to create a new object */
120 method.MethodID = OM_NEW;
121 method.ops_AttrList = tagList;
122 method.ops_GInfo = NULL;
123 object = (Object *) CoerceMethodA (classPtr, (Object *)classPtr, (Msg)&method);
125 /* Release the lock on the class. Rootclass also has increased this count. */
126 AROS_ATOMIC_DEC(classPtr->cl_ObjectCount);
128 DEBUG_NEWOBJECT(dprintf("NewObject[%x]: return 0x%lx\n", &method, object));
130 ReturnPtr("intuition::NewObjectA()", Object *, object);
132 AROS_LIBFUNC_EXIT
133 } /* NewObjectA() */