std::shared_ptr<Segment> SegmentHolder::getReference() { mRefCount++; //If mRefCount is 1 we're guaranteed to be the only one interacting with the segment, so it's thread safe to call Mercator::Segment::isValid if (mRefCount == 1 && mSegment->getMercatorSegment().isValid()) { mSegmentManager.unmarkHolder(this); } //When the shared pointer is deleted we should just decrease our internal reference counter. auto deleter=[&](Segment* ptr){ returnReference(); }; return std::shared_ptr<Segment>(mSegment, deleter); }
void PG_TestPropertyTypes::createInstance( const OperationContext& context, const CIMObjectPath& instanceReference, const CIMInstance& instanceObject, ObjectPathResponseHandler& handler) { // synchronously get references Array<CIMObjectPath> references = _enumerateInstanceNames(context, instanceReference); // ensure the Namespace is valid if (!instanceReference.getNameSpace().equal("test/static")) { throw CIMException(CIM_ERR_INVALID_NAMESPACE); } // ensure the class existing in the specified namespace if (!instanceReference.getClassName().equal("PG_TestPropertyTypes")) { throw CIMException(CIM_ERR_INVALID_CLASS); } // ensure the InstanceId key is valid Uint32 propIndex = instanceObject.findProperty("InstanceId"); if (propIndex == PEG_NOT_FOUND) { throw CIMException(CIM_ERR_INVALID_PARAMETER); } // Uint32 i; // for (i=0; i<keys.size() && keys[i].getName() != "InstanceId"; i++); // if (i==keys.size()) // { // throw CIMException(CIM_ERR_INVALID_PARAMETER); // } // create the CIMObjectPath to return Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding( instanceObject.getProperty(propIndex).getName(), instanceObject.getProperty(propIndex).getValue().toString(), CIMKeyBinding::NUMERIC)); keys.append(CIMKeyBinding( "CreationClassName", "PG_TestPropertyTypes", CIMKeyBinding::STRING)); CIMObjectPath returnReference( String::EMPTY, CIMNamespaceName(), instanceReference.getClassName(), keys); // ensure the property values are valid _testPropertyTypesValue(instanceObject); // Determine if a property exists in the class if (instanceObject.findProperty("PropertyUint8") == PEG_NOT_FOUND) { throw CIMException(CIM_ERR_INVALID_PARAMETER); } // ensure the requested object do not exist if (findObjectPath(references, instanceReference) != PEG_NOT_FOUND) { throw CIMException(CIM_ERR_ALREADY_EXISTS); } // begin processing the request handler.processing(); handler.deliver(returnReference); // complete processing request handler.complete(); }