2 Copyright © 1995-2015, 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 Allocates 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.
83 *****************************************************************************/
87 struct IntNamedObject
*no
= NULL
;
89 This is the size of the required sections of the NamedObject.
97 sizeof(struct IntNamedObject
) + strlen(name
) + 1,
98 MEMF_CLEAR
|MEMF_PUBLIC
104 /* The name is at the first byte after the IntNamedObject struct */
105 no
->no_Node
.ln_Name
= (STRPTR
)(no
+ 1);
106 strcpy(no
->no_Node
.ln_Name
, name
);
108 no
->no_Node
.ln_Pri
= GetTagData( ANO_Priority
, 0, (struct TagItem
*)tagList
);
110 no
->no_FreeObject
= FALSE
;
112 /* Find out if we need a NameSpace. */
113 if(GetTagData(ANO_NameSpace
, FALSE
, (struct TagItem
*)tagList
))
115 no
->no_NameSpace
= AllocMem(sizeof(struct NameSpace
), MEMF_CLEAR
|MEMF_PUBLIC
);
116 if(no
->no_NameSpace
!= NULL
)
118 no
->no_NameSpace
->ns_Flags
= GetTagData(ANO_Flags
, 0, (struct TagItem
*)tagList
);
119 InitSemaphore(&no
->no_NameSpace
->ns_Lock
);
120 NEWLIST((struct List
*)&no
->no_NameSpace
->ns_List
);
124 FreeNamedObject(GetNamedObject(no
));
129 /* Set up the UserSpace. Maybe in the future we will be able to
130 have a UserSpace who has a different memory type to the
134 if((size
= GetTagData(ANO_UserSpace
, 0, (struct TagItem
*)tagList
)))
136 GetNamedObject(no
)->no_Object
= AllocVec(size
, MEMF_CLEAR
|MEMF_PUBLIC
);
137 if(no
->no
.no_Object
== NULL
)
139 FreeNamedObject(GetNamedObject(no
));
144 /* We should free the object in FreeNamedObject(). */
145 no
->no_FreeObject
= TRUE
;
150 /* Don't free the object, we didn't allocate it. */
151 no
->no_FreeObject
= FALSE
;
152 GetNamedObject(no
)->no_Object
= NULL
;
156 return GetNamedObject(no
);
164 } /* AllocNamedObjectA */