Beispiel #1
0
STDAPI
ImplAAFCreateRawStorageCached
  (IAAFRawStorage * pRawStorage,
   aafUInt32  pageCount,
   aafUInt32  pageSize,
   ImplAAFRawStorage ** ppNewRawStorage)
{
  if (! pRawStorage)
	return AAFRESULT_NULL_PARAM;
  if (! ppNewRawStorage)
	return AAFRESULT_NULL_PARAM;

  IAAFCachePageAllocator * pCachePageAllocator = 0;
  HRESULT hr = AAFCreateBuiltinCachePageAllocator(pageSize, pageCount, &pCachePageAllocator);
  if (!AAFRESULT_SUCCEEDED(hr))
    return hr;

  hr = ImplAAFCreateRawStorageCached2(pRawStorage,
                                        pageCount,
                                        pageSize,
                                        pCachePageAllocator,
                                        ppNewRawStorage);

  pCachePageAllocator->Release();
  pCachePageAllocator = 0;

  return hr;
}
HRESULT TestCachePageAllocator::Create(IAAFCachePageAllocator** ppAllocator)
{
  if (ppAllocator == 0)
    return AAFRESULT_NULL_PARAM;

  IAAFCachePageAllocator* result = new TestCachePageAllocator();
  if (result == 0)
    return AAFRESULT_NOMEMORY;

  result->AddRef();
  *ppAllocator = result;
  return AAFRESULT_SUCCESS;
}
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;
}