(file) Return to ProviderIndicationCountTable.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / IndicationService

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2