⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 namespacemanager.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    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->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();}#endifvoid NameSpace::modify(    Boolean shareable,    Boolean updatesAllowed,    const String& nameSpacePath){    PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpace::modify()");    String newDir = sharedDirName;    if (newDir.size() == 0)        newDir = "SWF";    newDir[0] = 'S';    newDir[1] = updatesAllowed ? 'W' : 'R';    newDir[2] = shareable ? 'S' : 'F';    String tmp = newDir;    tmp.toLower();    if (tmp == "swf")    {        String path = nameSpacePath + "/" + sharedDirName;        FileSystem::removeFileNoCase(path);        newDir = "";    }    else if (sharedDirName != newDir)    {        String path = nameSpacePath + "/" + newDir;        if (!FileSystem::makeDirectory(path))            throw CannotCreateDirectory(path);        path = nameSpacePath + "/" + sharedDirName;        if (sharedDirName.size())            if (!FileSystem::removeDirectoryHier(path))                throw CannotRemoveDirectory(path);    }    ro = !updatesAllowed;    final = !shareable;    sharedDirName = newDir;}NameSpace* NameSpace::primaryParent(){    if (parent == NULL)        return this;    return parent->primaryParent();}NameSpace* NameSpace::rwParent(){   if (!ro)       return this;   return parent->rwParent();}const String NameSpace::getClassFilePath(const CIMName& className) const{    CIMName superClassName;    if (!_inheritanceTree.getSuperClass(className, superClassName))        throw PEGASUS_CIM_EXCEPTION(            CIM_ERR_NOT_FOUND, className.getString());    return _MakeClassFilePath(_nameSpacePath, className, superClassName);}const String NameSpace::getQualifierFilePath(const CIMName& qualifierName) const{    return _MakeQualifierFilePath(_nameSpacePath, qualifierName);}const String NameSpace::getInstanceDataFileBase(const CIMName& className) const{    return _MakeInstanceDataFileBase(_nameSpacePath, className);}void NameSpace::print(PEGASUS_STD(ostream)& os) const{    os << "=== NameSpace: " << _nameSpaceName << PEGASUS_STD(endl);    os << "_nameSpacePath: " << _nameSpacePath << PEGASUS_STD(endl);    _inheritanceTree.print(os);}//////////////////////////////////////////////////////////////////////////////////// NameSpaceManager//////////////////////////////////////////////////////////////////////////////////static Boolean _IsNameSpaceDir(const String& nameSpacePath){    if (!FileSystem::isDirectory(nameSpacePath))        return false;    if (!FileSystem::isDirectory(nameSpacePath + _CLASSES_SUFFIX))        return false;    if (!FileSystem::isDirectory(nameSpacePath + _INSTANCES_SUFFIX))        return false;    if (!FileSystem::isDirectory(nameSpacePath + _QUALIFIERS_SUFFIX))        return false;    return true;}static String _CreateNameSpaceDirectories(    const String& nameSpacePath,    Boolean shareable,    Boolean updatesAllowed,    const String& parent){    if (!FileSystem::makeDirectory(nameSpacePath))        throw CannotCreateDirectory(nameSpacePath);    String classesPath = nameSpacePath + _CLASSES_SUFFIX;    String instancesPath = nameSpacePath + _INSTANCES_SUFFIX;    String qualifiersPath = nameSpacePath + _QUALIFIERS_SUFFIX;    if (!FileSystem::makeDirectory(classesPath))        throw CannotCreateDirectory(classesPath);    if (!FileSystem::makeDirectory(instancesPath))        throw CannotCreateDirectory(instancesPath);    if (!FileSystem::makeDirectory(qualifiersPath))        throw CannotCreateDirectory(qualifiersPath);    String path = "";    if (shareable || !updatesAllowed || parent.size())    {        path = nameSpacePath + "/S" + (updatesAllowed ? "W" : "R") +            (shareable ? "S" : "F") + parent;        if (!FileSystem::makeDirectory(path))            throw CannotCreateDirectory(path);    }    return path;}static Boolean _NameSpaceDirHierIsEmpty(const String& nameSpacePath){    for (Dir dir(nameSpacePath); dir.more(); dir.next())    {        const char* name = dir.getName();        if (strcmp(name, ".") != 0 &&            strcmp(name, "..") != 0 &&            System::strcasecmp(name, _CLASSES_DIR) != 0 &&            System::strcasecmp(name, _INSTANCES_DIR) != 0 &&            System::strcasecmp(name, _QUALIFIERS_DIR) != 0)        {            return true;        }    }    String classesPath = nameSpacePath + _CLASSES_SUFFIX;    String instancesPath = nameSpacePath + _INSTANCES_SUFFIX;    String qualifiersPath = nameSpacePath + _QUALIFIERS_SUFFIX;    return        FileSystem::isDirectoryEmpty(classesPath) &&        FileSystem::isDirectoryEmpty(instancesPath) &&        FileSystem::isDirectoryEmpty(qualifiersPath);}NameSpaceManager::NameSpaceManager(const String& repositoryRoot)    : _repositoryRoot(repositoryRoot){    PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::NameSpaceManager()");    // Create directory if does not already exist:    if (!FileSystem::isDirectory(_repositoryRoot))    {        if (!FileSystem::makeDirectory(_repositoryRoot))            throw CannotCreateDirectory(_repositoryRoot);        // Create a root namespace per ...        // Specification for CIM Operations over HTTP        // Version 1.0        // 2.5 Namespace Manipulation        //        // There are no intrinsic methods defined specifically for the        // purpose of manipulating CIM Namespaces.  However, the        // modelling of the a CIM Namespace using the class        // __Namespace, together with the requirement that that        // root Namespace MUST be supported by all CIM Servers,        // implies that all Namespace operations can be supported.        //        _CreateNameSpaceDirectories(            _repositoryRoot + "/root",            false,            true,            String::EMPTY);    }    _rep = new NameSpaceManagerRep;    nameSpaceNames = new Array<String>;    specialNames = new Array<specialNameSpace*>;    String tmp;#ifdef PEGASUS_ENABLE_REMOTE_CMPI    for (Dir dir(repositoryRoot); dir.more(); dir.next())    {        String dirName = dir.getName();        if (dirName == ".." || dirName == ".")            continue;        String specialName = " ";        specialNameSpace* sns = NULL;        for (Dir dir(repositoryRoot + "/" + dirName); dir.more(); dir.next())        {            specialName = dir.getName();            tmp = specialName;            tmp.toLower();            if (specialName == ".." || specialName == ".")                continue;            switch (tmp[0])            {                case 's':                {                    if ((tmp[1]=='w' || tmp[1]=='r') &&                        (tmp[2]=='f' || tmp[2]=='s'))                    {                        if (sns == NULL)                            sns = new specialNameSpace();                        sns->setShared(                            tmp[1] == 'r',                            tmp[2] == 'f',                            specialName.subString(3),                            specialName);                    }                    else                    {                        PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,                            "Namespace " + dirName +                            " ignored - using incorrect parent namespace "                                "specification: " +                            specialName);                    }                    break;                }                case 'r':                {                    String id = tmp.subString(1, 2);                    Uint32 pos = specialName.find('@');                    String host, port;                    if (pos != PEG_NOT_FOUND)                    {                        host=specialName.subString(3, pos-3);                        port=specialName.subString(pos+1);                    }                    else                        host = specialName.subString(3);                    if (sns == NULL)                        sns = new specialNameSpace();                    sns->setRemote(id, host, port, specialName);                    PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,                        "Remote namespace: " + dirName + " >" + specialName);                    break;                }            }        }        if (sns == NULL)        {            nameSpaceNames->prepend(dirName);            specialNames->prepend(NULL);        }        else        {            nameSpaceNames->append(dirName);            specialNames->append(sns);        }     }#else    for (Dir dir(repositoryRoot); dir.more(); dir.next())    {        String dirName = dir.getName();        if (dirName == ".." || dirName == ".")            continue;        String specialName = " ";        for (Dir dir(repositoryRoot+"/"+dirName); dir.more(); dir.next())        {            specialName = dir.getName();            tmp = specialName;            tmp.toLower();            if (specialName == ".." || specialName == ".")                continue;            if (tmp[0]=='s')                break;        }        if (tmp[0] == 's')        {            if ((tmp[1]=='w' || tmp[1]=='r') &&                (tmp[2]=='f' || tmp[2]=='s'))            {                nameSpaceNames->append(dirName);                specialNames->append(new specialNameSpace(                    tmp[1]=='r',                    tmp[2]=='f',                    specialName.subString(3),                    specialName));                continue;            }            PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,                "Namespace: " + dirName +                " ignored - using incorrect parent namespace specification: " +                specialName);        }        else        {            nameSpaceNames->prepend(dirName);            specialNames->prepend(NULL);        }    }#endif    for (int i = 0, m = nameSpaceNames->size(), j = 0; i < m; i++)    {        String dirName = (*nameSpaceNames)[i];        if (dirName.size() == 0) continue;        if (!_IsNameSpaceDir(repositoryRoot + "/" + dirName))        {            (*nameSpaceNames)[i] = String::EMPTY;            i = -1;   //restart            PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,                "Namespace: " + dirName +                    " ignored - no sub directories found");            continue;        }        specialNameSpace* pns = (*specialNames)[i];        if (pns && pns->parent.size())        {            if ((*nameSpaceNames)[i].size())            {                if ((*nameSpaceNames)[i].size())                {                    for (j = 0; j < m; j++)                        if ((*nameSpaceNames)[j] == pns->parent)                            break;                    if (j >= m)                    {                        PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,                            "Namespace: " + (*nameSpaceNames)[i] +                            " ignored - parent namespace not found: " +                            pns->parent);                        (*nameSpaceNames)[i] = String::EMPTY;                        i = -1;   //restart                    }                }            }        }    }    // Create a NameSpace object for each directory under repositoryRoot.    // This will throw an exception if the directory does not exist:    for (int i = 0, m = nameSpaceNames->size(); i < m; i++)    {        if ((*nameSpaceNames)[i].size() == 0)            continue;        try        {            NameSpace::newNameSpace(i,this,_repositoryRoot);        }        catch (const Exception&)        {            throw;        }    }    delete nameSpaceNames;    if (specialNames)    {        for (int i = 0, m = specialNames->size(); i < m; i++)            delete (*specialNames)[i];        delete specialNames;    }    nameSpaceNames = NULL;    specialNames = NULL;}NameSpaceManager::~NameSpaceManager(){    for (Table::Iterator i = _rep->table.start(); i; i++)        delete i.value();    delete _rep;}Boolean NameSpaceManager::nameSpaceExists(    const CIMNamespaceName& nameSpaceName) const{    return _rep->table.contains(nameSpaceName.getString());}NameSpace* NameSpaceManager::lookupNameSpace(String& ns){    NameSpace* tns;    if (!_rep->table.lookup(ns, tns))        return NULL;    return tns;}void NameSpaceManager::createNameSpace(    const CIMNamespaceName& nameSpaceName,    const NameSpaceAttributes& attributes){    PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::createNameSpace()");    // Throw exception if namespace already exists:    String parent = "";    Boolean shareable = false;    Boolean updatesAllowed = true;    if (nameSpaceExists(nameSpaceName))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(            CIM_ERR_ALREADY_EXISTS, nameSpaceName.getString());    }    for (NameSpaceAttributes::Iterator i = attributes.start(); i; i++)    {        String key = i.key();        if (String::equalNoCase(key,"shareable"))        {            if (String::equalNoCase(i.value(), "true"))                shareable = true;        }        else if (String::equalNoCase(key,"updatesAllowed"))        {            if (String::equalNoCase(i.value(), "false"))                updatesAllowed = false;        }        else if (String::equalNoCase(key, "parent"))        {            parent=i.value();        }        else        {            PEG_METHOD_EXIT();            throw PEGASUS_CIM_EXCEPTION(                CIM_ERR_NOT_SUPPORTED,                nameSpaceName.getString() + " option not supported: " + key);        }    }    NameSpace* parentSpace = 0;    if (parent.size() && !(parentSpace=lookupNameSpace(parent)))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -