2 Copyright © 1995-2001, 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 ******************************************************************************/
69 AROS_LIBBASE_EXT_DECL(struct Library
*,OOPBase
)
72 struct iid_bucket
*idb
;
73 struct HashTable
*iidtable
= GetOBase(OOPBase
)->ob_IIDTable
;
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
));
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
++;
95 base
<<= NUM_METHOD_BITS
;
97 D(bug("Bucket found: id=%ld\n", base
));
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
);
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
));
130 FreeMem(idb
, sizeof (struct iid_bucket
));
132 /* Throw exception here ? */
140 /* Increase refcount of bucket */
144 ReleaseSemaphore(&GetOBase(OOPBase
)->ob_IIDTableLock
);
146 ReturnInt ("OOP_ObtainAttrBase", AttrBase
, base
);
150 } /* OOP_ObtainAttrBase */