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 marek 1.8.2.7 #include <Pegasus/ProviderManager2/CMPI/CMPI_ThreadContext.h>
|
36 r.kieninger 1.8.2.4 #include <Pegasus/Provider/CIMOMHandleRep.h>
|
37 marek 1.1 #include <Pegasus/Common/Tracer.h>
|
38 r.kieninger 1.8.2.1 #include <Pegasus/Common/CIMNameCast.h>
|
39 r.kieninger 1.8.2.9 #include <Pegasus/Common/SCMOClassCache.h>
|
40 marek 1.1
41 PEGASUS_NAMESPACE_BEGIN
42
43 CMPIClassCache::~CMPIClassCache()
44 {
45 // Cleanup the class cache
|
46 r.kieninger 1.8.2.1 ClassCacheSCMO::Iterator i2=_clsCacheSCMO->start();
47 for (; i2; i2++)
48 {
49 delete i2.value();
50 }
51 delete _clsCacheSCMO;
|
52 marek 1.8.2.8 delete _hint;
|
53 r.kieninger 1.8.2.1 }
54
55 void CMPIClassCache::_setHint(ClassCacheEntry& hint, SCMOClass* hintClass)
56 {
|
57 marek 1.8.2.8 delete _hint;
|
58 r.kieninger 1.8.2.1 _hint = new ClassCacheEntry(hint);
59 _hintClass = hintClass;
60 }
61
62 SCMOClass* CMPIClassCache::getSCMOClass(
63 const CMPI_Broker *mb,
64 const char* nsName,
|
65 marek 1.8.2.7 Uint32 nsNameLen,
66 const char* className,
67 Uint32 classNameLen)
|
68 r.kieninger 1.8.2.1 {
|
69 marek 1.8.2.8 if (!(nsName && className))
|
70 r.kieninger 1.8.2.1 {
|
71 marek 1.8.2.8 return 0;
72 }
73 SCMOClass *scmoClass = 0;
74 ClassCacheEntry key(nsName,nsNameLen,className,classNameLen);
75 {
76 ReadLock readLock(_rwsemClassCache);
|
77 r.kieninger 1.8.2.1
|
78 marek 1.8.2.8 // We first check if the last lookup was for the same class
79 // so we could directly use the saved hint.
80 if (_hint && ClassCacheEntry::equal(*_hint, key))
|
81 r.kieninger 1.8.2.1 {
|
82 marek 1.8.2.8 return _hintClass;
|
83 r.kieninger 1.8.2.1 }
84
|
85 marek 1.8.2.8 if (_clsCacheSCMO->lookup(key,scmoClass))
|
86 r.kieninger 1.8.2.1 {
87 _setHint(key, scmoClass);
88 return scmoClass;
89 }
|
90 marek 1.1 }
91
92 try
93 {
94 WriteLock writeLock(_rwsemClassCache);
95
|
96 marek 1.8.2.8 if (_clsCacheSCMO->lookup(key,scmoClass))
|
97 marek 1.1 {
|
98 marek 1.8.2.8 _setHint(key, scmoClass);
99 return scmoClass;
|
100 marek 1.1 }
|
101 kumpf 1.7
|
102 r.kieninger 1.8.2.9 SCMOClassCache* scmoCache = SCMOClassCache::getInstance();
|
103 marek 1.1
|
104 r.kieninger 1.8.2.9 SCMOClass tmp = scmoCache->getSCMOClass(
105 nsName, nsNameLen, className, classNameLen);
106
107 if (tmp.isEmpty())
108 {
109 // Do not add to cache, when we failed to retrieve a real class
110 return 0;
111 }
112
113 SCMOClass* scmoClass = new SCMOClass(tmp);
|
114 marek 1.8.2.8 _clsCacheSCMO->insert(key,scmoClass);
115 _setHint(key, scmoClass);
116 return scmoClass;
|
117 marek 1.1 }
118 catch (const CIMException &e)
119 {
|
120 thilo.boehm 1.3 PEG_TRACE((TRC_CMPIPROVIDERINTERFACE,Tracer::LEVEL1,
|
121 denise.eckstein 1.4 "CIMException: %s",(const char*)e.getMessage().getCString()));
|
122 marek 1.1 }
|
123 r.kieninger 1.8.2.9 catch (const Exception &e)
124 {
125 PEG_TRACE((TRC_CMPIPROVIDERINTERFACE,Tracer::LEVEL1,
126 "Exception: %s",(const char*)e.getMessage().getCString()));
127 }
|
128 marek 1.1 return 0;
129 }
130
131 PEGASUS_NAMESPACE_END
|