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

📄 cimrepository.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{    PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getClass");    ReadLock lock(_lock);    CIMClass cimClass = _getClass(nameSpace,                                  className,                                  localOnly,                                  includeQualifiers,                                  includeClassOrigin,                                  propertyList);    PEG_METHOD_EXIT();    return cimClass;}CIMClass CIMRepository::_getClass(    const CIMNamespaceName& nameSpace,    const CIMName& className,    Boolean localOnly,    Boolean includeQualifiers,    Boolean includeClassOrigin,    const CIMPropertyList& propertyList){    PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getClass");    PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "nameSpace= " +                     nameSpace.getString() + ", className= " +                     className.getString() +                     ", localOnly= " + _toString(localOnly) +                     ", includeQualifiers= " + _toString(includeQualifiers) +                     ", includeClassOrigin= " + _toString(includeClassOrigin));    String classFilePath;    classFilePath = _nameSpaceManager.getClassFilePath(        nameSpace, className, NameSpaceRead);    CIMClass cimClass;    try    {#ifdef PEGASUS_USE_CLASS_CACHE        // Check the cache first:        if (!_classCache.get(classFilePath, cimClass))        {            // Not in cache so load from disk:            _LoadObject(classFilePath, cimClass, streamer);            // Put in cache:            _classCache.put(classFilePath, cimClass);        }#else /* PEGASUS_USE_CLASS_CACHE */        _LoadObject(classFilePath, cimClass, streamer);#endif /* PEGASUS_USE_CLASS_CACHE */    }    catch (Exception&)    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, className.getString());    }    // Remove properties based on propertylist and localOnly flag (Bug 565)    Boolean propertyListNull = propertyList.isNull();    // if localOnly OR there is a property list, process properties    if ((!propertyListNull) || localOnly)    {        // Loop through properties to remove those that do not filter through        // local only attribute and are not in the property list.        Uint32 count = cimClass.getPropertyCount();        // Work backwards because removal may be cheaper. Sint32 covers count=0        for (Sint32 i = (count - 1); i >= 0; i--)        {            CIMProperty p = cimClass.getProperty(i);            // if localOnly==true, ignore properties defined in super class            if (localOnly && (p.getPropagated()))            {                cimClass.removeProperty(i);                continue;            }            // propertyList NULL means all properties.  PropertyList            // empty, none.            // Test for removal if propertyList not NULL. The empty list option            // is covered by fact that property is not in the list.            if (!propertyListNull)                if (!_containsProperty(p, propertyList))                    cimClass.removeProperty(i);        }    }    // remove methods based on localOnly flag    if (localOnly)    {        Uint32 count = cimClass.getMethodCount();        // Work backwards because removal may be cheaper.        for (Sint32 i = (count - 1); i >= 0; i--)        {            CIMMethod m = cimClass.getMethod(i);            // if localOnly==true, ignore properties defined in super class            if (localOnly && (m.getPropagated()))                cimClass.removeMethod(i);        }    }    // If includequalifiers false, remove all qualifiers from    // properties, methods and parameters.    if (!includeQualifiers)    {        _removeAllQualifiers(cimClass);    }    else    {        // if includequalifiers and localOnly, remove nonLocal qualifiers        if (localOnly)        {            _removePropagatedQualifiers(cimClass);        }    }    // if ClassOrigin Flag false, remove classOrigin info from class object    // by setting the property to Null.    if (!includeClassOrigin)    {        PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,            "Remove Class Origins");        Uint32 propertyCount = cimClass.getPropertyCount();        for (Uint32 i = 0; i < propertyCount ; i++)            cimClass.getProperty(i).setClassOrigin(CIMName());        Uint32 methodCount =  cimClass.getMethodCount();        for (Uint32 i=0; i < methodCount ; i++)            cimClass.getMethod(i).setClassOrigin(CIMName());    }    PEG_METHOD_EXIT();    return cimClass;}Boolean CIMRepository::_checkInstanceAlreadyExists(    const CIMNamespaceName& nameSpace,    const CIMObjectPath& instanceName) const{    PEG_METHOD_ENTER(TRC_REPOSITORY,        "CIMRepository::_checkInstanceAlreadyExists");    //    // Get the names of all superclasses and subclasses of this class    //    Array<CIMName> classNames;    CIMName className = instanceName.getClassName();    classNames.append(className);    _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);    _nameSpaceManager.getSuperClassNames(nameSpace, className, classNames);    //    // Search for an instance with the specified key values    //    for (Uint32 i = 0; i < classNames.size(); i++)    {        CIMObjectPath tmpInstanceName = instanceName;        tmpInstanceName.setClassName(classNames[i]);        String path = _getInstanceIndexFilePath(nameSpace, classNames[i]);        Uint32 index;        Uint32 size;        if (InstanceIndexFile::lookupEntry(path, tmpInstanceName, index, size))        {            PEG_METHOD_EXIT();            return true;        }    }    PEG_METHOD_EXIT();    return false;}CIMInstance CIMRepository::getInstance(    const CIMNamespaceName& nameSpace,    const CIMObjectPath& instanceName,    Boolean localOnly,    Boolean includeQualifiers,    Boolean includeClassOrigin,    const CIMPropertyList& propertyList){    PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getInstance");    ReadLock lock(_lock);    CIMInstance cimInstance = _getInstance(        nameSpace,        instanceName,        localOnly,        includeQualifiers,        includeClassOrigin,        propertyList);    PEG_METHOD_EXIT();    return cimInstance;}CIMInstance CIMRepository::_getInstance(    const CIMNamespaceName& nameSpace,    const CIMObjectPath& instanceName,    Boolean localOnly,    Boolean includeQualifiers,    Boolean includeClassOrigin,    const CIMPropertyList& propertyList){    PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getInstance");    //    // Validate namespace    //    if ((!instanceName.getNameSpace().isNull()) &&        (!instanceName.getNameSpace().equal(nameSpace)))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND,                                       instanceName.toString());    }    if (!_nameSpaceManager.classExists(nameSpace, instanceName.getClassName()))    {        throw PEGASUS_CIM_EXCEPTION(            CIM_ERR_INVALID_CLASS, instanceName.getClassName().getString());    }    //    // Get paths of index and data files:    //    String indexFilePath = _getInstanceIndexFilePath(        nameSpace, instanceName.getClassName());    String dataFilePath = _getInstanceDataFilePath(        nameSpace, instanceName.getClassName());    //    // Get the index for this instance:    //    Uint32 index;    Uint32 size;    if (!InstanceIndexFile::lookupEntry(            indexFilePath, instanceName, index, size))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());    }    //    // Load the instance from file:    //    CIMInstance cimInstance;    if (!_loadInstance(dataFilePath, cimInstance, index, size))    {        PEG_METHOD_EXIT();        throw CannotOpenFile(dataFilePath);    }    //    // Resolve the instance (if requested):    //    if (_resolveInstance)    {        CIMConstClass cimClass;        Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,            true);    }    _filterInstance(        cimInstance,        propertyList,        localOnly,        includeQualifiers,        includeClassOrigin);    PEG_METHOD_EXIT();    return cimInstance;}void CIMRepository::deleteClass(    const CIMNamespaceName& nameSpace,    const CIMName& className){    PEG_METHOD_ENTER(TRC_REPOSITORY,"CIMRepository::deleteClass");    WriteLock lock(_lock);    AutoFileLock fileLock(_lockFile);    //    // Get the class and check to see if it is an association class:    //    CIMClass cimClass = _getClass(        nameSpace, className, false, true, false, CIMPropertyList());    Boolean isAssociation = cimClass.isAssociation();    //    // Delete the class. The NameSpaceManager::deleteClass() method throws    // an exception if the class has subclasses.    //    try    {#ifdef PEGASUS_USE_CLASS_CACHE        _classCache.evict(_nameSpaceManager.getClassFilePath(            nameSpace, className, NameSpaceRead));#endif /* PEGASUS_USE_CLASS_CACHE */        _nameSpaceManager.deleteClass(nameSpace, className);    }    catch (const CIMException&)    {        PEG_METHOD_EXIT();        throw;    }    //    // Remove associations:    //    if (isAssociation)    {        Array<String> assocFileName =            _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceDelete);        if (FileSystem::exists(assocFileName[0]))            AssocClassTable::deleteAssociation(assocFileName[0], className);    }    PEG_METHOD_EXIT();}void _CompactInstanceRepository(    const String& indexFilePath,    const String& dataFilePath){    PEG_METHOD_ENTER(TRC_REPOSITORY,        "CIMRepository::_CompactInstanceRepository");    //    // Compact the data file first:    //    Array<Uint32> freeFlags;    Array<Uint32> indices;    Array<Uint32> sizes;    Array<CIMObjectPath> instanceNames;    if (!InstanceIndexFile::enumerateEntries(            indexFilePath, freeFlags, indices, sizes, instanceNames, true))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,            MessageLoaderParms("Repository.CIMRepository.COMPACT_FAILED",                "compact failed"));    }    if (!InstanceDataFile::compact(dataFilePath, freeFlags, indices, sizes))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,            MessageLoaderParms("Repository.CIMRepository.COMPACT_FAILED",                "compact failed"));    }    //    // Now compact the index file:    //    if (!InstanceIndexFile::compact(indexFilePath))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,            MessageLoaderParms("Repository.CIMRepository.COMPACT_FAILED",                "compact failed"));    }    PEG_METHOD_EXIT();}void CIMRepository::deleteInstance(    const CIMNamespaceName& nameSpace,    const CIMObjectPath& instanceName){    PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteInstance");    //    // Validate namespace    //    if ((!instanceName.getNameSpace().isNull()) &&        (!instanceName.getNameSpace().equal(nameSpace)))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(            CIM_ERR_NOT_FOUND, instanceName.toString());    }    WriteLock lock(_lock);    AutoFileLock fileLock(_lockFile);    String errMessage;    //    // Get paths of index and data files:    //    String indexFilePath = _getInstanceIndexFilePath(        nameSpace, instanceName.getClassName());    String dataFilePath = _getInstanceDataFilePath(

⌨️ 快捷键说明

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