Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afsadmsvr / TaAfsAdmSvrClientNotify.cpp
blob1e0599ab5fd624dfe040514b734765ae054be8bf
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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
8 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include "TaAfsAdmSvrClientInternal.h"
19 #include <WINNT/AfsAppLib.h>
23 * VARIABLES __________________________________________________________________
27 typedef struct
29 ASID idCell;
30 ASID idObject;
31 HWND hNotify;
32 } LISTENER, *LPLISTENER;
34 static struct
36 LPHASHLIST pListeners;
37 LPHASHLISTKEY pListenersKeyObject;
39 HWND *ahActionListeners;
40 size_t chActionListeners;
41 } l;
45 * PROTOTYPES _________________________________________________________________
49 BOOL CALLBACK ListenersKeyObject_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData);
50 HASHVALUE CALLBACK ListenersKeyObject_HashObject (LPHASHLISTKEY pKey, PVOID pObject);
51 HASHVALUE CALLBACK ListenersKeyObject_HashData (LPHASHLISTKEY pKey, PVOID pData);
55 * ROUTINES ___________________________________________________________________
59 BOOL AddObjectNotification (HWND hNotify, ASID idCell, ASID idObject)
61 asc_Enter();
63 if (!l.pListeners)
65 l.pListeners = New (HASHLIST);
66 l.pListenersKeyObject = l.pListeners->CreateKey (TEXT("idObject"), ListenersKeyObject_Compare, ListenersKeyObject_HashObject, ListenersKeyObject_HashData);
69 LPLISTENER pl = New (LISTENER);
70 pl->idCell = idCell;
71 pl->idObject = idObject;
72 pl->hNotify = hNotify;
73 l.pListeners->Add (pl);
75 asc_Leave();
76 return TRUE;
80 void ClearObjectNotifications (HWND hNotify)
82 asc_Enter();
84 if (l.pListeners)
86 for (LPENUM pEnum = l.pListeners->FindFirst(); pEnum; pEnum = pEnum->FindNext())
88 LPLISTENER pl = (LPLISTENER)( pEnum->GetObject() );
89 if (pl->hNotify == hNotify)
91 l.pListeners->Remove (pl);
92 Delete (pl);
97 asc_Leave();
101 void TestForNotifications (UINT_PTR idClient, ASID idCell, ASID idObject)
103 if (l.pListeners)
105 // First we'll zip through our list of listeners and
106 // build an ASIDLIST reflecting the objects in this cell
107 // for which we're listening.
109 LPASIDLIST pAsidList = NULL;
110 for (LPENUM pEnum = l.pListeners->FindFirst(); pEnum; pEnum = pEnum->FindNext())
112 LPLISTENER pl = (LPLISTENER)( pEnum->GetObject() );
113 if (pl->idCell != idCell)
114 continue;
115 if (idObject && (pl->idObject != idObject))
116 continue;
118 if (!pAsidList)
120 if (!asc_AsidListCreate (&pAsidList))
121 break;
123 if (!asc_AsidListAddEntry (&pAsidList, pl->idObject, 0))
124 break;
127 // Then we'll call one of our cache routines, which in turn will tell
128 // the admin server what version of the properties we have for each
129 // of these objects; if any have newer properties available, we'll
130 // get them back--and that will cause us to send out notifications to
131 // our listeners.
133 if (pAsidList)
135 ULONG status;
136 (void)RefreshCachedProperties (idClient, idCell, pAsidList, GET_ALL_DATA, &status);
142 void NotifyObjectListeners (ASID idCell, ASID idObject)
144 // If we get here, our cache of information for the specified object
145 // has just been updated. Check for listeners who may be interested
146 // in changes to this object.
148 if (l.pListeners)
150 for (LPENUM pEnum = l.pListenersKeyObject->FindFirst (&idObject); pEnum; pEnum = pEnum->FindNext())
152 LPLISTENER pl = (LPLISTENER)( pEnum->GetObject() );
153 if (pl->idCell != idCell)
154 continue;
156 if (!IsWindow (pl->hNotify))
158 l.pListeners->Remove (pl);
159 Delete (pl);
160 continue;
163 PostMessage (pl->hNotify, WM_ASC_NOTIFY_OBJECT, (WPARAM)0, (LPARAM)idObject);
170 * HASHLIST KEYS ______________________________________________________________
174 BOOL CALLBACK ListenersKeyObject_Compare (LPHASHLISTKEY pKey, PVOID pObject, PVOID pData)
176 return (((LPLISTENER)pObject)->idObject == *(ASID*)pData) ? TRUE : FALSE;
179 HASHVALUE CALLBACK ListenersKeyObject_HashObject (LPHASHLISTKEY pKey, PVOID pObject)
181 return ListenersKeyObject_HashData (pKey, &((LPLISTENER)pObject)->idObject);
184 HASHVALUE CALLBACK ListenersKeyObject_HashData (LPHASHLISTKEY pKey, PVOID pData)
186 return (HASHVALUE)*(ASID*)pData;
192 * ACTION NOTIFICATIONS _______________________________________________________
196 BOOL SetActionNotification (HWND hNotify, BOOL fSet)
198 BOOL rc = TRUE;
199 size_t ii = 0;
201 asc_Enter();
203 if (!fSet)
205 for (ii = 0; ii < l.chActionListeners; ++ii)
207 if (l.ahActionListeners[ ii ] == hNotify)
208 l.ahActionListeners[ ii ] = NULL;
211 else // (fSet)
213 for (ii = 0; ii < l.chActionListeners; ++ii)
215 if (l.ahActionListeners[ ii ] == NULL)
216 break;
218 if (!REALLOC (l.ahActionListeners, l.chActionListeners, 1+ii, 1))
220 rc = FALSE;
222 else
224 l.ahActionListeners[ ii ] = hNotify;
228 asc_Leave();
229 return rc;
233 void NotifyActionListeners (LPASACTION pAction, BOOL fFinished)
235 asc_Enter();
237 for (size_t ii = 0; ii < l.chActionListeners; ++ii)
239 if (IsWindow (l.ahActionListeners[ ii ]))
241 LPASACTION pActionPost = New (ASACTION);
242 memcpy (pActionPost, pAction, sizeof(ASACTION));
243 PostMessage (l.ahActionListeners[ ii ], WM_ASC_NOTIFY_ACTION, (WPARAM)fFinished, (LPARAM)pActionPost);
247 asc_Leave();