📄 cimsubcommand.cpp
字号:
if (_operationType == OPERATION_TYPE_UNINITIALIZED) { // // The command was not initialized // return 1; } else if (_operationType == OPERATION_TYPE_HELP) { errPrintWriter << usage << endl; return (RC_SUCCESS); } else if (_operationType == OPERATION_TYPE_VERSION) { errPrintWriter << "Version " << PEGASUS_PRODUCT_VERSION << endl; return (RC_SUCCESS); } try { // Construct the CIMClient and set to request server messages // in the default language of this client process. _client.reset(new CIMClient); _client->setRequestDefaultLanguages(); } catch (Exception & e) { errPrintWriter << e.getMessage() << endl; return (RC_ERROR); } try { // // Open connection with CIMSever // _client->connectLocal(); } catch (const Exception&) { errPrintWriter << localizeMessage(MSG_PATH, CIMOM_NOT_RUNNING_KEY, CIMOM_NOT_RUNNING) << endl; return (RC_CONNECTION_FAILED); } // // Perform the requested operation // try { CIMNamespaceName subscriptionNS; CIMNamespaceName filterNS = CIMNamespaceName(); CIMNamespaceName handlerNS = CIMNamespaceName(); if (_subscriptionNamespace != String::EMPTY) { subscriptionNS = _subscriptionNamespace; } if (_filterNamespace != String::EMPTY) { filterNS = _filterNamespace; } if (_handlerNamespace != String::EMPTY) { handlerNS = _handlerNamespace; } switch (_operationType) { case OPERATION_TYPE_ENABLE: return(_findAndModifyState(STATE_ENABLED, subscriptionNS, _filterName, filterNS, _handlerName, handlerNS, _handlerCreationClass, outPrintWriter)); case OPERATION_TYPE_DISABLE: return (_findAndModifyState(STATE_DISABLED, subscriptionNS, _filterName, filterNS, _handlerName, handlerNS, _handlerCreationClass, outPrintWriter)); case OPERATION_TYPE_LIST: if (_operationArg == ARG_SUBSCRIPTIONS) { if (subscriptionNS.isNull()) { _getAllNamespaces(namespaceNames); } else { namespaceNames.append(subscriptionNS); } _listSubscriptions(namespaceNames, _filterName, filterNS, _handlerName, handlerNS, _handlerCreationClass, _verbose, outPrintWriter, errPrintWriter); } else if (_operationArg == ARG_FILTERS) { if (filterNS.isNull()) { _getAllNamespaces(namespaceNames); } else { namespaceNames.append(filterNS); } _listFilters(_filterName, _verbose, namespaceNames, outPrintWriter, errPrintWriter); } else if (_operationArg == ARG_HANDLERS) { if (handlerNS.isNull()) { _getAllNamespaces(namespaceNames); } else { namespaceNames.append(handlerNS); } _listHandlers(_handlerName, namespaceNames, _handlerCreationClass, _verbose, outPrintWriter, errPrintWriter); } break; case OPERATION_TYPE_REMOVE: if ((_operationArg == ARG_SUBSCRIPTIONS) || (_operationArg == ARG_ALL)) { Boolean removeAll = false; if (_operationArg == ARG_ALL) { removeAll = true; } return _removeSubscription(subscriptionNS, _filterName, filterNS, _handlerName, handlerNS, _handlerCreationClass, removeAll, outPrintWriter, errPrintWriter); } else if (_operationArg == ARG_FILTERS) { return (_removeFilter(_filterName, filterNS, outPrintWriter, errPrintWriter)); } else { PEGASUS_ASSERT (_operationArg == ARG_HANDLERS); return _removeHandler(_handlerName, handlerNS, _handlerCreationClass, outPrintWriter, errPrintWriter); } break; default: PEGASUS_ASSERT(0); break; } } catch (CIMException& e) { CIMStatusCode code = e.getCode(); if (code == CIM_ERR_NOT_FOUND) { errPrintWriter << e.getMessage() << endl; return RC_OBJECT_NOT_FOUND; } else if (code == CIM_ERR_INVALID_NAMESPACE) { errPrintWriter << e.getMessage() << endl; return RC_NAMESPACE_NONEXISTENT; } else if (code == CIM_ERR_NOT_SUPPORTED) { errPrintWriter << e.getMessage() << endl; return RC_OPERATION_NOT_SUPPORTED; } else if (code == CIM_ERR_ACCESS_DENIED) { errPrintWriter << e.getMessage() << endl; return RC_ACCESS_DENIED; } else { errPrintWriter << e.getMessage() << endl; } return (RC_ERROR); } catch (ConnectionTimeoutException& e) { errPrintWriter << e.getMessage() << endl; return (RC_CONNECTION_TIMEOUT); } catch (Exception& e) { errPrintWriter << e.getMessage() << endl; return (RC_ERROR); } return (RC_SUCCESS);}//// parse the filter option string//void CIMSubCommand::_parseFilterName( const String& filterNameString, String& filterName, String& filterNamespace){ Uint32 nsDelimiterIndex = filterNameString.find( DELIMITER_NAMESPACE); if (nsDelimiterIndex == PEG_NOT_FOUND) { filterName = filterNameString; filterNamespace.clear(); } else { if((nsDelimiterIndex == 0 ) || ((nsDelimiterIndex + 1) == filterNameString.size())) { // Invalid - either no name or no class throw InvalidOptionArgumentException( filterNameString, OPTION_FILTER); } // Parse the filter namespace and filter name filterNamespace = filterNameString.subString(0, nsDelimiterIndex); filterName = filterNameString.subString( nsDelimiterIndex+1); }}//// parse the handler option string//void CIMSubCommand::_parseHandlerName( const String& handlerString, String& handlerName, String& handlerNamespace, String& handlerCreationClass){ Uint32 nsDelimiterIndex = handlerString.find ( DELIMITER_NAMESPACE); if (nsDelimiterIndex == PEG_NOT_FOUND) { // // handler namespace was not found // handlerNamespace.clear(); // // Check for handler class // Uint32 classDelimiterIndex = handlerString.find ( DELIMITER_HANDLER_CLASS); if (classDelimiterIndex == PEG_NOT_FOUND) { handlerName = handlerString; } else { // // Parse creation class and handler name // if ((classDelimiterIndex == 0) || ((classDelimiterIndex + 1) == handlerString.size())) { // Invalid - either no name or no class throw InvalidOptionArgumentException( handlerString, OPTION_HANDLER); } handlerCreationClass = handlerString.subString (0, classDelimiterIndex); handlerName = handlerString.subString( classDelimiterIndex+1); } } else { // // handler namespace was found // // Parse the handler namespace and handler name handlerNamespace = handlerString.subString(0, nsDelimiterIndex); if ((nsDelimiterIndex == 0) || ((nsDelimiterIndex + 1) == handlerString.size())) { // Invalid - either no name or no class throw InvalidOptionArgumentException( handlerString, OPTION_HANDLER); } Uint32 classDelimiterIndex = handlerString.find ( DELIMITER_HANDLER_CLASS); if (classDelimiterIndex == PEG_NOT_FOUND) { // No creation class specified, just the handler name handlerName = handlerString.subString(nsDelimiterIndex+1); } else { if ((nsDelimiterIndex + 1 ) == classDelimiterIndex) { // Invalid - no class throw InvalidOptionArgumentException( handlerString, OPTION_HANDLER); } if ((classDelimiterIndex + 1) == handlerString.size()) { // Invalid - no name throw InvalidOptionArgumentException( handlerString, OPTION_HANDLER); } // Parse the handler class and name String nameSubstring = handlerString.subString( nsDelimiterIndex+1); Uint32 slen = classDelimiterIndex - nsDelimiterIndex - 1; handlerCreationClass = handlerString.subString(nsDelimiterIndex+1, slen); handlerName = handlerString.subString( classDelimiterIndex+1); } }}//// remove an existing subscription instance//Uint32 CIMSubCommand::_removeSubscription( const CIMNamespaceName& subscriptionNamespace, const String& filterName, const CIMNamespaceName& filterNamespace, const String& handlerName, const CIMNamespaceName& handlerNamespace, const String& handlerCreationClass, const Boolean removeAll, ostream& outPrintWriter, ostream& errPrintWriter){ CIMObjectPath subPathFound; CIMNamespaceName filterNS; CIMNamespaceName handlerNS; CIMNamespaceName subscriptionNS = _DEFAULT_SUBSCRIPTION_NAMESPACE; if (!subscriptionNamespace.isNull()) { subscriptionNS = subscriptionNamespace; } if (!filterNamespace.isNull()) { filterNS = filterNamespace; } else { filterNS = subscriptionNS; } if (!handlerNamespace.isNull()) { handlerNS = handlerNamespace; } else { handlerNS = subscriptionNS; } if (_findSubscription(subscriptionNS, filterName, filterNS, handlerName, handlerNS, handlerCreationClass, subPathFound)) { if (!removeAll) { _client->deleteInstance(subscriptionNS, subPathFound); } else { // Delete subscription, filter and handler CIMObjectPath filterRef, handlerRef; // // Get the subscription Filter and Handler ObjectPaths // Array<CIMKeyBinding> keys = subPathFound.getKeyBindings(); for( Uint32 j=0; j < keys.size(); j++) { if (keys[j].getName().equal(PEGASUS_PROPERTYNAME_FILTER)) { filterRef = keys[j].getValue(); } if (keys[j].getName().equal(PEGASUS_PROPERTYNAME_HANDLER)) { handlerRef = keys[j].getValue(); } } _client->deleteInstance(subscriptionNS, subPathFound); _client->deleteInstance(filterNS, filterRef); _client->deleteInstance(handlerNS, handlerRef); } return (RC_SUCCESS); } else { outPrintWriter << localizeMessage(MSG_PATH, SUBSCRIPTION_NOT_FOUND_KEY, SUBSCRIPTION_NOT_FOUND_FAILURE) << endl; return (RC_OBJECT_NOT_FOUND); }}//// remove an existing filter instance
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -