Added a test for MUIA_Listview_SelectChange.
[AROS.git] / rom / utility / allocnamedobjecta.c
blob47c3c55519c10e9e21d93782f6ca2daec00d52bd
1 /*
2 Copyright © 1995-2015, 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 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.
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 *****************************************************************************/
85 AROS_LIBFUNC_INIT
87 struct IntNamedObject *no = NULL;
89 This is the size of the required sections of the NamedObject.
91 LONG size = 0;
93 if(name)
95 no = AllocVec
97 sizeof(struct IntNamedObject) + strlen(name) + 1,
98 MEMF_CLEAR|MEMF_PUBLIC
101 if (no == NULL)
102 return NULL;
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 );
109 no->no_UseCount = 0;
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);
122 else
124 FreeNamedObject(GetNamedObject(no));
125 return FALSE;
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
131 NamedObject.
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));
140 return NULL;
142 else
144 /* We should free the object in FreeNamedObject(). */
145 no->no_FreeObject = TRUE;
148 else
150 /* Don't free the object, we didn't allocate it. */
151 no->no_FreeObject = FALSE;
152 GetNamedObject(no)->no_Object = NULL;
155 no->no_UseCount = 1;
156 return GetNamedObject(no);
158 } /* if ( name ) */
160 return NULL;
162 AROS_LIBFUNC_EXIT
164 } /* AllocNamedObjectA */