Index: src/libchengine/TTask.cpp =================================================================== diff -u -N -rfa1b3554856407e4501db20d5093818e8d8c4068 -re45315d2ecd008df0162cba53a77dc6b8c5880d0 --- src/libchengine/TTask.cpp (.../TTask.cpp) (revision fa1b3554856407e4501db20d5093818e8d8c4068) +++ src/libchengine/TTask.cpp (.../TTask.cpp) (revision e45315d2ecd008df0162cba53a77dc6b8c5880d0) @@ -26,12 +26,12 @@ #include "TTaskStatsSnapshot.h" #include "TScopedRunningTimeTracker.h" #include "TScopedRunningTimeTrackerPause.h" -#include "TFeedbackHandlerWrapper.h" #include "TTaskConfigBufferSizes.h" #include #include "TLocalFilesystem.h" #include "TTaskConfigVerifier.h" #include "../liblogger/TAsyncMultiLogger.h" +#include using namespace chcore; using namespace string; @@ -45,13 +45,12 @@ TTask::TTask(const ISerializerPtr& spSerializer, const IFeedbackHandlerPtr& spFeedbackHandler, const TTaskDefinition& rTaskDefinition, const logger::TLogFileDataPtr& spLogFileData) : m_spSerializer(spSerializer), - m_spInternalFeedbackHandler(spFeedbackHandler), + m_spFeedbackManager(std::make_shared(spFeedbackHandler)), m_spLog(logger::MakeLogger(spLogFileData, L"Task")), m_spSrcPaths(new TBasePathDataContainer), + m_tSubTaskContext(m_tConfiguration, m_spSrcPaths, m_afFilters, m_cfgTracker, spLogFileData, m_workerThread, + std::make_shared(spLogFileData), m_spFeedbackManager), m_tSubTasksArray(m_tSubTaskContext), - m_tSubTaskContext(m_tConfiguration, m_spSrcPaths, m_afFilters, - m_cfgTracker, spLogFileData, m_workerThread, - std::make_shared(spLogFileData)), m_bForce(false), m_bContinue(false) { @@ -65,18 +64,15 @@ TTask::TTask(const ISerializerPtr& spSerializer, const IFeedbackHandlerPtr& spFeedbackHandler, const logger::TLogFileDataPtr& spLogFileData) : m_spSerializer(spSerializer), - m_spInternalFeedbackHandler(spFeedbackHandler), + m_spFeedbackManager(std::make_shared(spFeedbackHandler)), m_spLog(logger::MakeLogger(spLogFileData, L"Task")), m_spSrcPaths(new TBasePathDataContainer), + m_tSubTaskContext(m_tConfiguration, m_spSrcPaths, m_afFilters, m_cfgTracker, m_spLog->GetLogFileData(), m_workerThread, + std::make_shared(m_spLog->GetLogFileData()), m_spFeedbackManager), m_tSubTasksArray(m_tSubTaskContext), - m_tSubTaskContext(m_tConfiguration, m_spSrcPaths, m_afFilters, - m_cfgTracker, m_spLog->GetLogFileData(), m_workerThread, - std::make_shared(m_spLog->GetLogFileData())), m_bForce(false), m_bContinue(false) { - if(!spFeedbackHandler) - throw TCoreException(eErr_InvalidArgument, L"spFeedbackHandler", LOCATION); if(!spSerializer) throw TCoreException(eErr_InvalidArgument, L"spSerializer", LOCATION); } @@ -98,6 +94,7 @@ m_tConfiguration = rTaskDefinition.GetConfiguration(); *m_spSrcPaths = rTaskDefinition.GetSourcePaths(); m_afFilters = rTaskDefinition.GetFilters(); + m_spFeedbackManager->SetRules(rTaskDefinition.GetFeedbackRules()); m_tBaseData.SetTaskName(rTaskDefinition.GetTaskName()); m_tSubTasksArray.Init(rTaskDefinition.GetOperationPlan()); @@ -170,12 +167,11 @@ spContainer = m_spSerializer->GetContainer(_T("filters")); m_afFilters.Load(spContainer); + m_spFeedbackManager->Load(m_spSerializer); + spContainer = m_spSerializer->GetContainer(_T("local_stats")); m_tLocalStats.Load(spContainer); - spContainer = m_spSerializer->GetContainer(_T("feedback")); - m_spInternalFeedbackHandler->Load(spContainer); - // ensure copy-based context entries are properly updated after loading m_tSubTaskContext.SetDestinationPath(m_tBaseData.GetDestinationPath()); m_tSubTaskContext.SetOperationType(m_tSubTasksArray.GetOperationType()); @@ -274,12 +270,11 @@ spContainer = m_spSerializer->GetContainer(_T("filters")); m_afFilters.Store(spContainer); + m_spFeedbackManager->Store(m_spSerializer); + spContainer = m_spSerializer->GetContainer(_T("local_stats")); m_tLocalStats.Store(spContainer); - spContainer = m_spSerializer->GetContainer(_T("feedback")); - m_spInternalFeedbackHandler->Store(spContainer); - m_tSubTasksArray.Store(m_spSerializer); } @@ -349,7 +344,7 @@ SetTaskState(eTaskState_None); - m_spInternalFeedbackHandler->RestoreDefaults(); + m_spFeedbackManager->RestoreDefaults(); m_tSubTasksArray.ResetProgressAndStats(); m_tLocalStats.Clear(); m_spSrcPaths->ResetProcessingFlags(); @@ -362,7 +357,7 @@ void TTask::RestoreFeedbackDefaults() { - m_spInternalFeedbackHandler->RestoreDefaults(); + m_spFeedbackManager->RestoreDefaults(); } void TTask::PauseProcessing() @@ -402,21 +397,37 @@ spSnapshot->SetThreadPriority(GetTaskPropValue(m_tConfiguration)); spSnapshot->SetDestinationPath(m_tBaseData.GetDestinationPath().ToString()); spSnapshot->SetFilters(m_afFilters); + spSnapshot->SetFeedbackRules(m_spFeedbackManager->GetRules()); spSnapshot->SetTaskState(m_tBaseData.GetCurrentState()); spSnapshot->SetOperationType(m_tSubTasksArray.GetOperationType()); spSnapshot->SetIgnoreDirectories(GetTaskPropValue(m_tConfiguration)); spSnapshot->SetCreateEmptyFiles(GetTaskPropValue(m_tConfiguration)); + spSnapshot->SetExcludeEmptyDirectories(GetTaskPropValue(m_tConfiguration)); spSnapshot->SetBufferCount(GetTaskPropValue(m_tConfiguration)); TSubTaskStatsSnapshotPtr spCurrentSubTask = spSnapshot->GetSubTasksStats().GetCurrentSubTaskSnapshot(); - if(spCurrentSubTask) - spSnapshot->SetSourcePath(spCurrentSubTask->GetCurrentPath()); - else if(m_spSrcPaths->GetCount() > 0) + if(m_spSrcPaths->GetCount() > 0) { - TBasePathDataPtr spBasePath = m_spSrcPaths->GetAt(0); - if(spBasePath) - spSnapshot->SetSourcePath(spBasePath->GetSrcPath().ToString()); + std::wstring wstrPaths; + + const size_t stMaxPaths = std::min(2UL, m_spSrcPaths->GetCount()); + for(file_count_t stIndex = 0; stIndex < stMaxPaths; ++stIndex) + { + TBasePathDataPtr spBasePath = m_spSrcPaths->GetAt(stIndex); + if(spBasePath) + { + if(!wstrPaths.empty()) + wstrPaths += L"; "; + + wstrPaths += spBasePath->GetSrcPath().ToString(); + } + } + + if(stMaxPaths < m_spSrcPaths->GetCount()) + wstrPaths += L"; ..."; + + spSnapshot->SetSourcePath(wstrPaths.c_str()); } int iCurrentBufferIndex = spCurrentSubTask ? spCurrentSubTask->GetCurrentBufferIndex() : TBufferSizes::eBuffer_Default; @@ -550,8 +561,16 @@ { // start tracking time for this thread TScopedRunningTimeTracker tProcessingGuard(m_tLocalStats); - TFeedbackHandlerWrapperPtr spFeedbackHandler(std::make_shared(m_spInternalFeedbackHandler, tProcessingGuard)); + // set time tracker and ensure it is unset on scope exit + m_spFeedbackManager->SetTimeTracker(&tProcessingGuard); + +#pragma warning(push) +#pragma warning(disable: 4459) + BOOST_SCOPE_EXIT(&m_spFeedbackManager) { + m_spFeedbackManager->SetTimeTracker(nullptr); + } BOOST_SCOPE_EXIT_END +#pragma warning(pop) const size_t ExceptionBufferSize = 2048; std::unique_ptr upExceptionInfoBuffer(new wchar_t[ExceptionBufferSize]); try @@ -574,7 +593,7 @@ m_tSubTasksArray.InitBeforeExec(); // exec the estimation subtasks - TSubTaskBase::ESubOperationResult eResult = m_tSubTasksArray.Execute(spFeedbackHandler, true); + TSubTaskBase::ESubOperationResult eResult = m_tSubTasksArray.Execute(true); // go into wait state only in case the preprocessing did not finish the operation already // (only fast move can do that right now) @@ -585,7 +604,7 @@ eResult = CheckForWaitState(); // operation limiting } if (eResult == TSubTaskBase::eSubResult_Continue) - eResult = m_tSubTasksArray.Execute(spFeedbackHandler, false); + eResult = m_tSubTasksArray.Execute(false); // change status to finished if (eResult == TSubTaskBase::eSubResult_Continue) @@ -596,7 +615,7 @@ switch (eResult) { case TSubTaskBase::eSubResult_Error: - spFeedbackHandler->OperationError(); + m_spFeedbackManager->OperationEvent(eOperationEvent_Error); SetTaskState(eTaskState_Error); break; @@ -615,7 +634,7 @@ break; case TSubTaskBase::eSubResult_Continue: - spFeedbackHandler->OperationFinished(); + m_spFeedbackManager->OperationEvent(eOperationEvent_Finished); SetTaskState(eTaskState_Finished); break; @@ -664,7 +683,7 @@ LOG_ERROR(m_spLog) << strMsg.c_str(); // let others know some error happened - spFeedbackHandler->OperationError(); + m_spFeedbackManager->OperationEvent(eOperationEvent_Error); SetTaskState(eTaskState_Error); SetContinueFlag(false);