void SendIndication(int seqNum, char *UIDbuffer) { CIMInstance indicationInstance (CIMName ("IndicationStressTestClass")); indicationInstance.setPath(path); indicationInstance.addProperty (CIMProperty ("IndicationIdentifier",String(UIDbuffer))); indicationInstance.addProperty (CIMProperty ("CorrelatedIndications", correlatedIndications)); CIMDateTime currentDateTime = CIMDateTime::getCurrentDateTime (); indicationInstance.addProperty (CIMProperty ("IndicationTime", currentDateTime)); indicationInstance.addProperty (CIMProperty ("IndicationSequenceNumber", CIMValue(Uint64(seqNum)))); // cout << "IndicationStressTestProvider instance = " << ((CIMObject)indicationInstance).toString() << endl; _indication_handler->deliver (indicationInstance); return; }
PEGASUS_NAMESPACE_BEGIN // // Given the two references in the association, this function creates an // instance of the PG_ElementConformsToProfile class. // CIMInstance buildElementConformsToProfile( const CIMObjectPath & currentProfile, const CIMObjectPath & currentElement, const CIMClass & elementConformsClass) { Array<CIMName> elementPropArray; elementPropArray.append( ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD); elementPropArray.append( ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT); CIMPropertyList elementPropList(elementPropArray); CIMInstance tmpInstance = elementConformsClass.buildInstance(false, false, elementPropList); setPropertyValue(tmpInstance, ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD, currentProfile); setPropertyValue(tmpInstance, ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT, currentElement); tmpInstance.setPath(tmpInstance.buildPath( elementConformsClass)); return tmpInstance; }
void InstanceProvider::createInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const CIMInstance & instanceObject, ObjectPathResponseHandler & handler) { // Validate the class name if (!instanceObject.getClassName().equal("Sample_InstanceProviderClass")) { throw CIMNotSupportedException( instanceObject.getClassName().getString()); } // Find the key property Uint32 idIndex = instanceObject.findProperty("Identifier"); if (idIndex == PEG_NOT_FOUND) { throw CIMInvalidParameterException("Missing key value"); } CIMInstance cimInstance = instanceObject.clone(); // Create the new instance name CIMValue idValue = instanceObject.getProperty(idIndex).getValue(); Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding("Identifier", idValue)); CIMObjectPath instanceName = CIMObjectPath( String(), CIMNamespaceName(), instanceObject.getClassName(), keys); cimInstance.setPath(instanceName); // Determine whether this instance already exists for(Uint32 i = 0, n = _instances.size(); i < n; i++) { if(instanceName == _instances[i].getPath()) { throw CIMObjectAlreadyExistsException(instanceName.toString()); } } // begin processing the request handler.processing(); // add the new instance to the array _instances.append(cimInstance); // deliver the new instance name handler.deliver(instanceName); // complete processing the request handler.complete(); }
/** Stores a copy of the provided instance locally in the errorInstance class property, and also creates a copy of the instance in the static repository namespace. The instance is then read back out of the repository and compared against the one stored by the class. */ void EmbeddedInstanceProvider::createInstance( const OperationContext& context, const CIMObjectPath& ref, const CIMInstance& obj, ObjectPathResponseHandler& handler) { handler.processing(); errorInstance.reset(new CIMInstance(obj)); Array<CIMName> propNameList; propNameList.append(CIMName("errorKey")); propNameList.append(CIMName("EmbeddedInst")); CIMPropertyList propList(propNameList); CIMClass objClass = cimom.getClass( context, STATIC_REPOSITORY, obj.getClassName(), false, true, false, propList); CIMObjectPath objPath = obj.buildPath(objClass); errorInstance->setPath(objPath); repositoryPath = cimom.createInstance( context, STATIC_REPOSITORY, *errorInstance); CIMInstance repositoryInstance = cimom.getInstance( context, STATIC_REPOSITORY, repositoryPath, false, false, false, propList); repositoryInstance.setPath(repositoryPath); if (!errorInstance->identical(repositoryInstance)) { throw Exception( "Repository instance and local instance for embedded error not " "identical"); } handler.deliver(objPath); handler.complete(); }
static void _inject_object_path( CIMInstance& instance, const CIMObjectPath& objectPath, const char* tag) { Array<CIMKeyBinding> bindings; bindings.append(CIMKeyBinding("Tag", tag, CIMKeyBinding::STRING)); bindings.append(CIMKeyBinding( "CreationClassName", "Benchmark2", CIMKeyBinding::STRING)); instance.setPath(CIMObjectPath( objectPath.getHost(), objectPath.getNameSpace(), "Benchmark2", bindings)); }
void InstanceProvider::modifyInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const CIMInstance & instanceObject, const Boolean includeQualifiers, const CIMPropertyList & propertyList, ResponseHandler & handler) { // convert a potential fully qualified reference into a local reference // (class name and keys only). CIMObjectPath localReference = CIMObjectPath( String(), CIMNamespaceName(), instanceReference.getClassName(), instanceReference.getKeyBindings()); // begin processing the request handler.processing(); // instance index corresponds to reference index for(Uint32 i = 0, n = _instances.size(); i < n; i++) { if(localReference == _instances[i].getPath()) { CIMInstance cimInstance = instanceObject.clone(); CIMObjectPath instanceName = CIMObjectPath( String(), CIMNamespaceName(), instanceReference.getClassName(), instanceReference.getKeyBindings()); cimInstance.setPath(instanceName); // overwrite existing instance _instances[i] = instanceObject; break; } } // complete processing the request handler.complete(); }
Boolean setObjectManagerStatistics(CIMClient & client, Boolean newState) { CIMName gathStatName ("GatherStatisticalData"); Array<CIMInstance> instancesObjectManager; CIMInstance instObjectManager; Uint32 prop_num; Array<CIMName> plA; plA.append(gathStatName); CIMPropertyList statPropertyList(plA); // Create property list that represents correct request // get instance. Get only the gatherstatitistics property instancesObjectManager = client.enumerateInstances(PEGASUS_NAMESPACENAME_INTEROP, "CIM_ObjectManager", true, false, false, false, statPropertyList); PEGASUS_TEST_ASSERT(instancesObjectManager.size() == 1); instObjectManager = instancesObjectManager[0]; // set correct path into instance instObjectManager.setPath(instancesObjectManager[0].getPath()); prop_num = instObjectManager.findProperty(gathStatName); PEGASUS_TEST_ASSERT(prop_num != PEG_NOT_FOUND); instObjectManager.getProperty(prop_num).setValue(CIMValue(newState)); client.modifyInstance(PEGASUS_NAMESPACENAME_INTEROP, instObjectManager, false, statPropertyList); CIMInstance updatedInstance = client.getInstance(PEGASUS_NAMESPACENAME_INTEROP, instObjectManager.getPath(), false, false, false, statPropertyList); prop_num = updatedInstance.findProperty(gathStatName); PEGASUS_TEST_ASSERT(prop_num != PEG_NOT_FOUND); CIMProperty p = updatedInstance.getProperty(prop_num); CIMValue v = p.getValue(); Boolean rtn; v.get(rtn); //// Need to get it again cout << "Updated Status= " << ((rtn)? "true" : "false") << endl; return(rtn); }
int signalIndication(CIMClient& client) { AutoMutex a(*mut); Array<CIMParamValue> inParameters; Array<CIMParamValue> outParameters; try { inParameters.append(CIMParamValue("error", CIMValue(*errorInstance))); client.invokeMethod( TEST_NAMESPACE, errorPath, CIMName("PropagateError"), inParameters, outParameters); if (outParameters.size() != 1) { cout << "Expected to get 1 output parameter from PropagateError. " << "Received " << outParameters.size() << endl; return -1; } CIMInstance outParamInstance; outParameters[0].getValue().get(outParamInstance); outParamInstance.setPath(errorInstance->getPath()); if (!errorInstance->identical(outParamInstance)) { cout << "Output Instance differs from Input Instance" << endl; return -1; } } catch (Exception& e) { cout << "Exception caught during invoke method of PropagateError: " << e.getMessage() << endl; return -1; } return 0; }
void OperatingSystemProvider::enumerateInstances( const OperationContext& context, const CIMObjectPath& ref, const Boolean includeQualifiers, const Boolean includeClassOrigin, const CIMPropertyList& propertyList, InstanceResponseHandler& handler) { CIMName className; CIMInstance instance; CIMObjectPath newref; className = ref.getClassName(); // only return instances when enumerate on our subclass, CIMOM // will call us as natural part of recursing through subtree on // enumerate - if we return instances on enumerate of our superclass, // there would be dups if (className.equal (EXTENDEDOPERATINGSYSTEMCLASS)) { handler.processing(); newref = _fill_reference(ref.getNameSpace(), className); instance = _build_instance(ref); instance.setPath(newref); handler.deliver(instance); handler.complete(); } else if (className.equal (STANDARDOPERATINGSYSTEMCLASS)) { handler.processing(); handler.complete(); } else { throw CIMNotSupportedException("OperatingSystemProvider " "does not support class " + className.getString()); } return; }
void ComputerSystemProvider::enumerateInstances( const OperationContext& context, const CIMObjectPath& ref, const Boolean includeQualifiers, const Boolean includeClassOrigin, const CIMPropertyList& propertyList, InstanceResponseHandler& handler) { CIMName className = ref.getClassName(); _checkClass(className); handler.processing(); // Deliver instance only if request was for leaf class if (className.equal (CLASS_EXTENDED_COMPUTER_SYSTEM)) { Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding( PROPERTY_CREATION_CLASS_NAME, CLASS_EXTENDED_COMPUTER_SYSTEM, CIMKeyBinding::STRING)); keys.append(CIMKeyBinding( PROPERTY_NAME, _cs.getHostName(), CIMKeyBinding::STRING)); CIMObjectPath instanceName( String::EMPTY, // Hostname not required CIMNamespaceName(), // Namespace not required CLASS_EXTENDED_COMPUTER_SYSTEM, keys); CIMInstance instance = _cs.buildInstance(CLASS_EXTENDED_COMPUTER_SYSTEM); instance.setPath(instanceName); handler.deliver(instance); } handler.complete(); return; }
void _generateIndication ( IndicationResponseHandler * handler, const String & identifier) { if (_enabled) { CIMInstance indicationInstance (CIMName ("FailureTestIndication")); CIMObjectPath path; path.setNameSpace ("test/testProvider"); path.setClassName ("FailureTestIndication"); indicationInstance.setPath (path); indicationInstance.addProperty (CIMProperty ("IndicationIdentifier", identifier)); CIMDateTime currentDateTime = CIMDateTime::getCurrentDateTime (); indicationInstance.addProperty (CIMProperty ("IndicationTime", currentDateTime)); Array <String> correlatedIndications; indicationInstance.addProperty (CIMProperty ("CorrelatedIndications", correlatedIndications)); indicationInstance.addProperty (CIMProperty ("Description", String ("Failure Test Indication"))); indicationInstance.addProperty (CIMProperty ("AlertingManagedElement", System::getFullyQualifiedHostName ())); indicationInstance.addProperty (CIMProperty ("AlertingElementFormat", Uint16 (0))); indicationInstance.addProperty (CIMProperty ("AlertType", Uint16 (1))); indicationInstance.addProperty (CIMProperty ("OtherAlertType", String ("Test"))); indicationInstance.addProperty (CIMProperty ("PerceivedSeverity", Uint16 (2))); indicationInstance.addProperty (CIMProperty ("ProbableCause", Uint16 (1))); indicationInstance.addProperty (CIMProperty ("ProbableCauseDescription", String ("Test"))); indicationInstance.addProperty (CIMProperty ("Trending", Uint16 (4))); Array <String> recommendedActions; recommendedActions.append ("Test"); indicationInstance.addProperty (CIMProperty ("RecommendedActions", recommendedActions)); indicationInstance.addProperty (CIMProperty ("EventID", String ("Test"))); CIMDateTime eventTime = CIMDateTime::getCurrentDateTime (); indicationInstance.addProperty (CIMProperty ("EventTime", eventTime)); indicationInstance.addProperty (CIMProperty ("SystemCreationClassName", System::getSystemCreationClassName ())); indicationInstance.addProperty (CIMProperty ("SystemName", System::getFullyQualifiedHostName ())); indicationInstance.addProperty (CIMProperty ("ProviderName", _providerName)); CIMIndication cimIndication (indicationInstance); handler->deliver (cimIndication); } }
void _generateIndication ( IndicationResponseHandler * handler, const CIMName methodName) { if (_enabled) { CIMInstance indicationInstance; if (methodName.equal ("SendTestIndicationSubclass")) { CIMInstance theIndication (CIMName ("RT_TestIndicationSubclass")); indicationInstance = theIndication; } else { CIMInstance theIndication (CIMName ("RT_TestIndication")); indicationInstance = theIndication; } CIMObjectPath path; if (methodName.equal ("SendTestIndicationUnmatchingNamespace")) { // // For SendTestIndicationUnmatchingNamespace, generate an // indication instance with namespace that does not match the // subscription instance name included in the operation context // (nor does it match the namespace for which provider has // registered) // path.setNameSpace ("root/cimv2"); path.setClassName ("RT_TestIndication"); } else if (methodName.equal ("SendTestIndicationUnmatchingClassName")) { // the indication class name and object path class must match indicationInstance = CIMInstance("CIM_AlertIndication"); // // For SendTestIndicationUnmatchingClassName, generate an // indication instance with classname that does not match the // subscription instance name included in the operation context // (nor does it match the classname for which provider has // registered) // path.setNameSpace ("root/SampleProvider"); path.setClassName ("CIM_AlertIndication"); } else if (methodName.equal ("SendTestIndicationSubclass")) { // // For SendTestIndicationSubclass, generate an indication instance // of a the RT_TestIndicationSubclass subclass // path.setNameSpace ("root/SampleProvider"); path.setClassName ("RT_TestIndicationSubclass"); } else { path.setNameSpace("root/SampleProvider"); path.setClassName("RT_TestIndication"); } indicationInstance.setPath(path); char buffer[32]; sprintf(buffer, "%d", _nextUID++); indicationInstance.addProperty (CIMProperty ("IndicationIdentifier",String(buffer))); CIMDateTime currentDateTime = CIMDateTime::getCurrentDateTime (); indicationInstance.addProperty (CIMProperty ("IndicationTime", currentDateTime)); // // For SendTestIndicationMissingProperty, leave out the // CorrelatedIndications property // if (!methodName.equal ("SendTestIndicationMissingProperty")) { Array <String> correlatedIndications; indicationInstance.addProperty (CIMProperty ("CorrelatedIndications", correlatedIndications)); } if ((methodName.equal ("SendTestIndicationNormal")) || (methodName.equal ("SendTestIndicationSubclass")) || (methodName.equal ("SendTestIndicationMissingProperty")) || (methodName.equal ("SendTestIndicationExtraProperty")) || (methodName.equal ("SendTestIndicationMatchingInstance")) || (methodName.equal ("SendTestIndicationUnmatchingNamespace")) || (methodName.equal ("SendTestIndicationUnmatchingClassName"))) { indicationInstance.addProperty (CIMProperty ("MethodName", CIMValue (methodName.getString()))); } else { indicationInstance.addProperty (CIMProperty ("MethodName", CIMValue (String ("generateIndication")))); } // // For SendTestIndicationExtraProperty, add an extra property, // ExtraProperty, that is not a member of the indication class // if (methodName.equal ("SendTestIndicationExtraProperty")) { indicationInstance.addProperty (CIMProperty ("ExtraProperty", CIMValue (String ("extraProperty")))); } CIMIndication cimIndication (indicationInstance); // // For SendTestIndicationSubclass, // SendTestIndicationMatchingInstance, // SendTestIndicationUnmatchingNamespace or // SendTestIndicationUnmatchingClassName, include // SubscriptionInstanceNamesContainer in operation context // if ((methodName.equal ("SendTestIndicationSubclass")) || (methodName.equal ("SendTestIndicationMatchingInstance")) || (methodName.equal ("SendTestIndicationUnmatchingNamespace")) || (methodName.equal ("SendTestIndicationUnmatchingClassName"))) { Array <CIMObjectPath> subscriptionInstanceNames; Array <CIMKeyBinding> subscriptionKeyBindings; String filterString; filterString.append ("CIM_IndicationFilter.CreationClassName=\"CIM_IndicationFilter\",Name=\"PIFilter01\",SystemCreationClassName=\""); filterString.append (System::getSystemCreationClassName ()); filterString.append ("\",SystemName=\""); filterString.append (System::getFullyQualifiedHostName ()); filterString.append ("\""); subscriptionKeyBindings.append (CIMKeyBinding ("Filter", filterString, CIMKeyBinding::REFERENCE)); String handlerString; handlerString.append ("CIM_IndicationHandlerCIMXML.CreationClassName=\"CIM_IndicationHandlerCIMXML\",Name=\"PIHandler01\",SystemCreationClassName=\""); handlerString.append (System::getSystemCreationClassName ()); handlerString.append ("\",SystemName=\""); handlerString.append (System::getFullyQualifiedHostName ()); handlerString.append ("\""); subscriptionKeyBindings.append (CIMKeyBinding ("Handler", handlerString, CIMKeyBinding::REFERENCE)); CIMObjectPath subscriptionPath ("", CIMNamespaceName ("root/PG_InterOp"), CIMName ("CIM_IndicationSubscription"), subscriptionKeyBindings); subscriptionInstanceNames.append (subscriptionPath); OperationContext context; context.insert (SubscriptionInstanceNamesContainer (subscriptionInstanceNames)); handler->deliver (context, indicationInstance); } else { // deliver an indication without trapOid handler->deliver (indicationInstance); } // // Only deliver extra indication with trapOid for SendTestIndication // if ((!methodName.equal ("SendTestIndicationNormal")) && (!methodName.equal ("SendTestIndicationSubclass")) && (!methodName.equal ("SendTestIndicationMissingProperty")) && (!methodName.equal ("SendTestIndicationExtraProperty")) && (!methodName.equal ("SendTestIndicationMatchingInstance")) && (!methodName.equal ("SendTestIndicationUnmatchingNamespace")) && (!methodName.equal ("SendTestIndicationUnmatchingClassName"))) { // deliver another indication with a trapOid which contains in the // operationContext container OperationContext context; // add trap OID to the context context.insert (SnmpTrapOidContainer("1.3.6.1.4.1.900.2.3.9002.9600")); handler->deliver (context, indicationInstance); } } }
int main(int argc, char** argv) { cout << "+++++ testing Client Performance Statistics" << endl; try { // connecting to server CIMClient client; client.connect("localhost", 5988, String::EMPTY, String::EMPTY); // the value CIM_ObjectManager::GatherStatisticalData must be set to // true. the following code does this String className = "CIM_ObjectManager"; CIMName cN = CIMName(className); Boolean loc = true; String gath = "GatherStatisticalData"; CIMName gst = CIMName(gath); CIMValue val = CIMValue(loc); Array<CIMObjectPath> instanceNames; /* EnumerateInstances and */ try { instanceNames = client.enumerateInstanceNames( PEGASUS_NAMESPACENAME_INTEROP, cN); } catch (Exception& e) { cerr << "Exception : " << e.getMessage() << endl; exit(1); } catch (...) { cout << "enumerateInstancesNames in Client/tests/ClientStatistics " "has thrown an exception" << endl; exit(1); } // assert that we received one name PEGASUS_TEST_ASSERT(instanceNames.size() == 1); /* ModifyInstance */ CIMName gathStatName ("GatherStatisticalData"); // variables used with gatherstatistics setting. CIMInstance instObjectManager; Uint32 prop_num; Array<CIMName> plA; plA.append(gathStatName); CIMPropertyList statPropertyList(plA); try { // Create property list that represents correct request // get instance. Get only the gatherstatitistics property instObjectManager = client.getInstance( PEGASUS_NAMESPACENAME_INTEROP, instanceNames[0], true, false, false, statPropertyList); // set correct path into instance instObjectManager.setPath(instanceNames[0]); prop_num = instObjectManager.findProperty(gathStatName); PEGASUS_TEST_ASSERT(prop_num != PEG_NOT_FOUND); instObjectManager.getProperty(prop_num).setValue(CIMValue(true)); client.modifyInstance( PEGASUS_NAMESPACENAME_INTEROP, instObjectManager, false, statPropertyList); } catch (Exception& e) { cerr << "Exception : " << e.getMessage() << endl; exit(1); } //registering class that has the callback method CliStat stat = CliStat(); client.registerClientOpPerformanceDataHandler(stat); String classN = "PG_ComputerSystem"; Array<CIMObjectPath> instance = client.enumerateInstanceNames( PEGASUS_NAMESPACENAME_CIMV2, classN); instObjectManager.getProperty(prop_num).setValue(CIMValue(false)); client.modifyInstance( PEGASUS_NAMESPACENAME_INTEROP, instObjectManager, false, statPropertyList); } catch (Exception& e) { cerr << "Error: " << e.getMessage() << endl; exit(1); } cout << "+++++ passed all tests" << endl; return 0; }
// // Modify instance based on modifiedInstance. // void UserAuthProvider::modifyInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const CIMInstance& modifiedIns, const Boolean includeQualifiers, const CIMPropertyList & propertyList, ResponseHandler & handler) { PEG_METHOD_ENTER(TRC_USER_MANAGER,"UserAuthProvider::modifyInstance"); // // get userName // String user; try { IdentityContainer container = context.get(IdentityContainer::NAME); user= container.getUserName(); } catch (...) { user= String::EMPTY; } // // verify user authorizations // if ( user != String::EMPTY || user != "" ) { _verifyAuthorization(user); } // // check if the class name requested is PG_Authorization // if (!instanceReference.getClassName().equal (CLASS_NAME_PG_AUTHORIZATION)) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION ( CIM_ERR_NOT_SUPPORTED, instanceReference.getClassName().getString()); } CIMInstance newInstance = modifiedIns; // begin processing the request handler.processing(); try { // // Get the user name from the instance // String userNameStr; String namespaceStr; String authorizationStr; Uint32 pos = modifiedIns.findProperty ( PROPERTY_NAME_USERNAME ); CIMProperty prop = (CIMProperty)newInstance.getProperty(pos); prop.getValue().get(userNameStr); // // Get the namespace from the instance // pos = modifiedIns.findProperty ( PROPERTY_NAME_NAMESPACE ); prop = (CIMProperty)newInstance.getProperty(pos); prop.getValue().get(namespaceStr); // // Get the authorization from the instance // pos = modifiedIns.findProperty ( PROPERTY_NAME_AUTHORIZATION ); prop = (CIMProperty)newInstance.getProperty(pos); prop.getValue().get(authorizationStr); // // ATTN: Note that the following is a hack, because // modifyInstance() in repository does not like // the hostname and namespace included in the CIMObjectPath // passed to it as a parameter. // CIMObjectPath ref("", CIMNamespaceName (), modifiedIns.getClassName(), instanceReference.getKeyBindings()); CIMInstance newModifiedIns = modifiedIns.clone (); newModifiedIns.setPath (ref); // // call modifyInstances of the repository // _repository->modifyInstance( instanceReference.getNameSpace(), newModifiedIns); // // set authorization in the UserManager // _userManager->setAuthorization( userNameStr, namespaceStr, authorizationStr ); } catch(Exception& e) { PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage()); } // complete processing the request handler.complete(); PEG_METHOD_EXIT(); return; }
void LifecycleIndicationProvider::createInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const CIMInstance & instanceObject, ObjectPathResponseHandler & handler) { // cout << "LifecycleIndicationProvider::createInstance()" << endl; // Validate the class name if(!instanceObject.getClassName().equal( "Sample_LifecycleIndicationProviderClass")) { throw CIMNotSupportedException( instanceObject.getClassName().getString()); } // Find the key property Uint32 idIndex = instanceObject.findProperty("uniqueId"); if(idIndex == PEG_NOT_FOUND) { throw CIMInvalidParameterException("Missing key value"); } CIMInstance cimInstance = instanceObject.clone(); // Create the new instance name CIMValue idValue = instanceObject.getProperty(idIndex).getValue(); Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding("uniqueId", idValue)); CIMObjectPath instanceName = CIMObjectPath( String(), CIMNamespaceName(), instanceObject.getClassName(), keys); cimInstance.setPath(instanceName); // Determine whether this instance already exists for(Uint32 i = 0, n = _instances.size(); i < n; i++) { if(instanceName == _instances[i].getPath()) { throw CIMObjectAlreadyExistsException(instanceName.toString()); } } // begin processing the request handler.processing(); // add the new instance to the array _instances.append(cimInstance); // deliver the new instance name handler.deliver(instanceName); // complete processing the request handler.complete(); // If there is at least one subscription active for the lifecycle indication // InstCreation_for_Sample_LifecycleIndicationProviderClass, then generate // that indication here, embedding the newly-created instance as // the SourceInstance property. See LifecycleIndicationProviderR.mof. if (_lifecycle_indications_enabled) { CIMInstance indicationInstance( CIMName( "InstCreation_for_Sample_LifecycleIndicationProviderClass")); CIMObjectPath path; path.setNameSpace("root/SampleProvider"); path.setClassName( "InstCreation_for_Sample_LifecycleIndicationProviderClass"); indicationInstance.setPath(path); char buffer[32]; sprintf(buffer, "%d", _nextUID++); indicationInstance.addProperty (CIMProperty ("IndicationIdentifier",String(buffer))); CIMDateTime currentDateTime = CIMDateTime::getCurrentDateTime (); indicationInstance.addProperty (CIMProperty ("IndicationTime", currentDateTime)); indicationInstance.addProperty (CIMProperty ("SourceInstance",CIMObject(cimInstance))); _indication_handler->deliver (indicationInstance); // cout << "LifecycleIndicationProvider::createInstance() sent " // "InstCreation_for_Sample_LifecycleIndicationProviderClass" // << endl; } }
Array<CIMInstance> InteropProvider::getReferencedInstances( const Array<CIMInstance> &refs, const String &targetRole, const OperationContext & context, const CIMPropertyList & propertyList) { PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::getReferencedObjects"); Array<CIMInstance> referencedInstances; Array<CIMInstance> classInstances; CIMName prevClassName; ConstArrayIterator<CIMInstance> refsIter(refs); for(Uint32 i = 0; i < refsIter.size(); i++) { CIMInstance thisRef = refsIter[i]; CIMObjectPath thisTarget = getRequiredValue<CIMObjectPath>( thisRef, targetRole); // Test if we're looking for something outside of our namespace. This // will happen during associators calls from PG_RegisteredProfile // instances through the PG_ElementConformsToProfile association CIMNamespaceName opNamespace = thisTarget.getNameSpace(); CIMName opClass = thisTarget.getClassName(); if((opNamespace != PEGASUS_NAMESPACENAME_INTEROP && opClass != PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE) // Get CIM_IndicationService instance from IndicationService. #ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT || opClass == PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE #endif ) { AutoMutex mut(interopMut); CIMInstance gotInstance = cimomHandle.getInstance( context, opNamespace, thisTarget, false, false, false, propertyList); referencedInstances.append(gotInstance); continue; } TARGET_CLASS classEnum = translateClassInput(opClass); CIMInstance retInstance; switch(classEnum) { case PG_SOFTWAREIDENTITY: { CIMInstance retInstance = getSoftwareIdentityInstance(thisTarget); normalizeInstance( retInstance, thisTarget, false, false, propertyList); retInstance.setPath(thisTarget); referencedInstances.append(retInstance); } break; case PG_NAMESPACE: { CIMInstance retInstance = getNameSpaceInstance(thisTarget); normalizeInstance( retInstance, thisTarget, false, false, propertyList); retInstance.setPath(thisTarget); referencedInstances.append(retInstance); } break; default: { if( opClass != prevClassName ) { CIMObjectPath ref; ref.setHost(thisTarget.getHost()); ref.setClassName(thisTarget.getClassName()); ref.setNameSpace(thisTarget.getNameSpace()); classInstances = localEnumerateInstances( context, ref, propertyList); ArrayIterator<CIMInstance> instsIter(classInstances); for(Uint32 n = 0; n < instsIter.size(); n++) { CIMObjectPath tmpInst = instsIter[n].getPath(); tmpInst.setHost(thisTarget.getHost()); tmpInst.setNameSpace(thisTarget.getNameSpace()); instsIter[n].setPath(tmpInst); } prevClassName = opClass; } ConstArrayIterator<CIMInstance> instsConstIter(classInstances); for(Uint32 j = 0; j < instsConstIter.size(); j++) { if(thisTarget == instsConstIter[j].getPath()) { referencedInstances.append(instsConstIter[j]); break; } } } break; } } PEG_METHOD_EXIT(); return referencedInstances; }
/** When the "PropagateError" method is invoked, this function will read a CIM_Error embedded instance from the inParameters and use that instance to create an InstMethodIndication populating the Error[] property with the CIM_Error parameter and errorInstance stored in this class (if it's been created already). The output parameter of this method will contain the embedded instance received as input, and the newly created InstMethodIndication will be sent by the provider to any registered listeners. */ void EmbeddedInstanceProvider::invokeMethod( const OperationContext& context, const CIMObjectPath& objectReference, const CIMName& methodName, const Array<CIMParamValue>& inParameters, MethodResultResponseHandler& handler) { // This should start sending indications with the stored Job instance // embedded in the InstMethodIndication handler.processing(); if (!methodName.equal(CIMName("PropagateError"))) throw CIMException(CIM_ERR_METHOD_NOT_AVAILABLE); if (inParameters.size() != 1) { throw CIMException( CIM_ERR_INVALID_PARAMETER, "Did not receive exactly 1 parameter"); } CIMParamValue errorParam = inParameters[0]; if (!String::equal(errorParam.getParameterName(), String("error"))) { throw CIMException( CIM_ERR_INVALID_PARAMETER, "Did not find \"error\" parameter"); } CIMInstance errorParamInst; errorParam.getValue().get(errorParamInst); if (errorParamInst.getPath().getClassName() != "PG_EmbeddedError") { throw CIMException(CIM_ERR_INVALID_PARAMETER); } errorParamInst.setPath(errorInstance->getPath()); Array<CIMName> propList; for (unsigned int i = 0, n = errorParamInst.getPropertyCount(); i < n; i++) { propList.append(errorParamInst.getProperty(i).getName()); } CIMInstance tmpErrorInstance(errorInstance->clone()); if (!tmpErrorInstance.identical(errorParamInst)) { throw Exception("Did not receive expected ErrorInstance"); } // Build new indication instance CIMObjectPath indicationPath(System::getHostName(), CIMNamespaceName("test/EmbeddedInstance/Dynamic"), CIMName("PG_InstMethodIndication")); indicationInstance.reset(new CIMInstance("PG_InstMethodIndication")); indicationInstance->setPath(indicationPath); indicationInstance->addProperty(CIMProperty("MethodName", CIMValue(String("PropagateError")))); indicationInstance->addProperty(CIMProperty("PreCall", CIMValue(Boolean(false)))); indicationInstance->addProperty(CIMProperty("SourceInstance", CIMValue(CIMObject(*errorInstance)))); Array<CIMInstance> errorInstances; errorInstances.append(*errorInstance); errorInstances.append(*errorInstance); indicationInstance->addProperty(CIMProperty("Error", CIMValue(errorInstances))); handler.deliverParamValue(CIMParamValue(String("sameError"), CIMValue(errorParamInst))); handler.deliver(CIMValue(Uint32(1))); handler.complete(); indicationHandler->deliver(*indicationInstance); }
void OperatingSystemProvider::getInstance(const OperationContext& context, const CIMObjectPath& ref, const Boolean includeQualifiers, const Boolean includeClassOrigin, const CIMPropertyList& propertyList, InstanceResponseHandler &handler) { Array<CIMKeyBinding> keys; CIMInstance instance; OperatingSystem os; CIMName className; String csName; String name; //-- make sure we're working on the right class className = ref.getClassName(); if (!(className.equal (STANDARDOPERATINGSYSTEMCLASS)) && !(className.equal (EXTENDEDOPERATINGSYSTEMCLASS))) throw CIMNotSupportedException("OperatingSystemProvider does not support class " + className.getString()); //-- make sure we're the right instance int keyCount; CIMName keyName; keyCount = 4; keys = ref.getKeyBindings(); if ((unsigned int)keys.size() != (unsigned int)keyCount) throw CIMInvalidParameterException("Wrong number of keys"); // doesn't seem as though this code will handle duplicate keys, // but it appears as though the CIMOM strips those out for us. // Despite test cases, don't get invoked with 2 keys of the same // name. if (!os.getCSName(csName)) { throw CIMOperationFailedException("OperatingSystemProvider " "Can't determine name of computer system"); } if (!os.getName(name)) { throw CIMOperationFailedException("OperatingSystemProvider " "Can't determine name of Operating System"); } for (unsigned int ii = 0; ii < keys.size(); ii++) { keyName = keys[ii].getName(); if ((keyName.equal ("CSCreationClassName")) && String::equalNoCase(keys[ii].getValue(), CSCREATIONCLASSNAME.getString())) { keyCount--; } else if ((keyName.equal ("CSName")) && String::equalNoCase(keys[ii].getValue(), csName)) { keyCount--; } else if ((keyName.equal ("CreationClassName")) && String::equalNoCase(keys[ii].getValue(), STANDARDOPERATINGSYSTEMCLASS.getString())) { keyCount--; } else if ((keyName.equal ("Name")) && String::equalNoCase(keys[ii].getValue(), name)) { keyCount--; } else { throw CIMInvalidParameterException("OperatingSystemProvider" " unrecognized key " + keyName.getString()); } } if (keyCount) { throw CIMInvalidParameterException("Wrong keys"); } OSP_DEBUG("losp-> getInstance got the right keys"); handler.processing(); //-- fill 'er up... instance = _build_instance(ref); instance.setPath(ref); OSP_DEBUG("losp-> getInstance built an instance"); handler.deliver(instance); handler.complete(); OSP_DEBUG("losp-> getInstance done"); return; }
int retrieveErrorInstance(CIMClient& client) { try { PEGASUS_STD(cout) << "Getting error instance: " << errorPath.toString() << PEGASUS_STD(endl); CIMInstance ret = client.getInstance( TEST_NAMESPACE, errorPath, true, false, false, errorPropList); ret.setPath(errorPath); if (!errorInstance->identical(ret)) { if (!ret.getPath().identical(errorInstance->getPath())) { PEGASUS_STD(cout) << "Object Paths not identical" << PEGASUS_STD(endl); } PEGASUS_STD(cout) << "Error Instance and instance retrieved " << "through GetInstance operation not the same\n" << PEGASUS_STD(endl); PEGASUS_STD(cout) << "Local Error Instance: " << errorInstance->getPath().toString() << PEGASUS_STD(endl); for (unsigned int i = 0, n = errorInstance->getPropertyCount(); i < n; i++) { CIMProperty prop = errorInstance->getProperty(i); PEGASUS_STD(cout) << i << ". " << prop.getName().getString() << prop.getValue().toString() << PEGASUS_STD(endl); } PEGASUS_STD(cout) << "Retrieved Error Instance: " << ret.getPath().toString() << PEGASUS_STD(endl); for (unsigned int i = 0, n = ret.getPropertyCount(); i < n; i++) { CIMProperty prop = ret.getProperty(i); PEGASUS_STD(cout) << i << ". " << prop.getName().getString() << prop.getValue().toString() << PEGASUS_STD(endl); } CIMProperty localEmbeddedProp = errorInstance->getProperty( errorInstance->findProperty("EmbeddedInst")); CIMProperty retEmbeddedProp = ret.getProperty( ret.findProperty("EmbeddedInst")); CIMInstance localEmbeddedInst; CIMInstance retEmbeddedInst; localEmbeddedProp.getValue().get(localEmbeddedInst); retEmbeddedProp.getValue().get(retEmbeddedInst); CIMObjectPath localEmbeddedPath = localEmbeddedInst.getPath(); CIMObjectPath retEmbeddedPath = retEmbeddedInst.getPath(); PEGASUS_STD(cout) << "Local Embedded Path: " << localEmbeddedPath.toString() << PEGASUS_STD(endl); PEGASUS_STD(cout) << "Ret Embedded Path: " << retEmbeddedPath.toString() << PEGASUS_STD(endl); return -1; } } catch (Exception& e) { cout << "Exception caught while getting error instance: " << e.getMessage() << endl; return -1; } try { Array<CIMInstance> ret = client.enumerateInstances( TEST_NAMESPACE, "PG_EmbeddedError", true, true, false, false, errorPropList); int count = ret.size(); for (int i = 0; i < count; i++) { if (!errorInstance->identical(ret[i])) { printf("Error instance and instance retrieved through " "EnumerateInstances operation not the same\n"); return -1; } } } catch (Exception& e) { cout << "Exception caught while enumerating error instances: " << e.getMessage() << endl; return -1; } return 0; }