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

📄 cimrepository.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        nameSpace, instanceName.getClassName());    //    // Perform the operation in a transaction scope to enable rollback on    // failure.    //    InstanceTransactionHandler transaction(indexFilePath, dataFilePath);    //    // Lookup instance from the index file (raise error if not found).    //    Uint32 index;    Uint32 size;    if (!InstanceIndexFile::lookupEntry(            indexFilePath, instanceName, index, size))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());    }    //    // Remove entry from index file.    //    Uint32 freeCount;    if (!InstanceIndexFile::deleteEntry(indexFilePath, instanceName, freeCount))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,            MessageLoaderParms(                "Repository.CIMRepository.FAILED_TO_DELETE_INSTANCE",                "Failed to delete instance: $0",                instanceName.toString()));    }    transaction.complete();    //    // Compact the index and data files if the free count max was    // reached.    //    if (freeCount == _MAX_FREE_COUNT)        _CompactInstanceRepository(indexFilePath, dataFilePath);    //    // Delete from assocation table (if an assocation).    //    String assocFileName = _nameSpaceManager.getAssocInstPath(nameSpace);    if (FileSystem::exists(assocFileName))        AssocInstTable::deleteAssociation(assocFileName, instanceName);    PEG_METHOD_EXIT();}void CIMRepository::_createAssocClassEntries(    const CIMNamespaceName& nameSpace,    const CIMConstClass& assocClass){    PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createAssocClassEntries");    // Open input file:    Array<String> assocFileName =        _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceWrite);    ofstream os;    if (!OpenAppend(os, assocFileName[0]))    {        PEG_METHOD_EXIT();        throw CannotOpenFile(assocFileName[0]);    }    // Get the association's class name:    CIMName assocClassName = assocClass.getClassName();    // For each property:    Uint32 n = assocClass.getPropertyCount();    for (Uint32 i = 0; i < n; i++)    {        CIMConstProperty fromProp = assocClass.getProperty(i);        if (fromProp.getType() == CIMTYPE_REFERENCE)        {            for (Uint32 j = 0; j < n; j++)            {                CIMConstProperty toProp = assocClass.getProperty(j);                if (toProp.getType() == CIMTYPE_REFERENCE &&                    (!fromProp.getName().equal (toProp.getName())))                {                    CIMName fromClassName = fromProp.getReferenceClassName();                    CIMName fromPropertyName = fromProp.getName();                    CIMName toClassName = toProp.getReferenceClassName();                    CIMName toPropertyName = toProp.getName();                    AssocClassTable::append(                        os,                        assocFileName[0],                        assocClassName,                        fromClassName,                        fromPropertyName,                        toClassName,                        toPropertyName);                }            }        }    }    PEG_METHOD_EXIT();}void CIMRepository::createClass(    const CIMNamespaceName& nameSpace,    const CIMClass& newClass,    const ContentLanguageList& contentLangs){    PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createClass");    WriteLock lock(_lock);    AutoFileLock fileLock(_lockFile);    _createClass(nameSpace, newClass);    PEG_METHOD_EXIT();}void CIMRepository::_createClass(    const CIMNamespaceName& nameSpace,    const CIMClass& newClass){    PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createClass");    // -- Resolve the class:        CIMClass cimClass(newClass);    Resolver::resolveClass (cimClass, _context, nameSpace);    // -- If an association, populate associations file:    if (cimClass.isAssociation())        _createAssocClassEntries(nameSpace, cimClass);    // -- Create namespace manager entry:    String classFilePath;    _nameSpaceManager.createClass(nameSpace, cimClass.getClassName(),        cimClass.getSuperClassName(), classFilePath);    // -- Create the class file:    Buffer classXml;    streamer->encode(classXml, cimClass);    //XmlWriter::appendClassElement(classXml, cimClass);    _SaveObject(classFilePath, classXml,streamer);    PEG_METHOD_EXIT();}/*------------------------------------------------------------------------------    This routine does the following:        1.  Creates two entries in the association file for each relationship            formed by this new assocation instance. A binary association            (one with two references) ties two instances together. Suppose            there are two instances: I1 and I2. Then two entries are created:                I2 -> I1                I1 -> I2            For a ternary relationship, six entries will be created. Suppose            there are three instances: I1, I2, and I3:                I1 -> I2                I1 -> I3                I2 -> I1                I2 -> I3                I3 -> I1                I3 -> I2            So for an N-ary relationship, there will be 2*N entries created.        2.  Verifies that the association instance refers to real objects.            (note that an association reference may refer to either an instance            or a class). Throws an exception if one of the references does not            refer to a valid object.------------------------------------------------------------------------------*/void CIMRepository::_createAssocInstEntries(    const CIMNamespaceName& nameSpace,    const CIMConstClass& cimClass,    const CIMInstance& cimInstance,    const CIMObjectPath& instanceName){    PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createAssocInstEntries");    // Open input file:    String assocFileName = _nameSpaceManager.getAssocInstPath(nameSpace);    ofstream os;    if (!OpenAppend(os, assocFileName))    {        PEG_METHOD_EXIT();        throw CannotOpenFile(assocFileName);    }    // Get the association's instance name and class name:    String assocInstanceName = instanceName.toString();    CIMName assocClassName = instanceName.getClassName();    // For each property:    for (Uint32 i = 0, n = cimInstance.getPropertyCount(); i < n; i++)    {        CIMConstProperty fromProp = cimInstance.getProperty(i);        // If a reference property:        if (fromProp.getType() == CIMTYPE_REFERENCE)        {            // For each property:            for (Uint32 j = 0, n = cimInstance.getPropertyCount(); j < n; j++)            {                CIMConstProperty toProp = cimInstance.getProperty(j);                // If a reference property and not the same property:                if (toProp.getType() == CIMTYPE_REFERENCE &&                    (!fromProp.getName().equal (toProp.getName())))                {                    CIMObjectPath fromRef;                    fromProp.getValue().get(fromRef);                    CIMObjectPath toRef;                    toProp.getValue().get(toRef);                    // Fix for bugzilla 667:                    // Strip off the hostname if it is the same as the                    // local host                    if ((fromRef.getHost() != String::EMPTY) &&                        (System::isLocalHost(fromRef.getHost())))                    {                        PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,                            "_createAssocInstEntries() - Stripping off local "                                "hostName from fromRef");                       fromRef.setHost(String::EMPTY);                    }                    // Strip off the namespace when it is the same as the                    // one this instance is created in.                    if ((fromRef.getHost() == String::EMPTY) &&                        (fromRef.getNameSpace() == nameSpace))                    {                        PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,                            "_createAssocInstEntries() - Stripping off "                                "local nameSpace from fromRef");                        fromRef.setNameSpace(CIMNamespaceName());                    }                    // Strip off the hostname if it is the same as the                    // local host                    if ((toRef.getHost() != String::EMPTY) &&                        (System::isLocalHost(toRef.getHost())))                    {                        PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,                            "_createAssocInstEntries() - Stripping off "                                "local hostName from toRef");                        toRef.setHost(String::EMPTY);                    }                    // Strip off the namespace when it is the same as the                    // one this instance is created in.                    if ((toRef.getHost() == String::EMPTY) &&                        (toRef.getNameSpace() == nameSpace))                    {                       PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,                           "_createAssocInstEntries() - Stripping off "                               "local nameSpace from toRef");                       toRef.setNameSpace(CIMNamespaceName());                    }                    String fromObjectName = fromRef.toString();                    CIMName fromClassName = fromRef.getClassName();                    CIMName fromPropertyName = fromProp.getName();                    String toObjectName = toRef.toString();                    CIMName toClassName = toRef.getClassName();                    CIMName toPropertyName = toProp.getName();                    AssocInstTable::append(                        os,                        assocInstanceName,                        assocClassName,                        fromObjectName,                        fromClassName,                        fromPropertyName,                        toObjectName,                        toClassName,                        toPropertyName);                }            }        }    }    PEG_METHOD_EXIT();}CIMObjectPath CIMRepository::createInstance(    const CIMNamespaceName& nameSpace,    const CIMInstance& newInstance,    const ContentLanguageList& contentLangs){    PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createInstance");    WriteLock lock(_lock);    AutoFileLock fileLock(_lockFile);    CIMObjectPath instanceName = _createInstance(nameSpace, newInstance);    PEG_METHOD_EXIT();    return instanceName;}CIMObjectPath CIMRepository::_createInstance(    const CIMNamespaceName& nameSpace,    const CIMInstance& newInstance){    PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createInstance");    String errMessage;    //    // Resolve the instance. Looks up class and fills out properties but    // not the qualifiers.    //    CIMInstance cimInstance(newInstance);    CIMConstClass cimClass;    Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,        false);    CIMObjectPath instanceName = cimInstance.buildPath(cimClass);    //    // Make sure the class has keys (otherwise it will be impossible to    // create the instance).    //    if (!cimClass.hasKeys())    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,            MessageLoaderParms("Repository.CIMRepository.CLASS_HAS_NO_KEYS",                "class has no keys: $0",                cimClass.getClassName().getString()));    }    //    // Be sure instance does not already exist:    //    if (_checkInstanceAlreadyExists(nameSpace, instanceName))    {        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS,            instanceName.toString());    }    //    // Create association entries if an association instance.    //    if (cimClass.isAssociation())        _createAssocInstEntries(nameSpace, cimClass, cimInstance, instanceName);    //    // Get paths to data and index files:    //    String indexFilePath = _getInstanceIndexFilePath(        nameSpace, newInstance.getClassName());    String dataFilePath = _getInstanceDataFilePath(        nameSpace, newInstance.getClassName());    //    // Perform the operation in a transaction scope to enable rollback on    // failure.    //    InstanceTransactionHandler transaction(indexFilePath, dataFilePath);    //    // Save instance to file:    //    Uint32 index;    Uint32 size;    {        Buffer data;        streamer->encode(data, cimInstance);        size = data.size();        if (!InstanceDataFile::appendInstance(dataFilePath, data, index))        {            PEG_METHOD_EXIT();            throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,                MessageLoaderParms(                    "Repository.CIMRepository.FAILED_TO_CREATE_INSTANCE",                    "Failed to create instance: $0",                    instanceName.toString()));        }    }

⌨️ 快捷键说明

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