2 Copyright © 1995-2013, 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
);
76 /* Has ID already been mapped to a numeric ID? */
77 idb
= (struct iid_bucket
*)iidtable
->Lookup(iidtable
, (IPTR
)interfaceID
, GetOBase(OOPBase
));
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
++;
90 base
<<= NUM_METHOD_BITS
;
92 D(bug("Bucket found: id=%ld\n", base
));
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
);
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
));
125 FreeMem(idb
, sizeof (struct iid_bucket
));
127 /* Throw exception here ? */
135 /* Increase refcount of bucket */
139 ReleaseSemaphore(&GetOBase(OOPBase
)->ob_IIDTableLock
);
141 ReturnInt ("OOP_ObtainAttrBase", AttrBase
, base
);
145 } /* OOP_ObtainAttrBase */