Пример #1
0
AAFRESULT ImplAAFTypeDef::MergeTo( ImplAAFDictionary* pDstDictionary )
{
  ASSERTU( pDstDictionary );


  AAFRESULT hr = AAFRESULT_SUCCESS;

  aafUID_t  typeID;
  GetAUID( &typeID );

  ImplAAFTypeDef* pDstTypeDef = 0;
  if( AAFRESULT_FAILED( pDstDictionary->LookupTypeDef( typeID, &pDstTypeDef ) ) )
  {
    OMClassFactory* pDstFactory =
        dynamic_cast<OMClassFactory*>( pDstDictionary->metaDictionary() );
    // New storable object returned by shallowCopy() is
    // reference counted ImplAAFTypeDef.
    OMStorable* pDstStorable = shallowCopy( pDstFactory );
    ImplAAFTypeDef* pDstTypeDef =
        dynamic_cast<ImplAAFTypeDef*>( pDstStorable );
    ASSERTU( pDstTypeDef );

    hr = pDstDictionary->RegisterTypeDef( pDstTypeDef );
    if( AAFRESULT_SUCCEEDED(hr) )
    {
      pDstTypeDef->onCopy( 0 );
      deepCopyTo( pDstTypeDef, 0 );
    }

    // pDstTypeDef created by shallowCopy() is reference counted.
    pDstTypeDef->ReleaseReference();
    pDstTypeDef = 0;
  }
  else
  {
      pDstTypeDef->ReleaseReference();
      pDstTypeDef = 0;
  }


  return hr;
}
Пример #2
0
AAFRESULT STDMETHODCALLTYPE
    ImplAAFControlPoint::Initialize
    (ImplAAFVaryingValue * pVaryingValue,
     aafRational_constref  time,
     aafUInt32  valueSize,
     aafDataBuffer_t  pValue)
{
  AAFRESULT result = AAFRESULT_SUCCESS;
  ImplAAFTypeDef *pType = NULL;


  if (!pVaryingValue || !pValue)
    return (AAFRESULT_NULL_PARAM);
  if (_initialized)
    return (AAFRESULT_ALREADY_INITIALIZED);

  // First initialize the time.
  result = SetTime (time);
  if (AAFRESULT_SUCCEEDED (result))
  {
    // Lookup the type definition from this constrol point. If it fails
    // then the control point is invalid!
    result = pVaryingValue->GetTypeDefinition (&pType);
    if (AAFRESULT_SUCCEEDED (result))
    {
      _cachedTypeDef = pType;
      _cachedTypeDef->AcquireReference ();

      // Install the initial value.
      result = SetValue (valueSize, pValue);
    }
  }
  
  if (AAFRESULT_SUCCEEDED (result))
  {
    _initialized = true;
  }
  else
  {
    if (_cachedTypeDef)
    {
      _cachedTypeDef->ReleaseReference ();
      _cachedTypeDef = NULL;
    }
  }

  // Cleanup
  if (pType)
    pType->ReleaseReference ();

  return result;
}
Пример #3
0
const OMType* ImplAAFPropertyDef::type(void) const
{
  AAFRESULT hr;
  ImplAAFTypeDef * ptd = 0;

  hr = GetTypeDef (&ptd);
  ASSERTU (AAFRESULT_SUCCEEDED (hr));
  ASSERTU (ptd);
  // Don't reference count these!
  aafUInt32 refCount;
  refCount = ptd->ReleaseReference ();
  // make sure our assumption (dict owns a ref) is correct
  ASSERTU (refCount > 0);
  return ptd->type();
}
Пример #4
0
AAFRESULT STDMETHODCALLTYPE
    ImplAAFKLVData::Initialize (
      aafUID_t keyUID, 
      aafUInt32 valueSize, 
      aafDataBuffer_t pValue)
{
	ImplAAFDictionary		*pDict = NULL;
	ImplAAFTypeDef			*pDef = NULL;
	if (!pValue)
		return AAFRESULT_NULL_PARAM;
	if (_initialized)
		return AAFRESULT_ALREADY_INITIALIZED;
	
	XPROTECT()
	{
	// Save the type so that SetValue will know the type of the value data.
		CHECK(GetDictionary(&pDict));
		CHECK(pDict->LookupOpaqueTypeDef(keyUID, &pDef));
    pDef->ReleaseReference(); // This object is owned by the dictionary!

    _cachedRenameTypeDef = dynamic_cast<ImplAAFTypeDefRename*>(pDef);
		ASSERTU(_cachedRenameTypeDef);
    if (NULL == _cachedRenameTypeDef)
      RAISE(AAFRESULT_INVALID_OBJ);

		CHECK(SetValue (valueSize, pValue));
		_initialized = true;
		if(pDict)
		  pDict->ReleaseReference();
		pDict = 0;
	}
	XEXCEPT
	{
		if(pDict)
		  pDict->ReleaseReference();
		pDict = 0;
	}
	XEND
	
	
	return AAFRESULT_SUCCESS;
}
Пример #5
0
AAFRESULT STDMETHODCALLTYPE
    ImplAAFKLVData::SetValue (aafUInt32 valueSize, aafDataBuffer_t pValue)
{
  AAFRESULT result = AAFRESULT_SUCCESS;
	ImplAAFTypeDef		*pDef = NULL;
	ImplAAFDictionary	*pDict = NULL;
	aafUID_t			keyUID;

	if (!pValue)
		return AAFRESULT_NULL_PARAM;
	
	if (valueSize > OMPROPERTYSIZE_MAX)
		return AAFRESULT_BAD_SIZE;

	if (!_cachedRenameTypeDef)
	{
		// Lookup the type definition from this KLV data. If it fails
		// then the control point is invalid!
		result = GetKey(&keyUID);
    if (AAFRESULT_FAILED(result))
      return result;

    result = GetDictionary(&pDict);
    if (AAFRESULT_FAILED(result))
      return result;

    result = pDict->LookupTypeDef(keyUID, &pDef);
		pDict->ReleaseReference();
		pDict = 0;
    if (AAFRESULT_FAILED(result))
      return result;
    pDef->ReleaseReference(); // This object is owned by the dictionary!

    _cachedRenameTypeDef = dynamic_cast<ImplAAFTypeDefRename*>(pDef);
    if (NULL == _cachedRenameTypeDef)
      return AAFRESULT_INVALID_OBJ;
	}
	
	// Validate the property and get the property definition and type definition, 
	// and the actual length of the data
	return (ImplAAFTypeDefIndirect::SetActualPropertyValue (_value, _cachedRenameTypeDef, pValue, valueSize));
}
Пример #6
0
AAFRESULT STDMETHODCALLTYPE
    ImplAAFPropertyDef::GetTypeDef (
      ImplAAFTypeDef ** ppTypeDef) const
{
  if (! ppTypeDef) return AAFRESULT_NULL_PARAM;

  if (! _cachedType)
	{
	  ImplAAFDictionarySP pDict;
	  AAFRESULT hr;

	  hr = GetDictionary(&pDict);
	  if (AAFRESULT_FAILED (hr)) return hr;
	  ASSERTU (pDict);

	  ImplAAFPropertyDef * pNonConstThis =
		  (ImplAAFPropertyDef *) this;
	  aafUID_t typeId = _Type;

	  ImplAAFTypeDef * tmp = 0;
	  hr = pDict->LookupTypeDef (typeId, &tmp);
	  if (AAFRESULT_FAILED (hr))
		return hr;
	  ASSERTU (tmp);
	  if (!_cachedType) {
		pNonConstThis->_cachedType = tmp;
		_cachedType->AcquireReference();
	  }
	  // If lookup caused this to already be put into the cache, just
	  // throw away the current copy (in tmp)
	  tmp->ReleaseReference ();
	  tmp = 0;
	}
  ASSERTU (ppTypeDef);
  *ppTypeDef = _cachedType;
  ASSERTU (*ppTypeDef);
  (*ppTypeDef)->AcquireReference ();

  return AAFRESULT_SUCCESS;
}
Пример #7
0
AAFRESULT ImplAAFPropertyDef::MergeTo( ImplAAFClassDef* pDestClassDef )
{
    ASSERTU( pDestClassDef );

    AAFRESULT hr = AAFRESULT_SUCCESS;

    // This property ID
    aafUID_t propertyID;
    GetAUID( &propertyID );

    if( ! pDestClassDef->PvtIsPropertyDefRegistered( propertyID ) )
    {
        ImplAAFDictionary* pDestDictionary = NULL;
        pDestClassDef->GetDictionary( &pDestDictionary );

        aafUInt32  nameBufLen = 0;
        GetNameBufLen( &nameBufLen );
        aafUInt8* pName = new aafUInt8[ nameBufLen ];
        GetName( (aafCharacter*)pName, nameBufLen );

        // Find the property type definition in the destination file
        ImplAAFTypeDef* pTypeDef = NULL;
        GetTypeDef( &pTypeDef );
        aafUID_t  typeID;
        pTypeDef->GetAUID( &typeID );
        pTypeDef->MergeTo( pDestDictionary );
        pTypeDef->ReleaseReference();
        pTypeDef = NULL;

        ImplAAFTypeDef* pDestTypeDef = NULL;
        pDestDictionary->LookupTypeDef( typeID, &pDestTypeDef );
        ASSERTU( pDestTypeDef != NULL );

        // Register the property definition.
        // The property registering method to use depends on whether
        // this class definition is attached to or detached from
        // the dictionary.
        ImplAAFPropertyDef* pDestPropertyDef = NULL;
        aafUID_t  classID;
        pDestClassDef->GetAUID( &classID );
        if( pDestDictionary->PvtIsClassPresent( classID ) )
        {
            // This class definition is in the dictionary - only
            // optional properties can be registered.
            ASSERTU( _IsOptional == kAAFTrue );

            hr = pDestClassDef->RegisterOptionalPropertyDef( propertyID,
                                                             (aafCharacter*)pName,
                                                             pDestTypeDef,
                                                             &pDestPropertyDef );
        }
        else
        {
            // This class definition is not in the dictionary -
            // any properties can be registered.
            aafBoolean_t isUniqueIdentifier = kAAFFalse;
            if( _IsUniqueIdentifier.isPresent() )
            {
                isUniqueIdentifier = _IsUniqueIdentifier;
            }

            hr = pDestClassDef->RegisterNewPropertyDef( propertyID,
                                                        (aafCharacter*)pName,
                                                        pDestTypeDef,
                                                        _IsOptional,
                                                        isUniqueIdentifier,
                                                        &pDestPropertyDef );
        }


        // If present, copy the property definition description.
        if( AAFRESULT_SUCCEEDED( hr ) )
        {
            aafUInt32  descriptionBufLen = 0;
            GetDescriptionBufLen( &descriptionBufLen );
            if( descriptionBufLen > 0 )
            {
                aafUInt8* pDescription = new aafUInt8[ descriptionBufLen ];
                GetDescription( (aafCharacter*)pDescription,
                                descriptionBufLen );

                hr = pDestPropertyDef->SetDescription(
                        (aafCharacter*)pDescription );

                delete[] pDescription;
                pDescription = NULL;
            }
        }

        // Because RegisterOptionalPropertyDef/RegisterNewPropertyDef can
        // fail (for example, if the property's already registered with a
        // different class), pDestPropertyDef may not be a valid pointer.
        if( pDestPropertyDef )
        {
            pDestPropertyDef->ReleaseReference();
            pDestPropertyDef = NULL;
        }

        pDestTypeDef->ReleaseReference();
        pDestTypeDef = NULL;

        delete[] pName;
        pName = NULL;

        pDestDictionary->ReleaseReference();
        pDestDictionary = NULL;
    }


    return hr;
}
Пример #8
0
HRESULT STDMETHODCALLTYPE
    CAAFParameter::GetTypeDefinition (IAAFTypeDef ** ppTypeDef)
{
  HRESULT hr;

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

  //
  // set up for ppTypeDef
  //
  ImplAAFTypeDef * internalppTypeDef = NULL;
  ImplAAFTypeDef ** pinternalppTypeDef = NULL;
  if (ppTypeDef)
    {
      pinternalppTypeDef = &internalppTypeDef;
    }

  try
    {
      hr = ptr->GetTypeDefinition
       (pinternalppTypeDef);
    }
  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;
    }

  //
  // cleanup for ppTypeDef
  //
  if (SUCCEEDED(hr))
    {
      IUnknown *pUnknown;
      HRESULT hStat;

      if (internalppTypeDef)
        {
          pUnknown = static_cast<IUnknown *> (internalppTypeDef->GetContainer());
          hStat = pUnknown->QueryInterface(IID_IAAFTypeDef, (void **)ppTypeDef);
          assert (SUCCEEDED (hStat));
          //pUnknown->Release();
          internalppTypeDef->ReleaseReference(); // We are through with this pointer.
        }
    }
  return hr;
}