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

📄 namespace.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//String buildNamespacePath(    CIMObjectPath & namespacePath,    const CIMInstance& instance,    const String & objectManagerName){    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,        "InteropProvider::buildNamespacePath");    unsigned int propIndex = PEG_NOT_FOUND;    CIMName propertyName;    if(instance.findProperty(CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME)        == PEG_NOT_FOUND)    {        propertyName = CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME;    }    else if(instance.findProperty(CIM_NAMESPACE_PROPERTY_SYSTEMNAME)        == PEG_NOT_FOUND)    {        propertyName = CIM_NAMESPACE_PROPERTY_SYSTEMNAME;    }    else if(instance.findProperty(        CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME)        == PEG_NOT_FOUND)    {        propertyName = CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME;    }    else if(instance.findProperty(        CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME)        == PEG_NOT_FOUND)    {        propertyName = CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME;    }    else if(instance.findProperty(        CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME)        == PEG_NOT_FOUND)    {        propertyName = CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME;    }    else if((propIndex = instance.findProperty(CIM_NAMESPACE_PROPERTY_NAME))        == PEG_NOT_FOUND)    {        propertyName = CIM_NAMESPACE_PROPERTY_NAME;    }    if(propIndex == PEG_NOT_FOUND)    {        PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4,            "Invalid CIM_Namespace Key Property " +  propertyName.getString());        PEG_METHOD_EXIT();        throw CIMInvalidParameterException(            "Invalid CIM_Namespace key property: " + propertyName.getString());    }    PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4,        "CIM_Namespace Keys Valid");    Array<CIMKeyBinding> keyBindings;    String newNamespaceName;    instance.getProperty(propIndex).getValue().get(newNamespaceName);    keyBindings.append(CIMKeyBinding(        CIM_NAMESPACE_PROPERTY_NAME,        newNamespaceName, CIMKeyBinding::STRING));    keyBindings.append(CIMKeyBinding(        CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME,        PEGASUS_CLASSNAME_PGNAMESPACE.getString(), CIMKeyBinding::STRING));    keyBindings.append(CIMKeyBinding(        CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME,        System::getSystemCreationClassName(), CIMKeyBinding::STRING));    String hostName = System::getFullyQualifiedHostName();    keyBindings.append(CIMKeyBinding(        CIM_NAMESPACE_PROPERTY_SYSTEMNAME,        hostName, CIMKeyBinding::STRING));    keyBindings.append(CIMKeyBinding(        CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME,        PEGASUS_CLASSNAME_PG_OBJECTMANAGER.getString(),        CIMKeyBinding::STRING));    keyBindings.append(CIMKeyBinding(        CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME,        objectManagerName, CIMKeyBinding::STRING));    namespacePath = CIMObjectPath(hostName, PEGASUS_NAMESPACENAME_INTEROP,        PEGASUS_CLASSNAME_PGNAMESPACE, keyBindings);    return newNamespaceName;}//// Validates the keys for the ObjectPath representing an instance of// PG_Namespace. Having this function should be more efficient than creating an// instance of PG_Namespace and then comparing the object paths.//CIMNamespaceName validateNamespaceKeys(    const CIMObjectPath& objectPath,    const String & objectManagerName){    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,        "InteropProvider::validatePGNamespaceKeys");    CIMName propertyName;    if(!validateRequiredProperty(        objectPath,        CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME,        PEGASUS_CLASSNAME_PG_COMPUTERSYSTEM.getString()))    {        propertyName = CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME;    }    else if(!validateRequiredProperty(        objectPath,        CIM_NAMESPACE_PROPERTY_SYSTEMNAME,        System::getFullyQualifiedHostName()))    {        propertyName = CIM_NAMESPACE_PROPERTY_SYSTEMNAME;    }    else if(!validateRequiredProperty(        objectPath,        CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME,        PEGASUS_CLASSNAME_PG_OBJECTMANAGER.getString()))    {        propertyName = CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME;    }    else if(!validateRequiredProperty(        objectPath,        CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME,        objectManagerName))    {        propertyName = CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME;    }    else if(!validateRequiredProperty(        objectPath,        CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME,        PEGASUS_CLASSNAME_PGNAMESPACE.getString()))    {        propertyName = CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME;    }    else if(!validateRequiredProperty(objectPath,        CIM_NAMESPACE_PROPERTY_NAME,        String::EMPTY))    {        propertyName = CIM_NAMESPACE_PROPERTY_NAME;    }    if(!propertyName.isNull())    {        PEG_METHOD_EXIT();        throw CIMInvalidParameterException(            "Invalid key property: " + propertyName.getString());    }    PEG_METHOD_EXIT();    return CIMNamespaceName(getKeyValue(objectPath, CIM_NAMESPACE_PROPERTY_NAME));}void InteropProvider::deleteNamespace(    const CIMObjectPath & instanceName){    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,        "InteropProvider::deleteNamespace()");    // Validate requred keys and retrieve namespace name. An exception    // will be thrown if the object path is not valid.    CIMNamespaceName deleteNamespaceName =        validateNamespaceKeys(instanceName, objectManagerName);    if (deleteNamespaceName.equal(PEGASUS_NAMESPACENAME_ROOT))    {        PEG_METHOD_EXIT();        throw CIMNotSupportedException("root namespace cannot be deleted.");    }    repository->deleteNameSpace(deleteNamespaceName);    PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4,        "Namespace = " + deleteNamespaceName.getString() +            " successfully deleted.");    Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,        "Interop Provider Delete Namespace: $0",        deleteNamespaceName.getString());    PEG_METHOD_EXIT();}CIMObjectPath InteropProvider::createNamespace(    const CIMInstance & namespaceInstance){    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,        "InteropProvider::createNamespace()");    // The buildNamespacePath method performs some validation on the    // namespace instance, creates a valid object path that can be used    // by the client to access the instance later, and retrieves the    // namespace to be created.    CIMObjectPath newInstanceReference;    CIMNamespaceName newNamespaceName = buildNamespacePath(        newInstanceReference, namespaceInstance, objectManagerName);    // Create the new namespace    try    {        PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4,            "Namespace = " + newNamespaceName.getString() +                " to be created.");        CIMRepository::NameSpaceAttributes attributes;        // Set shareable attribute to "false" if property is not present        Boolean shareable = false;        if(getPropertyValue(namespaceInstance,            PG_NAMESPACE_PROPERTY_ISSHAREABLE, false))        {            attributes.insert("shareable", "true");        }        else        {            attributes.insert("shareable", "false");        }        // Set updatesAllowed attribute to "false" if property is not present        Boolean updatesAllowed = false;        if (getPropertyValue(namespaceInstance,            PG_NAMESPACE_PROPERTY_SCHEMAUPDATESALLOWED, false))        {            attributes.insert("updatesAllowed", "true");        }        else        {            attributes.insert("updatesAllowed", "false");        }        // Set the parent attribute if the property is present, but don't set        // it at all otherwise.        String parent = getPropertyValue(namespaceInstance,            PG_NAMESPACE_PROPERTY_PARENTNAMESPACE, String::EMPTY);        if (parent != String::EMPTY)            attributes.insert("parent",parent);        //        // Create the namespace with the retrieved attributes.        //        repository->createNameSpace(newNamespaceName, attributes);        PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4,            "Namespace = " + newNamespaceName.getString() +                " successfully created.");        Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,            "Create Namespace: Shareable = $0, Updates allowed: $1,  Parent: $2",            newNamespaceName.getString(), shareable?                     "true" : "false", shareable? "true" : "false", parent );    }    catch(const CIMException&)    {        PEG_METHOD_EXIT();        throw;    }    catch(const Exception&)    {        PEG_METHOD_EXIT();        throw;    }    return newInstanceReference;}PEGASUS_NAMESPACE_END// END OF FILE

⌨️ 快捷键说明

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