コード例 #1
0
ファイル: ImplAAFTypeDefArray.cpp プロジェクト: UIKit0/aaf
AAFRESULT STDMETHODCALLTYPE
ImplAAFTypeDefArray::CreateValueFromCArray (
											aafMemPtr_t pInitData,
											aafUInt32 initDataSize,
											ImplAAFPropertyValue ** ppPropVal)
{
	if (! pInitData)
		return AAFRESULT_NULL_PARAM;
	
	if (! ppPropVal)
		return AAFRESULT_NULL_PARAM;
	
  ImplAAFTypeDefSP pElementType;
  AAFRESULT result = GetType(&pElementType);
  if (AAFRESULT_FAILED(result))
    return result;     
      
  if (dynamic_cast<ImplAAFTypeDefObjectRef*>((ImplAAFTypeDef*) pElementType))
  {
    // This interface is not type-safe for accessing objects! There is also no
    // mechanism in place to convert between a buffer pointer and an array
    // of interface pointers; this convertion would not be necessary for
    // arrays of non-objects.
    return AAFRESULT_BAD_TYPE;
  }

	ImplAAFPropValDataSP pvd;
	ImplAAFPropValData * tmp;
	tmp = (ImplAAFPropValData*) CreateImpl (CLSID_AAFPropValData);
	if (!tmp) return AAFRESULT_NOMEMORY;
	pvd = tmp;
	// the pvd smart pointer will maintain a reference for us...
	aafUInt32 refCount;
	refCount = tmp->ReleaseReference ();
	// ...make sure it really does
	ASSERTU (1 == refCount);
	
	AAFRESULT hr;
	hr = pvd->Initialize(this);
	if (! AAFRESULT_SUCCEEDED (hr))
		return hr;
	
	hr = SetCArray (pvd, pInitData, initDataSize);
	if (AAFRESULT_FAILED (hr))
		return hr;
	
	ASSERTU (ppPropVal);
	*ppPropVal = pvd;
	ASSERTU (*ppPropVal);
	(*ppPropVal)->AcquireReference ();
	return AAFRESULT_SUCCESS;
}
コード例 #2
0
AAFRESULT STDMETHODCALLTYPE
ImplAAFTypeDefString::CreateValueFromCString (
    aafMemPtr_t  pInitData,
    aafUInt32  initDataSize,
    ImplAAFPropertyValue ** ppPropVal)
{
    if (! pInitData)
        return AAFRESULT_NULL_PARAM;

    if (! ppPropVal)
        return AAFRESULT_NULL_PARAM;

    if (! IsRegistered ())
        return AAFRESULT_NOT_REGISTERED;

    if (initDataSize > OMPROPERTYSIZE_MAX)
        return AAFRESULT_BAD_SIZE;

    ImplAAFPropValDataSP pvd;
    ImplAAFPropValData * tmp;
    tmp = (ImplAAFPropValData*) CreateImpl (CLSID_AAFPropValData);
    if (!tmp) return AAFRESULT_NOMEMORY;
    pvd = tmp;
    // the pvd smart pointer will maintain a reference for us...
    aafUInt32 refCount;
    refCount = tmp->ReleaseReference ();
    // ...make sure it really does
    ASSERTU (1 == refCount);

    AAFRESULT hr;
    hr = pvd->Initialize(this);
    if (! AAFRESULT_SUCCEEDED (hr))
        return hr;

    hr = SetCString (pvd, pInitData, initDataSize);
    if (AAFRESULT_FAILED (hr))
        return hr;

    ASSERTU (ppPropVal);
    *ppPropVal = pvd;
    ASSERTU (*ppPropVal);
    (*ppPropVal)->AcquireReference ();
    return AAFRESULT_SUCCESS;
}
コード例 #3
0
AAFRESULT STDMETHODCALLTYPE
    ImplAAFTypeDefCharacter::CreateValueFromCharacter (
      aafCharacter  character,
      ImplAAFPropertyValue ** ppCharacterValue)
{
  TRACE("ImplAAFTypeDefCharacter::CreateValueFromCharacter");
  
  if (! ppCharacterValue)
		return AAFRESULT_NULL_PARAM;
	
	aafUInt32 cbChar = NativeSize();
	
	// Create a temporary pointer to copy to the smartptr
	ImplAAFPropValData * tmp = (ImplAAFPropValData *)CreateImpl(CLSID_AAFPropValData);
	if (NULL == tmp)
		return AAFRESULT_NOMEMORY;
	ImplAAFPropValDataSP pv;
	pv = tmp;
	
	tmp->ReleaseReference(); // we don't need this reference anymore.
	tmp = 0;
	
	//Initialize
	check_hr ( pv->Initialize(this) );
	
	//Allocate appropriate bits
	aafMemPtr_t pBits = NULL;
	check_hr ( pv->AllocateBits (cbChar, &pBits) );
	
	//Set the bits to incoming character
	ASSERT("Valid bits", pBits != 0);
	memcpy (pBits, &character, cbChar);
	
	*ppCharacterValue = pv;
	(*ppCharacterValue)->AcquireReference ();
	return AAFRESULT_SUCCESS;
}
コード例 #4
0
ファイル: ImplAAFTypeDefArray.cpp プロジェクト: UIKit0/aaf
AAFRESULT STDMETHODCALLTYPE
ImplAAFTypeDefArray::CreateValue(ImplAAFPropertyValue ** ppPropVal, 
								 aafUInt32 dataSize)
{
	if (! ppPropVal)
		return AAFRESULT_NULL_PARAM;
	
	ImplAAFPropValDataSP pvd;
	ImplAAFPropValData * tmp;
	tmp = (ImplAAFPropValData*) CreateImpl (CLSID_AAFPropValData);
	if (!tmp) return AAFRESULT_NOMEMORY;
	pvd = tmp;
	// the pvd smart pointer will maintain a reference for us...
	tmp->ReleaseReference ();
	
	//Initialize pvd to this type
	HRESULT hr = pvd->Initialize(this);
	if (AAFRESULT_FAILED(hr)) return hr;
	
	//deal with dataSize - Allocate bits if this param is non-zero
	if (dataSize)
	{
		//Allocate the necesary bits
		aafMemPtr_t pTargetData = 0;
		hr = pvd->AllocateBits(dataSize, &pTargetData);
		if (AAFRESULT_FAILED (hr))
			return hr;
	}//if dataSize
	else
		//we're effectively creating an "Empty" value
		;
	
	*ppPropVal = pvd;
	ASSERTU (*ppPropVal);
	(*ppPropVal)->AcquireReference ();
	return AAFRESULT_SUCCESS;
}//CreateValue()
コード例 #5
0
ファイル: ImplAAFTypeDefArray.cpp プロジェクト: UIKit0/aaf
AAFRESULT STDMETHODCALLTYPE
ImplAAFTypeDefArray::SetCArray (
								ImplAAFPropertyValue * pPropVal,
								aafMemPtr_t pData,
								aafUInt32 dataSize)
{
	if (! pPropVal)
		return AAFRESULT_NULL_PARAM;
	
	if (! pData)
		return AAFRESULT_NULL_PARAM;
	
	if (! IsRegistered ())
		return AAFRESULT_NOT_REGISTERED;
	
	// Get the property value's embedded type and 
	// check if it's the same as the base type.
	ImplAAFTypeDefSP	pIncomingType;
	if( AAFRESULT_FAILED( pPropVal->GetType( &pIncomingType ) ) )
		return AAFRESULT_BAD_TYPE;
	ASSERTU (pIncomingType);
	if( (ImplAAFTypeDef *)pIncomingType != this )
		return AAFRESULT_BAD_TYPE;

	AAFRESULT hr;
	ImplAAFTypeDefSP pBaseType;
	hr = GetType (&pBaseType);
	
	ASSERTU (pBaseType->IsFixedSize ());
	pBaseType->AttemptBuiltinRegistration ();
	ASSERTU (pBaseType->IsRegistered ());
	
  ImplAAFRefArrayValue* pRefArray = dynamic_cast<ImplAAFRefArrayValue*>(pPropVal);
  if (NULL != pRefArray)
  {
    // This interface is not type-safe for accessing objects! There is also no
    // mechanism in place to convert between a buffer pointer and an array
    // of interface pointers; this convertion would not be necessary for
    // arrays of non-objects.
    return AAFRESULT_BAD_TYPE;
  }
	
	// Size of individual elements
	aafUInt32 elemSize = pBaseType->NativeSize ();
	// number of elements in input data.  If this is not an integral
	// number, this will round down and the test below will fail.
	aafUInt32 elemCount = dataSize / elemSize;
	// The size of the new property, calculated from number of elements
	// and the size of each element.
	aafUInt32 propSize = elemSize * elemCount;
	
	// If the given dataSize was not an integral multiple of the size of
	// each element, then we'll signal an error.
	if (propSize != dataSize)
		return AAFRESULT_BAD_SIZE;
	
	// In case of fixed-size arrays, we'll also have to see if the data
	// size matches what we're expecting.
	if (IsFixedSize ())
	{
		aafUInt32 nativeSize = NativeSize ();
		if (nativeSize != dataSize)
			return AAFRESULT_BAD_SIZE;
	}
	
	ImplAAFPropValData * pvd = 0;
	ASSERTU (pPropVal);
	pvd = dynamic_cast<ImplAAFPropValData*> (pPropVal);
	ASSERTU (pvd);
	
	aafMemPtr_t pBits = 0;
	hr = pvd->AllocateBits (propSize, &pBits);
	if (AAFRESULT_FAILED (hr))
		return hr;
	ASSERTU (pBits);
	
	memcpy (pBits, pData, propSize);
	return AAFRESULT_SUCCESS;
}
コード例 #6
0
ファイル: ImplAAFTypeDefArray.cpp プロジェクト: UIKit0/aaf
AAFRESULT STDMETHODCALLTYPE
ImplAAFTypeDefArray::GetCArray (
								ImplAAFPropertyValue * pPropVal,
								aafMemPtr_t pData,
								aafUInt32 dataSize)
{
	if (! pPropVal)
		return AAFRESULT_NULL_PARAM;
	
	if (! pData)
		return AAFRESULT_NULL_PARAM;
	
	if (! IsRegistered ())
		return AAFRESULT_NOT_REGISTERED;
	
	// Get the property value's embedded type and 
	// check if it's the same as the base type.
	ImplAAFTypeDefSP	pIncomingType;
	if( AAFRESULT_FAILED( pPropVal->GetType( &pIncomingType ) ) )
		return AAFRESULT_BAD_TYPE;
	ASSERTU (pIncomingType);
	if( (ImplAAFTypeDef *)pIncomingType != this )
		return AAFRESULT_BAD_TYPE;

	ImplAAFTypeDefSP pBaseType;
	HRESULT hr = GetType (&pBaseType);
	
	ASSERTU (pBaseType->IsFixedSize ());
	pBaseType->AttemptBuiltinRegistration ();
	ASSERTU (pBaseType->IsRegistered ());

	
  ImplAAFRefArrayValue* pRefArray = dynamic_cast<ImplAAFRefArrayValue*>(pPropVal);
  if (NULL != pRefArray)
  {
    // This interface is not type-safe for accessing objects! There is also no
    // mechanism in place to convert between a buffer pointer and an array
    // of interface pointers; this convertion would not be necessary for
    // arrays of non-objects.
    return AAFRESULT_BAD_TYPE;
  }


	aafUInt32 elemSize = pBaseType->NativeSize ();
	aafUInt32 elemCount = pvtCount (pPropVal);
	aafUInt32 propSize = elemSize * elemCount;
	
	if (dataSize < propSize)
		return AAFRESULT_BAD_SIZE;
	
	ImplAAFPropValData * pvd = 0;
	ASSERTU (pPropVal);
	pvd = dynamic_cast<ImplAAFPropValData*> (pPropVal);
	ASSERTU (pvd);
	
	aafUInt32 bitsSize;
	hr = pvd->GetBitsSize (&bitsSize);
	if (AAFRESULT_FAILED (hr))
		return hr;
	ASSERTU (bitsSize >= propSize);
	
	aafMemPtr_t pBits = 0;
	hr = pvd->GetBits (&pBits);
	if (AAFRESULT_FAILED (hr))
		return hr;
	ASSERTU (pBits);
	
	memcpy (pData, pBits, propSize);
	return AAFRESULT_SUCCESS;
}
コード例 #7
0
ファイル: ImplAAFTypeDef.cpp プロジェクト: UIKit0/aaf
// Allocate and initialize the correct subclass of ImplAAFPropertyValue 
// for the given OMProperty.
AAFRESULT STDMETHODCALLTYPE
  ImplAAFTypeDef::CreatePropertyValue(
    OMProperty *property,
    ImplAAFPropertyValue ** ppPropertyValue ) const
{
  AAFRESULT result = AAFRESULT_SUCCESS;
  ASSERTU (property && ppPropertyValue);
  if (NULL == property || NULL == ppPropertyValue)
    return AAFRESULT_NULL_PARAM;
  *ppPropertyValue = NULL; // initialize out parameter
  ASSERTU (property->definition());
  if (NULL == property->definition())
    return AAFRESULT_INVALID_PARAM;
  const OMType *type = property->definition()->type();
  ASSERTU (type);
  ImplAAFTypeDef *ptd = const_cast<ImplAAFTypeDef *>
                          (dynamic_cast<const ImplAAFTypeDef *>(type));
  ASSERTU (ptd);
  if (NULL == ptd)
    return AAFRESULT_INVALID_PARAM;
 
  ImplAAFPropValData *pvd = NULL;
  pvd = (ImplAAFPropValData*) CreateImpl (CLSID_AAFPropValData);
  if (!pvd) 
    return AAFRESULT_NOMEMORY;

  result = pvd->Initialize (ptd);
  if (AAFRESULT_SUCCEEDED(result))
  {
    // set the storage in the prop value
    OMUInt32 bitsSize;
    ASSERTU (property);
    bitsSize = property->bitsSize ();
    aafMemPtr_t pBits = NULL;
    // Bobt hack! This should be removed once we have proper
    // integration with OM property def support.
    if (! property->isOptional() || property->isPresent ())
    {
      result = pvd->AllocateBits (bitsSize, &pBits);
      if (AAFRESULT_SUCCEEDED (result))
      {
	if (bitsSize)
        {
          ASSERTU (pBits);
          property->getBits (pBits, bitsSize);
        }
      }
    }
  }

  if (AAFRESULT_SUCCEEDED(result))
  {
    *ppPropertyValue = pvd; // ref count is already 1.
    pvd = NULL;
  }
  else
  {
    pvd->ReleaseReference(); // delete the new object.
  }

  return (result) ;
}
コード例 #8
0
AAFRESULT STDMETHODCALLTYPE
ImplAAFTypeDefString::SetCString (
    ImplAAFPropertyValue * pPropVal,
    aafMemPtr_t pData,
    aafUInt32 dataSize)
{
    if (! pPropVal)
        return AAFRESULT_NULL_PARAM;

    if (! pData)
        return AAFRESULT_NULL_PARAM;

    if (! IsRegistered ())
        return AAFRESULT_NOT_REGISTERED;

    if (dataSize > OMPROPERTYSIZE_MAX)
        return AAFRESULT_BAD_SIZE;

    // Get the property value's embedded type and
    // check if it's the same as the base type.
    ImplAAFTypeDefSP pIncomingType;
    if( AAFRESULT_FAILED( pPropVal->GetType( &pIncomingType ) ) )
        return AAFRESULT_BAD_TYPE;
    ASSERTU (pIncomingType);
    if( (ImplAAFTypeDef *)pIncomingType != this )
        return AAFRESULT_BAD_TYPE;

    AAFRESULT hr;
    ImplAAFTypeDefSP pBaseType;
    hr = GetType (&pBaseType);

    ASSERTU (pBaseType->IsFixedSize ());
    pBaseType->AttemptBuiltinRegistration ();
    ASSERTU (pBaseType->IsRegistered ());
    // Size of individual elements
    aafUInt32 elemSize = pBaseType->NativeSize ();
    // number of elements in input data.  If this is not an integral
    // number, this will round down and the test below will fail.
    aafUInt32 elemCount = dataSize / elemSize;
    // The size of the new property, calculated from number of elements
    // and the size of each element.
    aafUInt32 propSize = elemSize * elemCount;

    // If the given dataSize was not an integral multiple of the size of
    // each element, then we'll signal an error.
    if (propSize != dataSize)
        return AAFRESULT_BAD_SIZE;

    ImplAAFPropValData * pvd = 0;
    ASSERTU (pPropVal);
    pvd = dynamic_cast<ImplAAFPropValData*> (pPropVal);
    ASSERTU (pvd);

    aafMemPtr_t pBits = 0;
    hr = pvd->AllocateBits (propSize, &pBits);
    if (AAFRESULT_FAILED (hr))
        return hr;
    ASSERTU (pBits);

    memcpy (pBits, pData, propSize);
    return AAFRESULT_SUCCESS;
}