📄 memfsys.cpp
字号:
delete [] pNewPath; pNewPath = 0; } pFileObject = new CMemoryFileObject(new_path, m_pFileSystem, m_pContext); if (!pFileObject) { return HXR_OUTOFMEMORY; } lReturnVal = pFileObject->QueryInterface(IID_IUnknown, (void**)&pUnknown); response->FileObjectReady(lReturnVal == HXR_OK ? HXR_OK : HXR_FAILED, pUnknown); if(pUnknown) { pUnknown->Release(); pUnknown = NULL; } return lReturnVal;}// IHXFileExists interface/************************************************************************ * Method: * IHXFileExists::DoesExist * Purpose: */STDMETHODIMP CMemoryFileObject::DoesExist(const char* /*IN*/ pPath, IHXFileExistsResponse* /*IN*/ pFileResponse){ HX_ASSERT(pFileResponse); BOOL bExists = FALSE; IHXMemoryFileSystem* pFS = GetMemoryFileSystem(); if (pFS) { bExists = pFS->Exists(m_pFilename); } pFileResponse->DoesExistDone(bExists); return HXR_OK;}/************************************************************************ * Method: * Private interface::_OpenFile * Purpose: * open a chunky res */STDMETHODIMP CMemoryFileObject::_OpenFile(ULONG32 ulFlags){ HX_RESULT lReturnVal = HXR_FAIL; CHXString strURL; UpdateFileNameMember(); strURL = m_pFilename; HX_ASSERT(g_pChunkyResMgr && g_pMapChunkyToStatus); HX_ASSERT(!m_pChunkyRes); IHXMemoryFileSystem* pFS = GetMemoryFileSystem(); if (pFS && pFS->Exists(m_pFilename)) { m_ulFlags = ulFlags; lReturnVal = g_pChunkyResMgr->OpenResource(&m_pChunkyRes, m_pFilename); HX_ASSERT(m_pChunkyRes && lReturnVal == HXR_OK); HX_ASSERT(!m_pStatus); // m_pStatus = NULL; g_pMapChunkyToStatus->Lookup(m_pChunkyRes, (void*&)m_pStatus); HX_ASSERT(m_pStatus); m_pStatus->AddRef(); } HX_RELEASE(pFS); return lReturnVal;}/************************************************************************ * Method: * Private interface::_CloseFile * Purpose: * close a chunky res */STDMETHODIMP CMemoryFileObject::_CloseFile(){ if (m_pChunkyRes) { if (!m_pStatus->Release()) { g_pMapChunkyToStatus->RemoveKey(m_pChunkyRes); m_pStatus = NULL; HX_VERIFY(SUCCEEDED(g_pChunkyResMgr->CloseResource(m_pChunkyRes))); } m_pStatus = NULL; m_pChunkyRes = NULL; } return HXR_OK;}voidCMemoryFileObject::UpdateFileNameMember(){ if (m_pRequest) { const char* pURL = 0; if (m_pRequest->GetURL(pURL) != HXR_OK) { delete[] m_pFilename; m_pFilename = 0; } if (pURL) { CHXString strFilename = m_base_path + pURL; CHXURL url(strFilename); strFilename = url.GetURL(); /* * Strip off the parameters *//* INT32 index = strFilename.Find('?'); if (index >= 0) { strFilename = strFilename.Left(index); }*/ /* * Strip off the '+' *//* index = strFilename.Find('+'); if (index >= 0) { strFilename = strFilename.Left(index); }*/ if (m_pFilename) { delete[] m_pFilename; } m_pFilename = new_string((const char*)strFilename); } }}STDMETHODIMP CMemoryFileObject::SetRequest( IHXRequest* pRequest){ if (!pRequest) { return HXR_INVALID_PARAMETER; } HX_RELEASE(m_pRequest); m_pRequest = pRequest; m_pRequest->AddRef(); UpdateFileNameMember(); return HXR_OK;}STDMETHODIMP CMemoryFileObject::GetRequest( REF(IHXRequest*) pRequest){ pRequest = m_pRequest; if (pRequest) { pRequest->AddRef(); } return pRequest ? HXR_OK : HXR_FAIL;}voidCMemoryFileObject::Process(void){ if (m_ulPendingReadCount > 0) { UINT32 ulCount = m_ulPendingReadCount; m_ulPendingReadCount = 0; Read(ulCount); }}// CMemoryFileObject::SMPLFileObjCallbackCMemoryFileObject::SMPLFileObjCallback::SMPLFileObjCallback(CMemoryFileObject* pFileObject) : m_lRefCount (0) , m_pSMPLFileObject (pFileObject) , m_bCallbackPending (FALSE) , m_ulPendingCallbackID (0) , m_bIgnoreCallback(FALSE){ HX_ASSERT(m_pSMPLFileObject); g_nMemFSysRefCount++;}CMemoryFileObject::SMPLFileObjCallback::~SMPLFileObjCallback(){ HX_ASSERT(g_nMemFSysRefCount > 0); g_nMemFSysRefCount--;}/* * IUnknown methods *//////////////////////////////////////////////////////////////////////////// Method:// IUnknown::QueryInterface// Purpose:// Implement this to export the interfaces supported by your // object.//STDMETHODIMP CMemoryFileObject::SMPLFileObjCallback::QueryInterface(REFIID riid, void** ppvObj){ if (IsEqualIID(riid, IID_IUnknown)) { AddRef(); *ppvObj = this; return HXR_OK; } else if (IsEqualIID(riid, IID_IHXCallback)) { AddRef(); *ppvObj = (IHXCallback*)this; return HXR_OK; } *ppvObj = NULL; return HXR_NOINTERFACE;}/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::AddRef// Purpose:// Everyone usually implements this the same... feel free to use// this implementation.//STDMETHODIMP_(ULONG32) CMemoryFileObject::SMPLFileObjCallback::AddRef(){ return InterlockedIncrement(&m_lRefCount);}/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::Release// Purpose:// Everyone usually implements this the same... feel free to use// this implementation.//STDMETHODIMP_(ULONG32) CMemoryFileObject::SMPLFileObjCallback::Release(){ if (InterlockedDecrement(&m_lRefCount) > 0) { return m_lRefCount; } delete this; return 0;}/* * IHXCallback methods */STDMETHODIMP CMemoryFileObject::SMPLFileObjCallback::Func(void){ /* * To ensure the CMemoryFileObject does not get destroyed before we are * done with it, we AddRef()/Release() it here */ if (m_pSMPLFileObject) { HX_ASSERT(m_bCallbackPending); m_bCallbackPending = FALSE; m_ulPendingCallbackID = 0; //if seek has not cancelled this... if(!m_bIgnoreCallback) { m_pSMPLFileObject->AddRef(); m_pSMPLFileObject->Process(); m_pSMPLFileObject->Release(); } m_bIgnoreCallback = FALSE; } return HXR_OK;}/* * IHXPendingStatus methods *//************************************************************************ * Method: * IHXPendingStatus::GetStatus * Purpose: * Called by the user to get the current pending status from an object */STDMETHODIMPCMemoryFileObject::GetStatus(REF(UINT16) uStatusCode, REF(IHXBuffer*) pStatusDesc, REF(UINT16) ulPercentDone){ /* Default values*/ uStatusCode = HX_STATUS_READY; pStatusDesc = 0; ulPercentDone = 0; if (!m_pStatus) { uStatusCode = HX_STATUS_INITIALIZING; // we're still initializing! return HXR_OK; } if (m_pStatus->GetDone()) { uStatusCode = HX_STATUS_READY; ulPercentDone = 0; } else if (m_bSeekPending || m_ulPendingReadCount) { uStatusCode = HX_STATUS_BUFFERING; ULONG32 ulReadCount = 0; if (m_ulPendingReadCount) { ulReadCount = (ULONG32)m_ulPendingReadCount; } int nContentRead = m_pStatus->GetSize(); if (m_ulPos+ulReadCount) { ulPercentDone = (UINT16) ((nContentRead*100)/(m_ulPos+ulReadCount)); ulPercentDone = ulPercentDone <= 100 ? ulPercentDone : 100; } else { ulPercentDone = (UINT16) 100; } } return HXR_OK;}/************************************************************************ * Method: * GetMemoryFileSystem * Purpose: * QI the file system for the memory file system interface. */IHXMemoryFileSystem*CMemoryFileObject::GetMemoryFileSystem(void){ IHXMemoryFileSystem* pFS = NULL; if (m_pFileSystem && m_pFileSystem->QueryInterface(IID_IHXMemoryFileSystem, (void**)&pFS) == HXR_OK) { return pFS; } return NULL;}/************************************************************************ * Method: * GetMemoryFileSystem2 * Purpose: * QI the file system for the memory file system interface. */IHXMemoryFileSystem2*CMemoryFileObject::GetMemoryFileSystem2(void){ IHXMemoryFileSystem2* pFS = NULL; if (m_pFileSystem && m_pFileSystem->QueryInterface(IID_IHXMemoryFileSystem2, (void**)&pFS) == HXR_OK) { return pFS; } return NULL;}/************************************************************************ * Method: * IHXFileMimeMapper::FindMimeType * Purpose: */STDMETHODIMPCMemoryFileObject::FindMimeType(const char* pURL, IHXFileMimeMapperResponse* pMimeMapperResponse){ HX_ASSERT(pMimeMapperResponse); IHXValues* pHeader = NULL; IHXBuffer* pValue = NULL; HX_RESULT retVal = HXR_FAIL; if (m_pStatus) { char* pMime = m_pStatus->GetMime(); if (pMime) { pMimeMapperResponse->MimeTypeFound(HXR_OK, pMime); return HXR_OK; } } // ok if we do not have it, maybe the request object has it. if (m_pRequest) { m_pRequest->GetResponseHeaders(pHeader); if (pHeader && HXR_OK == pHeader->GetPropertyCString("Content-Type", pValue) && pValue) { m_strHeaderContentType = (const char*)pValue->GetBuffer(); retVal = HXR_OK; HX_RELEASE(pValue); } HX_RELEASE(pHeader); } if (retVal == HXR_OK) { pMimeMapperResponse->MimeTypeFound(retVal, (const char*)m_strHeaderContentType); } else { pMimeMapperResponse->MimeTypeFound(HXR_OK, NULL); } return HXR_OK;}/************************************************************************ * Method: * IHXFileResponse::InitDone * Purpose: * Notification interface provided by users of the IHXFileObject * interface. This method is called by the IHXFileObject when the * initialization of the file is complete. If the file is not valid * for the file system, the status HXR_FAILED should be * returned. */STDMETHODIMPCMemoryFileObject::InitDone(HX_RESULT status){ if (m_bAsynchInit) { m_bAsynchInit = FALSE; // attempt to init the file if (status == HXR_OK) { _OpenFile(m_ulFlags); } if (m_pFileResponse) { m_pFileResponse->InitDone(status); } } return HXR_OK;}/************************************************************************ * Method: * IHXFileResponse::CloseDone * Purpose: * Notification interface provided by users of the IHXFileObject * interface. This method is called by the IHXFileObject when the * close of the file is complete. */STDMETHODIMPCMemoryFileObject::CloseDone(HX_RESULT status){ return HXR_NOTIMPL;}/************************************************************************ * Method: * IHXFileResponse::ReadDone * Purpose: * Notification interface provided by users of the IHXFileObject * interface. This method is called by the IHXFileObject when the * last read from the file is complete and a buffer is available. */STDMETHODIMPCMemoryFileObject::ReadDone(HX_RESULT status, IHXBuffer* pBuffer){ return HXR_NOTIMPL;}/************************************************************************ * Method: * IHXFileResponse::WriteDone * Purpose: * Notification interface provided by users of the IHXFileObject * interface. This method is called by the IHXFileObject when the * last write to the file is complete. */STDMETHODIMPCMemoryFileObject::WriteDone(HX_RESULT status){ return HXR_NOTIMPL;}/************************************************************************ * Method: * IHXFileResponse::SeekDone * Purpose: * Notification interface provided by users of the IHXFileObject * interface. This method is called by the IHXFileObject when the * last seek in the file is complete. */STDMETHODIMPCMemoryFileObject::SeekDone(HX_RESULT status){ return HXR_NOTIMPL;}/* * IHXValues methods */STDMETHODIMPCMemoryFileSystem::SetPropertyULONG32(const char* pPropertyName, ULONG32 uPropertyValue){ if (!strcmp(pPropertyName, MEMFS_RECURSION_DEPTH)) { z_uMaxRecursionLevel = uPropertyValue; if (z_uMaxRecursionLevel == 0) { // use the default z_uMaxRecursionLevel = MAX_RECURSION_LEVEL; } return HXR_OK; } return HXR_FAIL;}STDMETHODIMPCMemoryFileSystem::GetPropertyULONG32(const char* pPropertyName, REF(ULONG32) uPropertyValue){ uPropertyValue = 0; if (!strcmp(pPropertyName, MEMFS_RECURSION_DEPTH)) { uPropertyValue = z_uMaxRecursionLevel; return HXR_OK; } return HXR_FAIL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -