2 Copyright © 1995-2019, 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(CONST_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 a
33 per machine basis. The AttrBase can be combined
34 with attribute offsets to generate attribute IDs.
37 interfaceID - globally unique interface identifier.
38 for which to obtain an attrbase.
41 Numeric AttrBase that is unique for this machine.
42 A return value of 0 means that the call failed.
45 Obtained attrbases should be released with ReleaseAttrBase().
48 #define aTimer_CurrentTime (__AB_Timer + aoTime_CurrentTime)
51 __AB_Timer = OOP_ObtainAttrBase(IID_Timer);
53 SetAttrs(timer, aTimer_CurrentTime, "10:37:00");
62 ******************************************************************************/
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
);
75 /* Has ID already been mapped to a numeric ID? */
76 idb
= (struct iid_bucket
*)iidtable
->Lookup(iidtable
, (IPTR
)interfaceID
, GetOBase(OOPBase
));
80 /* If so, it has been stored in the hashtable, and we have
81 ** to return the same numeric ID now.
83 if (idb
->attrbase
== (ULONG
)-1)
85 idb
->attrbase
= ++GetOBase(OOPBase
)->ob_CurrentAttrBase
;
89 base
<<= NUM_METHOD_BITS
;
91 D(bug("Bucket found: id=%ld\n", base
));
96 D(bug("No existing bucket\n"));
99 /* If not, then map it and create a new bucket in the
100 ** hashtable to store it
102 idb
= AllocMem(sizeof (struct iid_bucket
), MEMF_ANY
|MEMF_CLEAR
);
105 idb
->interface_id
= AllocVec(strlen(interfaceID
) + 1, MEMF_ANY
);
106 if (idb
->interface_id
)
108 D(bug("Allocated bucket\n"));
109 strcpy(idb
->interface_id
, interfaceID
);
111 /* Get next free ID, and increase the free ID count to mark it as used */
112 base
= idb
->attrbase
= ++GetOBase(OOPBase
)->ob_CurrentAttrBase
;
114 base
<<= NUM_METHOD_BITS
;
116 /* Methodbase not inited yet */
117 idb
->methodbase
= (ULONG
)-1;
119 /* Insert bucket into hash table */
120 InsertBucket(iidtable
, (struct Bucket
*)idb
, GetOBase(OOPBase
));
124 FreeMem(idb
, sizeof (struct iid_bucket
));
126 /* Throw exception here ? */
134 /* Increase refcount of bucket */
138 ReleaseSemaphore(&GetOBase(OOPBase
)->ob_IIDTableLock
);
140 ReturnInt ("OOP_ObtainAttrBase", OOP_AttrBase
, base
);
144 } /* OOP_ObtainAttrBase */