📄 filehdlr.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: filehdlr.cpp,v 1.2.24.1 2004/07/09 01:52:03 hubbe Exp $ * * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. * * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks. You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL. Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. * * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. * * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. * * Technology Compatibility Kit Test Suite(s) Location: * http://www.helixcommunity.org/content/tck * * Contributor(s): * * ***** END LICENSE BLOCK ***** */// include#include "hxtypes.h"#include "hxwintyp.h"#include "hxcom.h"#include "hxresult.h"#include "hxcomm.h"#include "hxengin.h"#include "ihxpckts.h"#include "hxfiles.h"#include "hxformt.h"#include "hxplugn.h"#include "hxengin.h"#include "hxmon.h"#include "ihxfgbuf.h"// pnmisc#include "baseobj.h"#include "unkimp.h"// pncont#include "hxslist.h"#include "hxmap.h"#include "hxbuffer.h"#include "carray.h"#include "chxfgbuf.h"// pxcomlib#include "pxrect.h"#include "pxcolor.h"#include "pxeffect.h"#include "pxcmpmgr.h"#include "wirefmgr.h"#include "pxffmcod.h"#include "rpfile.h"#include "pxffcmgr.h"// pxff#include "pxschedu.h"#include "pxff2.h"#include "filehdlr.h"// pndebug#include "errdbg.h"#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE static char HX_THIS_FILE[] = __FILE__;#endifPXFileHandler::PXFileHandler(){#ifdef XXXMEH_DEBUG_LOG DEBUG_OUTF("c:\\pxff.log", (s, "PXFileHandler::PXFileHandler(0x%08X)\n", this));#endif m_lRefCount = 0; m_pContext = NULL; m_pRPFileObject = NULL; m_pResponse = NULL; m_pCommonClassFactory = NULL; m_pFileSystemManager = NULL; m_pFileObject = NULL; m_pFragBuffer = NULL; m_pImageNameStr = NULL; m_pImageMimeTypeStr = NULL; m_pFileStat = NULL; m_pFileMimeMapper = NULL; Reset();}PXFileHandler::~PXFileHandler(){#ifdef XXXMEH_DEBUG_LOG DEBUG_OUTF("c:\\pxff.log", (s, "PXFileHandler::~PXFileHandler(0x%08X)\n", this));#endif Deallocate();}STDMETHODIMP PXFileHandler::Init(IUnknown* pContext, IHXFileObject* pRPFileObject, CRealPixFileFormat* pResponse, ULONG32 ulReadChunkSize){#ifdef XXXMEH_DEBUG_LOG DEBUG_OUTF("c:\\pxff.log", (s, "PXFileHandler::Init(0x%08X,0x%08X,0x%08X,0x%08X)\n", this, pContext, pRPFileObject, pResponse));#endif HX_RESULT retVal = HXR_OK; if (pContext && pRPFileObject && pResponse) { // Clear out everything Deallocate(); Reset(); m_ulReadChunkSize = ulReadChunkSize; // Save arguments into members m_pContext = pContext; m_pContext->AddRef(); m_pRPFileObject = pRPFileObject; m_pRPFileObject->AddRef(); m_pResponse = pResponse; m_pResponse->AddRef(); // Get an IHXCommonClassFactory interface retVal = m_pContext->QueryInterface(IID_IHXCommonClassFactory, (void**) &m_pCommonClassFactory); if (SUCCEEDED(retVal)) { // Get an IHXFileSystemManager interface retVal = m_pCommonClassFactory->CreateInstance(CLSID_IHXFileSystemManager, (void**) &m_pFileSystemManager); if (SUCCEEDED(retVal)) { // Set the state m_ulState = kStateInitialized; } } } else { retVal = HXR_INVALID_PARAMETER; } if (FAILED(retVal)) { m_ulState = kStateError; } return retVal;}STDMETHODIMP PXFileHandler::ReadRPFile(){#ifdef XXXMEH_DEBUG_LOG DEBUG_OUTF("c:\\pxff.log", (s, "PXFileHandler::ReadRPFile(0x%08X)\n", this));#endif HX_RESULT retVal = HXR_OK; if (m_ulState == kStateInitialized) { // Set state m_ulState = kStateReadRPFileInit; // Init the file object m_pRPFileObject->Init(HX_FILE_READ | HX_FILE_BINARY, this); } else { retVal = HXR_UNEXPECTED; } return retVal;}STDMETHODIMP PXFileHandler::StatImageFile(UINT32 ulInstance, IHXBuffer* pImageNameStr){#ifdef XXXMEH_DEBUG_LOG DEBUG_OUTF("c:\\pxff.log", (s, "PXFileHandler::StatImageFile(0x%08X,%lu,%s)\n", this, ulInstance, (const char*) pImageNameStr->GetBuffer()));#endif HX_RESULT retVal = HXR_OK; if (m_ulState == kStateInitialized) { if (pImageNameStr) { // Save the instance index m_ulInstance = ulInstance; // Save the name buffer HX_RELEASE(m_pImageNameStr); m_pImageNameStr = pImageNameStr; m_pImageNameStr->AddRef(); // Set the state m_ulState = kStateStatImageFileFSMInit; // Init the file system manager retVal = m_pFileSystemManager->Init(this); } else { retVal = HXR_INVALID_PARAMETER; } if (FAILED(retVal)) { m_ulState = kStateError; m_pResponse->StatImageFileDone(retVal, ulInstance, 0, NULL); } } else { retVal = HXR_UNEXPECTED; } return retVal;}STDMETHODIMP PXFileHandler::ReadImageFile(UINT32 ulInstance, IHXBuffer* pImageNameStr){#ifdef XXXMEH_DEBUG_LOG DEBUG_OUTF("c:\\pxff.log", (s, "PXFileHandler::ReadImageFile(0x%08X,%lu,%s)\n", this, ulInstance, (const char*) pImageNameStr->GetBuffer()));#endif HX_RESULT retVal = HXR_OK; if (m_ulState == kStateInitialized) { if (ulInstance && pImageNameStr) { // Save the handle m_ulInstance = ulInstance; // Save the image name HX_RELEASE(m_pImageNameStr); m_pImageNameStr = pImageNameStr; m_pImageNameStr->AddRef(); // Set the state m_ulState = kStateReadImageFileFSMInit; // Init the file system manager m_pFileSystemManager->Init(this); } else { retVal = HXR_INVALID_PARAMETER; } if (FAILED(retVal)) { m_ulState = kStateError; m_pResponse->ReadImageFileDone(retVal, ulInstance, NULL); } } else { retVal = HXR_UNEXPECTED; } return retVal;}STDMETHODIMP PXFileHandler::Shutdown(){#ifdef XXXMEH_DEBUG_LOG DEBUG_OUTF("c:\\pxff.log", (s, "PXFileHandler::Shutdown(0x%08X)\n", this));#endif HX_RESULT retVal = HXR_OK; if (m_pResponse) { if (m_ulState == kStateConstructed || m_ulState == kStateError || m_ulState == kStateInitialized || m_ulState == kStateReadRPFileDone || m_ulState == kStateStatImageFileDone || m_ulState == kStateReadImageFileDone) { // In these cases, we there is no pending callback // because we either finished or we never started. // Therefore we simply change the state to the final // state and call ShutdownDone(). m_ulState = kStateShutdownDone; // Call ShutdownDone() m_pResponse->ShutdownDone(HXR_OK, m_ulInstance); } else if (m_ulState == kStateReadRPFileInit || m_ulState == kStateReadRPFileRead || m_ulState == kStateReadRPFileHold) { // Here we have an .rp file object for which we're // waiting on a pending callback. We will call // Close() on this file object and then wait on // the CloseDone() to call ShutdownDone() in the application. // Depending on the file system, the pending callback may come // back immediately or it may come back normally. // All that we have to do is make sure that we do // nothing in that callback. // // First we change the state m_ulState = kStateShutdownClose; // Call Close on the .rp file object m_pRPFileObject->Close(); } else if (m_ulState == kStateStatImageFileInit || m_ulState == kStateStatImageFileStat || m_ulState == kStateStatImageFileMime || m_ulState == kStateReadImageFileInit || m_ulState == kStateReadImageFileRead) { // Here we have an image file object for which we're // waiting on a pending callback. We will call // Close() on this image file object and then wait on // the CloseDone() to call ShutdownDone() in the application. // Depending on the file system, the pending callback may come // back immediately or it may come back normally. // All that we have to do is make sure that we do // nothing in that callback. // // First change the state m_ulState = kStateShutdownClose; // Call Close() m_pFileObject->Close(); } else if (m_ulState == kStateReadRPFileClose || m_ulState == kStateStatImageFileClose || m_ulState == kStateReadImageFileClose) { // Here we have already called Close() on the // file object so we don't have to do it again. // We simply have to set the state and when we // get called back with CloseDone(), then we need // to call ShutdownDone() instead of the normal // callback to the application. m_ulState = kStateShutdownClose; } else if (m_ulState == kStateStatImageFileFSMInit || m_ulState == kStateStatImageFileCreate || m_ulState == kStateReadImageFileFSMInit || m_ulState == kStateReadImageFileCreate) { // Here we are waiting on callbacks from the // file system manager. In these cases, we simply // need to change the state to the final state // and then call ShutdownDone() in the application. // Also, we need to make sure that we don't do anything // when/if the pending callback comes back. m_ulState = kStateShutdownDone; // Call ShutdownDone() in the application m_pResponse->ShutdownDone(HXR_OK, m_ulInstance); } else if (m_ulState == kStateShutdownClose) { // We've already set this object up for shutdown // and are awaiting a CloseDone() from the file // object. Therefore, we will return HXR_UNEXPECTED; retVal = HXR_UNEXPECTED; } else if (m_ulState == kStateShutdownDone) { // We've already shut this object down, so // will return HXR_UNEXPECTED retVal = HXR_UNEXPECTED; } else { // Unknown state retVal = HXR_UNEXPECTED; } } else { retVal = HXR_UNEXPECTED; } return retVal;}STDMETHODIMP_(UINT32) PXFileHandler::GetInstanceHandle(){ return m_ulInstance;}STDMETHODIMP_(BOOL) PXFileHandler::IsShutdownDone(){ return (m_ulState == kStateShutdownDone ? TRUE : FALSE);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -