(file) Return to CMPIClassCache.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPI

  1 martin 1.5 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.6 //
  3 martin 1.5 // 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.6 //
 10 martin 1.5 // 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.6 //
 17 martin 1.5 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.6 //
 20 martin 1.5 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.6 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.5 // 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.6 //
 28 martin 1.5 //////////////////////////////////////////////////////////////////////////
 29 marek  1.1 //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32            #include <Pegasus/ProviderManager2/CMPI/CMPIClassCache.h>
 33            #include <Pegasus/ProviderManager2/CMPI/CMPI_Broker.h>
 34 marek  1.8 #include <Pegasus/ProviderManager2/CMPI/CMPI_ContextArgs.h>
 35 r.kieninger 1.8.2.4 #include <Pegasus/Provider/CIMOMHandleRep.h>
 36 marek       1.1     #include <Pegasus/Common/Tracer.h>
 37 r.kieninger 1.8.2.1 #include <Pegasus/Common/CIMNameCast.h>
 38 marek       1.1     
 39                     PEGASUS_NAMESPACE_BEGIN
 40                     
 41                     CMPIClassCache::~CMPIClassCache()
 42                     {
 43                         // Cleanup the class cache
 44                         ClassCache::Iterator i=_clsCache->start();
 45                         for (; i; i++)
 46                         {
 47                             delete i.value();
 48                         }
 49                         delete _clsCache;
 50 r.kieninger 1.8.2.1 
 51                         ClassCacheSCMO::Iterator i2=_clsCacheSCMO->start();
 52                         for (; i2; i2++)
 53                         {
 54                             delete i2.value();
 55                         }
 56                         delete _clsCacheSCMO;
 57                     
 58                         if (_hint)
 59                         {
 60                             delete( _hint );
 61                         }
 62                     }
 63                     
 64                     
 65                     
 66                     void CMPIClassCache::_setHint(ClassCacheEntry& hint, SCMOClass* hintClass)
 67                     {
 68                         if (_hint)
 69                         {
 70                             delete(_hint);
 71 r.kieninger 1.8.2.1     }
 72                         _hint = new ClassCacheEntry(hint);
 73                         _hintClass = hintClass;
 74                     }
 75                     
 76                     
 77                     SCMOClass* CMPIClassCache::getSCMOClass(
 78                         const CMPI_Broker *mb,
 79                         const char* nsName,
 80                         const char* className)
 81                     {
 82                         if (nsName && className)
 83                         {
 84                     
 85                             ClassCacheEntry key(nsName, className);
 86                     
 87                             SCMOClass *scmoClass;
 88                     
 89                             {
 90                                 ReadLock readLock(_rwsemClassCache);
 91                     
 92 r.kieninger 1.8.2.1             // We first check if the last lookup was for the same class
 93                                 // so we could directly use the saved hint.
 94                                 if (_hint && ClassCacheEntry::equal(*_hint, key))
 95                                 {
 96                                     return _hintClass;
 97                                 }
 98                     
 99                                 if (_clsCacheSCMO->lookup(key,scmoClass))
100                                 {
101                                     _setHint(key, scmoClass);
102                                     return scmoClass;
103                                 }
104                             }
105                     
106                             try
107                             {
108                                 WriteLock writeLock(_rwsemClassCache);
109                     
110                                 if (_clsCacheSCMO->lookup(key,scmoClass))
111                                 {
112                                     _setHint(key, scmoClass);
113 r.kieninger 1.8.2.1                 return scmoClass;
114                                 }
115                     
116 r.kieninger 1.8.2.5             CIMOMHandleRep* handle=CM_CIMOM(mb);
117                     
118                                 const CIMClass cc = handle->getClass(
119 r.kieninger 1.8.2.1                 OperationContext(),
120                                     CIMNamespaceNameCast(nsName),
121                                     CIMNameCast(className),
122                                     (bool)0,
123                                     (bool)1,
124 r.kieninger 1.8.2.3                 (bool)1,
125 r.kieninger 1.8.2.1                 CIMPropertyList());
126                     
127                                 scmoClass = new SCMOClass(cc,nsName);
128                                 _clsCacheSCMO->insert(key,scmoClass);
129                     
130                                 _setHint(key, scmoClass);
131                                 return scmoClass;
132                             }
133                             catch (const CIMException &e)
134                             {
135                                 PEG_TRACE((TRC_CMPIPROVIDERINTERFACE,Tracer::LEVEL1,
136                                     "CIMException: %s",(const char*)e.getMessage().getCString()));
137                             }
138                         }
139                     
140                         return 0;
141 marek       1.1     }
142                     
143 r.kieninger 1.8.2.1 
144                     
145                     
146 marek       1.1     CIMClass* CMPIClassCache::getClass(
147                         const CMPI_Broker *mb,
148                         const CIMObjectPath & cop)
149                     {
150                         String clsId =
151                             cop.getNameSpace().getString()+":"+cop.getClassName().getString();
152                     
153                         CIMClass *ccp;
154                     
155                         {
156                             ReadLock readLock(_rwsemClassCache);
157                     
158                             if (_clsCache->lookup(clsId,ccp))
159                             {
160                                 return ccp;
161                             }
162                         }
163                     
164                         try
165                         {
166                             WriteLock writeLock(_rwsemClassCache);
167 marek       1.1     
168                             if (_clsCache->lookup(clsId,ccp))
169                             {
170                                 return ccp;
171                             }
172 kumpf       1.7     
173 marek       1.8             const CMPIContext *ctx = CMPI_ThreadContext::getContext();
174                     
175 r.kieninger 1.8.2.4         CIMClass cc = CM_CIMOM(mb)->getClass(
176 marek       1.8                 *CM_Context(ctx),
177 marek       1.1                 cop.getNameSpace(),
178                                 cop.getClassName(),
179                                 (bool)0,
180                                 (bool)1,
181                                 (bool)0,
182                                 CIMPropertyList());
183                     
184                             ccp = new CIMClass(cc);
185                             _clsCache->insert(clsId,ccp);
186                             return ccp;
187                         }
188                         catch (const CIMException &e)
189                         {
190 thilo.boehm 1.3             PEG_TRACE((TRC_CMPIPROVIDERINTERFACE,Tracer::LEVEL1,
191 denise.eckstein 1.4                 "CIMException: %s",(const char*)e.getMessage().getCString()));
192 marek           1.1         }
193                             return 0;
194                         }
195                         
196                         PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2