1 thilo.boehm 1.1.2.1 //%LICENSE////////////////////////////////////////////////////////////////
2 //
3 // 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 //
10 // 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 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 thilo.boehm 1.1.2.1 // 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 //
28 //////////////////////////////////////////////////////////////////////////
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <Pegasus/Common/Linkage.h>
33 #include <Pegasus/Common/SCMOClassCache.h>
34 #include <Pegasus/Provider/CIMOMHandle.h>
35 #include <Pegasus/Common/Tracer.h>
36 #include <Pegasus/Common/CIMNameCast.h>
37
38 PEGASUS_NAMESPACE_BEGIN
39
40 SCMOClassCache* SCMOClassCache::_theInstance = NULL;
41
42 SCMOClassCache::~SCMOClassCache()
43 thilo.boehm 1.1.2.1 {
44 // Cleanup the class cache
45 SCMOClassHashTable::Iterator i2=_clsCacheSCMO->start();
46 for (; i2; i2++)
47 {
48 delete i2.value();
49 }
50 delete _clsCacheSCMO;
51
52 if (_hint)
53 {
54 delete( _hint );
55 }
56 }
57
58 void SCMOClassCache::destroy()
59 {
60 delete _theInstance;
61 _theInstance == NULL;
62 }
63
64 thilo.boehm 1.1.2.1 SCMOClassCache* SCMOClassCache::getInstance()
65 {
66 if(_theInstance == NULL)
67 {
68 _theInstance = new SCMOClassCache();
69 }
70 return _theInstance;
71 }
72
73
74 void SCMOClassCache::_setHint(ClassCacheEntry& hint, SCMOClass* hintClass)
75 {
76 if (_hint)
77 {
78 delete(_hint);
79 }
80 _hint = new ClassCacheEntry(hint);
81 _hintClass = hintClass;
82 }
83
84
85 thilo.boehm 1.1.2.1 SCMOClass* SCMOClassCache::getSCMOClass(
86 const char* nsName,
87 Uint32 nsNameLen,
88 const char* className,
89 Uint32 classNameLen)
90 {
91 //fprintf(stderr,"SCMOClassCache::getSCMOClass - Enter()\n");
92
93 if (nsName && className)
94 {
95
96 ClassCacheEntry key(nsName,nsNameLen,className,classNameLen);
97
98 SCMOClass *scmoClass;
99
100 {
101 ReadLock readLock(_rwsemClassCache);
102
103 // We first check if the last lookup was for the same class
104 // so we could directly use the saved hint.
105 if (_hint && ClassCacheEntry::equal(*_hint, key))
106 thilo.boehm 1.1.2.1 {
107 return _hintClass;
108 }
109
110 if (_clsCacheSCMO->lookup(key,scmoClass))
111 {
112 _setHint(key, scmoClass);
113 return scmoClass;
114 }
115 }
116
117 try
118 {
119 WriteLock writeLock(_rwsemClassCache);
120
121 if (_clsCacheSCMO->lookup(key,scmoClass))
122 {
123 _setHint(key, scmoClass);
124 return scmoClass;
125 }
126
127 thilo.boehm 1.1.2.1 PEGASUS_ASSERT(_resolveCallBack);
128
129 CIMClass cc = _resolveCallBack(
130 CIMNamespaceNameCast(String(nsName,nsNameLen)),
131 CIMNameCast(String(className,classNameLen)));
132
133 scmoClass = new SCMOClass(cc,nsName);
134
135 _clsCacheSCMO->insert(key,scmoClass);
136
137 _setHint(key, scmoClass);
138 return scmoClass;
139 }
140 catch (const CIMException &e)
141 {
142 PEG_TRACE((TRC_SERVER,Tracer::LEVEL1,
143 "CIMException: %s",(const char*)e.getMessage().getCString()));
144 }
145 }
146
147 return 0;
148 thilo.boehm 1.1.2.1 }
149
150 PEGASUS_NAMESPACE_END
|