50739b9c7d1d78c4e48f1c4ec7e98c50ff80ad25
[openafs.git] / src / WINNT / afsclass / c_notify.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include <WINNT/afsclass.h>
16 #include "internal.h"
17
18
19 /*
20  * DEFINITIONS ________________________________________________________________
21  *
22  */
23
24 #define cREALLOC_NOTIFY  4      // allocate space for 4 notifies at once
25
26
27 /*
28  * VARIABLES __________________________________________________________________
29  *
30  */
31
32 size_t            NOTIFYCALLBACK::nNotifyList = 0;
33 LPNOTIFYCALLBACK *NOTIFYCALLBACK::aNotifyList = NULL;
34
35
36 /*
37  * PROTOTYPES _________________________________________________________________
38  *
39  */
40
41
42 /*
43  * ROUTINES ___________________________________________________________________
44  *
45  */
46
47 NOTIFYCALLBACK::NOTIFYCALLBACK (NOTIFYCALLBACKPROC procUser, LPARAM lpUser)
48 {
49    procSupplied = procUser;
50    lpSupplied = lpUser;
51    size_t iNotify;
52
53    for (iNotify = 0; iNotify < nNotifyList; ++iNotify)
54       {
55       if (aNotifyList[ iNotify ] == NULL)
56          break;
57       }
58
59    if (iNotify >= nNotifyList)
60       {
61       REALLOC (aNotifyList, nNotifyList, 1+iNotify, cREALLOC_NOTIFY );
62       }
63
64    if (iNotify < nNotifyList)
65       {
66       aNotifyList[ iNotify ] = this;
67       }
68 }
69
70
71 NOTIFYCALLBACK::~NOTIFYCALLBACK (void)
72 {
73    for (size_t iNotify = 0; iNotify < nNotifyList; ++iNotify)
74       {
75       if (aNotifyList[ iNotify ] == this)
76          aNotifyList[ iNotify ] = NULL;
77       }
78 }
79
80
81 BOOL NOTIFYCALLBACK::SendNotificationToAll (NOTIFYEVENT evt, ULONG status)
82 {
83    return SendNotificationToAll (evt, NULL, NULL, NULL, NULL, 0, status);
84 }
85
86 BOOL NOTIFYCALLBACK::SendNotificationToAll (NOTIFYEVENT evt, LPIDENT lpi1, ULONG status)
87 {
88    return SendNotificationToAll (evt, lpi1, NULL, NULL, NULL, 0, status);
89 }
90
91 BOOL NOTIFYCALLBACK::SendNotificationToAll (NOTIFYEVENT evt, LPTSTR psz1, ULONG status)
92 {
93    return SendNotificationToAll (evt, NULL, NULL, psz1, NULL, 0, status);
94 }
95
96 BOOL NOTIFYCALLBACK::SendNotificationToAll (NOTIFYEVENT evt, LPIDENT lpi1, LPTSTR psz1, ULONG status)
97 {
98    return SendNotificationToAll (evt, lpi1, NULL, psz1, NULL, 0, status);
99 }
100
101 BOOL NOTIFYCALLBACK::SendNotificationToAll (NOTIFYEVENT evt, LPIDENT lpi1, LPIDENT lpi2, LPTSTR psz1, LPTSTR psz2, DWORD dw1, ULONG status)
102 {
103    BOOL rc = TRUE;
104
105    NOTIFYPARAMS Params;
106    memset (&Params, 0x00, sizeof(Params));
107    Params.lpi1 = lpi1;
108    Params.lpi2 = lpi2;
109    lstrcpy (Params.sz1, (psz1) ? psz1 : TEXT(""));
110    lstrcpy (Params.sz2, (psz2) ? psz2 : TEXT(""));
111    Params.dw1 = dw1;
112    Params.status = status;
113
114    for (size_t iNotify = 0; iNotify < nNotifyList; ++iNotify)
115       {
116       if (aNotifyList[ iNotify ] != NULL)
117          {
118          Params.lpUser = aNotifyList[ iNotify ]->lpSupplied;
119          if (!aNotifyList[ iNotify ]->SendNotification (evt, &Params))
120             rc = FALSE;
121          }
122       }
123
124    return rc;
125 }
126
127
128 BOOL NOTIFYCALLBACK::SendNotification (NOTIFYEVENT evt, PNOTIFYPARAMS pParams)
129 {
130    BOOL rc = TRUE;
131
132    if (procSupplied != NULL) {
133       try {
134          if (!(*procSupplied)( evt, pParams ))
135             rc = FALSE;
136       } catch(...) {
137          // whoops--never trust a callback.
138 #ifdef DEBUG
139          DebugBreak();
140 #endif
141          rc = FALSE;
142       }
143    }
144
145    return rc;
146 }
147