📄 cimsubcommand.cpp
字号:
//Uint32 CIMSubCommand::_removeFilter( const String& filterName, const CIMNamespaceName& filterNamespace, ostream& outPrintWriter, ostream& errPrintWriter){ CIMObjectPath filterPath; CIMNamespaceName filterNS = _DEFAULT_SUBSCRIPTION_NAMESPACE; if (!filterNamespace.isNull()) { filterNS = filterNamespace; } if (_findFilter(filterName, filterNS, errPrintWriter, filterPath)) { _client->deleteInstance(filterNS, filterPath); return (RC_SUCCESS); } else { outPrintWriter << localizeMessage(MSG_PATH, FILTER_NOT_FOUND_KEY, FILTER_NOT_FOUND_FAILURE) << endl; return (RC_OBJECT_NOT_FOUND); }}//// find a filter//Boolean CIMSubCommand::_findFilter( const String& filterName, const CIMNamespaceName& filterNamespace, ostream& errPrintWriter, CIMObjectPath& filterPath){ Array<CIMObjectPath> filterPaths; Boolean status = false; try { filterPaths = _client->enumerateInstanceNames( filterNamespace, PEGASUS_CLASSNAME_INDFILTER); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_CLASS) { return false; } else { throw; } } Uint32 filterCount = filterPaths.size(); if (filterCount > 0) { // find matching indication filter for (Uint32 i = 0; i < filterCount; i++) { CIMObjectPath fPath = filterPaths[i]; Array<CIMKeyBinding> keys = fPath.getKeyBindings(); for(Uint32 j=0; j < keys.size(); j++) { String filterNameValue; if(keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME)) { filterNameValue = keys[j].getValue(); } if (filterNameValue == filterName) { status = true; filterPath = fPath; break; } } } } return status;}//// remove an existing handler instance//Uint32 CIMSubCommand::_removeHandler( const String& handlerName, const CIMNamespaceName& handlerNamespace, const String& handlerCreationClass, ostream& outPrintWriter, ostream& errPrintWriter){ CIMObjectPath handlerPath; CIMNamespaceName handlerNS = _DEFAULT_SUBSCRIPTION_NAMESPACE; if (!handlerNamespace.isNull()) { handlerNS = handlerNamespace; } if (_findHandler(handlerName, handlerNS, handlerCreationClass, errPrintWriter, handlerPath)) { _client->deleteInstance(handlerNS, handlerPath); return (RC_SUCCESS); } else { outPrintWriter << localizeMessage(MSG_PATH, HANDLER_NOT_FOUND_KEY, HANDLER_NOT_FOUND_FAILURE) << endl; return RC_OBJECT_NOT_FOUND; }}//// find a matching handler//Boolean CIMSubCommand::_findHandler( const String& handlerName, const CIMNamespaceName& handlerNamespace, const String& handlerCreationClass, ostream& errPrintWriter, CIMObjectPath& handlerPath){ Array<CIMObjectPath> handlerPaths; String handlerCC = PEGASUS_CLASSNAME_LSTNRDST_CIMXML.getString(); Boolean status = false; if (handlerCreationClass != String::EMPTY) { handlerCC = handlerCreationClass; } try { handlerPaths = _client->enumerateInstanceNames( handlerNamespace, handlerCC); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_CLASS) { return false; } else { throw; } } Uint32 handlerCount = handlerPaths.size(); if (handlerCount > 0) { // find matching indication handler for (Uint32 i = 0; i < handlerCount; i++) { Boolean nameFound = false; CIMObjectPath hPath = handlerPaths[i]; Array<CIMKeyBinding> keys = hPath.getKeyBindings(); for( Uint32 j=0; j < keys.size(); j++) { if (keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME)) { String handlerNameValue = keys[j].getValue(); if (handlerNameValue == handlerName ) { nameFound = true; break; } } } if (nameFound) { status = true; handlerPath = hPath; break; } } } return status;}//// Modify a subscription state//void CIMSubCommand::_modifySubscriptionState( const CIMNamespaceName& subscriptionNS, const CIMObjectPath& targetPath, const Uint16 newState, ostream& outPrintWriter){ Boolean alreadySet = false; CIMInstance targetInstance = _client->getInstance(subscriptionNS, targetPath); Uint32 pos = targetInstance.findProperty ( PEGASUS_PROPERTYNAME_SUBSCRIPTION_STATE); if (pos != PEG_NOT_FOUND) { Uint16 subscriptionState; if (targetInstance.getProperty(pos).getValue().isNull()) { subscriptionState = STATE_UNKNOWN; } else { targetInstance.getProperty(pos).getValue().get (subscriptionState); if (subscriptionState == newState) { if (newState == STATE_ENABLED ) { outPrintWriter << localizeMessage(MSG_PATH, SUBSCRIPTION_ALREADY_ENABLED_KEY, SUBSCRIPTION_ALREADY_ENABLED) << endl; } else { outPrintWriter << localizeMessage(MSG_PATH, SUBSCRIPTION_ALREADY_DISABLED_KEY, SUBSCRIPTION_ALREADY_DISABLED) << endl; } alreadySet = true; } } if (!alreadySet) { targetInstance.getProperty(pos).setValue(newState); Array <CIMName> propertyNames; propertyNames.append(PEGASUS_PROPERTYNAME_SUBSCRIPTION_STATE); CIMPropertyList properties(propertyNames); targetInstance.setPath(targetPath); _client->modifyInstance(subscriptionNS, targetInstance, false, properties); } }}//// find a subscription//Boolean CIMSubCommand::_findSubscription( const CIMNamespaceName& subscriptionNamespace, const String& filterName, const CIMNamespaceName& filterNamespace, const String& handlerName, const CIMNamespaceName& handlerNamespace, const String& handlerCC, CIMObjectPath& subscriptionFound){ Array<CIMObjectPath> subscriptionPaths; String handlerCreationClass = PEGASUS_CLASSNAME_LSTNRDST_CIMXML.getString(); if (handlerCC != String::EMPTY) { handlerCreationClass = handlerCC; } try { subscriptionPaths = _client->enumerateInstanceNames( subscriptionNamespace, PEGASUS_CLASSNAME_INDSUBSCRIPTION); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_CLASS) { return false; } else { throw; } } Uint32 subscriptionCount = subscriptionPaths.size(); if (subscriptionCount > 0) { String handlerNameString, filterNameString; CIMNamespaceName handlerNS, filterNS; // Search the indication subscriptions instances for (Uint32 i = 0; i < subscriptionCount; i++) { CIMObjectPath subPath = subscriptionPaths[i]; CIMObjectPath filterRef; if (_filterMatches(subPath, subscriptionNamespace, filterName, filterNamespace, filterNS, filterRef)) { CIMObjectPath handlerRef; if(_handlerMatches(subPath, subscriptionNamespace, handlerName, handlerNamespace, handlerCreationClass, handlerNS, handlerRef)) { subscriptionFound = subPath; return true; } } } } return false;}//// Find a subscription and modify it's state//Uint32 CIMSubCommand::_findAndModifyState( const Uint16 newState, const CIMNamespaceName& subscriptionNamespace, const String& filterName, const CIMNamespaceName& filterNamespace, const String& handlerName, const CIMNamespaceName& handlerNamespace, const String& handlerCreationClass, ostream& outPrintWriter){ CIMObjectPath subscriptionFound; 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; } // Find subscriptions in the namespace specified by the user if (_findSubscription(subscriptionNS, filterName, filterNS, handlerName, handlerNS, handlerCreationClass, subscriptionFound)) { _modifySubscriptionState(subscriptionNS, subscriptionFound, newState, outPrintWriter); return(RC_SUCCESS); } else { outPrintWriter << localizeMessage(MSG_PATH, SUBSCRIPTION_NOT_FOUND_KEY, SUBSCRIPTION_NOT_FOUND_FAILURE) << endl; return(RC_OBJECT_NOT_FOUND); }}//// Get the name from a CIMObjectPath//String CIMSubCommand::_getNameInKey(const CIMObjectPath& r){ String nameValue; Array<CIMKeyBinding> keys = r.getKeyBindings(); for (Uint32 j=0; j < keys.size(); j++) { if (keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME)) { nameValue = keys[j].getValue(); } } return (nameValue);}//// Get all namespaces////void CIMSubCommand::_getAllNamespaces( Array<CIMNamespaceName>& namespaceNames){ Array<CIMObjectPath> instanceNames = _client->enumerateInstanceNames( PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_CIMNAMESPACE); // for all new elements in the output array for (Uint32 i = 0; i < instanceNames.size(); i++) { Array<CIMKeyBinding> keys = instanceNames[i].getKeyBindings(); for (Uint32 j=0; j < keys.size(); j++) { if (keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME)) { namespaceNames.append(keys[j].getValue()); } } }}//// get a list of all Handlers in the specified namespace(s)//void CIMSubCommand::_listHandlers( const String& handlerName, const Array<CIMNamespaceName>& namespaceNames, const String& handlerCreationClass, const Boolean verbose, ostream& outPrintWriter, ostream& errPrintWriter){ Array <Uint32> maxColumnWidth; Array <ListColumnEntry> listOutputTable; Array<String> handlersFound; Array<String> destinationsFound; Array<CIMInstance> instancesFound; Array<Uint32> handlerTypesFound; const String handlerTitle = "HANDLER"; const String destinationTitle = "DESTINATION"; if (!verbose) { handlersFound.append(handlerTitle);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -