// ============================================================================ // Copyright (C) 2001-2012 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. // ============================================================================ /// @file TSubTaskStatsInfo.h /// @date 2012/02/22 /// @brief Contains declaration of class responsible for tracking stats for subtasks. // ============================================================================ #ifndef __TSUBTASKSTATSINFO_H__ #define __TSUBTASKSTATSINFO_H__ #include "libchcore.h" #include "TString.h" #include "TSimpleTimer.h" #include "TSpeedTracker.h" #include "ESubTaskTypes.h" #include "TSubTaskStatsSnapshot.h" #include "ISerializerRowData.h" #include "ISerializerRowReader.h" #include "TSharedModificationTracker.h" #include #include "CommonDataTypes.h" BEGIN_CHCORE_NAMESPACE class TSubTaskStatsInfo; class TSubTaskStatsSnapshot; // class used to guard scope of the subtask processing ( class TSubTaskProcessingGuard { public: TSubTaskProcessingGuard(TSubTaskStatsInfo& rStats); ~TSubTaskProcessingGuard(); private: TSubTaskProcessingGuard(const TSubTaskProcessingGuard&); TSubTaskProcessingGuard& operator=(const TSubTaskProcessingGuard&); private: TSubTaskStatsInfo& m_rStats; }; class TSubTaskStatsInfo { private: static const unsigned long long DefaultSpeedTrackTime = 1000; // in miliseconds static const unsigned long long DefaultSpeedSampleTime = 100; // in miliseconds public: TSubTaskStatsInfo(); void Init(int iCurrentBufferIndex, file_count_t fcTotalCount, file_count_t fcProcessedCount, unsigned long long ullTotalSize, unsigned long long ullProcessedSize, const TString& strCurrentPath); void Clear(); bool WasAdded() const; bool IsInitialized() const; void GetSnapshot(TSubTaskStatsSnapshotPtr& spStatsSnapshot) const; void IncreaseProcessedCount(file_count_t fcIncreaseBy); void SetProcessedCount(file_count_t fcIndex); void SetTotalCount(file_count_t fcCount); // size stats void IncreaseProcessedSize(unsigned long long ullIncreaseBy); void DecreaseProcessedSize(unsigned long long ullDecreaseBy); void SetProcessedSize(unsigned long long ullProcessedSize); void IncreaseTotalSize(unsigned long long ullIncreaseBy); void DecreaseTotalSize(unsigned long long ullDecreaseBy); void SetTotalSize(unsigned long long ullTotalSize); // current item void IncreaseCurrentItemProcessedSize(unsigned long long ullIncreaseBy); void DecreaseCurrentItemProcessedSize(unsigned long long ullDecreaseBy); void SetCurrentItemProcessedSize(unsigned long long ullProcessedSize); void IncreaseCurrentItemTotalSize(unsigned long long ullIncreaseBy); void DecreaseCurrentItemTotalSize(unsigned long long ullDecreaseBy); void SetCurrentItemTotalSize(unsigned long long ullTotalSize); unsigned long long GetCurrentItemProcessedSize() const; unsigned long long GetCurrentItemTotalSize() const; bool CanCurrentItemSilentResume() const; void SetCurrentItemSilentResume(bool bEnableSilentResume); // current index void SetCurrentIndex(file_count_t fcIndex); file_count_t GetCurrentIndex() const; // buffer index void SetCurrentBufferIndex(int iCurrentIndex); // current path void SetCurrentPath(const TString& strPath); ESubOperationType GetSubOperationType() const { return m_eSubOperationType; } void SetSubOperationType(ESubOperationType val) { m_eSubOperationType = val; } // serialization void Store(ISerializerRowData& rRowData) const; static void InitColumns(IColumnsDefinition& rColumnDefs); void Load(const ISerializerRowReaderPtr& spRowReader); private: TSubTaskStatsInfo(const TSubTaskStatsInfo&); TSubTaskStatsInfo& operator=(const TSubTaskStatsInfo&); // is running? void MarkAsRunning(); void MarkAsNotRunning(); // time tracking void EnableTimeTracking(); void DisableTimeTracking(); void UpdateTime(boost::upgrade_lock& lock) const; private: enum EModifications { eMod_Added = 0, eMod_IsRunning, eMod_TotalSize, eMod_ProcessedSize, eMod_SizeSpeed, eMod_TotalCount, eMod_ProcessedCount, eMod_CountSpeed, eMod_CurrentItemProcessedSize, eMod_CurrentItemTotalSize, eMod_Timer, eMod_CurrentBufferIndex, eMod_CurrentPath, eMod_SubOperationType, eMod_IsInitialized, eMod_CurrentItemIndex, eMod_CurrentItemCanResumeSilently, // last item eMod_Last }; typedef std::bitset Bitset; mutable Bitset m_setModifications; TSharedModificationTracker m_bSubTaskIsRunning; TSharedModificationTracker m_ullTotalSize; TSharedModificationTracker m_ullProcessedSize; mutable TSharedModificationTracker m_tSizeSpeed; TSharedModificationTracker m_fcTotalCount; TSharedModificationTracker m_fcProcessedCount; mutable TSharedModificationTracker m_tCountSpeed; TSharedModificationTracker m_fcCurrentIndex; TSharedModificationTracker m_ullCurrentItemProcessedSize; TSharedModificationTracker m_ullCurrentItemTotalSize; TSharedModificationTracker m_bCurrentItemSilentResume; mutable TSharedModificationTracker m_tTimer; TSharedModificationTracker m_iCurrentBufferIndex; TSharedModificationTracker m_strCurrentPath; // currently processed path TSharedModificationTracker m_eSubOperationType; TSharedModificationTracker m_bIsInitialized; #pragma warning(push) #pragma warning(disable: 4251) mutable boost::shared_mutex m_lock; #pragma warning(pop) friend class TSubTaskProcessingGuard; }; END_CHCORE_NAMESPACE #endif