HRESULT CAAFCachePageAllocator_test(testMode_t /* mode */, aafUID_t fileKind, testRawStorageType_t /* rawStorageType */, aafProductIdentification_t productID) { const size_t fileNameBufLen = 128; aafWChar pFileName[ fileNameBufLen ] = L""; GenerateTestFileName( productID.productName, fileKind, fileNameBufLen, pFileName ); (void)RemoveTestFile(pFileName ); IAAFRawStorage* pRawStorage = 0; HRESULT hr = AAFCreateRawStorageDisk(pFileName, kAAFFileExistence_new, kAAFFileAccess_modify, &pRawStorage); if (!AAFRESULT_SUCCEEDED(hr)) return hr; IAAFCachePageAllocator* pAllocator = 0; hr = TestCachePageAllocator::Create(&pAllocator); if (!AAFRESULT_SUCCEEDED(hr)) { pRawStorage->Release(); pRawStorage = 0; return hr; } IAAFRawStorage* pCachedRawStorage = 0; hr = AAFCreateRawStorageCached2(pRawStorage, 16, 4096, pAllocator, &pCachedRawStorage); if (!AAFRESULT_SUCCEEDED(hr)) { pRawStorage->Release(); pRawStorage = 0; pAllocator->Release(); pAllocator = 0; return hr; } aafUID_t encoding = EffectiveTestFileEncoding(fileKind); IAAFFile* pFile = 0; hr = AAFCreateAAFFileOnRawStorage(pCachedRawStorage, kAAFFileExistence_new, kAAFFileAccess_modify, &encoding, 0, &productID, &pFile); if (!AAFRESULT_SUCCEEDED(hr)) { pRawStorage->Release(); pRawStorage = 0; pAllocator->Release(); pAllocator = 0; pCachedRawStorage->Release(); pCachedRawStorage = 0; return hr; } hr = pFile->Open(); if (!AAFRESULT_SUCCEEDED(hr)) { pRawStorage->Release(); pRawStorage = 0; pAllocator->Release(); pAllocator = 0; pCachedRawStorage->Release(); pCachedRawStorage = 0; pFile->Release(); pFile = 0; return hr; } hr = pFile->Save(); if (!AAFRESULT_SUCCEEDED(hr)) return hr; hr = pFile->Close(); if (!AAFRESULT_SUCCEEDED(hr)) return hr; pRawStorage->Release(); pRawStorage = 0; pAllocator->Release(); pAllocator = 0; pCachedRawStorage->Release(); pCachedRawStorage = 0; pFile->Release(); pFile = 0; return hr; }
//*********************************************************** // // 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 }
// Create an AAF file to be used by module test. AAFRESULT CreateTestFile( const aafCharacter* p_file_name, aafUID_constref file_kind, const testRawStorageType_t raw_storage_type, aafUInt32 file_mode_flags, aafProductIdentification_constref product_identification, IAAFFile** pp_new_file ) { assert( p_file_name != 0 ); assert( pp_new_file != 0 ); // // Determine the file encoding to use. // aafUID_t use_file_kind = EffectiveTestFileEncoding( file_kind ); // // Create a raw storage object if necessary. // AAFRESULT hr = AAFRESULT_SUCCESS; IAAFRawStorage* p_raw_storage = 0; if( raw_storage_type == kAAFNamedFile ) { p_raw_storage = 0; hr = AAFRESULT_SUCCESS; } else if( raw_storage_type == kAAFDiskRawStorage ) { // Attempt to create an IAAFRawStorage object // of the specified type. hr = AAFCreateRawStorageDisk( p_file_name, kAAFFileExistence_new, kAAFFileAccess_modify, &p_raw_storage ); } else if( raw_storage_type == kAAFCachedDiskRawStorage ) { hr = AAFRESULT_NOT_IMPLEMENTED; } else if( raw_storage_type == kAAFMappedFileRawStorage ) { hr = AAFRESULT_NOT_IMPLEMENTED; } else if( raw_storage_type == kAAFMemoryRawStorage ) { hr = AAFRESULT_NOT_IMPLEMENTED; } else { // The raw storage type is not supported by the toolkit hr = AAFRESULT_INVALID_PARAM; } // // Create a file object. // if( hr == AAFRESULT_SUCCESS ) { // // Create a file object. // IAAFFile* p_file = 0; if( p_raw_storage != 0 ) { // Use raw storage API to create a file. hr = AAFCreateAAFFileOnRawStorage( p_raw_storage, kAAFFileExistence_new, kAAFFileAccess_modify, &use_file_kind, file_mode_flags, &product_identification, &p_file ); p_raw_storage->Release(); p_raw_storage = 0; // Open the file. if( hr == AAFRESULT_SUCCESS ) { hr = p_file->Open(); if( hr != AAFRESULT_SUCCESS ) { p_file->Release(); p_file = 0; } } } else { // Use 'traditional' API to create a file. hr = AAFFileOpenNewModifyEx( p_file_name, &use_file_kind, file_mode_flags, const_cast<aafProductIdentification_t*>( &product_identification ), &p_file ); } if( hr == AAFRESULT_SUCCESS ) { assert( p_file != 0 ); *pp_new_file = p_file; } } return hr; }
//*********************************************************** // // 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 }