2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afs/param.h>
15 #include "TaAfsAdmSvrClientInternal.h"
16 #include <WINNT/AfsAppLib.h>
20 * VARIABLES __________________________________________________________________
28 LPHASHLISTKEY pCacheKeyAsid;
30 } CELLCACHE, *LPCELLCACHE;
35 LPHASHLISTKEY pCellsKeyAsid;
40 * PROTOTYPES _________________________________________________________________
44 BOOL CALLBACK CacheKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData);
45 HASHVALUE CALLBACK CacheKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject);
46 HASHVALUE CALLBACK CacheKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData);
48 BOOL CALLBACK CellsKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData);
49 HASHVALUE CALLBACK CellsKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject);
50 HASHVALUE CALLBACK CellsKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData);
54 * ROUTINES ___________________________________________________________________
58 LPCELLCACHE GetCellCache (ASID idCell)
63 return (LPCELLCACHE)(l.pCellsKeyAsid->GetFirstObject (&idCell));
67 BOOL CreateCellCache (ASID idCell)
73 l.pCells = New (HASHLIST);
74 l.pCells->SetCriticalSection (asc_GetCriticalSection());
75 l.pCellsKeyAsid = l.pCells->CreateKey (TEXT("ASID"), CellsKeyAsid_Compare, CellsKeyAsid_HashObject, CellsKeyAsid_HashData);
79 if ((pcc = GetCellCache (idCell)) == NULL)
81 pcc = New (CELLCACHE);
82 memset (pcc, 0x00, sizeof(CELLCACHE));
84 pcc->pCache = New (HASHLIST);
85 pcc->pCache->SetCriticalSection (asc_GetCriticalSection());
86 pcc->pCacheKeyAsid = pcc->pCache->CreateKey (TEXT("ASID"), CacheKeyAsid_Compare, CacheKeyAsid_HashObject, CacheKeyAsid_HashData);
96 BOOL DestroyCellCache (ASID idCell)
101 if ((pcc = GetCellCache (idCell)) == NULL)
107 if (!pcc->cReqCache || !(--(pcc->cReqCache)))
111 for (LPENUM pEnum = pcc->pCache->FindFirst(); pEnum; pEnum = pEnum->FindNext())
113 LPASOBJPROP pProp = (LPASOBJPROP)( pEnum->GetObject() );
114 pcc->pCache->Remove (pProp);
118 Delete (pcc->pCache);
121 l.pCells->Remove (pcc);
130 LPASOBJPROP GetCachedProperties (ASID idCell, ASID idObject)
132 LPASOBJPROP pCachedProperties = NULL;
136 if ((pcc = GetCellCache (idCell)) != NULL)
138 pCachedProperties = (LPASOBJPROP)(pcc->pCacheKeyAsid->GetFirstObject (&idObject));
142 return pCachedProperties;
146 void UpdateCachedProperties (ASID idCell, ASID idObject, LPASOBJPROP pProperties)
153 if ((pcc = GetCellCache (idCell)) != NULL)
155 LPASOBJPROP pCachedProperties;
156 if ((pCachedProperties = (LPASOBJPROP)(pcc->pCacheKeyAsid->GetFirstObject (&idObject))) == NULL)
158 pCachedProperties = New (ASOBJPROP);
159 memcpy (pCachedProperties, pProperties, sizeof(ASOBJPROP));
160 pcc->pCache->Add (pCachedProperties);
164 memcpy (pCachedProperties, pProperties, sizeof(ASOBJPROP));
165 // Note: don't need to call pcc->pCache->Update(), because
166 // we haven't affected any indices (the old and new ASOBJPROP
167 // structures should have the same ASID)
171 NotifyObjectListeners (idCell, idObject);
177 BOOL RefreshCachedProperties (UINT_PTR idClient, ASID idCell, ASID idObject, AFSADMSVR_GET_LEVEL GetLevel, ULONG *pStatus)
184 LPASOBJPROP pProperties = GetCachedProperties (idCell, idObject);
185 DWORD verProperties = (pProperties) ? (pProperties->verProperties) : verPROP_NO_OBJECT;
187 ASOBJPROP NewProperties;
188 if ((rc = AfsAdmSvr_GetObject (idClient, RETURN_IF_OUT_OF_DATE, GetLevel, idObject, verProperties, &NewProperties, &status)) != FALSE)
190 if (NewProperties.idObject == idObject)
192 UpdateCachedProperties (idCell, idObject, &NewProperties);
199 status = RPC_S_CALL_FAILED_DNE;
209 BOOL RefreshCachedProperties (UINT_PTR idClient, ASID idCell, LPASIDLIST pAsidList, AFSADMSVR_GET_LEVEL GetLevel, ULONG *pStatus)
214 if (pAsidList->cEntries)
218 for (size_t iObject = 0; iObject < pAsidList->cEntries; ++iObject)
220 LPASOBJPROP pProperties = GetCachedProperties (idCell, pAsidList->aEntries[ iObject ].idObject);
221 pAsidList->aEntries[ iObject ].lParam = (pProperties) ? (pProperties->verProperties) : verPROP_NO_OBJECT;
224 LPASOBJPROPLIST pNewProperties = NULL;
225 if ((rc = AfsAdmSvr_GetObjects (idClient, RETURN_IF_OUT_OF_DATE, GetLevel, pAsidList, &pNewProperties, &status)) != FALSE)
229 for (size_t iObject = 0; iObject < pNewProperties->cEntries; ++iObject)
231 UpdateCachedProperties (idCell, pNewProperties->aEntries[ iObject ].ObjectProperties.idObject, &pNewProperties->aEntries[ iObject ].ObjectProperties);
233 AfsAdmSvr_FreeObjPropList (&pNewProperties);
240 status = RPC_S_CALL_FAILED_DNE;
252 * HASHLIST KEYS ______________________________________________________________
256 BOOL CALLBACK CacheKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData)
258 return (((LPASOBJPROP)pObject)->idObject == *(ASID*)pData);
261 HASHVALUE CALLBACK CacheKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject)
263 return CacheKeyAsid_HashData (pKey, &((LPASOBJPROP)pObject)->idObject);
266 HASHVALUE CALLBACK CacheKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData)
268 return (HASHVALUE)*(ASID*)pData;
272 BOOL CALLBACK CellsKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData)
274 return (((LPCELLCACHE)pObject)->idCell == *(ASID*)pData);
277 HASHVALUE CALLBACK CellsKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject)
279 return CellsKeyAsid_HashData (pKey, &((LPCELLCACHE)pObject)->idCell);
282 HASHVALUE CALLBACK CellsKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData)
284 return (HASHVALUE)*(ASID*)pData;