📄 namespacemanager.cpp
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// 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.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/System.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Common/String.h>#include <Pegasus/Common/HashTable.h>#include <Pegasus/Common/Dir.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/CommonUTF.h>#include "InstanceIndexFile.h"#include "NameSpaceManager.h"PEGASUS_NAMESPACE_BEGINstatic char _CLASSES_DIR[] = "classes";static char _INSTANCES_DIR[] = "instances";static char _QUALIFIERS_DIR[] = "qualifiers";static char _CLASSES_SUFFIX[] = "/classes";static char _INSTANCES_SUFFIX[] = "/instances";static char _QUALIFIERS_SUFFIX[] = "/qualifiers";static char _ASSOCIATIONS_SUFFIX[] = "/associations";//////////////////////////////////////////////////////////////////////////////////// _namespaceNameToDirName()//////////////////////////////////////////////////////////////////////////////////static String _namespaceNameToDirName(const CIMNamespaceName& namespaceName){ String dirName = namespaceName.getString(); for (Uint32 i=0; i<dirName.size(); i++) { if (dirName[i] == '/') { dirName[i] = '#'; } }#ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8 // All chars above 0x7F will be escape. return escapeStringEncoder(dirName);#else return dirName;#endif}//////////////////////////////////////////////////////////////////////////////////// _dirNameToNamespaceName()//////////////////////////////////////////////////////////////////////////////////static String _dirNameToNamespaceName(const String& dirName){ String namespaceName = dirName; for (Uint32 i=0; i<namespaceName.size(); i++) { if (namespaceName[i] == '#') { namespaceName[i] = '/'; } }#ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8 // All chars above 0x7F will be escape. return escapeStringDecoder(namespaceName);#else return namespaceName;#endif}//////////////////////////////////////////////////////////////////////////////////// _MakeClassFilePath()//////////////////////////////////////////////////////////////////////////////////static inline String _MakeClassFilePath( const String& nameSpacePath, const CIMName& className, const CIMName& superClassName){ String returnString; if (!superClassName.isNull()) { returnString.assign(nameSpacePath); returnString.append(_CLASSES_SUFFIX); returnString.append('/'); returnString.append(className.getString()); returnString.append('.'); returnString.append(superClassName.getString()); } else { returnString.assign(nameSpacePath); returnString.append(_CLASSES_SUFFIX); returnString.append('/'); returnString.append(className.getString()); returnString.append(".#"); }#ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8 // All chars above 0x7F will be escape. return escapeStringEncoder(returnString);#else return returnString;#endif}//////////////////////////////////////////////////////////////////////////////////// _MakeQualifierFilePath()//////////////////////////////////////////////////////////////////////////////////static inline String _MakeQualifierFilePath( const String& nameSpacePath, const CIMName& qualifierName){ String returnString(nameSpacePath); returnString.append(_QUALIFIERS_SUFFIX); returnString.append('/'); returnString.append(qualifierName.getString());#ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8 // All chars above 0x7F will be escape. return escapeStringEncoder(returnString);#else return returnString;#endif}//////////////////////////////////////////////////////////////////////////////////// _MakeInstanceDataFileBase()//////////////////////////////////////////////////////////////////////////////////static inline String _MakeInstanceDataFileBase( const String& nameSpacePath, const CIMName& className){ String returnString(nameSpacePath); returnString.append(_INSTANCES_SUFFIX); returnString.append('/'); returnString.append(className.getString());#ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8 // All chars above 0x7F will be escape. return escapeStringEncoder(returnString);#else return returnString;#endif}//////////////////////////////////////////////////////////////////////////////////// NameSpaceManagerRep//////////////////////////////////////////////////////////////////////////////////typedef HashTable <String, NameSpace*, EqualNoCaseFunc, HashLowerCaseFunc> Table;struct NameSpaceManagerRep{ Table table;};//////////////////////////////////////////////////////////////////////////////////// NameSpace//////////////////////////////////////////////////////////////////////////////////struct specialNameSpace;class NameSpace{ friend class NameSpaceManager;public: NameSpace( const String& nameSpacePath, const CIMNamespaceName& nameSpaceName, specialNameSpace* pns = NULL, String* extDir = NULL); void modify( Boolean shareable, Boolean updatesAllowed, const String& nameSpacePath); ~NameSpace(); static NameSpace* newNameSpace( int index, NameSpaceManager* nsm, String& repositoryRoot); Boolean readOnly() { return ro; } NameSpace* primaryParent(); NameSpace* rwParent(); const String& getNameSpacePath() const { return _nameSpacePath; } const CIMNamespaceName& getNameSpaceName() const { return _nameSpaceName; } const String getClassFilePath(const CIMName& className) const; const String getQualifierFilePath(const CIMName& qualifierName) const; const String getInstanceDataFileBase(const CIMName& className) const; InheritanceTree& getInheritanceTree() { return _inheritanceTree; } /** Print this namespace. */ void print(PEGASUS_STD(ostream)& os) const;private: InheritanceTree _inheritanceTree; String _nameSpacePath; CIMNamespaceName _nameSpaceName; NameSpace* parent; NameSpace* dependent; NameSpace* nextDependent; Boolean ro, final; String sharedDirName; String remoteDirName;};static Array<String>* nameSpaceNames = NULL;static Array<specialNameSpace*>* specialNames = NULL;#ifdef PEGASUS_ENABLE_REMOTE_CMPIstruct specialNameSpace{ specialNameSpace() : shared(false), parentSpace(NULL), parent(String::EMPTY), sharedDirName(String::EMPTY), remote(false) { } void setShared(bool r, bool f, String p, String x) { shared = true; ro = r; final = f; parentSpace = NULL; parent = p; sharedDirName = x; } void setShared(bool r, bool f, NameSpace* pns, String p, String x) { shared = true; ro = r; final = f; parentSpace = pns; parent = p; sharedDirName = x; } void setRemote(String id, String host, String port, String x) { remote = true; remId = id; remHost = host; remPort = port; remDirName = x; } Boolean shared; Boolean ro; Boolean final; NameSpace* parentSpace; String parent; String sharedDirName; Boolean remote; String remId; String remHost; String remPort; String remDirName;};#elsestruct specialNameSpace{ specialNameSpace(bool r, bool f, String p, String x) : ro(r), final(f), parentSpace(NULL), parent(p), sharedDirName(x) {} specialNameSpace(bool r, bool f, NameSpace* pns, String p, String x) : ro(r), final(f), parentSpace(pns), parent(p), sharedDirName(x) {} Boolean ro; Boolean final; NameSpace* parentSpace; String parent; String sharedDirName;};#endif#ifdef PEGASUS_ENABLE_REMOTE_CMPINameSpace::NameSpace( const String& nameSpacePath, const CIMNamespaceName& nameSpaceName, specialNameSpace* pns, String* extDir) : _nameSpacePath(nameSpacePath), _nameSpaceName(nameSpaceName), parent(NULL), dependent(NULL), nextDependent(NULL), ro(false), final(false){ PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpace::NameSpace()"); if (pns == NULL) { _inheritanceTree.insertFromPath(nameSpacePath + "/classes"); } else { if (pns->shared) { ro = pns->ro; final = pns->final; parent = pns->parentSpace; if (parent == NULL) { _inheritanceTree.insertFromPath(nameSpacePath + "/classes"); } else { if (!pns->ro) _inheritanceTree.insertFromPath( nameSpacePath + "/classes", &parent->_inheritanceTree, this); NameSpace* ens = parent->primaryParent(); nextDependent = ens->dependent; ens->dependent = this; } } else _inheritanceTree.insertFromPath(nameSpacePath + "/classes"); if (pns->remote) { PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "Remote namespace: " + nameSpacePath + " >" + pns->remDirName); remoteDirName=pns->remDirName; } } if (extDir) sharedDirName = *extDir;}#elseNameSpace::NameSpace( const String& nameSpacePath, const CIMNamespaceName& nameSpaceName, specialNameSpace* pns, String* extDir) : _nameSpacePath(nameSpacePath), _nameSpaceName(nameSpaceName), parent(NULL), dependent(NULL), nextDependent(NULL), ro(false), final(false){ PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpace::NameSpace()"); if (pns == NULL) { _inheritanceTree.insertFromPath(nameSpacePath + "/classes"); } else { ro=pns->ro; final=pns->final; parent=pns->parentSpace; if (parent == NULL) { _inheritanceTree.insertFromPath(nameSpacePath +"/classes"); } else { if (!pns->ro) _inheritanceTree.insertFromPath( nameSpacePath + "/classes", &parent->_inheritanceTree, this); NameSpace* ens=parent->primaryParent(); nextDependent = ens->dependent; ens->dependent = this; } } if (extDir) sharedDirName = *extDir;}#endifNameSpace::~NameSpace(){}#ifdef PEGASUS_ENABLE_REMOTE_CMPINameSpace* NameSpace::newNameSpace( int index, NameSpaceManager* nsm, String& repositoryRoot){ PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpace::newNameSpace()"); AutoPtr<NameSpace> nameSpace; String nameSpaceName = _dirNameToNamespaceName((*nameSpaceNames)[index]); nameSpace.reset(nsm->lookupNameSpace(nameSpaceName)); if ((nameSpace.get()) != 0) return nameSpace.release(); specialNameSpace* pns = (*specialNames)[index]; if (pns && pns->shared && pns->parent.size()) { int j = 0, m = 0; for (m = nameSpaceNames->size(); j < m; j++) if ((*nameSpaceNames)[j] == pns->parent) break; if (j >= m) { PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "Namespace not found in parent namespace."); } pns->parentSpace=newNameSpace(j, nsm, repositoryRoot); } else if (pns) pns->parentSpace = NULL; String nameSpacePath = repositoryRoot + "/" + (*nameSpaceNames)[index]; nameSpace.reset(new NameSpace(nameSpacePath, nameSpaceName,pns)); nsm->_rep->table.insert(nameSpaceName, nameSpace.get()); return nameSpace.release();}#elseNameSpace* NameSpace::newNameSpace( int index,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -