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_H 9 #define INDEX_SERVER_H 10 11 12 #include <Application.h> 13 #include <MessageRunner.h> 14 #include <VolumeRoster.h> 15 16 #include <AddOnMonitorHandler.h> 17 #include <ObjectList.h> 18 19 #include "IndexServerAddOn.h" 20 #include "VolumeWatcher.h" 21 22 23 #define DEBUG_INDEX_SERVER 24 #ifdef DEBUG_INDEX_SERVER 25 #include <stdio.h> 26 # define STRACE(x...) printf(x) 27 #else 28 # define STRACE(x...) ; 29 #endif 30 31 32 class IndexServer; 33 34 35 class VolumeObserverHandler : public BHandler { 36 public: 37 VolumeObserverHandler(IndexServer* indexServer); 38 void MessageReceived(BMessage *message); 39 private: 40 IndexServer* fIndexServer; 41 }; 42 43 44 class AnalyserMonitorHandler : public AddOnMonitorHandler { 45 public: 46 AnalyserMonitorHandler( 47 IndexServer* indexServer); 48 49 private: 50 void AddOnEnabled( 51 const add_on_entry_info* entryInfo); 52 void AddOnDisabled( 53 const add_on_entry_info* entryInfo); 54 55 IndexServer* fIndexServer; 56 }; 57 58 59 class IndexServer : public BApplication { 60 public: 61 IndexServer(); 62 virtual ~IndexServer(); 63 64 virtual void ReadyToRun(); 65 virtual void MessageReceived(BMessage *message); 66 67 virtual bool QuitRequested(); 68 69 void AddVolume(const BVolume& volume); 70 void RemoveVolume(const BVolume& volume); 71 72 void RegisterAddOn(entry_ref ref); 73 void UnregisterAddOn(entry_ref ref); 74 75 //! thread safe 76 FileAnalyser* CreateFileAnalyser(const BString& name, 77 const BVolume& volume); 78 private: 79 void _StartWatchingVolumes(); 80 void _StopWatchingVolumes(); 81 82 void _SetupVolumeWatcher(VolumeWatcher* watcher); 83 FileAnalyser* _SetupFileAnalyser(IndexServerAddOn* addon, 84 const BVolume& volume); 85 void _StartWatchingAddOns(); 86 87 inline IndexServerAddOn* _FindAddon(const BString& name); 88 89 BVolumeRoster fVolumeRoster; 90 BObjectList<VolumeWatcher> fVolumeWatcherList; 91 BObjectList<IndexServerAddOn> fAddOnList; 92 93 VolumeObserverHandler fVolumeObserverHandler; 94 95 AnalyserMonitorHandler fAddOnMonitorHandler; 96 BMessageRunner* fPulseRunner; 97 }; 98 99 100 #endif 101