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