![]() ![]() |
![]() |
File: [Pegasus] / pegasus / src / Pegasus / Common / SCMOClassCache.h
(download)
Revision: 1.1.2.2, Tue Oct 20 12:21:19 2009 UTC (14 years, 8 months ago) by marek Branch: TASK-PEP348_SCMO-branch Changes since 1.1.2.1: +6 -7 lines PEP#:348 TITLE: Complete SCMOXmlWriter DESCRIPTION: - added support for Reference Values - added support of instance/object values - added embedded instance/object support - added extra-fast strncasecmp() to System class |
//%LICENSE//////////////////////////////////////////////////////////////// // // Licensed to The Open Group (TOG) under one or more contributor license // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with // this work for additional information regarding copyright ownership. // Each contributor licenses this file to you under the OpenPegasus Open // Source License; you may not use this file except in compliance with the // License. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ////////////////////////////////////////////////////////////////////////// // //%///////////////////////////////////////////////////////////////////////////// #ifndef _SCMOClassCache_H_ #define _SCMOClassCache_H_ #include <Pegasus/Common/Linkage.h> #include <Pegasus/Common/String.h> #include <Pegasus/Common/CIMClass.h> #include <Pegasus/Common/HashTable.h> #include <Pegasus/Common/ReadWriteSem.h> #include <Pegasus/Common/CharSet.h> #include <Pegasus/Common/SCMOClass.h> #include <Pegasus/Common/System.h> PEGASUS_NAMESPACE_BEGIN typedef CIMClass (*SCMOClassCacheCallbackPtr)( const CIMNamespaceName& nameSpace, const CIMName& className); class PEGASUS_COMMON_LINKAGE ClassCacheEntry { const char* nsName; Uint32 nsLen; const char* clsName; Uint32 clsLen; Boolean allocated; public: ClassCacheEntry(const char* namespaceName, Uint32 namespaceNameLen, const char* className, Uint32 classNameLen ) { nsLen = namespaceNameLen; clsLen = classNameLen; nsName = namespaceName; clsName = className; allocated = false; }; ClassCacheEntry( const ClassCacheEntry& oldEntry) { nsLen = oldEntry.nsLen; nsName = new char[nsLen+1]; memcpy((void*)nsName, oldEntry.nsName, nsLen+1); clsLen = oldEntry.clsLen; clsName = new char[clsLen+1]; memcpy((void*)clsName, oldEntry.clsName, clsLen+1); allocated = true; }; ~ClassCacheEntry() { if (allocated) { delete[](clsName); delete[](nsName); } } static Boolean equal(const ClassCacheEntry& x, const ClassCacheEntry& y) { return System::strncasecmp(x.clsName,x.clsLen,y.clsName,y.clsLen); } static Uint32 hash(const ClassCacheEntry& entry) { // Simply use the lenght of the classname as hash. return entry.clsLen; } }; class PEGASUS_COMMON_LINKAGE SCMOClassCache { public: SCMOClass* getSCMOClass( const char* nsName, Uint32 nsNameLen, const char* className, Uint32 classNameLen); static SCMOClassCache* getInstance(); void setCallBack(SCMOClassCacheCallbackPtr clb) { _resolveCallBack = clb; } static void destroy(); private: typedef HashTable<ClassCacheEntry, SCMOClass *, ClassCacheEntry, ClassCacheEntry> SCMOClassHashTable; static SCMOClassCache* _theInstance; SCMOClassCache() : _hintClass(NULL), _hint(NULL), _resolveCallBack(NULL) { _clsCacheSCMO = new SCMOClassHashTable(); }; // clean-up cache data ~SCMOClassCache(); SCMOClassHashTable * _clsCacheSCMO; // auto-initialisation due to being on the stack ReadWriteSem _rwsemClassCache; SCMOClass* _hintClass; ClassCacheEntry* _hint; // the call back function pointer to get CIMClass's SCMOClassCacheCallbackPtr _resolveCallBack; //Optimization for continuos lookups of the same class //Simply store away the last lookup result void _setHint(ClassCacheEntry& hint, SCMOClass* hintClass); }; PEGASUS_NAMESPACE_END #endif
No CVS admin address has been configured |
Powered by ViewCVS 0.9.2 |