Index: src/libchcore/task.h =================================================================== diff -u -N --- src/libchcore/task.h (revision 0cf74c78280b58c363868caafb9bf493a57aa006) +++ src/libchcore/task.h (revision 0) @@ -1,340 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by Jozef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __TASK_H__ -#define __TASK_H__ - -#include "libchcore.h" -#include "TAutoHandles.h" -#include "TWorkerThreadController.h" -#include "FileInfo.h" -#include "DataBuffer.h" -#include "FeedbackHandlerBase.h" -#include "FileFilter.h" -#include "TTaskDefinition.h" -#include "TTaskConfigTracker.h" -#include "TBasePathData.h" -#include "TSubTaskBase.h" -#include "TTaskLocalStats.h" -#include "TTaskGlobalStats.h" -#include "TBasicProgressInfo.h" -#include "TLocalFilesystem.h" -#include "..\libicpf\log.h" - -BEGIN_CHCORE_NAMESPACE - -// enum representing current processing state of the task -enum ETaskCurrentState -{ - eTaskState_None, - eTaskState_Waiting, - eTaskState_Processing, - eTaskState_Paused, - eTaskState_Cancelled, - eTaskState_Error, - eTaskState_Finished, - - // insert new values before this one - eTaskState_Max -}; - -// special value representing no task -#define NO_TASK_SESSION_UNIQUE_ID 0 - -// structure for getting status of a task -struct TASK_DISPLAY_DATA -{ - TString m_strFullFilePath; - TString m_strFileName; - - int m_iCurrentBufferSize; - int m_iCurrentBufferIndex; - size_t m_stIndex; - size_t m_stSize; - - TSmartPath m_pathDstPath; - TFiltersArray* m_pafFilters; - - ETaskCurrentState m_eTaskState; - EOperationType m_eOperationType; - ESubOperationType m_eSubOperationType; - - int m_nPriority; - - ull_t m_ullProcessedSize; - ull_t m_ullSizeAll; - int m_nPercent; - - time_t m_timeElapsed; - - TString m_strUniqueName; // doesn't change from first setting - - bool m_bIgnoreDirectories; - bool m_bCreateEmptyFiles; -}; - -struct TASK_MINI_DISPLAY_DATA -{ - TString m_strPath; - - ETaskCurrentState m_eTaskState; - - int m_nPercent; -}; - -/////////////////////////////////////////////////////////////////////////// -// CTask - -class LIBCHCORE_API CTask -{ -public: - enum EPathType - { - ePathType_TaskDefinition, - ePathType_TaskRarelyChangingState, - ePathType_TaskOftenChangingState, - ePathType_TaskLogFile, - }; - -public: - ~CTask(); - - const TTaskDefinition& GetTaskDefinition() const { return m_tTaskDefinition; } - - void SetTaskState(ETaskCurrentState eTaskState); - ETaskCurrentState GetTaskState() const; - - // m_nBufferSize - void SetBufferSizes(const TBufferSizes& bsSizes); - void GetBufferSizes(TBufferSizes& bsSizes); - int GetCurrentBufferIndex(); - - // thread - void SetPriority(int nPriority); - - void Load(const TSmartPath& strPath); - void Store(); - - void BeginProcessing(); - - void PauseProcessing(); // pause - void ResumeProcessing(); // resume - bool RetryProcessing(); // retry - void RestartProcessing(); // from beginning - void CancelProcessing(); // cancel - - void GetSnapshot(TASK_DISPLAY_DATA *pData); - void GetMiniSnapshot(TASK_MINI_DISPLAY_DATA *pData); - - void SetTaskDirectory(const TSmartPath& strDir); - TSmartPath GetTaskDirectory() const; - - void SetTaskFilePath(const TSmartPath& strPath); - TSmartPath GetTaskFilePath() const; - - void SetForceFlag(bool bFlag = true); - bool GetForceFlag(); - - size_t GetSessionUniqueID() const { return m_stSessionUniqueID; } - - TSmartPath GetRelatedPath(EPathType ePathType); - -protected: - CTask(IFeedbackHandler* piFeedbackHandler, size_t stSessionUniqueID); - - void SetTaskDefinition(const TTaskDefinition& rTaskDefinition); - - // methods are called when task is being added or removed from the global task array - /// Method is called when this task is being added to a CTaskArray object - void OnRegisterTask(TTasksGlobalStats& rtGlobalStats); - /// Method is called when task is being removed from the CTaskArray object - void OnUnregisterTask(); - - /// Method is called when processing is being started - void OnBeginOperation(); - /// Method is called when processing is being ended - void OnEndOperation(); - - // Processing operations - - /// Thread function that delegates call to the CTask::ThrdProc - static DWORD WINAPI DelegateThreadProc(LPVOID pParam); - - /// Main function for the task processing thread - DWORD WINAPI ThrdProc(); - - TSubTaskBase::ESubOperationResult CheckForWaitState(); - - // m_nStatus - void SetStatusNL(UINT nStatus, UINT nMask); - UINT GetStatusNL(UINT nMask = 0xffffffff); - - void CalculateProcessedSize(); - void CalculateProcessedSizeNL(); - - void CalculateTotalSizeNL(); - - void DeleteProgress(); - - void SetForceFlagNL(bool bFlag = true); - bool GetForceFlagNL(); - - void SetContinueFlag(bool bFlag = true); - bool GetContinueFlag(); - void SetContinueFlagNL(bool bFlag = true); - bool GetContinueFlagNL(); - - bool CanBegin(); - - void KillThread(); - void RequestStopThread(); - - TSmartPath GetRelatedPathNL(EPathType ePathType); - - static void OnCfgOptionChanged(const TStringSet& rsetChanges, void* pParam); - -private: - // task initial information (needed to start a task); might be a bit processed. - TTaskDefinition m_tTaskDefinition; - - TTaskConfigTracker m_cfgTracker; - - TBasePathDataContainer m_arrSourcePathsInfo; - - // current task state (derivatives of the task initial information) - // changing slowly or only partially - TFileInfoArray m_files; // list of files/directories found during operating on the task input data (filled by search for files) - - // changing fast - volatile ETaskCurrentState m_eCurrentState; // current state of processing this task represents - - TTaskBasicProgressInfo m_tTaskBasicProgressInfo; // task progress information - - // task control variables (per-session state) - TTaskLocalStats m_localStats; // local statistics - - // task settings - TFiltersArray m_afFilters; // filtering settings for files (will be filtered according to the rules inside when searching for files) - - bool m_bForce; // if the continuation of tasks should be independent of max concurrently running task limit - bool m_bContinue; // allows task to continue - - TSmartPath m_strTaskDirectory; // base path at which the files will be stored - TSmartPath m_strFilePath; // exact filename with path to the task definition file - - bool m_bRareStateModified; // rarely changing state has been modified - bool m_bOftenStateModified; // rarely changing state has been modified - - size_t m_stSessionUniqueID; ///< Per-session unique ID for this task - - // other helpers - icpf::log_file m_log; ///< Log file where task information will be stored - - // Local filesystem access - TLocalFilesystem m_fsLocal; - - /// Thread controlling object - TWorkerThreadController m_workerThread; - - /// Mutex for locking concurrent access to members of this class -#pragma warning(push) -#pragma warning(disable: 4251) - mutable boost::shared_mutex m_lock; -#pragma warning(pop) - - /// Pointer to the feedback handler, providing responses to feedback requests - IFeedbackHandler* m_piFeedbackHandler; - - friend class CTaskArray; -}; - -typedef boost::shared_ptr CTaskPtr; - -/////////////////////////////////////////////////////////////////////////// -// CTaskArray - -class LIBCHCORE_API CTaskArray -{ -public: - CTaskArray(); - ~CTaskArray(); - - void Create(IFeedbackHandlerFactory* piFeedbackHandlerFactory); - - CTaskPtr CreateTask(const TTaskDefinition& tTaskDefinition); - CTaskPtr ImportTask(const TSmartPath& strTaskPath); - - size_t GetSize() const; - - CTaskPtr GetAt(size_t stIndex) const; - CTaskPtr GetTaskBySessionUniqueID(size_t stSessionUniqueID) const; - - size_t Add(const CTaskPtr& spNewTask); - - void RemoveAt(size_t stIndex, size_t stCount = 1); - void RemoveAll(); - void RemoveAllFinished(); - void RemoveFinished(const CTaskPtr& spSelTask); - - void ResumeWaitingTasks(size_t stMaxRunningTasks); - void StopAllTasks(); - - void SaveData(); - void LoadDataProgress(); - - void TasksBeginProcessing(); - void TasksPauseProcessing(); - void TasksResumeProcessing(); - void TasksRestartProcessing(); - bool TasksRetryProcessing(); - void TasksCancelProcessing(); - - ull_t GetPosition(); - ull_t GetRange(); - int GetPercent(); - - bool AreAllFinished(); - - void SetTasksDir(const TSmartPath& pathDir); - -protected: - void StopAllTasksNL(); - - CTaskPtr CreateEmptyTask(); - -public: - TSmartPath m_pathTasksDir; - -private: -#pragma warning(push) -#pragma warning(disable: 4251) - mutable boost::shared_mutex m_lock; - std::vector m_vTasks; // vector with tasks objects -#pragma warning(pop) - - TTasksGlobalStats m_globalStats; // global stats for all tasks - - size_t m_stNextSessionUniqueID; // global counter for providing unique ids for tasks per session (launch of the program) - -protected: - IFeedbackHandlerFactory* m_piFeedbackFactory; -}; - -END_CHCORE_NAMESPACE - -#endif