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 22class analyser_settings { 23public: 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 35class FileAnalyser; 36 37 38/*! Thread safe class to sync settings between different FileAnalyser. For 39example the watcher analyser and the catch up analyser. Because the lock 40overhead use it only when necessary or use a cached analyser_settings if 41possible. */ 42class AnalyserSettings : public BReferenceable { 43public: 44 AnalyserSettings(const BString& name, 45 const BVolume& volume); 46 47 const BString& Name() { return fName; } 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(); 65private: 66 BString fName; 67 BVolume fVolume; 68 69 BLocker fSettingsLock; 70 analyser_settings fAnalyserSettings; 71}; 72 73 74class FileAnalyser { 75public: 76 FileAnalyser(const BString& name, 77 const BVolume& volume); 78 virtual ~FileAnalyser() {} 79 80 void SetSettings(AnalyserSettings* settings); 81 AnalyserSettings* Settings() const; 82 const analyser_settings& CachedSettings() const; 83 void UpdateSettingsCache(); 84 85 const BString& Name() const { return fName; } 86 const BVolume& Volume() const { return fVolume; } 87 88 virtual status_t InitCheck() = 0; 89 90 virtual void AnalyseEntry(const entry_ref& ref) = 0; 91 virtual void DeleteEntry(const entry_ref& ref) { } 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. 96 virtual void LastEntry() { } 97 98protected: 99 BVolume fVolume; 100 BReference<AnalyserSettings> fAnalyserSettings; 101 analyser_settings fCachedSettings; 102private: 103 BString fName; 104}; 105 106 107typedef BObjectList<FileAnalyser> FileAnalyserList; 108 109 110class IndexServerAddOn { 111public: 112 IndexServerAddOn(image_id id, const char* name) 113 : 114 fImageId(id), 115 fName(name) 116 { 117 } 118 119 virtual ~IndexServerAddOn() {} 120 121 image_id ImageId() { return fImageId; } 122 BString Name() { return fName; } 123 124 virtual FileAnalyser* CreateFileAnalyser(const BVolume& volume) = 0; 125 126private: 127 image_id fImageId; 128 BString fName; 129}; 130 131 132typedef IndexServerAddOn* create_index_server_addon(image_id id, 133 const char* name); 134 135 136#endif 137