2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: OOP function OOP_ObtainAttrBase
11 /*****************************************************************************
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
,
25 AROS_LHA(STRPTR
, interfaceID
, A0
),
28 struct Library
*, OOPBase
, 6, OOP
)
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.
39 interfaceID - globally unique interface identifier.
40 for which to obtain an attrbase.
43 Numeric AttrBase that is unique for this machine.
44 A return value of 0 means that the call failed.
47 Obtained attrbases should be released with ReleasAttrBase().
50 #define aTimer_CurrentTime (__AB_Timer + aoTime_CurrentTime)
53 __AB_Timer = OOP_ObtainAttrBase(IID_Timer);
55 SetAttrs(timer, aTimer_CurrentTime, "10:37:00");
66 ******************************************************************************/
71 struct iid_bucket
*idb
;
72 struct HashTable
*iidtable
= GetOBase(OOPBase
)->ob_IIDTable
;
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
));
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
++;
94 base
<<= NUM_METHOD_BITS
;
96 D(bug("Bucket found: id=%ld\n", base
));
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
);
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
));
129 FreeMem(idb
, sizeof (struct iid_bucket
));
131 /* Throw exception here ? */
139 /* Increase refcount of bucket */
143 ReleaseSemaphore(&GetOBase(OOPBase
)->ob_IIDTableLock
);
145 ReturnInt ("OOP_ObtainAttrBase", AttrBase
, base
);
149 } /* OOP_ObtainAttrBase */