Language file for the Maltese language.
[AROS.git] / rom / oop / obtainattrbase.c
blobe8a5afc734e54c9ac961aee9cd52059293103373
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: OOP function OOP_ObtainAttrBase
6 Lang: english
7 */
9 #include "intern.h"
10 #include "hash.h"
11 /*****************************************************************************
13 NAME */
14 #include <string.h>
16 #include <proto/exec.h>
17 #include <exec/memory.h>
18 #include <aros/libcall.h>
20 #include <aros/debug.h>
22 AROS_LH1(OOP_AttrBase, OOP_ObtainAttrBase,
24 /* SYNOPSIS */
25 AROS_LHA(STRPTR , interfaceID, A0),
27 /* LOCATION */
28 struct Library *, OOPBase, 6, OOP)
30 /* FUNCTION
31 Maps a globally unique string interface ID into
32 a numeric AttrBase ID that is unique on
33 pr. machine basis. The AttrBase can be combiner
34 with attribute offsets to generate attribute IDs.
38 INPUTS
39 interfaceID - globally unique interface identifier.
40 for which to obtain an attrbase.
42 RESULT
43 Numeric AttrBase that is unique for this machine.
44 A return value of 0 means that the call failed.
46 NOTES
47 Obtained attrbases should be released with ReleasAttrBase().
49 EXAMPLE
50 #define aTimer_CurrentTime (__AB_Timer + aoTime_CurrentTime)
53 __AB_Timer = OOP_ObtainAttrBase(IID_Timer);
55 SetAttrs(timer, aTimer_CurrentTime, "10:37:00");
58 BUGS
60 SEE ALSO
62 INTERNALS
64 HISTORY
66 ******************************************************************************/
68 AROS_LIBFUNC_INIT
70 /* Look up ID */
71 struct iid_bucket *idb;
72 struct HashTable *iidtable = GetOBase(OOPBase)->ob_IIDTable;
73 ULONG base = -1UL;
75 EnterFunc(bug("OOP_ObtainAttrBase(interfaceID=%s)\n", interfaceID));
77 ObtainSemaphore(&GetOBase(OOPBase)->ob_IIDTableLock);
80 /* Has ID allready been mapped to a numeric ID ? */
81 idb = (struct iid_bucket *)iidtable->Lookup(iidtable, (IPTR)interfaceID, GetOBase(OOPBase));
82 if (idb)
85 /* If so, it has been stored in the hashtable, and we have
86 ** to return the same numeric ID now.
88 if (idb->attrbase == (ULONG)-1)
90 idb->attrbase = GetOBase(OOPBase)->ob_CurrentAttrBase ++;
93 base = idb->attrbase;
94 base <<= NUM_METHOD_BITS;
96 D(bug("Bucket found: id=%ld\n", base));
98 else
101 D(bug("No existing bucket\n"));
104 /* If not, then map it and create a new bucket in the
105 ** hashtable to store it
107 idb = AllocMem(sizeof (struct iid_bucket), MEMF_ANY|MEMF_CLEAR);
108 if (idb)
110 idb->interface_id = AllocVec(strlen(interfaceID) + 1, MEMF_ANY);
111 if (idb->interface_id)
113 D(bug("Allocated bucket\n"));
114 strcpy(idb->interface_id, interfaceID);
116 /* Get next free ID, and increase the free ID count to mark it as used */
117 base = idb->attrbase = ++ GetOBase(OOPBase)->ob_CurrentAttrBase;
119 base <<= NUM_METHOD_BITS;
121 /* Methodbase not inited yet */
122 idb->methodbase = -1UL;
124 /* Insert bucket into hash table */
125 InsertBucket(iidtable, (struct Bucket *)idb, GetOBase(OOPBase));
127 else
129 FreeMem(idb, sizeof (struct iid_bucket));
131 /* Throw exception here ? */
132 base = 0UL;
137 if (base)
139 /* Increase refcount of bucket */
140 idb->refcount ++;
143 ReleaseSemaphore(&GetOBase(OOPBase)->ob_IIDTableLock);
145 ReturnInt ("OOP_ObtainAttrBase", AttrBase, base);
147 AROS_LIBFUNC_EXIT
149 } /* OOP_ObtainAttrBase */