📄 cimrepository.cpp
字号:
if (!includeClassOrigin) { _removeClassOrigins(cimInstance); }}//////////////////////////////////////////////////////////////////////////////////// _LoadObject()//// Loads objects (classes and qualifiers) from disk to// memory objects.//////////////////////////////////////////////////////////////////////////////////template<class Object>void _LoadObject( const String& path, Object& object, ObjectStreamer* streamer){ PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_LoadObject"); // Get the real path of the file: String realPath; if (!FileSystem::existsNoCase(path, realPath)) { String traceString = path + " does not exist."; PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, traceString); PEG_METHOD_EXIT(); throw CannotOpenFile(path); } PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "realpath = " + realPath); // Load file into memory: Buffer data; _LoadFileToMemory(data, realPath); // PEP214 data.append('\0'); streamer->decode(data, 0, object); //XmlParser parser((char*)data.getData()); //XmlReader::getObject(parser, object); PEG_METHOD_EXIT();}//////////////////////////////////////////////////////////////////////////////////// _SaveObject()//// Saves objects (classes and qualifiers) from memory to// disk files.//////////////////////////////////////////////////////////////////////////////////void _SaveObject( const String& path, Buffer& objectXml, ObjectStreamer* streamer){ PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_SaveObject");#ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY if (compressMode) // PEP214 { PEGASUS_STD(ostringstream) os; streamer->write(os, objectXml); string str = os.str(); gzFile fp = gzopen(path.getCString(), "wb"); if (fp == NULL) throw CannotOpenFile(path); const char* ptr = str.data(); size_t rem = str.size(); int n; while (rem > 0 && (n = gzwrite(fp, (char*)ptr, rem)) > 0) { ptr += n; rem -= n; } gzclose(fp); } else#endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */ { PEGASUS_STD(ofstream) os(path.getCString() PEGASUS_IOS_BINARY); if (!os) { PEG_METHOD_EXIT(); throw CannotOpenFile(path); } streamer->write(os, objectXml); } PEG_METHOD_EXIT();}//////////////////////////////////////////////////////////////////////////////////// _beginInstanceTransaction()//// Creates rollback files to allow an incomplete transaction to be voided.//////////////////////////////////////////////////////////////////////////////////void _beginInstanceTransaction( const String& indexFilePath, const String& dataFilePath){ PEG_METHOD_ENTER(TRC_REPOSITORY, "_beginInstanceTransaction"); // // Begin the transaction (an incomplete transaction will cause // a rollback the next time an instance-oriented routine is invoked). // if (!InstanceIndexFile::beginTransaction(indexFilePath)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED", "begin failed")); } if (!InstanceDataFile::beginTransaction(dataFilePath)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED", "begin failed")); } PEG_METHOD_EXIT();}//////////////////////////////////////////////////////////////////////////////////// _commitInstanceTransaction()//// Removes the rollback files to complete the transaction.//////////////////////////////////////////////////////////////////////////////////void _commitInstanceTransaction( const String& indexFilePath, const String& dataFilePath){ PEG_METHOD_ENTER(TRC_REPOSITORY, "_commitInstanceTransaction"); // // Commit the transaction by removing the rollback files. // if (!InstanceIndexFile::commitTransaction(indexFilePath)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED", "commit failed")); } if (!InstanceDataFile::commitTransaction(dataFilePath)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED", "commit failed")); } PEG_METHOD_EXIT();}//////////////////////////////////////////////////////////////////////////////////// _rollbackInstanceTransaction()//// Restores instance index and data files to void an incomplete operation.// If there are no rollback files, this method has no effect.//////////////////////////////////////////////////////////////////////////////////void _rollbackInstanceTransaction( const String& indexFilePath, const String& dataFilePath){ PEG_METHOD_ENTER(TRC_REPOSITORY, "_rollbackInstanceTransaction"); if (!InstanceIndexFile::rollbackTransaction(indexFilePath)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.ROLLBACK_FAILED", "rollback failed")); } if (!InstanceDataFile::rollbackTransaction(dataFilePath)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( "Repository.CIMRepository.ROLLBACK_FAILED", "rollback failed")); } PEG_METHOD_EXIT();}//////////////////////////////////////////////////////////////////////////////////// InstanceTransactionHandler//// This class is used to manage a repository instance transaction. The// transaction is started when the class is instantiated, committed when// the complete() method is called, and rolled back if the destructor is// called without a prior call to complete().//// The appropriate repository write locks must be owned while an// InstanceTransactionHandler instance exists.//////////////////////////////////////////////////////////////////////////////////class InstanceTransactionHandler{public: InstanceTransactionHandler( const String& indexFilePath, const String& dataFilePath) : _indexFilePath(indexFilePath), _dataFilePath(dataFilePath), _isComplete(false) { _rollbackInstanceTransaction(_indexFilePath, _dataFilePath); _beginInstanceTransaction(_indexFilePath, _dataFilePath); } ~InstanceTransactionHandler() { if (!_isComplete) { _rollbackInstanceTransaction(_indexFilePath, _dataFilePath); } } void complete() { _commitInstanceTransaction(_indexFilePath, _dataFilePath); _isComplete = true; }private: String _indexFilePath; String _dataFilePath; Boolean _isComplete;};//////////////////////////////////////////////////////////////////////////////////// CIMRepository::_rollbackIncompleteTransactions()//// Searches for incomplete instance transactions for all classes in all// namespaces. Restores instance index and data files to void an// incomplete operation. If no incomplete instance transactions are// outstanding, this method has no effect.//////////////////////////////////////////////////////////////////////////////////void CIMRepository::_rollbackIncompleteTransactions(){ PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_rollbackIncompleteTransactions"); WriteLock lock(_lock); AutoFileLock fileLock(_lockFile); Array<CIMNamespaceName> namespaceNames; _nameSpaceManager.getNameSpaceNames(namespaceNames); for (Uint32 i = 0; i < namespaceNames.size(); i++) { Array<CIMName> classNames; _nameSpaceManager.getSubClassNames( namespaceNames[i], CIMName(), true, classNames); for (Uint32 j = 0; j < classNames.size(); j++) { // // Get paths of index and data files: // String indexFilePath = _getInstanceIndexFilePath( namespaceNames[i], classNames[j]); String dataFilePath = _getInstanceDataFilePath( namespaceNames[i], classNames[j]); // // Attempt rollback (if there are no rollback files, this will // have no effect). This code is here to rollback uncommitted // changes left over from last time an instance-oriented function // was called. // _rollbackInstanceTransaction(indexFilePath, dataFilePath); } } PEG_METHOD_EXIT();}//////////////////////////////////////////////////////////////////////////////////// CIMRepository//// The following are not implemented://// CIMRepository::execQuery()// CIMRepository::invokeMethod()//// Note that invokeMethod() will not never implemented since it is not// meaningful for a repository.//////////////////////////////////////////////////////////////////////////////////CIMRepository::CIMRepository( const String& repositoryRoot, Uint32 mode) : _repositoryRoot(repositoryRoot), _nameSpaceManager(repositoryRoot), _lock(), _resolveInstance(true){ PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::CIMRepository"); Boolean binaryMode = mode & CIMRepository::MODE_BIN; if (mode == CIMRepository::MODE_DEFAULT) { binaryMode = ConfigManager::parseBooleanValue( ConfigManager::getInstance()->getCurrentValue( "enableBinaryRepository")); }#ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY // PEP214 // FUTURE?? - compressMode = mode & CIMRepository::MODE_COMPRESSED; compressMode=1; char* s = getenv("PEGASUS_ENABLE_COMPRESSED_REPOSITORY"); if (s && (strcmp(s, "build_non_compressed") == 0)) { compressMode =0;#ifdef TEST_OUTPUT cout << "In Compress mode: build_non_compresed found" << endl;#endif /* TEST_OUTPUT */ }#endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */#ifdef TEST_OUTPUT cout << "repositoryRoot = " << repositoryRoot << endl; cout << "CIMRepository: binaryMode=" << binaryMode << ", mode=" << mode << endl; cout << "CIMRepository: compressMode= " << compressMode << endl;#endif /* TEST_OUTPUT */ if (binaryMode>0) { // BUILD BINARY streamer = new AutoStreamer(new BinaryStreamer(), BINREP_MARKER); ((AutoStreamer*)streamer)->addReader(new XmlStreamer(), 0); } else { // BUILD XML streamer = new AutoStreamer(new XmlStreamer(),0xff); ((AutoStreamer*)streamer)->addReader( new BinaryStreamer(), BINREP_MARKER); ((AutoStreamer*)streamer)->addReader(new XmlStreamer(), 0); } _context = new RepositoryDeclContext(this); _isDefaultInstanceProvider = ConfigManager::parseBooleanValue( ConfigManager::getInstance()->getCurrentValue( "repositoryIsDefaultInstanceProvider")); _lockFile = ConfigManager::getInstance()->getHomedPath( PEGASUS_REPOSITORY_LOCK_FILE).getCString(); _rollbackIncompleteTransactions(); PEG_METHOD_EXIT();}CIMRepository::~CIMRepository(){ PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::~CIMRepository"); delete streamer; delete _context; AssocClassTable::removeCaches(); PEG_METHOD_EXIT();}String _toString(Boolean x){ return(x ? "true" : "false");}CIMClass CIMRepository::getClass( const CIMNamespaceName& nameSpace, const CIMName& className, Boolean localOnly, Boolean includeQualifiers, Boolean includeClassOrigin, const CIMPropertyList& propertyList)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -