1/*
2 * Copyright 2010, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Clemens Zeidler <haiku@clemens-zeidler.de>
7 */
8#ifndef CATCH_UP_MANAGER_H
9#define CATCH_UP_MANAGER_H
10
11
12#include "AnalyserDispatcher.h"
13
14
15#define DEBUG_CATCH_UP
16#ifdef DEBUG_CATCH_UP
17#include <stdio.h>
18#	define STRACE(x...) printf(x)
19#else
20#	define STRACE(x...) ;
21#endif
22
23
24class CatchUpAnalyser : public AnalyserDispatcher {
25public:
26								CatchUpAnalyser(const BVolume& volume,
27									time_t start, time_t end,
28									BHandler* manager);
29
30			void				MessageReceived(BMessage *message);
31			void				StartAnalysing();
32
33			void				AnalyseEntry(const entry_ref& ref);
34
35			const BVolume&		Volume() { return fVolume; }
36
37private:
38			void				_CatchUp();
39			void				_WriteSyncSatus(bigtime_t syncTime);
40
41			BVolume				fVolume;
42			time_t				fStart;
43			time_t				fEnd;
44
45			BHandler*			fCatchUpManager;
46};
47
48
49typedef BObjectList<CatchUpAnalyser> CatchUpAnalyserList;
50
51
52class CatchUpManager : public BHandler {
53public:
54								CatchUpManager(const BVolume& volume);
55								~CatchUpManager();
56
57			void				MessageReceived(BMessage *message);
58
59			//! Add analyser to the queue.
60			bool				AddAnalyser(const FileAnalyser* analyser);
61			void				RemoveAnalyser(const BString& name);
62
63			//! Spawn a CatchUpAnalyser and fill it with the analyser in the
64			//! queue
65			bool				CatchUp();
66			//! Stop all catch up threads and put the analyser back into the
67			//! queue.
68			void				Stop();
69
70private:
71			BVolume				fVolume;
72
73			FileAnalyserList	fFileAnalyserQueue;
74			CatchUpAnalyserList	fCatchUpAnalyserList;
75};
76
77#endif
78