Example #1
0
STDAPI MemoryFileOpenNewModify (
  aafUInt32  modeFlags,
  aafProductIdentification_t*  pIdent,
  IAAFFile** ppFile)
{
  HRESULT hr;
  IAAFRawStorage* rs = 0;

  hr = AAFCreateRawStorageMemory(
    kAAFFileAccess_modify,
    &rs);
  if (!SUCCEEDED(hr)) {
    return hr;
  }

  hr = AAFCreateAAFFileOnRawStorage(
    rs,
    kAAFFileExistence_new,
    kAAFFileAccess_write,
    &kAAFFileKind_Aaf4KBinary,
    modeFlags,
    pIdent,
    ppFile);
  if (!SUCCEEDED(hr)) {
    (*ppFile)->Release();
    return hr;
  }

  hr = (*ppFile)->Open();
  if (!SUCCEEDED(hr)) {
    (*ppFile)->Release();
    rs->Release();
    return hr;
  }

  rs->Release();
  rs = 0;

  return S_OK;
}
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;
}
Example #3
0
//***********************************************************
//
// 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
}
Example #4
0
//***********************************************************
//
// 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
}
Example #5
0
//***********************************************************
//
// 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
}