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

  1 martin 1.3 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.4 //
  3 martin 1.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 martin 1.4 //
 10 martin 1.3 // 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.4 //
 17 martin 1.3 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.4 //
 20 martin 1.3 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.4 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.3 // 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.4 //
 28 martin 1.3 //////////////////////////////////////////////////////////////////////////
 29 marek  1.1 //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            #ifndef _CMPIClassCache_H_
 32            #define _CMPIClassCache_H_
 33            
 34 thilo.boehm 1.6 #include <Pegasus/Common/Config.h>
 35                 
 36                 #ifndef PEGASUS_OS_TYPE_WINDOWS
 37                 #include <strings.h>
 38                 #endif
 39                 
 40 marek       1.1 #include <Pegasus/Common/String.h>
 41                 #include <Pegasus/Common/CIMClass.h>
 42                 #include <Pegasus/Common/HashTable.h>
 43                 #include <Pegasus/Common/ReadWriteSem.h>
 44 thilo.boehm 1.6 #include <Pegasus/Common/CharSet.h>
 45                 #include <Pegasus/Common/SCMOClass.h>
 46                 #include <Pegasus/Common/System.h>
 47 marek       1.1 
 48                 PEGASUS_NAMESPACE_BEGIN
 49                 
 50 marek       1.2 struct CMPI_Broker;
 51 marek       1.1 
 52 thilo.boehm 1.6 class ClassCacheEntry
 53                 {
 54                 public:
 55                     ClassCacheEntry(
 56                         const char* namespaceName,
 57                         Uint32 namespaceNameLen,
 58                         const char* className,
 59                         Uint32 classNameLen)
 60                     {
 61                         nsLen = namespaceNameLen;
 62                         clsLen = classNameLen;
 63                         nsName = namespaceName;
 64                         clsName = className;
 65                         allocated = false;
 66                     };
 67                 
 68                     ClassCacheEntry( const ClassCacheEntry& oldEntry)
 69                     {
 70                         nsLen = oldEntry.nsLen;
 71                         nsName = (char*) malloc(nsLen+1);
 72                         if (0 == nsName)
 73 thilo.boehm 1.6         {
 74                             throw PEGASUS_STD(bad_alloc)();
 75                         }
 76                         memcpy((void*)nsName, oldEntry.nsName, nsLen+1);
 77                 
 78                         clsLen = oldEntry.clsLen;
 79                         clsName =  (char*) malloc(clsLen+1);
 80                         if (0 == clsName)
 81                         {
 82                             free((void*)nsName);
 83                             throw PEGASUS_STD(bad_alloc)();
 84                         }
 85                         memcpy((void*)clsName, oldEntry.clsName, clsLen+1);
 86                 
 87                         allocated = true;
 88                     };
 89                 
 90                     ~ClassCacheEntry()
 91                     {
 92                         if (allocated)
 93                         {
 94 thilo.boehm 1.6             free((void*)clsName);
 95                             free((void*)nsName);
 96                         }
 97                     }
 98                 
 99                     static Boolean equal(const ClassCacheEntry& x, const ClassCacheEntry& y)
100                     {
101                         return
102                             System::strncasecmp(x.clsName,x.clsLen,y.clsName,y.clsLen) &&
103                             System::strncasecmp(x.nsName,x.nsLen,y.nsName,y.nsLen);
104                     }
105                 
106                     static Uint32 hash(const ClassCacheEntry& entry)
107                     {
108                         // Simply use the lenght of the classname and namespace name as hash.
109                         return entry.clsLen+entry.nsLen;
110                     }
111                 
112                 private:
113                     const char* nsName;
114                     Uint32 nsLen;
115 thilo.boehm 1.6     const char* clsName;
116                     Uint32 clsLen;
117                     Boolean allocated;
118                 
119                 };
120                 
121                 
122                 
123 marek       1.1 class CMPIClassCache
124                 {
125                 
126                 public:
127                     CMPIClassCache()
128                     {
129 thilo.boehm 1.6         _clsCacheSCMO = new ClassCacheSCMO();
130                         _hintClass = NULL;
131                         _hint = NULL;
132 marek       1.1     };
133                 
134                     // clean-up cache data
135                     ~CMPIClassCache();
136                 
137                     // a single function as point of control for now
138                     // target is to reduce the critical section as much as possible
139 thilo.boehm 1.6     SCMOClass* getSCMOClass(
140 marek       1.1         const CMPI_Broker *mb,
141 thilo.boehm 1.6         const char* nsName,
142                         Uint32 nsNameLen,
143                         const char* className,
144                         Uint32 classNameLen);
145 marek       1.1 
146                 private:
147 thilo.boehm 1.6     typedef HashTable<ClassCacheEntry, SCMOClass *,
148                         ClassCacheEntry, ClassCacheEntry> ClassCacheSCMO;
149 marek       1.1 
150 thilo.boehm 1.6     ClassCacheSCMO * _clsCacheSCMO;
151 marek       1.1     // auto-initialisation due to being on the stack
152                     ReadWriteSem _rwsemClassCache;
153                 
154 thilo.boehm 1.6     //Optimization for continuos lookups of the same class
155                     //Simply store away the last lookup result
156                     void _setHint(ClassCacheEntry& hint, SCMOClass* hintClass);
157                     SCMOClass* _hintClass;
158                     ClassCacheEntry* _hint;
159                 
160 marek       1.1 };
161                 
162                 PEGASUS_NAMESPACE_END
163                 
164 kumpf       1.5 #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2