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
14 #include <afs/param.h>
18 #include "TaAfsAdmSvrClientInternal.h"
19 #include <WINNT/AfsAppLib.h>
23 * VARIABLES __________________________________________________________________
31 LPHASHLISTKEY pCacheKeyAsid;
33 } CELLCACHE, *LPCELLCACHE;
38 LPHASHLISTKEY pCellsKeyAsid;
43 * PROTOTYPES _________________________________________________________________
47 BOOL CALLBACK CacheKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData);
48 HASHVALUE CALLBACK CacheKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject);
49 HASHVALUE CALLBACK CacheKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData);
51 BOOL CALLBACK CellsKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData);
52 HASHVALUE CALLBACK CellsKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject);
53 HASHVALUE CALLBACK CellsKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData);
57 * ROUTINES ___________________________________________________________________
61 LPCELLCACHE GetCellCache (ASID idCell)
66 return (LPCELLCACHE)(l.pCellsKeyAsid->GetFirstObject (&idCell));
70 BOOL CreateCellCache (ASID idCell)
76 l.pCells = New (HASHLIST);
77 l.pCells->SetCriticalSection (asc_GetCriticalSection());
78 l.pCellsKeyAsid = l.pCells->CreateKey (TEXT("ASID"), CellsKeyAsid_Compare, CellsKeyAsid_HashObject, CellsKeyAsid_HashData);
82 if ((pcc = GetCellCache (idCell)) == NULL)
84 pcc = New (CELLCACHE);
85 memset (pcc, 0x00, sizeof(CELLCACHE));
87 pcc->pCache = New (HASHLIST);
88 pcc->pCache->SetCriticalSection (asc_GetCriticalSection());
89 pcc->pCacheKeyAsid = pcc->pCache->CreateKey (TEXT("ASID"), CacheKeyAsid_Compare, CacheKeyAsid_HashObject, CacheKeyAsid_HashData);
99 BOOL DestroyCellCache (ASID idCell)
104 if ((pcc = GetCellCache (idCell)) == NULL)
110 if (!pcc->cReqCache || !(--(pcc->cReqCache)))
114 for (LPENUM pEnum = pcc->pCache->FindFirst(); pEnum; pEnum = pEnum->FindNext())
116 LPASOBJPROP pProp = (LPASOBJPROP)( pEnum->GetObject() );
117 pcc->pCache->Remove (pProp);
121 Delete (pcc->pCache);
124 l.pCells->Remove (pcc);
133 LPASOBJPROP GetCachedProperties (ASID idCell, ASID idObject)
135 LPASOBJPROP pCachedProperties = NULL;
139 if ((pcc = GetCellCache (idCell)) != NULL)
141 pCachedProperties = (LPASOBJPROP)(pcc->pCacheKeyAsid->GetFirstObject (&idObject));
145 return pCachedProperties;
149 void UpdateCachedProperties (ASID idCell, ASID idObject, LPASOBJPROP pProperties)
156 if ((pcc = GetCellCache (idCell)) != NULL)
158 LPASOBJPROP pCachedProperties;
159 if ((pCachedProperties = (LPASOBJPROP)(pcc->pCacheKeyAsid->GetFirstObject (&idObject))) == NULL)
161 pCachedProperties = New (ASOBJPROP);
162 memcpy (pCachedProperties, pProperties, sizeof(ASOBJPROP));
163 pcc->pCache->Add (pCachedProperties);
167 memcpy (pCachedProperties, pProperties, sizeof(ASOBJPROP));
168 // Note: don't need to call pcc->pCache->Update(), because
169 // we haven't affected any indices (the old and new ASOBJPROP
170 // structures should have the same ASID)
174 NotifyObjectListeners (idCell, idObject);
180 BOOL RefreshCachedProperties (UINT_PTR idClient, ASID idCell, ASID idObject, AFSADMSVR_GET_LEVEL GetLevel, ULONG *pStatus)
187 LPASOBJPROP pProperties = GetCachedProperties (idCell, idObject);
188 DWORD verProperties = (pProperties) ? (pProperties->verProperties) : verPROP_NO_OBJECT;
190 ASOBJPROP NewProperties;
191 if ((rc = AfsAdmSvr_GetObject (idClient, RETURN_IF_OUT_OF_DATE, GetLevel, idObject, verProperties, &NewProperties, &status)) != FALSE)
193 if (NewProperties.idObject == idObject)
195 UpdateCachedProperties (idCell, idObject, &NewProperties);
202 status = RPC_S_CALL_FAILED_DNE;
212 BOOL RefreshCachedProperties (UINT_PTR idClient, ASID idCell, LPASIDLIST pAsidList, AFSADMSVR_GET_LEVEL GetLevel, ULONG *pStatus)
217 if (pAsidList->cEntries)
221 for (size_t iObject = 0; iObject < pAsidList->cEntries; ++iObject)
223 LPASOBJPROP pProperties = GetCachedProperties (idCell, pAsidList->aEntries[ iObject ].idObject);
224 pAsidList->aEntries[ iObject ].lParam = (pProperties) ? (pProperties->verProperties) : verPROP_NO_OBJECT;
227 LPASOBJPROPLIST pNewProperties = NULL;
228 if ((rc = AfsAdmSvr_GetObjects (idClient, RETURN_IF_OUT_OF_DATE, GetLevel, pAsidList, &pNewProperties, &status)) != FALSE)
232 for (size_t iObject = 0; iObject < pNewProperties->cEntries; ++iObject)
234 UpdateCachedProperties (idCell, pNewProperties->aEntries[ iObject ].ObjectProperties.idObject, &pNewProperties->aEntries[ iObject ].ObjectProperties);
236 AfsAdmSvr_FreeObjPropList (&pNewProperties);
243 status = RPC_S_CALL_FAILED_DNE;
255 * HASHLIST KEYS ______________________________________________________________
259 BOOL CALLBACK CacheKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData)
261 return (((LPASOBJPROP)pObject)->idObject == *(ASID*)pData);
264 HASHVALUE CALLBACK CacheKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject)
266 return CacheKeyAsid_HashData (pKey, &((LPASOBJPROP)pObject)->idObject);
269 HASHVALUE CALLBACK CacheKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData)
271 return (HASHVALUE)*(ASID*)pData;
275 BOOL CALLBACK CellsKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData)
277 return (((LPCELLCACHE)pObject)->idCell == *(ASID*)pData);
280 HASHVALUE CALLBACK CellsKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject)
282 return CellsKeyAsid_HashData (pKey, &((LPCELLCACHE)pObject)->idCell);
285 HASHVALUE CALLBACK CellsKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData)
287 return (HASHVALUE)*(ASID*)pData;