1 yi.zhou 1.2 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 yi.zhou 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <Pegasus/Common/Constants.h>
35 #include <Pegasus/Common/Tracer.h>
36 #include <Pegasus/Common/StringConversion.h>
37 #include <Pegasus/Server/ProviderRegistrationManager/\
38 ProviderRegistrationManager.h>
39
40 #include "ProviderIndicationCountTable.h"
41
42 PEGASUS_NAMESPACE_BEGIN
43 yi.zhou 1.2
44 Uint32 ProviderIndicationCountTable::_ProviderIndicationCountHashFunc::hash(
45 const String& key)
46 {
47 Uint32 hashCode = 0;
48
49 const Uint16* p = (const Uint16*)key.getChar16Data();
50 Uint32 keySize = key.size();
51
52 if (keySize > 1)
53 {
54 hashCode = p[0] + p[keySize/2] + 3*p[keySize - 1];
55 }
56
57 return hashCode;
58 }
59
60 ProviderIndicationCountTable::ProviderIndicationCountTable()
61 {
62 }
63
64 yi.zhou 1.2 ProviderIndicationCountTable::~ProviderIndicationCountTable()
65 {
66 }
67
68 void ProviderIndicationCountTable::insertEntry(
69 const CIMInstance& providerInstance)
70 {
71 PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
72 "ProviderIndicationCountTable::insertEntry");
73
74 String providerModuleName;
75 String providerName;
76 getProviderKeys(providerInstance, providerModuleName, providerName);
77
78 String providerKey = _generateKey(providerModuleName, providerName);
79 _ProviderIndicationCountTableEntry entry;
80
81 WriteLock lock(_tableLock);
82
83 if (!_table.lookup(providerKey, entry))
84 {
85 yi.zhou 1.2 //
86 // The entry is not in the table yet; insert a new entry.
87 //
88 _ProviderIndicationCountTableEntry newEntry;
89 newEntry.providerModuleName = providerModuleName;
90 newEntry.providerName = providerName;
91 newEntry.indicationCount = 0;
92 newEntry.orphanIndicationCount = 0;
93
94 Boolean succeeded = _table.insert(providerKey, newEntry);
95 PEGASUS_ASSERT(succeeded);
96 }
97
98 PEG_METHOD_EXIT();
99 }
100
101 void ProviderIndicationCountTable::incrementEntry(
102 const CIMInstance& providerInstance,
103 Boolean isOrphan)
104 {
105 PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
106 yi.zhou 1.2 "ProviderIndicationCountTable::incrementEntry");
107
108 String providerModuleName;
109 String providerName;
110 getProviderKeys(providerInstance, providerModuleName, providerName);
111
112 String providerKey = _generateKey(providerModuleName, providerName);
113 _ProviderIndicationCountTableEntry* entry = 0;
114
115 WriteLock lock(_tableLock);
116
117 if (_table.lookupReference(providerKey, entry))
118 {
119 entry->indicationCount++;
120
121 if (isOrphan)
122 {
123 entry->orphanIndicationCount++;
124 }
125 }
126
127 yi.zhou 1.2 PEG_METHOD_EXIT();
128 }
129
130 void ProviderIndicationCountTable::removeEntry(
131 const CIMInstance& providerInstance)
132 {
133 PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
134 "ProviderIndicationCountTable::removeEntry");
135
136 String providerModuleName;
137 String providerName;
138 getProviderKeys(providerInstance, providerModuleName, providerName);
139 String providerKey = _generateKey(providerModuleName, providerName);
140
141 WriteLock lock(_tableLock);
142 _table.remove(providerKey);
143
144 PEG_METHOD_EXIT();
145 }
146
147 void ProviderIndicationCountTable::removeModuleEntries(
148 yi.zhou 1.2 const String& providerModuleName)
149 {
150 PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
151 "ProviderIndicationCountTable::removeModuleEntries");
152
153 {
154 WriteLock lock(_tableLock);
155 Array<String> keysToRemove;
156
157 // First collect a list of ProviderIndicationCountTable entries for
158 // this provider module.
159 for (_ProviderIndicationCountTable::Iterator i = _table.start(); i; i++)
160 {
161 if (i.value().providerModuleName == providerModuleName)
162 {
163 keysToRemove.append(i.key());
164 }
165 }
166
167 // Now remove the entries, outside the Iterator scope.
168 for (Uint32 i = 0; i < keysToRemove.size(); i++)
169 yi.zhou 1.2 {
170 Boolean isRemoved = _table.remove(keysToRemove[i]);
171 PEGASUS_ASSERT(isRemoved);
172 }
173 }
174
175 PEG_METHOD_EXIT();
176 }
177
178 void ProviderIndicationCountTable::getProviderKeys(
179 const CIMInstance& providerInstance,
180 String& providerModuleName,
181 String& providerName)
182 {
183 Array<CIMKeyBinding> keys = providerInstance.getPath().getKeyBindings();
184
185 for (Uint32 i = 0; i < keys.size(); i++)
186 {
187 if (keys[i].getName() == PEGASUS_PROPERTYNAME_NAME)
188 {
189 providerName = keys[i].getValue();
190 yi.zhou 1.2 }
191 else if (keys[i].getName() == _PROPERTY_PROVIDERMODULENAME)
192 {
193 providerModuleName = keys[i].getValue();
194 }
195 }
196 }
197
198 Array<ProviderIndicationCountTable::_ProviderIndicationCountTableEntry>
199 ProviderIndicationCountTable::_getAllEntries()
200 {
201 PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
202 "ProviderIndicationCountTable::_getAllEntries");
203
204 Array <_ProviderIndicationCountTableEntry> providerIndicationCountEntries;
205
206 //
207 // Iterate through the ProviderIndicationCountTable to get all the entries.
208 //
209
210 {
211 yi.zhou 1.2 ReadLock lock(_tableLock);
212 for (_ProviderIndicationCountTable::Iterator i = _table.start(); i; i++)
213 {
214 providerIndicationCountEntries.append(i.value());
215 }
216 }
217
218 PEG_METHOD_EXIT();
219 return providerIndicationCountEntries;
220 }
221
222 String ProviderIndicationCountTable::_generateKey(
223 const String& providerModuleName,
224 const String& providerName)
225 {
226 PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
227 "ProviderIndicationCountTable::_generateKey");
228
229 String providerIndicationCountKey(providerName);
230 providerIndicationCountKey.append(providerModuleName);
231 providerIndicationCountKey.append(":");
232 yi.zhou 1.2
233 char buffer[22];
234 Uint32 length;
235 const char* providerNameSize =
236 Uint32ToString(buffer, providerName.size(), length);
237 providerIndicationCountKey.append(providerNameSize, length);
238
239 PEG_METHOD_EXIT();
240 return providerIndicationCountKey;
241 }
242
243 Array<CIMInstance>
244 ProviderIndicationCountTable::enumerateProviderIndicationDataInstances()
245 {
246 PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
247 "ProviderIndicationCountTable::"
248 "enumerateProviderIndicationDataInstances");
249
250 Array<CIMInstance> instances;
251
252 //
253 yi.zhou 1.2 // get entire provider indication count table entries
254 //
255 Array<_ProviderIndicationCountTableEntry> indicationCountEntries =
256 _getAllEntries();
257
258 for (Uint32 i = 0; i < indicationCountEntries.size(); i++)
259 {
|
269 yi.zhou 1.3 Array<CIMObjectPath>
270 ProviderIndicationCountTable::enumerateProviderIndicationDataInstanceNames()
271 {
272 PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
273 "ProviderIndicationCountTable::"
274 "enumerateProviderIndicationDataInstanceNames");
275
276 Array<CIMObjectPath> instanceNames;
277
278 //
279 // get entire provider indication count table entries
280 //
281 Array<_ProviderIndicationCountTableEntry> indicationCountEntries =
282 _getAllEntries();
283
284 for (Uint32 i = 0; i < indicationCountEntries.size(); i++)
285 {
286 CIMObjectPath path = _buildProviderIndDataInstanceName(
287 indicationCountEntries[i]);
288
289 instanceNames.append(path);
290 yi.zhou 1.3 }
291
292 PEG_METHOD_EXIT();
293 return instanceNames;
294 }
295
296 CIMInstance ProviderIndicationCountTable::getProviderIndicationDataInstance(
297 const CIMObjectPath& instanceName)
298 {
299 PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
300 "ProviderIndicationCountTable::getProviderIndicationDataInstance");
301
302 //
303 // Gets provider module name and provider name from the provider indication
304 // data instance object path
305 //
306 String providerModuleName;
307 String providerName;
308 Array<CIMKeyBinding> keys = instanceName.getKeyBindings();
309
310 for (Uint32 i = 0; i < keys.size(); i++)
311 yi.zhou 1.3 {
312 if (keys[i].getName() == _PROPERTY_PROVIDERNAME)
313 {
314 providerName = keys[i].getValue();
315 }
316 else if (keys[i].getName() == _PROPERTY_PROVIDERMODULENAME)
317 {
318 providerModuleName = keys[i].getValue();
319 }
320 }
321
322 String providerKey = _generateKey(providerModuleName, providerName);
323
324 _ProviderIndicationCountTableEntry entry;
325
326 WriteLock lock(_tableLock);
327
328 if (_table.lookup(providerKey, entry))
329 {
330 CIMInstance providerIndDataInstance =
331 _buildProviderIndDataInstance(entry);
332 yi.zhou 1.3
333 PEG_METHOD_EXIT();
334 return providerIndDataInstance;
335 }
336
337 PEG_METHOD_EXIT();
338 throw CIMObjectNotFoundException(instanceName.toString());
339 }
340
341 CIMObjectPath ProviderIndicationCountTable::_buildProviderIndDataInstanceName(
342 const _ProviderIndicationCountTableEntry& indicationCountEntry)
343 {
344 PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
345 "ProviderIndicationCountTable::_buildProviderIndDataInstanceName");
346
347 CIMObjectPath instanceName;
348 Array<CIMKeyBinding> keyBindings;
349 keyBindings.append(CIMKeyBinding(
350 "ProviderModuleName",
351 indicationCountEntry.providerModuleName,
352 CIMKeyBinding::STRING));
353 yi.zhou 1.3 keyBindings.append(CIMKeyBinding(
354 "ProviderName",
355 indicationCountEntry.providerName,
356 CIMKeyBinding::STRING));
357
358 instanceName.setClassName(PEGASUS_CLASSNAME_PROVIDERINDDATA);
359 instanceName.setKeyBindings(keyBindings);
360
361 PEG_METHOD_EXIT();
362 return instanceName;
363 }
364
365 CIMInstance ProviderIndicationCountTable::_buildProviderIndDataInstance(
366 const _ProviderIndicationCountTableEntry& indicationCountEntry)
367 {
368 PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
369 "ProviderIndicationCountTable::_buildProviderIndDataInstance");
370
371 CIMInstance providerIndDataInstance(PEGASUS_CLASSNAME_PROVIDERINDDATA);
372 providerIndDataInstance.addProperty(CIMProperty(
373 CIMName("ProviderModuleName"),
374 yi.zhou 1.3 indicationCountEntry.providerModuleName));
375 providerIndDataInstance.addProperty(CIMProperty(
376 CIMName("ProviderName"),
377 indicationCountEntry.providerName));
378 providerIndDataInstance.addProperty(CIMProperty(
379 CIMName("IndicationCount"),
380 indicationCountEntry.indicationCount));
381 providerIndDataInstance.addProperty(CIMProperty(
382 CIMName("OrphanIndicationCount"),
383 indicationCountEntry.orphanIndicationCount));
384
385 CIMObjectPath path = _buildProviderIndDataInstanceName(
386 indicationCountEntry);
387 providerIndDataInstance.setPath(path);
388
389 PEG_METHOD_EXIT();
390 return providerIndDataInstance;
391 }
392
|