Check for SYS/GL during library init. Reason is that
[AROS.git] / rom / oop / obtainattrbase.c
blob6c64bd84a00721ab6cb68c70436b526bdebc7608
1 /*
2 Copyright © 1995-2013, 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(CONST_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 a
33 per machine basis. The AttrBase can be combined
34 with attribute offsets to generate attribute IDs.
36 INPUTS
37 interfaceID - globally unique interface identifier.
38 for which to obtain an attrbase.
40 RESULT
41 Numeric AttrBase that is unique for this machine.
42 A return value of 0 means that the call failed.
44 NOTES
45 Obtained attrbases should be released with ReleaseAttrBase().
47 EXAMPLE
48 #define aTimer_CurrentTime (__AB_Timer + aoTime_CurrentTime)
51 __AB_Timer = OOP_ObtainAttrBase(IID_Timer);
53 SetAttrs(timer, aTimer_CurrentTime, "10:37:00");
56 BUGS
58 SEE ALSO
60 INTERNALS
62 ******************************************************************************/
64 AROS_LIBFUNC_INIT
66 /* Look up ID */
67 struct iid_bucket *idb;
68 struct HashTable *iidtable = GetOBase(OOPBase)->ob_IIDTable;
69 ULONG base = (ULONG)-1;
71 EnterFunc(bug("OOP_ObtainAttrBase(interfaceID=%s)\n", interfaceID));
73 ObtainSemaphore(&GetOBase(OOPBase)->ob_IIDTableLock);
76 /* Has ID already been mapped to a numeric ID? */
77 idb = (struct iid_bucket *)iidtable->Lookup(iidtable, (IPTR)interfaceID, GetOBase(OOPBase));
78 if (idb)
81 /* If so, it has been stored in the hashtable, and we have
82 ** to return the same numeric ID now.
84 if (idb->attrbase == (ULONG)-1)
86 idb->attrbase = GetOBase(OOPBase)->ob_CurrentAttrBase ++;
89 base = idb->attrbase;
90 base <<= NUM_METHOD_BITS;
92 D(bug("Bucket found: id=%ld\n", base));
94 else
97 D(bug("No existing bucket\n"));
100 /* If not, then map it and create a new bucket in the
101 ** hashtable to store it
103 idb = AllocMem(sizeof (struct iid_bucket), MEMF_ANY|MEMF_CLEAR);
104 if (idb)
106 idb->interface_id = AllocVec(strlen(interfaceID) + 1, MEMF_ANY);
107 if (idb->interface_id)
109 D(bug("Allocated bucket\n"));
110 strcpy(idb->interface_id, interfaceID);
112 /* Get next free ID, and increase the free ID count to mark it as used */
113 base = idb->attrbase = ++ GetOBase(OOPBase)->ob_CurrentAttrBase;
115 base <<= NUM_METHOD_BITS;
117 /* Methodbase not inited yet */
118 idb->methodbase = (ULONG)-1;
120 /* Insert bucket into hash table */
121 InsertBucket(iidtable, (struct Bucket *)idb, GetOBase(OOPBase));
123 else
125 FreeMem(idb, sizeof (struct iid_bucket));
127 /* Throw exception here ? */
128 base = 0UL;
133 if (base)
135 /* Increase refcount of bucket */
136 idb->refcount ++;
139 ReleaseSemaphore(&GetOBase(OOPBase)->ob_IIDTableLock);
141 ReturnInt ("OOP_ObtainAttrBase", OOP_AttrBase, base);
143 AROS_LIBFUNC_EXIT
145 } /* OOP_ObtainAttrBase */