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