6 #include "TaAfsAdmSvrClientInternal.h"
7 #include <WINNT/AfsAppLib.h>
11 * VARIABLES __________________________________________________________________
19 LPHASHLISTKEY pCacheKeyAsid;
21 } CELLCACHE, *LPCELLCACHE;
26 LPHASHLISTKEY pCellsKeyAsid;
31 * PROTOTYPES _________________________________________________________________
35 BOOL CALLBACK CacheKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData);
36 HASHVALUE CALLBACK CacheKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject);
37 HASHVALUE CALLBACK CacheKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData);
39 BOOL CALLBACK CellsKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData);
40 HASHVALUE CALLBACK CellsKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject);
41 HASHVALUE CALLBACK CellsKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData);
45 * ROUTINES ___________________________________________________________________
49 LPCELLCACHE GetCellCache (ASID idCell)
54 return (LPCELLCACHE)(l.pCellsKeyAsid->GetFirstObject (&idCell));
58 BOOL CreateCellCache (ASID idCell)
64 l.pCells = New (HASHLIST);
65 l.pCells->SetCriticalSection (asc_GetCriticalSection());
66 l.pCellsKeyAsid = l.pCells->CreateKey (TEXT("ASID"), CellsKeyAsid_Compare, CellsKeyAsid_HashObject, CellsKeyAsid_HashData);
70 if ((pcc = GetCellCache (idCell)) == NULL)
72 pcc = New (CELLCACHE);
73 memset (pcc, 0x00, sizeof(CELLCACHE));
75 pcc->pCache = New (HASHLIST);
76 pcc->pCache->SetCriticalSection (asc_GetCriticalSection());
77 pcc->pCacheKeyAsid = pcc->pCache->CreateKey (TEXT("ASID"), CacheKeyAsid_Compare, CacheKeyAsid_HashObject, CacheKeyAsid_HashData);
87 BOOL DestroyCellCache (ASID idCell)
92 if ((pcc = GetCellCache (idCell)) == NULL)
98 if (!pcc->cReqCache || !(--(pcc->cReqCache)))
102 for (LPENUM pEnum = pcc->pCache->FindFirst(); pEnum; pEnum = pEnum->FindNext())
104 LPASOBJPROP pProp = (LPASOBJPROP)( pEnum->GetObject() );
105 pcc->pCache->Remove (pProp);
109 Delete (pcc->pCache);
112 l.pCells->Remove (pcc);
121 LPASOBJPROP GetCachedProperties (ASID idCell, ASID idObject)
123 LPASOBJPROP pCachedProperties = NULL;
127 if ((pcc = GetCellCache (idCell)) != NULL)
129 pCachedProperties = (LPASOBJPROP)(pcc->pCacheKeyAsid->GetFirstObject (&idObject));
133 return pCachedProperties;
137 void UpdateCachedProperties (ASID idCell, ASID idObject, LPASOBJPROP pProperties)
144 if ((pcc = GetCellCache (idCell)) != NULL)
146 LPASOBJPROP pCachedProperties;
147 if ((pCachedProperties = (LPASOBJPROP)(pcc->pCacheKeyAsid->GetFirstObject (&idObject))) == NULL)
149 pCachedProperties = New (ASOBJPROP);
150 memcpy (pCachedProperties, pProperties, sizeof(ASOBJPROP));
151 pcc->pCache->Add (pCachedProperties);
155 memcpy (pCachedProperties, pProperties, sizeof(ASOBJPROP));
156 // Note: don't need to call pcc->pCache->Update(), because
157 // we haven't affected any indices (the old and new ASOBJPROP
158 // structures should have the same ASID)
162 NotifyObjectListeners (idCell, idObject);
168 BOOL RefreshCachedProperties (DWORD idClient, ASID idCell, ASID idObject, AFSADMSVR_GET_LEVEL GetLevel, ULONG *pStatus)
175 LPASOBJPROP pProperties = GetCachedProperties (idCell, idObject);
176 DWORD verProperties = (pProperties) ? (pProperties->verProperties) : verPROP_NO_OBJECT;
178 ASOBJPROP NewProperties;
179 if ((rc = AfsAdmSvr_GetObject (idClient, RETURN_IF_OUT_OF_DATE, GetLevel, idObject, verProperties, &NewProperties, &status)) != FALSE)
181 if (NewProperties.idObject == idObject)
183 UpdateCachedProperties (idCell, idObject, &NewProperties);
190 status = RPC_S_CALL_FAILED_DNE;
200 BOOL RefreshCachedProperties (DWORD idClient, ASID idCell, LPASIDLIST pAsidList, AFSADMSVR_GET_LEVEL GetLevel, ULONG *pStatus)
205 if (pAsidList->cEntries)
209 for (size_t iObject = 0; iObject < pAsidList->cEntries; ++iObject)
211 LPASOBJPROP pProperties = GetCachedProperties (idCell, pAsidList->aEntries[ iObject ].idObject);
212 pAsidList->aEntries[ iObject ].lParam = (pProperties) ? (pProperties->verProperties) : verPROP_NO_OBJECT;
215 LPASOBJPROPLIST pNewProperties = NULL;
216 if ((rc = AfsAdmSvr_GetObjects (idClient, RETURN_IF_OUT_OF_DATE, GetLevel, pAsidList, &pNewProperties, &status)) != FALSE)
220 for (size_t iObject = 0; iObject < pNewProperties->cEntries; ++iObject)
222 UpdateCachedProperties (idCell, pNewProperties->aEntries[ iObject ].ObjectProperties.idObject, &pNewProperties->aEntries[ iObject ].ObjectProperties);
224 AfsAdmSvr_FreeObjPropList (&pNewProperties);
231 status = RPC_S_CALL_FAILED_DNE;
243 * HASHLIST KEYS ______________________________________________________________
247 BOOL CALLBACK CacheKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData)
249 return (((LPASOBJPROP)pObject)->idObject == *(ASID*)pData);
252 HASHVALUE CALLBACK CacheKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject)
254 return CacheKeyAsid_HashData (pKey, &((LPASOBJPROP)pObject)->idObject);
257 HASHVALUE CALLBACK CacheKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData)
259 return (HASHVALUE)*(ASID*)pData;
263 BOOL CALLBACK CellsKeyAsid_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData)
265 return (((LPCELLCACHE)pObject)->idCell == *(ASID*)pData);
268 HASHVALUE CALLBACK CellsKeyAsid_HashObject (LPHASHLISTKEY pKey, PVOID pObject)
270 return CellsKeyAsid_HashData (pKey, &((LPCELLCACHE)pObject)->idCell);
273 HASHVALUE CALLBACK CellsKeyAsid_HashData (LPHASHLISTKEY pKey, PVOID pData)
275 return (HASHVALUE)*(ASID*)pData;