LINUX: afs_create infinite fetchStatus loop
[pkg-k5-afs_openafs.git] / src / WINNT / afsclass / c_notify.cpp
blob748e8309eab602d8e6942f6940414745f873902f
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 <afsconfig.h>
15 #include <afs/param.h>
16 #include <roken.h>
19 #include <WINNT/afsclass.h>
20 #include "internal.h"
24 * DEFINITIONS ________________________________________________________________
28 #define cREALLOC_NOTIFY 4 // allocate space for 4 notifies at once
32 * VARIABLES __________________________________________________________________
36 size_t NOTIFYCALLBACK::nNotifyList = 0;
37 LPNOTIFYCALLBACK *NOTIFYCALLBACK::aNotifyList = NULL;
41 * PROTOTYPES _________________________________________________________________
47 * ROUTINES ___________________________________________________________________
51 NOTIFYCALLBACK::NOTIFYCALLBACK (NOTIFYCALLBACKPROC procUser, LPARAM lpUser)
53 procSupplied = procUser;
54 lpSupplied = lpUser;
55 size_t iNotify;
57 for (iNotify = 0; iNotify < nNotifyList; ++iNotify)
59 if (aNotifyList[ iNotify ] == NULL)
60 break;
63 if (iNotify >= nNotifyList)
65 REALLOC (aNotifyList, nNotifyList, 1+iNotify, cREALLOC_NOTIFY );
68 if (iNotify < nNotifyList)
70 aNotifyList[ iNotify ] = this;
75 NOTIFYCALLBACK::~NOTIFYCALLBACK (void)
77 for (size_t iNotify = 0; iNotify < nNotifyList; ++iNotify)
79 if (aNotifyList[ iNotify ] == this)
80 aNotifyList[ iNotify ] = NULL;
85 BOOL NOTIFYCALLBACK::SendNotificationToAll (NOTIFYEVENT evt, ULONG status)
87 return SendNotificationToAll (evt, NULL, NULL, NULL, NULL, 0, status);
90 BOOL NOTIFYCALLBACK::SendNotificationToAll (NOTIFYEVENT evt, LPIDENT lpi1, ULONG status)
92 return SendNotificationToAll (evt, lpi1, NULL, NULL, NULL, 0, status);
95 BOOL NOTIFYCALLBACK::SendNotificationToAll (NOTIFYEVENT evt, LPTSTR psz1, ULONG status)
97 return SendNotificationToAll (evt, NULL, NULL, psz1, NULL, 0, status);
100 BOOL NOTIFYCALLBACK::SendNotificationToAll (NOTIFYEVENT evt, LPIDENT lpi1, LPTSTR psz1, ULONG status)
102 return SendNotificationToAll (evt, lpi1, NULL, psz1, NULL, 0, status);
105 BOOL NOTIFYCALLBACK::SendNotificationToAll (NOTIFYEVENT evt, LPIDENT lpi1, LPIDENT lpi2, LPTSTR psz1, LPTSTR psz2, DWORD dw1, ULONG status)
107 BOOL rc = TRUE;
109 NOTIFYPARAMS Params;
110 memset (&Params, 0x00, sizeof(Params));
111 Params.lpi1 = lpi1;
112 Params.lpi2 = lpi2;
113 lstrcpy (Params.sz1, (psz1) ? psz1 : TEXT(""));
114 lstrcpy (Params.sz2, (psz2) ? psz2 : TEXT(""));
115 Params.dw1 = dw1;
116 Params.status = status;
118 for (size_t iNotify = 0; iNotify < nNotifyList; ++iNotify)
120 if (aNotifyList[ iNotify ] != NULL)
122 Params.lpUser = aNotifyList[ iNotify ]->lpSupplied;
123 if (!aNotifyList[ iNotify ]->SendNotification (evt, &Params))
124 rc = FALSE;
128 return rc;
132 BOOL NOTIFYCALLBACK::SendNotification (NOTIFYEVENT evt, PNOTIFYPARAMS pParams)
134 BOOL rc = TRUE;
136 if (procSupplied != NULL) {
137 try {
138 if (!(*procSupplied)( evt, pParams ))
139 rc = FALSE;
140 } catch(...) {
141 // whoops--never trust a callback.
142 #ifdef DEBUG
143 DebugBreak();
144 #endif
145 rc = FALSE;
149 return rc;