more-rx-updates-20060504
[openafs.git] / src / WINNT / afssvrmgr / propcache.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 #include <winsock2.h>
11 #include <ws2tcpip.h>
12
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
16 }
17
18 #include "svrmgr.h"
19 #include "propcache.h"
20
21
22 /*
23  * PROPERTIES-DIALOG CACHE ____________________________________________________
24  *
25  */
26
27 typedef struct
28    {
29    BOOL fInUse;
30    PropCache pcType;
31    PVOID pv;
32    HWND hDialog;
33    } PropCacheEntry;
34
35 static size_t PropCache_nEntries = 0;
36 static PropCacheEntry *PropCache_apce = NULL;
37
38 void PropCache_Add (PropCache pcType, PVOID pv, HWND hDialog)
39 {
40    if (!PropCache_Search (pcType, pv))
41       {
42       size_t iEntry;
43       for (iEntry = 0; iEntry < PropCache_nEntries; ++iEntry)
44          {
45          if (!PropCache_apce[ iEntry ].fInUse)
46             break;
47          }
48
49       if (iEntry == PropCache_nEntries)
50          {
51          if (!REALLOC (PropCache_apce, PropCache_nEntries, 1+iEntry, 16))
52             return;
53          }
54
55       PropCache_apce[ iEntry ].fInUse = TRUE;
56       PropCache_apce[ iEntry ].pcType = pcType;
57       PropCache_apce[ iEntry ].pv = pv;
58       PropCache_apce[ iEntry ].hDialog = hDialog;
59
60       if (pcType != pcSERVER)
61          AfsAppLib_RegisterModelessDialog (hDialog);
62       }
63 }
64
65
66 HWND PropCache_Search (PropCache pcType, PVOID pv, HWND hwndStart)
67 {
68    size_t iEntry = 0;
69
70    if (hwndStart != NULL)
71       {
72       for ( ; iEntry < PropCache_nEntries; ++iEntry)
73          {
74          if (!PropCache_apce[ iEntry ].fInUse)
75             continue;
76          if (PropCache_apce[ iEntry ].hDialog == hwndStart)
77             {
78             ++iEntry;
79             break;
80             }
81          }
82       }
83
84    for ( ; iEntry < PropCache_nEntries; ++iEntry)
85       {
86       if (!PropCache_apce[ iEntry ].fInUse)
87          continue;
88
89       if ( (PropCache_apce[ iEntry ].pcType == pcType) &&
90            ((pv == ANYVALUE) || (PropCache_apce[ iEntry ].pv == pv)) )
91          {
92          if (!IsWindow (PropCache_apce[ iEntry ].hDialog))
93             {
94             PropCache_apce[ iEntry ].fInUse = FALSE;
95             continue;
96             }
97
98          return PropCache_apce[ iEntry ].hDialog;
99          }
100       }
101
102    return NULL;
103 }
104
105
106 void PropCache_Delete (PropCache pcType, PVOID pv)
107 {
108    for (size_t iEntry = 0; iEntry < PropCache_nEntries; ++iEntry)
109       {
110       if (!PropCache_apce[ iEntry ].fInUse)
111          continue;
112
113       if ( (PropCache_apce[ iEntry ].pcType == pcType) &&
114            ((pv == ANYVALUE) || (PropCache_apce[ iEntry ].pv == pv)) )
115          {
116          PropCache_apce[ iEntry ].fInUse = FALSE;
117          }
118       }
119 }
120
121
122 void PropCache_Delete (HWND hDialog)
123 {
124    for (size_t iEntry = 0; iEntry < PropCache_nEntries; ++iEntry)
125       {
126       if (!PropCache_apce[ iEntry ].fInUse)
127          continue;
128
129       if (PropCache_apce[ iEntry ].hDialog == hDialog)
130          {
131          PropCache_apce[ iEntry ].fInUse = FALSE;
132          }
133       }
134 }
135