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;
}
Example #2
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
}