AAFRESULT STDMETHODCALLTYPE ImplAAFWeakRefValue::SetObject(ImplAAFStorable *pObject) { AAFRESULT result = AAFRESULT_SUCCESS; if (NULL == pObject) return AAFRESULT_NULL_PARAM; ASSERTU (isInitialized()); if (!isInitialized()) return AAFRESULT_NOT_INITIALIZED; if (!pObject->attached()) { return AAFRESULT_OBJECT_NOT_ATTACHED; } if (NULL != referenceProperty()) { // Save the reference in the OMReferenceProperty result = SetNewObjectReference(referenceProperty(), pObject); } else { // Use an "indirect access" method of saving a weak object reference. // // If there was not associated reference property then we MUST // set the local object pointer for this instance. // // This weak reference should be an element of a weak reference set or // weak reference array. SetLocalObject(pObject); } return result; }
static AAFRDLIRESULT testPluginProc(const char *path, const char* name, char isDirectory, void * userData) { AAFTestLibraryProcData *pData = (AAFTestLibraryProcData *)userData; ASSERTU(pData && pData->plugins && pData->pluginFiles && pData->currentLibraryPath && pData->pluginPrefix && pData->pluginPrefixSize); // // If the current name is not a directory and not equal to the // path this dll (the reference implementation dll) and // the name begins with the plugin prefix, // attempt to register the file and any contained plugins. // if (!isDirectory && (pData->pluginPrefixSize < strlen(name))) { // Compare prefix if (prefixtest(name, pData)) { if ( 0 != strcmp(path, pData->currentLibraryPath) ) (pData->plugins)->RegisterPluginFile(path); } } // Ignore error results and continue processing plugins... return 0; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefString::GetCount ( ImplAAFPropertyValue * pPropVal, aafUInt32 * pCount) { ImplAAFTypeDefSP pIncomingType; ImplAAFTypeDefSP ptd; AAFRESULT hr; if (! pPropVal) return AAFRESULT_NULL_PARAM; if (! pCount) return AAFRESULT_NULL_PARAM; // Get the property value's embedded type and // check if it's the same as the base type. if( AAFRESULT_FAILED( pPropVal->GetType( &pIncomingType ) ) ) return AAFRESULT_BAD_TYPE; ASSERTU (pIncomingType); if( (ImplAAFTypeDef *)pIncomingType != this ) return AAFRESULT_BAD_TYPE; hr = GetType (&ptd); if (AAFRESULT_FAILED(hr)) return hr; ASSERTU (ptd); ASSERTU (ptd->IsFixedSize()); aafUInt32 elemSize = ptd->ActualSize(); aafUInt32 propSize; ASSERTU (pPropVal); ImplAAFPropValDataSP pvd; pvd = dynamic_cast<ImplAAFPropValData *>(pPropVal); ASSERTU (pvd); hr = pvd->GetBitsSize (&propSize); if (AAFRESULT_FAILED(hr)) return hr; ASSERTU (pCount); *pCount = propSize / elemSize; return AAFRESULT_SUCCESS; }
OMUInt32 ImplAAFTypeDef::PropValSize (void) const { // Should be implemented in derived class. ASSERTU (0); return 0; // not reached! }
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; }
void ImplAAFTypeDefStream::reorder(OMByte* /* bytes */, OMUInt32 /* bytesSize */) const { // Should be properly implemented ASSERTU (0); }
void ImplAAFPropertyDef::SetOMPropCreateFunc (ImplAAFOMPropertyCreateFunc_t pFunc) { ASSERTU (pFunc); _OMPropCreateFunc = pFunc; }
//*********************************************************** // // AAFFileOpenExistingRead() // // Creates an object associated with with an existing // filesystem file that contains data which is only to be read. // Does the following: // - Opens the existing named file in the filesystem for reading. // - Associates an object with that filesystem file. // - Places the object into the Open-read-only state. // - This AAFFile object then can be used as the root of the // containment tree representing all AAF objects contained within // the file. // // Succeeds if: // - The pFileName argument is valid. // - Only valid flags have been specified. // - A valid combination of flags has been specified. // - The named file exists in the filesystem. // - The named filesystem file is readable. // - The named file represents itself as a valid AAF file. Even if // this succeeds, it is not guaranteed that the named file is in // fact a valid AAF file. // // This function will return the following codes. If more than one of // the listed errors is in effect, it will return the first one // encountered in the order given below: // // AAFRESULT_SUCCESS // - succeeded. (This is the only code indicating success.) // // AAFRESULT_NULL_PARAM // - the pFileName pointer arg is NULL. // // AAFRESULT_BAD_FLAGS // - one or more illegal flags were specified. // // AAFRESULT_BAD_FLAG_COMBINATION // - illegal combination of otherwise valid flags was specified. // // AAFRESULT_FILE_NOT_FOUND // - The named file does not exist in the filesystem. // // AAFRESULT_NOT_READABLE // - The named file cannot be read. // // AAFRESULT_NOT_AAF_FILE // - The named file does not claim to be a valid AAF file. // STDAPI ImplAAFFileOpenExistingRead ( // Null-terminated string containing name of filesystem file to be // opened for reading. Filename must be in a form that would be // acceptable to StgOpenStorage() for this platform. /*[in, string]*/ const aafCharacter * pFileName, // File open mode flags. May be any of the following ORed together. // All other bits must be set to zero. // - kAAFFileModeUnbuffered - to indicate buffered mode. Default // is buffered. /*[in]*/ aafUInt32 modeFlags, // Pointer to buffer to receive pointer to new file. /*[out]*/ ImplAAFFile ** ppFile) { #if USE_RAW_STORAGE IAAFRawStorage * pRawStg = 0; AAFRESULT hr = AAFCreateRawStorageDisk (pFileName, kAAFFileExistence_existing, kAAFFileAccess_read, &pRawStg); if (AAFRESULT_SUCCEEDED (hr)) { const aafUID_t* pFileKind; if (modeFlags & AAF_FILE_MODE_USE_LARGE_SS_SECTORS) pFileKind = &kAAFFileKind_Aaf4KBinary; else pFileKind = &kAAFFileKind_Aaf512Binary; hr = ImplAAFCreateAAFFileOnRawStorage (pRawStg, kAAFFileExistence_existing, kAAFFileAccess_read, pFileKind, modeFlags, 0, ppFile); if (AAFRESULT_SUCCEEDED (hr)) { ASSERTU (ppFile); ASSERTU (*ppFile); hr = (*ppFile)->Open (); } } if (pRawStg) { pRawStg->Release (); } return hr; #else // ! USE_RAW_STORAGE HRESULT hr = S_OK; ImplAAFFile * pFile = 0; if (!pFileName || !ppFile) return AAFRESULT_NULL_PARAM; // Check that the file is an AAF file aafUID_t fileKind; aafBool isAnAAFFile; hr = ImplAAFFileIsAAFFile(pFileName, &fileKind, &isAnAAFFile); if (FAILED(hr)) return hr; if (isAnAAFFile == kAAFFalse) return AAFRESULT_NOT_AAF_FILE; // Initialize the out parameter. *ppFile = 0; // // For backwards compatibility with existing client code // the first checked in version of this function is implemented // the same as the old client code which this function is // intended to replace... // // Create an instance of an uninitialized file object. pFile = static_cast<ImplAAFFile *>(::CreateImpl(CLSID_AAFFile)); if(!pFile) { hr = AAFRESULT_NOMEMORY; } else { // Make sure the file is initialized (not open yet...) hr = pFile->Initialize(); if (SUCCEEDED(hr)) { // Attempt to open the file read only. hr = pFile->OpenExistingRead(pFileName, modeFlags); if (SUCCEEDED(hr)) { *ppFile = pFile; pFile = 0; } } // Cleanup the file if it could not be initialized and opened. if (FAILED(hr) && pFile) pFile->ReleaseReference(); } return hr; #endif // USE_RAW_STORAGE }
//*********************************************************** // // AAFFileOpenTransient() // // Creates an object associated with with a transient file, // meaning that it is not associated with any filesystem file but // may still be used to contain AAF objects as if it was associated // with a filesystem file. Associates the given identification with // this file. // // Transient files are never considered Revertable. // // Succeeds if: // - This object has already been Initialize()d. // - The pIdent argument is valid. // - This object is currently closed. // // This function will return the following codes. If more than one of // the listed errors is in effect, it will return the first one // encountered in the order given below: // // AAFRESULT_SUCCESS // - succeeded. (This is the only code indicating success.) // // AAFRESULT_NOT_INITIALIZED // - This object has not yet had Initialize() called on it. // // AAFRESULT_ALREADY_OPEN // - This object is already open. // // AAFRESULT_NULL_PARAM // - the pIdent pointer argument is NULL. // STDAPI ImplAAFFileOpenTransient ( // Identification which is to be associated with this file. /*[in]*/ aafProductIdentification_t * pIdent, // Pointer to buffer to receive pointer to new file. /*[out]*/ ImplAAFFile ** ppFile) { #if USE_RAW_STORAGE IAAFRawStorage * pRawStg = 0; AAFRESULT hr = AAFCreateRawStorageMemory (kAAFFileAccess_modify, &pRawStg); if (AAFRESULT_SUCCEEDED (hr)) { const aafUID_t* pFileKind; if (modeFlags & AAF_FILE_MODE_USE_LARGE_SS_SECTORS) pFileKind = &kAAFFileKind_Aaf4KBinary; else pFileKind = &kAAFFileKind_Aaf512Binary; hr = ImplAAFCreateAAFFileOnRawStorage (pRawStg, kAAFFileExistence_new, kAAFFileAccess_modify, pFileKind, 0, pIdent, ppFile); if (AAFRESULT_SUCCEEDED (hr)) { ASSERTU (ppFile); ASSERTU (*ppFile); hr = (*ppFile)->Open (); } } if (pRawStg) { pRawStg->Release (); } return hr; #else // ! USE_RAW_STORAGE HRESULT hr = S_OK; const aafClassID_t& fileID = *reinterpret_cast<const aafClassID_t *>(&CLSID_AAFFile); ImplAAFFile * pFile = 0; if (!pIdent || !ppFile) return AAFRESULT_NULL_PARAM; // Initialize the out parameter. *ppFile = 0; // // For backwards compatibility with existing client code // the first checked in version of this function is implemented // the same as the old client code which this function is // intended to replace... // // Create an instance of an uninitialized file object. pFile = static_cast<ImplAAFFile *>(::CreateImpl(fileID)); if(!pFile) hr = AAFRESULT_NOMEMORY; else { // Make sure the file is initialized (not open yet...) hr = pFile->Initialize(); if (SUCCEEDED(hr)) { // Attempt to open a new transient file. hr = pFile->OpenTransient(pIdent); if (SUCCEEDED(hr)) { *ppFile = pFile; pFile = 0; } } // Cleanup the file if it could not be initialized and opened. if (FAILED(hr) && pFile) pFile->ReleaseReference(); } return hr; #endif // USE_RAW_STORAGE }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefExtEnum::CreateValueFromName ( /*[in]*/ aafCharacter_constptr Name, /*[out]*/ ImplAAFPropertyValue ** ppPropVal) { if (! ppPropVal ) return AAFRESULT_NULL_PARAM; if (! Name ) return AAFRESULT_NULL_PARAM; if (!IsRegistered()) return AAFRESULT_NOT_INITIALIZED; //Now try to do a Name lookup aafUID_t the_value = {0}; AAFRESULT rc; rc = LookupValByName(&the_value, Name); if (rc == AAFRESULT_INVALID_PARAM) { // Built-In names changed from v1.0 -> v1.1 // to remove kAAF prefix. so we have to deal with both // old and new style names. // The lookup on the originally provided name failed due to // the name not being found (not some other error). // So here we add kAAF if it isn't there or // remove kAAF if it is there. Then look up again. aafCharacter *Name_mod; if ( wcsncmp (Name, L"kAAF", 4) == 0 ) { // Look past kAAF Name_mod = new aafCharacter[wcslen(Name) - 3]; wcscpy(Name_mod, Name + 4); } else { // Prepend kAAF Name_mod = new aafCharacter[wcslen(Name) + 5]; if (!Name_mod) return AAFRESULT_NOMEMORY; wcscpy(Name_mod, L"kAAF"); wcscat(Name_mod, Name); } // Look up again - Return checked later. rc = LookupValByName(&the_value, Name_mod); // Cleanup of allocated memory delete[] Name_mod; } // At this point, we have a successful lookup and the_val is // set, the name was not found (even with variation), or // some other error occurred. Check the result and return // if we are not successful. check_hr( rc ); //else FOUND //Now allocate a New PV based on the local INT size .... ImplAAFTypeDef* ptd; ImplAAFTypeDefRecord* ptdAuid; ptd = NonRefCountedBaseType (); ASSERTU (ptd); ptdAuid = dynamic_cast<ImplAAFTypeDefRecord*> ((ImplAAFTypeDef*) ptd); ASSERTU (ptdAuid); HRESULT hr = ptdAuid->CreateValueFromStruct ((aafMemPtr_t) &the_value, sizeof (aafUID_t), ppPropVal); return hr; }
// // private method // AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefExtEnum::GetElementNameBufLen ( aafUInt32 index, aafUInt32 * pLen) { AAFRESULT hr; aafUInt32 count; aafUInt32 indexIntoProp; aafUInt32 currentIndex; if (!pLen) return AAFRESULT_NULL_PARAM; hr = CountElements(&count); if (AAFRESULT_FAILED(hr)) return hr; if (index >= count) return AAFRESULT_ILLEGAL_VALUE; wchar_t c; size_t numChars = _ElementNames.count(); indexIntoProp = 0; currentIndex = 0; if (0 != index) { for (OMUInt32 i = 0; i < numChars; i++) { indexIntoProp++; _ElementNames.getValueAt(&c, i); if (0 == c) { // We've found the null just before the string we want. // We'll increment the indexIntoProp to the start of the // string and break out of the loop, but first make sure // there's more string there to index into. ASSERTU (i < numChars); currentIndex++; if (index == currentIndex) break; } } // Make sure we didn't terminate the loop by dropping out before // the correct index was found. ASSERTU (indexIntoProp < numChars); } // indexIntoProp now indicates the starting char we want. Start // counting until we get to the next null. aafUInt32 nameLength = 0; do { _ElementNames.getValueAt(&c, indexIntoProp++); if (c) nameLength += sizeof(wchar_t); } while (c); // increment once more for trailing null nameLength += sizeof (wchar_t); ASSERTU (pLen); *pLen = nameLength; return AAFRESULT_SUCCESS; }
bool ImplAAFTypeDef::IsStringable () const { ASSERTU (0); return false; }
void ImplAAFTypeDef::accept(OMTypeVisitor& visitor) const { // should be pure virtual, but if we allow client extension // of behavior, clients may have to instantiate this ASSERTU (0); }
bool ImplAAFTypeDef::IsVariableArrayable () const { ASSERTU (0); return false; }
bool ImplAAFTypeDef::IsFixedArrayable () const { ASSERTU (0); return false; }
// These all should be pure virtual, but if we allow client extension // of behavior, clients may have to instantiate these. bool ImplAAFTypeDef::IsAggregatable () const { ASSERTU (0); return false; }
// 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) ; }
OMUInt32 ImplAAFTypeDefString::PropValSize (void) const { ASSERTU (0); return 0; // not reached! }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefExtEnum::AppendElement ( const aafUID_t & value, const aafCharacter * pName) { if (! pName) return AAFRESULT_NULL_PARAM; AAFRESULT hr; aafUInt32 origNumElems = 0; hr = CountElements(&origNumElems); if (AAFRESULT_FAILED(hr)) return hr; aafWChar * namesBuf = 0; aafUID_t * valsBuf = 0; AAFRESULT rReturned = AAFRESULT_SUCCESS; try { // // First, calculate new names // aafUInt32 origNameCharCount = 0; aafUInt32 newNameCharCount = 0; // _ElementNames.count() includes final trailing null origNameCharCount = _ElementNames.count(); ASSERTU (pName); aafUInt32 nvbc = (origNumElems+1)*sizeof (aafUID_t); if (nvbc > OMPROPERTYSIZE_MAX) return AAFRESULT_BAD_SIZE; OMPropertySize newValueByteCount = static_cast<OMPropertySize>(nvbc); aafUInt32 ovbc = origNumElems*sizeof (aafUID_t); OMPropertySize origValueByteCount = static_cast<OMPropertySize>(ovbc); // Add length for name to be appended. Don't forget to add one // character for new name's trailing null size_t mnl = wcslen (pName); ASSERTU(mnl <= OMUINT32_MAX); OMUInt32 memberNameLength = static_cast<OMUInt32>(mnl); newNameCharCount = origNameCharCount + memberNameLength + 1; aafUInt32 nnbc = newNameCharCount * sizeof(aafWChar); if (nnbc > OMPROPERTYSIZE_MAX) return AAFRESULT_BAD_SIZE; OMPropertySize newNameByteCount = static_cast<OMPropertySize>(nnbc); aafUInt32 onbc = origNameCharCount*sizeof(aafWChar); OMPropertySize origNameByteCount = static_cast<OMPropertySize>(onbc); namesBuf = new aafWChar[newNameCharCount]; if (origNameCharCount) _ElementNames.getValue (namesBuf, origNameByteCount); // Append new name to end of buffer. Don't forget that original // buffer may have embedded nulls, so start copying at desired // point immediately (don't use strcat or equiv). wcscpy (namesBuf+origNameCharCount, pName); // // now, calculate the new value // // add one for new element to be appended valsBuf = new aafUID_t[origNumElems+1]; if (origNumElems) _ElementValues.getValue (valsBuf, origValueByteCount); valsBuf[origNumElems] = value; // Copy newly-appended name and value buffers out. _ElementNames.setValue (namesBuf, newNameByteCount); _ElementValues.setValue (valsBuf, newValueByteCount); } catch (AAFRESULT &rCaught) { rReturned = rCaught; } if (namesBuf) delete[] namesBuf; if (valsBuf) delete[] valsBuf; return rReturned; }
aafBool ImplAAFTypeDef::IsRegistered (void) const { // Should be implemented in derived class. ASSERTU (0); return kAAFFalse; // not reached! }
STDAPI ImplAAFCreateRawStorageCachedDisk (aafCharacter_constptr pFilename, aafFileExistence_t existence, aafFileAccess_t access, aafUInt32 pageCount, aafUInt32 pageSize, ImplAAFRawStorage ** ppNewRawStorage) { if (! pFilename) return AAFRESULT_NULL_PARAM; if (! ppNewRawStorage) return AAFRESULT_NULL_PARAM; OMRawStorage * stg = 0; if (kAAFFileExistence_new == existence) { switch (access) { case kAAFFileAccess_read: return AAFRESULT_WRONG_OPENMODE; break; case kAAFFileAccess_write: case kAAFFileAccess_modify: stg = OMCachedDiskRawStorage::openNewModify (pFilename, pageSize, pageCount); break; default: return AAFRESULT_WRONG_OPENMODE; } } else if (kAAFFileExistence_existing == existence) { switch (access) { case kAAFFileAccess_read: stg = OMCachedDiskRawStorage::openExistingRead (pFilename, pageSize, pageCount); break; case kAAFFileAccess_write: case kAAFFileAccess_modify: stg = OMCachedDiskRawStorage::openExistingModify (pFilename, pageSize, pageCount); break; default: return AAFRESULT_WRONG_OPENMODE; } } else { return AAFRESULT_WRONG_OPENMODE; } ASSERTU (stg); ImplAAFRawStorage * prs = 0; if (stg->isPositionable ()) prs = static_cast<ImplAAFRawStorage *> (::CreateImpl(CLSID_AAFRandomRawStorage)); else prs = static_cast<ImplAAFRawStorage *> (::CreateImpl(CLSID_AAFRawStorage)); if(!prs) { delete stg; return AAFRESULT_NOMEMORY; } prs->Initialize (stg, access); ASSERTU (ppNewRawStorage); *ppNewRawStorage = prs; return AAFRESULT_SUCCESS; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::CopyValuesIntoValue ( ImplAAFPropertyValue ** ppElementValues, aafUInt32 numElements, aafUInt32 sizeElem, ImplAAFPropertyValue ** ppPropVal) { AAFRESULT hr; //first validate params if (!ppElementValues || !ppPropVal) return AAFRESULT_NULL_PARAM; if (!*ppPropVal) return AAFRESULT_NOT_INITIALIZED; // Get the property value's embedded type and // check if it's the same as the base type. ImplAAFTypeDefSP pIncomingType; if( AAFRESULT_FAILED( (*ppPropVal)->GetType( &pIncomingType ) ) ) return AAFRESULT_BAD_TYPE; ASSERTU (pIncomingType); if( (ImplAAFTypeDef *)pIncomingType != this ) return AAFRESULT_BAD_TYPE; // proceed .... //get pTargetData ImplAAFPropValData * pvd_Target; pvd_Target = dynamic_cast<ImplAAFPropValData*> (*ppPropVal); if (!pvd_Target) return AAFRESULT_BAD_TYPE; //get Bits from Target Data aafMemPtr_t pTargetData = 0; hr = pvd_Target->GetBits(&pTargetData); if (AAFRESULT_FAILED (hr)) return hr; //Copy each source elements' bits over ... for (aafUInt32 i=0; i<numElements; i++) { //get Source Data ImplAAFPropValData * pvd_Source = dynamic_cast<ImplAAFPropValData*> (ppElementValues[i]); if (!pvd_Source) return AAFRESULT_BAD_TYPE; aafUInt32 source_bitsSize; hr = pvd_Source->GetBitsSize (&source_bitsSize); if (AAFRESULT_FAILED (hr)) return hr; //make sure the bits-size is same as the reference if (source_bitsSize != sizeElem) return AAFRESULT_BAD_SIZE; aafMemPtr_t pSourceData = 0; hr = pvd_Source->GetBits (&pSourceData); if (AAFRESULT_FAILED (hr)) return hr; //copy the bits memcpy(pTargetData, pSourceData, source_bitsSize); //once done, incr the target pointer by the amt. of bits copied pTargetData += source_bitsSize; }//for each element *ppPropVal = pvd_Target; return AAFRESULT_SUCCESS; }
//*********************************************************** // // AAFFileOpenNewModifyEx() // STDAPI ImplAAFFileOpenNewModifyEx ( // Null-terminated string containing name of filesystem file to be // opened for modification. Filename must be in a form that would // be acceptable to StgOpenStorage() for this platform. /*[in, string]*/ const aafCharacter * pFileName, // the FileKind to create. Must be one of the constants defined in // include/AAFFileKinds.h, or 0 // a stored object factory must have been registered by ImplAAFFile.cpp /*[in]*/ aafUID_constptr pFileKind, // File open mode flags. May be any of the following ORed together. // All other bits must be set to zero. // - kAAFFileModeUnbuffered - to indicate unbuffered mode. // Default is buffered. // - kAAFFileModeRevertable - to indicate that Revert is possible // on this file (for all changes except those to essence). /*[in]*/ aafUInt32 modeFlags, // Identification of the application which is creating this file. /*[in]*/ aafProductIdentification_t * pIdent, // Pointer to buffer to receive pointer to new file. /*[out]*/ ImplAAFFile ** ppFile) { #if USE_RAW_STORAGE IAAFRawStorage * pRawStg = 0; AAFRESULT hr = AAFCreateRawStorageDisk (pFileName, kAAFFileExistence_new, kAAFFileAccess_modify, &pRawStg); if (AAFRESULT_SUCCEEDED (hr)) { hr = ImplAAFCreateAAFFileOnRawStorage (pRawStg, kAAFFileExistence_new, kAAFFileAccess_modify, pFileKind, modeFlags, pIdent, ppFile); if (AAFRESULT_SUCCEEDED (hr)) { ASSERTU (ppFile); ASSERTU (*ppFile); hr = (*ppFile)->Open (); } } if (pRawStg) { pRawStg->Release (); } return hr; #else // ! USE_RAW_STORAGE HRESULT hr = S_OK; ImplAAFFile * pFile = 0; if (!pFileName || !pIdent || !ppFile) return AAFRESULT_NULL_PARAM; // Initialize the out parameter. *ppFile = 0; // // For backwards compatibility with existing client code // the first checked in version of this function is implemented // the same as the old client code which this function is // intended to replace... // // Create an instance of an uninitialized file object. pFile = static_cast<ImplAAFFile *>(::CreateImpl(CLSID_AAFFile)); if(!pFile) hr = AAFRESULT_NOMEMORY; else { // Make sure the file is initialized (not open yet...) hr = pFile->Initialize(); if (SUCCEEDED(hr)) { // Attempt to open a new file for modification. hr = pFile->OpenNewModify(pFileName, pFileKind, modeFlags, pIdent); if (SUCCEEDED(hr)) { *ppFile = pFile; pFile = 0; } } // Cleanup the file if it could not be initialized and opened. if (FAILED(hr) && pFile) pFile->ReleaseReference(); } return hr; #endif // USE_RAW_STORAGE }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::CreateValueFromValues ( ImplAAFPropertyValue ** ppElementValues, aafUInt32 numElements, ImplAAFPropertyValue ** ppPropVal) { AAFRESULT hr = AAFRESULT_SUCCESS; //first validate params ... if (!ppPropVal) return AAFRESULT_NULL_PARAM; hr = ValidateInputParams(ppElementValues, numElements); if (AAFRESULT_FAILED (hr)) return hr; // All params validated; proceed .... // PATCH DR4_CPR: transdel. Create the appropriate ImplAAFRefArray without an associated // property. The property value's writeTo method needs to copy (or replace) the contents // of the current property. This a hybrid of the old-pseudo "direct access" and the new // more direct property access. ImplAAFTypeDefSP pElementType; hr = GetType(&pElementType); if (AAFRESULT_FAILED(hr)) return hr; if (dynamic_cast<ImplAAFTypeDefObjectRef*>((ImplAAFTypeDef*) pElementType)) { ImplAAFPropertyValue *pPropertyValue = NULL; hr = CreateEmptyValue(&pPropertyValue); if (AAFRESULT_SUCCEEDED(hr)) { ImplAAFRefArrayValue *pRefArray = dynamic_cast<ImplAAFRefArrayValue *>(pPropertyValue); ASSERTU(NULL != pRefArray); if (NULL == pRefArray) hr = AAFRESULT_INVALID_OBJ; aafUInt32 index; for (index = 0; (index < numElements) && AAFRESULT_SUCCEEDED(hr); ++index) { hr = pRefArray->AppendElement(ppElementValues[index]); } if (AAFRESULT_SUCCEEDED(hr)) *ppPropVal = pPropertyValue; // refcount already incremented else pPropertyValue->ReleaseReference(); pPropertyValue = NULL; } } else { //2nd step - Create the value; defer to base impl //first, calculate the total size needed for allocation, based on type //get Base TD ImplAAFTypeDefSP spTargetTD; hr = GetType(&spTargetTD); //gets base elem type if (AAFRESULT_FAILED (hr)) return hr; //Get Elem size aafUInt32 targetElemSize = spTargetTD->NativeSize(); //Total size ... aafUInt32 totalSize = targetElemSize * numElements; //size based on "n" Elements //create the value hr = ImplAAFTypeDefArray::CreateValue(ppPropVal, totalSize); if (AAFRESULT_FAILED(hr)) return hr; //... Copy the values ; defer to base impl hr = ImplAAFTypeDefArray::CopyValuesIntoValue(ppElementValues,numElements, targetElemSize, ppPropVal); } return hr; }
//*********************************************************** // // ImplAAFRawStorageIsAAFFileKind() // // STDAPI ImplAAFRawStorageIsAAFFileKind ( IAAFRawStorage * pRawStorage, aafUID_constptr pAAFFileKind, aafBool * pRawStorageIsAAFFile) { if (pRawStorage == 0) return AAFRESULT_NULL_PARAM; if (pAAFFileKind == 0) return AAFRESULT_NULL_PARAM; if (pRawStorageIsAAFFile == 0) return AAFRESULT_NULL_PARAM; CHECK_CLIENT_IMPLEMENTED_QI(pRawStorage, IID_IAAFRawStorage); HRESULT hr = S_OK; aafBool is_file_kind = kAAFFalse; // Obtain OM representation of pRawStorage. IAAFRoot* p_root_object = 0; hr = pRawStorage->QueryInterface( IID_IAAFRoot, reinterpret_cast<void**>(&p_root_object)); ASSERTU(p_root_object != 0); ImplAAFRoot* p_impl_root_object = 0; p_root_object->GetImplRep( reinterpret_cast<void**>(&p_impl_root_object) ); ASSERTU(p_impl_root_object != 0); p_root_object->Release(); p_root_object = 0; ImplAAFRawStorage* p_impl_raw_storage = dynamic_cast<ImplAAFRawStorage*>(p_impl_root_object); ASSERTU(p_impl_raw_storage != 0); OMRawStorage* p_om_raw_storage = p_impl_raw_storage->GetOMStorage(); ASSERTU(p_om_raw_storage != 0); const OMStoredObjectEncoding* p_om_encoding = reinterpret_cast<const OMStoredObjectEncoding*>(pAAFFileKind); const bool has_factory = OMFile::hasFactory (*p_om_encoding); if (has_factory) { OMStoredObjectFactory* p_factory = OMFile::findFactory (*p_om_encoding); // Does the factory recognize this file? if( p_factory->isRecognized( p_om_raw_storage ) ) { is_file_kind = kAAFTrue; } else { is_file_kind = kAAFFalse; } hr = S_OK; } else { is_file_kind = false; hr = AAFRESULT_FILEKIND_NOT_REGISTERED; } if( hr == S_OK ) { *pRawStorageIsAAFFile = is_file_kind; } return hr; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::GetElementValue ( ImplAAFPropertyValue * pInPropVal, aafUInt32 index, ImplAAFPropertyValue ** ppOutPropVal) { if (! pInPropVal) return AAFRESULT_NULL_PARAM; if (! ppOutPropVal) return AAFRESULT_NULL_PARAM; // Get the property value's embedded type and // check if it's the same as the base type. ImplAAFTypeDefSP pIncomingType; if( AAFRESULT_FAILED( pInPropVal->GetType( &pIncomingType ) ) ) return AAFRESULT_BAD_TYPE; ASSERTU (pIncomingType); if( (ImplAAFTypeDef *)pIncomingType != this ) return AAFRESULT_BAD_TYPE; ImplAAFRefArrayValue* pRefArray = dynamic_cast<ImplAAFRefArrayValue*>(pInPropVal); if (NULL != pRefArray) { return pRefArray->GetElementAt(index, ppOutPropVal); } if (index >= pvtCount (pInPropVal)) return AAFRESULT_BADINDEX; aafUInt32 inBitsSize; ImplAAFPropValDataSP pOutPVData; ImplAAFPropValDataSP pvd; ImplAAFTypeDefSP ptd; AAFRESULT hr; hr = GetType (&ptd); if (AAFRESULT_FAILED (hr)) return hr; // aafUInt32 elementSize = ptd->PropValSize(); aafUInt32 elementSize = ptd->ActualSize(); // okay for data not to be registered? ASSERTU (pInPropVal); pvd = dynamic_cast<ImplAAFPropValData*> (pInPropVal); hr = pvd->GetBitsSize (&inBitsSize); if (! AAFRESULT_SUCCEEDED (hr)) return hr; ASSERTU ((index+1) * elementSize <= inBitsSize); pOutPVData = (ImplAAFPropValData *)CreateImpl(CLSID_AAFPropValData); if (! pOutPVData) return AAFRESULT_NOMEMORY; // Bobt: Hack bugfix! SmartPointer operator= will automatically // AddRef; CreateImpl *also* will addref, so we've got one too // many. Put us back to normal. pOutPVData->ReleaseReference (); hr = pOutPVData->Initialize (ptd); if (AAFRESULT_FAILED(hr)) return hr; hr = pOutPVData->AllocateFromPropVal (pvd, index * elementSize, elementSize, NULL); if (AAFRESULT_FAILED(hr)) return hr; ASSERTU (ppOutPropVal); *ppOutPropVal = pOutPVData; ASSERTU (*ppOutPropVal); (*ppOutPropVal)->AcquireReference (); return AAFRESULT_SUCCESS; }
OMUInt32 ImplAAFTypeDefStream::NativeSize (void) const { ASSERTU (0); return 0; // not reached! }
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; }
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; }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::SetElementValue ( ImplAAFPropertyValue * pPropVal, aafUInt32 index, ImplAAFPropertyValue * pMemberPropVal) { //Ensure our input pointers are valid if (!pPropVal || !pMemberPropVal) return AAFRESULT_NULL_PARAM; // 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; ImplAAFRefArrayValue* pRefArray = dynamic_cast<ImplAAFRefArrayValue*>(pPropVal); if (NULL != pRefArray) { return pRefArray->SetElementAt(pMemberPropVal, index); } //Ensure index is within range if (index >= pvtCount(pPropVal)) //if index is > 0..n-1 return AAFRESULT_BADINDEX; //AAFRESULT_BAD_PARAM; //all parameters validated; proceed .... AAFRESULT hr; //get source size ImplAAFTypeDefSP spSourceTD; hr = pMemberPropVal->GetType (&spSourceTD); if (AAFRESULT_FAILED (hr)) return hr; if (! spSourceTD->IsRegistered ()) return AAFRESULT_NOT_REGISTERED; aafUInt32 sourceSize = spSourceTD->NativeSize(); //get Base TD and size ImplAAFTypeDefSP spTargetTD; hr = GetType (&spTargetTD); //gets base elem type if (AAFRESULT_FAILED (hr)) return hr; aafUInt32 targetElemSize = spTargetTD->NativeSize(); //verify that spTargetTD == spSourceTD if (spTargetTD != spSourceTD) return AAFRESULT_BAD_TYPE; //verify that the target elem size is equal to that of source if (targetElemSize != sourceSize) return AAFRESULT_BAD_SIZE; //// On to data ... //get Source Data ImplAAFPropValData * pvd_Source = dynamic_cast<ImplAAFPropValData*> (pMemberPropVal); ASSERTU (pvd_Source); aafUInt32 source_bitsSize; hr = pvd_Source->GetBitsSize (&source_bitsSize); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (source_bitsSize); ASSERTU ( targetElemSize == source_bitsSize); aafMemPtr_t pSourceData = 0; hr = pvd_Source->GetBits (&pSourceData); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (pSourceData); //get Target Data ImplAAFPropValData * pvd_Target = dynamic_cast<ImplAAFPropValData*> (pPropVal); ASSERTU (pvd_Target); aafUInt32 target_bitsSize; hr = pvd_Target->GetBitsSize (&target_bitsSize); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU ( target_bitsSize >= ((index+1) * targetElemSize) ); aafMemPtr_t pTargetData = 0; hr = pvd_Target->GetBits (&pTargetData); //gets the 0th index location if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (pTargetData); //make target point to the right element pTargetData += (index * targetElemSize); //finally, copy over the appropriate bits memcpy (pTargetData, pSourceData, sourceSize); return AAFRESULT_SUCCESS; }