xref: /haiku/headers/private/index_server/IndexServerAddOn.h (revision 1294543de9ac0eff000eaea1b18368c36435d08e)
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 INDEX_SERVER_ADD_ON_H
9 #define INDEX_SERVER_ADD_ON_H
10 
11 
12 #include <Autolock.h>
13 #include <Entry.h>
14 #include <image.h>
15 #include <ObjectList.h>
16 #include <String.h>
17 #include <Volume.h>
18 
19 #include "Referenceable.h"
20 
21 
22 class analyser_settings {
23 public:
24 						analyser_settings();
25 
26 	bool				catchUpEnabled;
27 	//! the volume is scanned form 0 to syncPosition, from
28 	//! syncPosition to watchingStart the volume is not scanned
29 	bigtime_t			syncPosition;
30 	bigtime_t			watchingStart;
31 	bigtime_t			watchingPosition;
32 };
33 
34 
35 class FileAnalyser;
36 
37 
38 /*! Thread safe class to sync settings between different FileAnalyser. For
39 example the watcher analyser and the catch up analyser. Because the lock
40 overhead use it only when necessary or use a cached analyser_settings if
41 possible. */
42 class AnalyserSettings : public BReferenceable {
43 public:
44 								AnalyserSettings(const BString& name,
45 									const BVolume& volume);
46 
Name()47 			const BString&		Name() { return fName; }
Volume()48 			const BVolume&		Volume() { return fVolume; }
49 
50 			bool				ReadSettings();
51 			bool				WriteSettings();
52 
53 			analyser_settings	RawSettings();
54 
55 			// settings
56 			void				SetCatchUpEnabled(bool enabled);
57 			void				SetSyncPosition(bigtime_t time);
58 			void				SetWatchingStart(bigtime_t time);
59 			void				SetWatchingPosition(bigtime_t time);
60 
61 			bool				CatchUpEnabled();
62 			bigtime_t			SyncPosition();
63 			bigtime_t			WatchingStart();
64 			bigtime_t			WatchingPosition();
65 private:
66 			BString				fName;
67 			BVolume				fVolume;
68 
69 			BLocker				fSettingsLock;
70 			analyser_settings	fAnalyserSettings;
71 };
72 
73 
74 class FileAnalyser {
75 public:
76 								FileAnalyser(const BString& name,
77 									const BVolume& volume);
~FileAnalyser()78 	virtual						~FileAnalyser() {}
79 
80 			void				SetSettings(AnalyserSettings* settings);
81 			AnalyserSettings*	Settings() const;
82 			const analyser_settings&	CachedSettings() const;
83 			void				UpdateSettingsCache();
84 
Name()85 			const BString&		Name() const { return fName; }
Volume()86 			const BVolume&		Volume() const { return fVolume; }
87 
88 	virtual status_t			InitCheck() = 0;
89 
90 	virtual void				AnalyseEntry(const entry_ref& ref) = 0;
DeleteEntry(const entry_ref & ref)91 	virtual void				DeleteEntry(const entry_ref& ref) { }
MoveEntry(const entry_ref & oldRef,const entry_ref & newRef)92 	virtual void				MoveEntry(const entry_ref& oldRef,
93 									const entry_ref& newRef) { }
94 	//! If the indexer send a bunch of entry this indicates that the last one
95 	//! has been arrived.
LastEntry()96 	virtual void				LastEntry() { }
97 
98 protected:
99 			BVolume				fVolume;
100 			BReference<AnalyserSettings>	fAnalyserSettings;
101 			analyser_settings	fCachedSettings;
102 private:
103 			BString				fName;
104 };
105 
106 
107 typedef BObjectList<FileAnalyser> FileAnalyserList;
108 
109 
110 class IndexServerAddOn {
111 public:
IndexServerAddOn(image_id id,const char * name)112 	IndexServerAddOn(image_id id, const char* name)
113 		:
114 		fImageId(id),
115 		fName(name)
116 	{
117 	}
118 
~IndexServerAddOn()119 	virtual						~IndexServerAddOn() {}
120 
ImageId()121 			image_id			ImageId() { return fImageId; }
Name()122 			BString				Name() { return fName; }
123 
124 	virtual FileAnalyser*		CreateFileAnalyser(const BVolume& volume) = 0;
125 
126 private:
127 		image_id				fImageId;
128 		BString					fName;
129 };
130 
131 
132 typedef IndexServerAddOn* create_index_server_addon(image_id id,
133 	const char* name);
134 
135 
136 #endif
137