(file) Return to SCMOClassCache.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  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                     #ifndef _SCMOClassCache_H_
 32                     #define _SCMOClassCache_H_
 33                     
 34                     #include <Pegasus/Common/Linkage.h>
 35                     #include <Pegasus/Common/String.h>
 36                     #include <Pegasus/Common/CIMClass.h>
 37                     #include <Pegasus/Common/HashTable.h>
 38                     #include <Pegasus/Common/ReadWriteSem.h>
 39                     #include <Pegasus/Common/CharSet.h>
 40                     #include <Pegasus/Common/SCMOClass.h>
 41 marek       1.1.2.2 #include <Pegasus/Common/System.h>
 42                     
 43 thilo.boehm 1.1.2.1 PEGASUS_NAMESPACE_BEGIN
 44                     
 45                     typedef CIMClass (*SCMOClassCacheCallbackPtr)(
 46                             const CIMNamespaceName& nameSpace,
 47                             const CIMName& className);
 48                     
 49                     
 50                     class PEGASUS_COMMON_LINKAGE ClassCacheEntry
 51                     {
 52 marek       1.1.2.3     char* nsName;
 53 thilo.boehm 1.1.2.1     Uint32 nsLen;
 54 marek       1.1.2.3     char* clsName;
 55 thilo.boehm 1.1.2.1     Uint32 clsLen;
 56                         Boolean allocated;
 57                     
 58                     public:
 59                         ClassCacheEntry(const char* namespaceName,
 60                                         Uint32 namespaceNameLen,
 61                                         const char* className,
 62 marek       1.1.2.3                     Uint32 classNameLen ):
 63                             nsLen(namespaceNameLen),        
 64                             clsLen(classNameLen)
 65                         {
 66                             nsName = (char*) malloc(nsLen+1);
 67                             clsName = (char*) malloc(clsLen+1);
 68                             if (0 == clsName || 0 == nsName)
 69                             {
 70                                 free(nsName);
 71                                 free(clsName);
 72                                 throw PEGASUS_STD(bad_alloc)();
 73                             }
 74                             memcpy(nsName, namespaceName, namespaceNameLen);
 75                             memcpy(clsName, className, classNameLen);        
 76 thilo.boehm 1.1.2.1     };
 77                     
 78 marek       1.1.2.3     ClassCacheEntry( const ClassCacheEntry& x)
 79 thilo.boehm 1.1.2.1     {
 80 marek       1.1.2.3         // free up what we currently have, whatever that might be
 81                             free(nsName);
 82                             free(clsName);
 83                     
 84                             nsName = (char*) malloc(x.nsLen+1);
 85                             clsName = (char*) malloc(x.clsLen+1);
 86                             if (0 == clsName || 0 == nsName)
 87                             {
 88                                 free(nsName);
 89                                 free(clsName);
 90                                 nsName=0;
 91                                 clsName=0;
 92                                 throw PEGASUS_STD(bad_alloc)();
 93                             }
 94 thilo.boehm 1.1.2.1 
 95 marek       1.1.2.3         nsLen = x.nsLen;
 96                             clsLen = x.clsLen;
 97 thilo.boehm 1.1.2.1 
 98 marek       1.1.2.3         memcpy(nsName, x.nsName, nsLen+1);
 99                             memcpy(clsName, x.clsName, clsLen+1);
100 thilo.boehm 1.1.2.1     };
101                     
102                         ~ClassCacheEntry()
103                         {
104 marek       1.1.2.3         free(clsName);
105                             free(nsName);
106 thilo.boehm 1.1.2.1     }
107                     
108 marek       1.1.2.2     static Boolean equal(const ClassCacheEntry& x, const ClassCacheEntry& y)
109 thilo.boehm 1.1.2.1     {
110 marek       1.1.2.2         return System::strncasecmp(x.clsName,x.clsLen,y.clsName,y.clsLen);
111 thilo.boehm 1.1.2.1     }
112                     
113                         static Uint32 hash(const ClassCacheEntry& entry)
114                         {
115                             // Simply use the lenght of the classname as hash.
116                             return entry.clsLen;
117                         }
118                     };
119                     
120                     
121                     
122                     class PEGASUS_COMMON_LINKAGE SCMOClassCache
123                     {
124                     
125                     public:
126                     
127                         SCMOClass* getSCMOClass(
128                             const char* nsName,
129                             Uint32 nsNameLen,
130                             const char* className,
131                             Uint32 classNameLen);
132 thilo.boehm 1.1.2.1 
133                         static SCMOClassCache* getInstance();
134                     
135                         void setCallBack(SCMOClassCacheCallbackPtr clb)
136                         {
137                            _resolveCallBack = clb;
138                         }
139                     
140                         static void destroy();
141                     
142                     private:
143                     
144 marek       1.1.2.2     typedef HashTable<ClassCacheEntry, SCMOClass *,
145 thilo.boehm 1.1.2.1         ClassCacheEntry, ClassCacheEntry> SCMOClassHashTable;
146                     
147                         static SCMOClassCache* _theInstance;
148                     
149                         SCMOClassCache()
150                             : _hintClass(NULL),
151                               _hint(NULL),
152                               _resolveCallBack(NULL)
153 marek       1.1.2.2     {
154 thilo.boehm 1.1.2.1         _clsCacheSCMO = new SCMOClassHashTable();
155                         };
156                     
157                         // clean-up cache data
158                         ~SCMOClassCache();
159                     
160                         SCMOClassHashTable * _clsCacheSCMO;
161                     
162                         // auto-initialisation due to being on the stack
163                         ReadWriteSem _rwsemClassCache;
164                     
165                         SCMOClass* _hintClass;
166                         ClassCacheEntry* _hint;
167                     
168                         // the call back function pointer to get CIMClass's
169                         SCMOClassCacheCallbackPtr _resolveCallBack;
170                     
171                         //Optimization for continuos lookups of the same class
172                         //Simply store away the last lookup result
173                         void _setHint(ClassCacheEntry& hint, SCMOClass* hintClass);
174                     
175 thilo.boehm 1.1.2.1 };
176                     
177                     PEGASUS_NAMESPACE_END
178                     
179                     #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2