Added chip revision constant
[AROS.git] / rom / utility / allocnamedobjecta.c
blob85c65491b7deaea3932e83b3a930c2da071ba09f
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: AllocNamedObject() - allocate a NamedObject.
6 Lang: english
7 */
8 #include "intern.h"
9 #include <proto/exec.h>
10 #include <string.h>
12 /*****************************************************************************
14 NAME */
15 #include <proto/utility.h>
17 AROS_LH2(struct NamedObject *, AllocNamedObjectA,
19 /* SYNOPSIS */
20 AROS_LHA(CONST_STRPTR , name, A0),
21 AROS_LHA(CONST struct TagItem *, tagList, A1),
23 /* LOCATION */
24 struct UtilityBase *, UtilityBase, 38, Utility)
26 /* FUNCTION
27 Allocate a new NamedObject and initializes it as requested.
28 This object can then be used as an object in a name space.
29 Optionally you give this object a name space, and use it to
30 nest name spaces. You can also allocate some memory which is
31 attached to this object for your own personal use.
33 When the object is allocated, it will automatically have one user.
34 To allow other users to remove this object from a namespace, you
35 must call ReleaseNamedObject() on this object.
37 INPUTS
38 name - The name of the NamedObject. Obviously this MUST be
39 specified (otherwise it wouldn't be named would it?)
40 tagList - A TagList containing some extra information for this
41 NamedObject. These are:
43 ANO_NameSpace: Allocate a NameSpace for this
44 NamedObject. This will allow you to link other
45 NamedObjects into a group. You cannot add a
46 NamedObject with a NameSpace to another NameSpace.
47 Boolean, default is FALSE.
49 ANO_UserSpace: This tag says that you want extra memory
50 allocated for a UserSpace. The ti_Data field of
51 this TagItem contains the amount of memory to
52 allocate. Specifying this Tag with a ti_Data of 0,
53 is equivalent to the default, which is no UserSpace.
54 The UserSpace address can be found in the no_Object
55 field of the NamedObject structure.
57 ANO_Priority: This is the List priority of the
58 NamedObject and should be a signed BYTE value
59 between -128 and 127. This is taken into account
60 in adding and finding NamedObjects, as the highest
61 priority NamedObject will be returned first. The
62 default value is 0.
64 ANO_Flags: This allows you to initialize the value of
65 the NameSpace flags which control certain aspects
66 of the NameSpace. See the file utility/name.h.
68 RESULT
69 A pointer to a new NamedObject, or NULL if the allocation failed
70 due to no free memory.
72 NOTES
74 EXAMPLE
76 BUGS
78 SEE ALSO
79 FreeNamedObject()
81 INTERNALS
83 HISTORY
84 29-10-95 digulla automatically created from
85 utility_lib.fd and clib/utility_protos.h
86 11-08-96 iaint Reworked for AROS.
87 08-10-96 iaint Changed to three memory areas after discussion
88 in AROS-DEV today.
89 18-10-96 iaint Completely rewrote.
90 04-02-97 iaint Updated documentation.
91 16-04-01 iaint Combined the memory for the IntNamedObject and
92 the name as an optimisation.
94 *****************************************************************************/
96 AROS_LIBFUNC_INIT
98 struct IntNamedObject *no = NULL;
100 This is the size of the required sections of the NamedObject.
102 LONG size = 0;
104 if(name)
106 no = AllocVec
108 sizeof(struct IntNamedObject) + strlen(name) + 1,
109 MEMF_CLEAR|MEMF_PUBLIC
112 if (no == NULL)
113 return NULL;
115 /* The name is at the first byte after the IntNamedObject struct */
116 no->no_Node.ln_Name = (STRPTR)(no + 1);
117 strcpy(no->no_Node.ln_Name, name);
119 no->no_Node.ln_Pri = GetTagData( ANO_Priority, 0, tagList );
120 no->no_UseCount = 0;
121 no->no_FreeObject = FALSE;
123 /* Find out if we need a NameSpace. */
124 if(GetTagData(ANO_NameSpace, FALSE, tagList))
126 no->no_NameSpace = AllocMem(sizeof(struct NameSpace), MEMF_CLEAR|MEMF_PUBLIC);
127 if(no->no_NameSpace != NULL)
129 no->no_NameSpace->ns_Flags = GetTagData(ANO_Flags, 0, tagList);
130 InitSemaphore(&no->no_NameSpace->ns_Lock);
131 NEWLIST((struct List *)&no->no_NameSpace->ns_List);
133 else
135 FreeNamedObject(GetNamedObject(no));
136 return FALSE;
140 /* Set up the UserSpace. Maybe in the future we will be able to
141 have a UserSpace who has a different memory type to the
142 NamedObject.
145 if((size = GetTagData(ANO_UserSpace, 0, tagList)))
147 GetNamedObject(no)->no_Object = AllocVec(size, MEMF_CLEAR|MEMF_PUBLIC);
148 if(no->no.no_Object == NULL)
150 FreeNamedObject(GetNamedObject(no));
151 return NULL;
153 else
155 /* We should free the object in FreeNamedObject(). */
156 no->no_FreeObject = TRUE;
159 else
161 /* Don't free the object, we didn't allocate it. */
162 no->no_FreeObject = FALSE;
163 GetNamedObject(no)->no_Object = NULL;
166 no->no_UseCount = 1;
167 return GetNamedObject(no);
169 } /* if ( name ) */
171 return NULL;
173 AROS_LIBFUNC_EXIT
175 } /* AllocNamedObjectA */