diff --git a/platform/gucefVFS/src/gucefVFS_CVFS.cpp b/platform/gucefVFS/src/gucefVFS_CVFS.cpp index 547040d51..34682066e 100644 --- a/platform/gucefVFS/src/gucefVFS_CVFS.cpp +++ b/platform/gucefVFS/src/gucefVFS_CVFS.cpp @@ -256,17 +256,31 @@ CVFS::StoreAsFileAsync( const CORE::CString& filepath , const CORE::CString& asyncRequestId ) {GUCEF_TRACE; - CStoreAsFileTaskData operationData; - operationData.operationType = ASYNCVFSOPERATIONTYPE_STOREDATAASFILE; - operationData.asyncRequestId = asyncRequestId; - operationData.filepath = filepath; - operationData.data.LinkTo( data ); - operationData.offset = offset; - operationData.overwrite = overwrite; - operationData.SetRequestorData( requestorData ); - - CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); - return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + try + { + CStoreAsFileTaskData operationData; + operationData.operationType = ASYNCVFSOPERATIONTYPE_STOREDATAASFILE; + operationData.asyncRequestId = asyncRequestId; + operationData.filepath = filepath; + operationData.data.LinkTo( data ); + operationData.offset = offset; + operationData.overwrite = overwrite; + operationData.SetRequestorData( requestorData ); + + CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); + return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + } + catch ( const timeout_exception& ) + { + GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "VFS:StoreAsFileAsync: Failed to queue task due to timeout. asyncRequestId=" + + asyncRequestId ); + } + catch ( const std::exception& e ) + { + GUCEF_EXCEPTION_LOG( CORE::LOGLEVEL_IMPORTANT, "VFS:StoreAsFileAsync: Failed to queue task due to exception. asyncRequestId=" + + asyncRequestId + " what=" + CORE::ToString( e.what() ) ); + } + return false; } /*-------------------------------------------------------------------------*/ @@ -277,14 +291,28 @@ CVFS::MountArchiveAsync( const CArchiveSettings& settings , const CORE::CString& asyncRequestId ) {GUCEF_TRACE; - CMountArchiveTaskData operationData; - operationData.operationType = ASYNCVFSOPERATIONTYPE_MOUNTARCHIVE; - operationData.asyncRequestId = asyncRequestId; - operationData.settings = settings; - operationData.SetRequestorData( requestorData ); + try + { + CMountArchiveTaskData operationData; + operationData.operationType = ASYNCVFSOPERATIONTYPE_MOUNTARCHIVE; + operationData.asyncRequestId = asyncRequestId; + operationData.settings = settings; + operationData.SetRequestorData( requestorData ); - CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); - return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); + return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + } + catch ( const timeout_exception& ) + { + GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "VFS:MountArchiveAsync: Failed to queue task due to timeout. asyncRequestId=" + + asyncRequestId ); + } + catch ( const std::exception& e ) + { + GUCEF_EXCEPTION_LOG( CORE::LOGLEVEL_IMPORTANT, "VFS:MountArchiveAsync: Failed to queue task due to exception. asyncRequestId=" + + asyncRequestId + " what=" + CORE::ToString( e.what() ) ); + } + return false; } /*-------------------------------------------------------------------------*/ @@ -606,15 +634,29 @@ CVFS::MoveFileAsync( const CORE::CString& oldFilePath , const CORE::CString& asyncRequestId ) {GUCEF_TRACE; - CMoveFileTaskData operationData; - operationData.operationType = ASYNCVFSOPERATIONTYPE_MOVEFILE; - operationData.asyncRequestId = asyncRequestId; - operationData.originalFilepath = oldFilePath; - operationData.newFilepath = newFilePath; - operationData.overwrite = overwrite; + try + { + CMoveFileTaskData operationData; + operationData.operationType = ASYNCVFSOPERATIONTYPE_MOVEFILE; + operationData.asyncRequestId = asyncRequestId; + operationData.originalFilepath = oldFilePath; + operationData.newFilepath = newFilePath; + operationData.overwrite = overwrite; - CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); - return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); + return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + } + catch ( const timeout_exception& ) + { + GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "VFS:MoveFileAsync: Failed to queue task due to timeout. asyncRequestId=" + + asyncRequestId ); + } + catch ( const std::exception& e ) + { + GUCEF_EXCEPTION_LOG( CORE::LOGLEVEL_IMPORTANT, "VFS:MoveFileAsync: Failed to queue task due to exception. asyncRequestId=" + + asyncRequestId + " what=" + CORE::ToString( e.what() ) ); + } + return false; } /*-------------------------------------------------------------------------*/ @@ -661,15 +703,29 @@ CVFS::CopyFileAsync( const CORE::CString& originalFilepath , const CORE::CString& asyncRequestId ) {GUCEF_TRACE; - CCopyFileTaskData operationData; - operationData.operationType = ASYNCVFSOPERATIONTYPE_COPYFILE; - operationData.asyncRequestId = asyncRequestId; - operationData.originalFilepath = originalFilepath; - operationData.copyFilepath = copyFilepath; - operationData.overwrite = overwrite; + try + { + CCopyFileTaskData operationData; + operationData.operationType = ASYNCVFSOPERATIONTYPE_COPYFILE; + operationData.asyncRequestId = asyncRequestId; + operationData.originalFilepath = originalFilepath; + operationData.copyFilepath = copyFilepath; + operationData.overwrite = overwrite; - CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); - return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); + return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + } + catch ( const timeout_exception& ) + { + GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "VFS:CopyFileAsync: Failed to queue task due to timeout. asyncRequestId=" + + asyncRequestId ); + } + catch ( const std::exception& e ) + { + GUCEF_EXCEPTION_LOG( CORE::LOGLEVEL_IMPORTANT, "VFS:CopyFileAsync: Failed to queue task due to exception. asyncRequestId=" + + asyncRequestId + " what=" + CORE::ToString( e.what() ) ); + } + return false; } /*-------------------------------------------------------------------------*/ @@ -734,17 +790,31 @@ CVFS::EncodeFileAsync( const CORE::CString& originalFilepath , const CORE::CString& asyncRequestId ) {GUCEF_TRACE; - CEncodeFileTaskData operationData; - operationData.operationType = ASYNCVFSOPERATIONTYPE_ENCODEFILE; - operationData.asyncRequestId = asyncRequestId; - operationData.originalFilepath = originalFilepath; - operationData.encodedFilepath = encodedFilepath; - operationData.overwrite = overwrite; - operationData.codecFamily = codecFamily; - operationData.encodeCodec = encodeCodec; + try + { + CEncodeFileTaskData operationData; + operationData.operationType = ASYNCVFSOPERATIONTYPE_ENCODEFILE; + operationData.asyncRequestId = asyncRequestId; + operationData.originalFilepath = originalFilepath; + operationData.encodedFilepath = encodedFilepath; + operationData.overwrite = overwrite; + operationData.codecFamily = codecFamily; + operationData.encodeCodec = encodeCodec; - CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); - return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); + return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + } + catch ( const timeout_exception& ) + { + GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "VFS:EncodeFileAsync: Failed to queue task due to timeout. asyncRequestId=" + + asyncRequestId ); + } + catch ( const std::exception& e ) + { + GUCEF_EXCEPTION_LOG( CORE::LOGLEVEL_IMPORTANT, "VFS:EncodeFileAsync: Failed to queue task due to exception. asyncRequestId=" + + asyncRequestId + " what=" + CORE::ToString( e.what() ) ); + } + return false; } /*-------------------------------------------------------------------------*/ @@ -851,18 +921,32 @@ CVFS::EncodeAsFileAsync( const CORE::CDynamicBuffer& data , const CORE::CString& asyncRequestId ) {GUCEF_TRACE; - CEncodeBufferAsFileTaskData operationData; - operationData.operationType = ASYNCVFSOPERATIONTYPE_ENCODEDATAASFILE; - operationData.asyncRequestId = asyncRequestId; - operationData.data = data; - operationData.bufferOffset = bufferOffset; - operationData.encodedFilepath = encodedFilepath; - operationData.overwrite = overwrite; - operationData.codecFamily = codecFamily; - operationData.encodeCodec = encodeCodec; + try + { + CEncodeBufferAsFileTaskData operationData; + operationData.operationType = ASYNCVFSOPERATIONTYPE_ENCODEDATAASFILE; + operationData.asyncRequestId = asyncRequestId; + operationData.data = data; + operationData.bufferOffset = bufferOffset; + operationData.encodedFilepath = encodedFilepath; + operationData.overwrite = overwrite; + operationData.codecFamily = codecFamily; + operationData.encodeCodec = encodeCodec; - CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); - return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); + return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + } + catch ( const timeout_exception& ) + { + GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "VFS:EncodeAsFileAsync: Failed to queue task due to timeout. asyncRequestId=" + + asyncRequestId ); + } + catch ( const std::exception& e ) + { + GUCEF_EXCEPTION_LOG( CORE::LOGLEVEL_IMPORTANT, "VFS:EncodeAsFileAsync: Failed to queue task due to exception. asyncRequestId=" + + asyncRequestId + " what=" + CORE::ToString( e.what() ) ); + } + return false; } /*-------------------------------------------------------------------------*/ @@ -966,17 +1050,31 @@ CVFS::DecodeFileAsync( const CORE::CString& originalFilepath , const CORE::CString& asyncRequestId ) {GUCEF_TRACE; - CDecodeFileTaskData operationData; - operationData.operationType = ASYNCVFSOPERATIONTYPE_DECODEFILE; - operationData.asyncRequestId = asyncRequestId; - operationData.originalFilepath = originalFilepath; - operationData.decodedFilepath = decodedFilepath; - operationData.overwrite = overwrite; - operationData.codecFamily = codecFamily; - operationData.decodeCodec = decodeCodec; + try + { + CDecodeFileTaskData operationData; + operationData.operationType = ASYNCVFSOPERATIONTYPE_DECODEFILE; + operationData.asyncRequestId = asyncRequestId; + operationData.originalFilepath = originalFilepath; + operationData.decodedFilepath = decodedFilepath; + operationData.overwrite = overwrite; + operationData.codecFamily = codecFamily; + operationData.decodeCodec = decodeCodec; - CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); - return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + CORE::ThreadPoolPtr threadPool = CORE::CCoreGlobal::Instance()->GetTaskManager().GetOrCreateThreadPool( m_asyncOpsThreadpool ); + return !CORE::TaskStatusIsAnError( threadPool->QueueTask( CAsyncVfsOperation::TaskType, &operationData, GUCEF_NULL, &AsObserver() ) ); + } + catch ( const timeout_exception& ) + { + GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "VFS:DecodeFileAsync: Failed to queue task due to timeout. asyncRequestId=" + + asyncRequestId ); + } + catch ( const std::exception& e ) + { + GUCEF_EXCEPTION_LOG( CORE::LOGLEVEL_IMPORTANT, "VFS:DecodeFileAsync: Failed to queue task due to exception. asyncRequestId=" + + asyncRequestId + " what=" + CORE::ToString( e.what() ) ); + } + return false; } /*-------------------------------------------------------------------------*/ diff --git a/tools/FilePusher/src/FilePusher.cpp b/tools/FilePusher/src/FilePusher.cpp index 4ff265eb9..66335a893 100644 --- a/tools/FilePusher/src/FilePusher.cpp +++ b/tools/FilePusher/src/FilePusher.cpp @@ -1040,7 +1040,7 @@ FilePushDestination::OnAsyncVfsFileEncodeOpCompleted( CORE::CNotifier* notifier TStringInFlightEntryPtrMap::iterator i = m_inflight.find( originalFilePath ); if ( i != m_inflight.end() ) { - InFlightEntryPtr& slot = (*i).second; + InFlightEntryPtr slot = (*i).second; switch ( asyncOpResult->operationType ) { @@ -1058,7 +1058,7 @@ FilePushDestination::OnAsyncVfsFileEncodeOpCompleted( CORE::CNotifier* notifier m_encodeQueue.erase( pushEntry->filePath ); GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "FilePushDestination:OnAsyncVfsFileEncodeOpCompleted: Async encode operation successfull for \"" + - pushEntry->filePath + "\" which was encoded at path \"" + slot->entryInfo->encodedFilepath + "\"" ); + pushEntry->filePath + "\" which was encoded at path \"" + pushEntry->encodedFilepath + "\"" ); QueueFileForPushing( pushEntry ); break; @@ -1385,7 +1385,6 @@ FilePushDestination::PushFileUsingVfs( PushEntryPtr entry ) pushUrlForFile = pushUrlForFile.CompactRepeatingChar( '/' ); // Store the file as an async operation - m_inflight[ entry->filePath ] = slot; m_pushQueue.erase( entry->filePath ); if ( VFS::CVfsGlobal::Instance()->GetVfs().StoreAsFileAsync( pushUrlForFile, slot->buffer, 0, true, GUCEF_NULL, entry->filePath ) ) { @@ -1401,6 +1400,8 @@ FilePushDestination::PushFileUsingVfs( PushEntryPtr entry ) YieldInFlightSlot( slot ); return false; } + + return true; } /*-------------------------------------------------------------------------*/ @@ -1631,7 +1632,7 @@ FilePushDestination::OnFileEncodeTimerCycle( CORE::CNotifier* notifier , TStringPushEntryPtrMap::iterator i = m_encodeQueue.begin(); while ( i != m_encodeQueue.end() ) { - const CORE::CString& filePath = (*i).first; + CORE::CString filePath = (*i).first; PushEntryPtr pushEntry = (*i).second; // We limit the nr of in flight operations to limit system load @@ -1646,8 +1647,6 @@ FilePushDestination::OnFileEncodeTimerCycle( CORE::CNotifier* notifier , if ( fileAccess.Open( filePath, "rb" ) ) { // Encode the file as an async operation - m_inflight[ slot->entryInfo->filePath ] = slot; - m_encodeQueue.erase( slot->entryInfo->filePath ); if ( VFS::CVfsGlobal::Instance()->GetVfs().EncodeAsFileAsync( fileAccess , slot->entryInfo->encodedFilepath , true , @@ -1655,36 +1654,36 @@ FilePushDestination::OnFileEncodeTimerCycle( CORE::CNotifier* notifier , m_settings.fileCompressionCodecToUse , slot->entryInfo->filePath ) ) { + + GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "FilePushDestination:OnFileEncodeTimerCycle: Commenced async encode of content from file \"" + - filePath + "\" to VFS path \"" + slot->entryInfo->encodedFilepath + "\"" ); - return; + filePath + "\" to VFS path \"" + slot->entryInfo->encodedFilepath + "\"" ); + i = m_encodeQueue.erase( i ); } else { GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "FilePushDestination:OnFileEncodeTimerCycle: Failed to request async push of content from file \"" + filePath + "\" to VFS path \"" + slot->entryInfo->encodedFilepath + "\". Skipping the file for now" ); - m_encodeQueue[ slot->entryInfo->filePath ] = slot->entryInfo; - m_inflight.erase( slot->entryInfo->filePath ); YieldInFlightSlot( slot ); - return; + ++i; + continue; } } else { GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "FilePushDestination:OnFileEncodeTimerCycle: Failed to open file for when we were about to request async encoding it: \"" + filePath + "\", removing it from the queue" ); YieldInFlightSlot( slot ); - m_encodeQueue.erase( i ); - return; + i = m_encodeQueue.erase( i ); + continue; } } else { GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "FilePushDestination:OnFileEncodeTimerCycle: File no longer exists when we were about to request async encoding it: \"" + filePath + "\", removing it from the queue" ); YieldInFlightSlot( slot ); - m_encodeQueue.erase( i ); - return; + i = m_encodeQueue.erase( i ); + continue; } - ++i; } } @@ -1703,7 +1702,7 @@ FilePushDestination::OnFilePushTimerCycle( CORE::CNotifier* notifier , TStringPushEntryPtrMap::iterator i = m_pushQueue.begin(); while ( i != m_pushQueue.end() ) { - const CORE::CString& filePath = (*i).first; + CORE::CString filePath = (*i).first; PushEntryPtr entry = (*i).second; if ( CORE::FileExists( filePath ) ) @@ -1716,8 +1715,8 @@ FilePushDestination::OnFilePushTimerCycle( CORE::CNotifier* notifier , GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "FilePushDestination:OnFilePushTimerCycle: Encoded file does not exists when we were about to commence pushing it: \"" + entry->encodedFilepath + "\", queuing file again for encoding instead" ); m_encodeQueue[ filePath ] = entry; - m_pushQueue.erase( i ); - return; + i = m_pushQueue.erase( i ); + continue; } } @@ -1726,7 +1725,6 @@ FilePushDestination::OnFilePushTimerCycle( CORE::CNotifier* notifier , if ( PushFileUsingHttp( entry ) ) { m_pushTimer.RequestImmediateTrigger(); - return; } } if ( 0 == m_settings.filePushDestinationUri.HasSubstr( "vfs://", true ) ) @@ -1734,17 +1732,18 @@ FilePushDestination::OnFilePushTimerCycle( CORE::CNotifier* notifier , if ( PushFileUsingVfs( entry ) ) { m_pushTimer.RequestImmediateTrigger(); - return; } } } else { GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "FilePushDestination:OnFilePushTimerCycle: File no longer exists when we were about to commence pushing it: \"" + filePath + "\", removing it from the queue" ); - m_pushQueue.erase( i ); - return; + i = m_pushQueue.erase( i ); + continue; } - ++i; + + if ( i != m_pushQueue.end() ) + ++i; } }