2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: AllocNamedObject() - allocate a NamedObject.
9 #include <proto/exec.h>
12 /*****************************************************************************
15 #include <proto/utility.h>
17 AROS_LH2(struct NamedObject
*, AllocNamedObjectA
,
20 AROS_LHA(CONST_STRPTR
, name
, A0
),
21 AROS_LHA(CONST
struct TagItem
*, tagList
, A1
),
24 struct UtilityBase
*, UtilityBase
, 38, Utility
)
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.
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
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.
69 A pointer to a new NamedObject, or NULL if the allocation failed
70 due to no free memory.
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
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 *****************************************************************************/
98 struct IntNamedObject
*no
= NULL
;
100 This is the size of the required sections of the NamedObject.
108 sizeof(struct IntNamedObject
) + strlen(name
) + 1,
109 MEMF_CLEAR
|MEMF_PUBLIC
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
);
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
);
135 FreeNamedObject(GetNamedObject(no
));
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
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
));
155 /* We should free the object in FreeNamedObject(). */
156 no
->no_FreeObject
= TRUE
;
161 /* Don't free the object, we didn't allocate it. */
162 no
->no_FreeObject
= FALSE
;
163 GetNamedObject(no
)->no_Object
= NULL
;
167 return GetNamedObject(no
);
175 } /* AllocNamedObjectA */