New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / oop / obtainattrbase.c
blobd7d549f2967eb81e5e91a0d3d33a373a76d6f0cb
1 /*
2 Copyright © 1995-2001, 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
69 AROS_LIBBASE_EXT_DECL(struct Library*,OOPBase)
71 /* Look up ID */
72 struct iid_bucket *idb;
73 struct HashTable *iidtable = GetOBase(OOPBase)->ob_IIDTable;
74 ULONG base = -1UL;
76 EnterFunc(bug("OOP_ObtainAttrBase(interfaceID=%s)\n", interfaceID));
78 ObtainSemaphore(&GetOBase(OOPBase)->ob_IIDTableLock);
81 /* Has ID allready been mapped to a numeric ID ? */
82 idb = (struct iid_bucket *)iidtable->Lookup(iidtable, (IPTR)interfaceID, GetOBase(OOPBase));
83 if (idb)
86 /* If so, it has been stored in the hashtable, and we have
87 ** to return the same numeric ID now.
89 if (idb->attrbase == -1UL)
91 idb->attrbase = GetOBase(OOPBase)->ob_CurrentAttrBase ++;
94 base = idb->attrbase;
95 base <<= NUM_METHOD_BITS;
97 D(bug("Bucket found: id=%ld\n", base));
99 else
102 D(bug("No existing bucket\n"));
105 /* If not, then map it and create a new bucket in the
106 ** hashtable to store it
108 idb = AllocMem(sizeof (struct iid_bucket), MEMF_ANY|MEMF_CLEAR);
109 if (idb)
111 idb->interface_id = AllocVec(strlen(interfaceID) + 1, MEMF_ANY);
112 if (idb->interface_id)
114 D(bug("Allocated bucket\n"));
115 strcpy(idb->interface_id, interfaceID);
117 /* Get next free ID, and increase the free ID count to mark it as used */
118 base = idb->attrbase = ++ GetOBase(OOPBase)->ob_CurrentAttrBase;
120 base <<= NUM_METHOD_BITS;
122 /* Methodbase not inited yet */
123 idb->methodbase = -1UL;
125 /* Insert bucket into hash table */
126 InsertBucket(iidtable, (struct Bucket *)idb, GetOBase(OOPBase));
128 else
130 FreeMem(idb, sizeof (struct iid_bucket));
132 /* Throw exception here ? */
133 base = 0UL;
138 if (base)
140 /* Increase refcount of bucket */
141 idb->refcount ++;
144 ReleaseSemaphore(&GetOBase(OOPBase)->ob_IIDTableLock);
146 ReturnInt ("OOP_ObtainAttrBase", AttrBase, base);
148 AROS_LIBFUNC_EXIT
150 } /* OOP_ObtainAttrBase */