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 __________________________________________________________________
32 } LISTENER
, *LPLISTENER
;
36 LPHASHLIST pListeners
;
37 LPHASHLISTKEY pListenersKeyObject
;
39 HWND
*ahActionListeners
;
40 size_t chActionListeners
;
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
)
65 l
.pListeners
= New (HASHLIST
);
66 l
.pListenersKeyObject
= l
.pListeners
->CreateKey (TEXT("idObject"), ListenersKeyObject_Compare
, ListenersKeyObject_HashObject
, ListenersKeyObject_HashData
);
69 LPLISTENER pl
= New (LISTENER
);
71 pl
->idObject
= idObject
;
72 pl
->hNotify
= hNotify
;
73 l
.pListeners
->Add (pl
);
80 void ClearObjectNotifications (HWND hNotify
)
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
);
101 void TestForNotifications (UINT_PTR idClient
, ASID idCell
, ASID idObject
)
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
)
115 if (idObject
&& (pl
->idObject
!= idObject
))
120 if (!asc_AsidListCreate (&pAsidList
))
123 if (!asc_AsidListAddEntry (&pAsidList
, pl
->idObject
, 0))
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
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.
150 for (LPENUM pEnum
= l
.pListenersKeyObject
->FindFirst (&idObject
); pEnum
; pEnum
= pEnum
->FindNext())
152 LPLISTENER pl
= (LPLISTENER
)( pEnum
->GetObject() );
153 if (pl
->idCell
!= idCell
)
156 if (!IsWindow (pl
->hNotify
))
158 l
.pListeners
->Remove (pl
);
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
)
205 for (ii
= 0; ii
< l
.chActionListeners
; ++ii
)
207 if (l
.ahActionListeners
[ ii
] == hNotify
)
208 l
.ahActionListeners
[ ii
] = NULL
;
213 for (ii
= 0; ii
< l
.chActionListeners
; ++ii
)
215 if (l
.ahActionListeners
[ ii
] == NULL
)
218 if (!REALLOC (l
.ahActionListeners
, l
.chActionListeners
, 1+ii
, 1))
224 l
.ahActionListeners
[ ii
] = hNotify
;
233 void NotifyActionListeners (LPASACTION pAction
, BOOL fFinished
)
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
);