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 __________________________________________________________________
29 } LISTENER, *LPLISTENER;
33 LPHASHLIST pListeners;
34 LPHASHLISTKEY pListenersKeyObject;
36 HWND *ahActionListeners;
37 size_t chActionListeners;
42 * PROTOTYPES _________________________________________________________________
46 BOOL CALLBACK ListenersKeyObject_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData);
47 HASHVALUE CALLBACK ListenersKeyObject_HashObject (LPHASHLISTKEY pKey, PVOID pObject);
48 HASHVALUE CALLBACK ListenersKeyObject_HashData (LPHASHLISTKEY pKey, PVOID pData);
52 * ROUTINES ___________________________________________________________________
56 BOOL AddObjectNotification (HWND hNotify, ASID idCell, ASID idObject)
62 l.pListeners = New (HASHLIST);
63 l.pListenersKeyObject = l.pListeners->CreateKey (TEXT("idObject"), ListenersKeyObject_Compare, ListenersKeyObject_HashObject, ListenersKeyObject_HashData);
66 LPLISTENER pl = New (LISTENER);
68 pl->idObject = idObject;
69 pl->hNotify = hNotify;
70 l.pListeners->Add (pl);
77 void ClearObjectNotifications (HWND hNotify)
83 for (LPENUM pEnum = l.pListeners->FindFirst(); pEnum; pEnum = pEnum->FindNext())
85 LPLISTENER pl = (LPLISTENER)( pEnum->GetObject() );
86 if (pl->hNotify == hNotify)
88 l.pListeners->Remove (pl);
98 void TestForNotifications (DWORD idClient, ASID idCell, ASID idObject)
102 // First we'll zip through our list of listeners and
103 // build an ASIDLIST reflecting the objects in this cell
104 // for which we're listening.
106 LPASIDLIST pAsidList = NULL;
107 for (LPENUM pEnum = l.pListeners->FindFirst(); pEnum; pEnum = pEnum->FindNext())
109 LPLISTENER pl = (LPLISTENER)( pEnum->GetObject() );
110 if (pl->idCell != idCell)
112 if (idObject && (pl->idObject != idObject))
117 if (!asc_AsidListCreate (&pAsidList))
120 if (!asc_AsidListAddEntry (&pAsidList, pl->idObject, 0))
124 // Then we'll call one of our cache routines, which in turn will tell
125 // the admin server what version of the properties we have for each
126 // of these objects; if any have newer properties available, we'll
127 // get them back--and that will cause us to send out notifications to
133 (void)RefreshCachedProperties (idClient, idCell, pAsidList, GET_ALL_DATA, &status);
139 void NotifyObjectListeners (ASID idCell, ASID idObject)
141 // If we get here, our cache of information for the specified object
142 // has just been updated. Check for listeners who may be interested
143 // in changes to this object.
147 for (LPENUM pEnum = l.pListenersKeyObject->FindFirst (&idObject); pEnum; pEnum = pEnum->FindNext())
149 LPLISTENER pl = (LPLISTENER)( pEnum->GetObject() );
150 if (pl->idCell != idCell)
153 if (!IsWindow (pl->hNotify))
155 l.pListeners->Remove (pl);
160 PostMessage (pl->hNotify, WM_ASC_NOTIFY_OBJECT, (WPARAM)0, (LPARAM)idObject);
167 * HASHLIST KEYS ______________________________________________________________
171 BOOL CALLBACK ListenersKeyObject_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData)
173 return (((LPLISTENER)pObject)->idObject == *(ASID*)pData) ? TRUE : FALSE;
176 HASHVALUE CALLBACK ListenersKeyObject_HashObject (LPHASHLISTKEY pKey, PVOID pObject)
178 return ListenersKeyObject_HashData (pKey, &((LPLISTENER)pObject)->idObject);
181 HASHVALUE CALLBACK ListenersKeyObject_HashData (LPHASHLISTKEY pKey, PVOID pData)
183 return (HASHVALUE)*(ASID*)pData;
189 * ACTION NOTIFICATIONS _______________________________________________________
193 BOOL SetActionNotification (HWND hNotify, BOOL fSet)
200 for (size_t ii = 0; ii < l.chActionListeners; ++ii)
202 if (l.ahActionListeners[ ii ] == hNotify)
203 l.ahActionListeners[ ii ] = NULL;
208 for (size_t ii = 0; ii < l.chActionListeners; ++ii)
210 if (l.ahActionListeners[ ii ] == NULL)
213 if (!REALLOC (l.ahActionListeners, l.chActionListeners, 1+ii, 1))
219 l.ahActionListeners[ ii ] = hNotify;
228 void NotifyActionListeners (LPASACTION pAction, BOOL fFinished)
232 for (size_t ii = 0; ii < l.chActionListeners; ++ii)
234 if (IsWindow (l.ahActionListeners[ ii ]))
236 LPASACTION pActionPost = New (ASACTION);
237 memcpy (pActionPost, pAction, sizeof(ASACTION));
238 PostMessage (l.ahActionListeners[ ii ], WM_ASC_NOTIFY_ACTION, (WPARAM)fFinished, (LPARAM)pActionPost);