Exemplo n.º 1
0
/* static */ ImplAAFStorable * ImplAAFRefContainerValue::GetStorableFromPropertyValue(
  ImplAAFPropertyValue* pPropertyValue,
  AAFRESULT & result)
{
  result = AAFRESULT_SUCCESS;
  ASSERTU(NULL != pPropertyValue);
  
  ImplAAFStorable* storable = NULL; // initialize the returned parameter
  
  // Make sure that the type definition can contain a single object
  // reference.
  ImplAAFTypeDefSP pPropertyValueType;
  result = pPropertyValue->GetType(&pPropertyValueType);
  if (AAFRESULT_FAILED(result))
    return NULL;
  ImplAAFTypeDefObjectRef* pObjectRefType = NULL;
  pObjectRefType = dynamic_cast<ImplAAFTypeDefObjectRef *>((ImplAAFTypeDef *)pPropertyValueType);
  if (NULL == pObjectRefType)
  {
    result = AAFRESULT_INVALID_PARAM;
    return NULL;
  }
  
  // Use the type to extract the object from the input property
  // value.
  ImplAAFRoot *pObject = NULL;
  result = pObjectRefType->GetObject(pPropertyValue, &pObject); // returns reference counted object!
  if (AAFRESULT_FAILED(result))
    return NULL;
    
  // the returned object is NOT reference counted.
  pObject->ReleaseReference();

  storable = ImplAAFRefValue::ConvertRootToOMStorable(pObject);
  ASSERTU(NULL != storable);
  if (NULL == storable)
    result = AAFRESULT_INVALID_OBJ; 

  
  return storable;  
}
Exemplo n.º 2
0
HRESULT STDMETHODCALLTYPE
    CAAFTypeDefObjectRef::GetObject (IAAFPropertyValue * pPropVal,
        REFIID  iid,
        IUnknown ** ppObject)
{
  HRESULT hr = S_OK;

  try
    {
    

  ImplAAFTypeDefObjectRef * ptr;
  ImplAAFRoot * pO;
  pO = GetRepObject ();
  assert (pO);
  ptr = static_cast<ImplAAFTypeDefObjectRef*> (pO);
  assert (ptr);

  //
  // set up for pPropVal
  //
  ImplAAFPropertyValue * internalpPropVal = NULL;
  if (pPropVal)
    {
      HRESULT hStat;
      IAAFRoot * iObj;
      ImplAAFRoot *arg;
      hStat = pPropVal->QueryInterface (IID_IAAFRoot, (void **)&iObj);
      assert (SUCCEEDED (hStat));
      assert (iObj);
      hStat = iObj->GetImplRep((void **)&arg);
      assert (SUCCEEDED (hStat));
      iObj->Release(); // we are through with this interface pointer.
      internalpPropVal = static_cast<ImplAAFPropertyValue*>(arg);
      assert (internalpPropVal);
    }

  //
  // set up for ppObject
  //
  ImplAAFRoot * internalppObject = NULL;
  ImplAAFRoot ** pinternalppObject = NULL;
  if (ppObject)
    {
      pinternalppObject = &internalppObject;
    }


  hr = ptr->GetObject
       (internalpPropVal,
        pinternalppObject);

  //
  // no cleanup necessary for pPropVal
  //

  //
  // cleanup for ppObject
  //
  if (internalppObject)
    {
      IUnknown *pUnknown = static_cast<IUnknown *> (internalppObject->GetContainer());
      HRESULT hStat = pUnknown->QueryInterface(iid, (void **)ppObject);
      if (SUCCEEDED(hr) && FAILED(hStat))
        hr = hStat;
      internalppObject->ReleaseReference(); // We are through with this pointer.
    }


    }
  catch (OMException& e)
    {
      // OMExceptions should be handled by the impl code. However, if an
      // unhandled OMException occurs, control reaches here. We must not
      // allow the unhandled exception to reach the client code, so we
      // turn it into a failure status code.
      //
      // If the OMException contains an HRESULT, it is returned to the
      // client, if not, AAFRESULT_UHANDLED_EXCEPTION is returned.
      //
      hr = OMExceptionToResult(e, AAFRESULT_UNHANDLED_EXCEPTION);
    }
  catch (OMAssertionViolation &)
    {
      // Control reaches here if there is a programming error in the
      // impl code that was detected by an assertion violation.
      // We must not allow the assertion to reach the client code so
      // here we turn it into a failure status code.
      //
      hr = AAFRESULT_ASSERTION_VIOLATION;
    }
  catch (...)
    {
      // We CANNOT throw an exception out of a COM interface method!
      // Return a reasonable exception code.
      //
      hr = AAFRESULT_UNEXPECTED_EXCEPTION;
    }


  return hr;
}