1 /* 2 * Copyright 2004-2013, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _ADD_ON_MONITOR_HANDLER_H 6 #define _ADD_ON_MONITOR_HANDLER_H 7 8 9 #include <list> 10 11 #include "NodeMonitorHandler.h" 12 13 14 namespace BPrivate { 15 namespace Storage { 16 17 18 struct add_on_entry_info { 19 char name[B_FILE_NAME_LENGTH]; 20 node_ref nref; 21 node_ref dir_nref; 22 node_ref addon_nref; 23 }; 24 25 26 class AddOnMonitorHandler : public NodeMonitorHandler { 27 public: 28 AddOnMonitorHandler(const char* name = NULL); 29 virtual ~AddOnMonitorHandler(); 30 31 virtual void MessageReceived(BMessage* message); 32 33 // Supply the add-on directories here, in the order you want them checked. 34 // Add-ons in directories added earlier will shadow add-ons in directories 35 // added later, if they share the same file name. If an add-on is removed 36 // from or renamed in a directory and it has previously shadowed another 37 // add-on, the previously shadowed add-on shall become enabled 38 // (AddOnEnabled()). If an add-on appears in a directory, or is renamed, 39 // it can cause another add-on to become disabled, if it has the same name. 40 // Note that directories are not watched recursively, and all entries 41 // are reported as add-ons regardless of their node type (files, 42 // directories, symlinks). 43 // If sync is true all pending add-on entries are handled immediately. 44 // Including entries from other directories. 45 virtual status_t AddDirectory(const node_ref* nref, 46 bool sync = false); 47 48 status_t AddAddOnDirectories(const char* leafPath = ""); 49 50 protected: 51 // hooks for sub-class 52 virtual void AddOnCreated( 53 const add_on_entry_info* entryInfo); 54 virtual void AddOnEnabled( 55 const add_on_entry_info* entryInfo); 56 virtual void AddOnDisabled( 57 const add_on_entry_info* entryInfo); 58 // name field will be invalid! 59 virtual void AddOnRemoved( 60 const add_on_entry_info* entryInfo); 61 // name field will be invalid! 62 63 protected: 64 virtual void EntryCreated(const char* name, ino_t directory, 65 dev_t device, ino_t node); 66 virtual void EntryRemoved(const char *name, ino_t directory, 67 dev_t device, ino_t node); 68 virtual void EntryMoved(const char *name, 69 const char *fromName, ino_t fromDirectory, 70 ino_t toDirectory, dev_t device, 71 ino_t node, dev_t nodeDevice); 72 virtual void StatChanged(ino_t node, dev_t device, 73 int32 statFields); 74 75 private: 76 void _HandlePendingEntries(); 77 void _EntryCreated(add_on_entry_info& info); 78 79 typedef NodeMonitorHandler inherited; 80 typedef std::list<add_on_entry_info> EntryList; 81 82 struct add_on_directory_info { 83 node_ref nref; 84 EntryList entries; 85 }; 86 87 typedef std::list<add_on_directory_info> DirectoryList; 88 89 bool _FindEntry(const node_ref& entry, 90 const EntryList& list, 91 EntryList::iterator& it) const; 92 bool _FindEntry(const char* name, 93 const EntryList& list, 94 EntryList::iterator& it) const; 95 96 bool _HasEntry(const node_ref& entry, 97 EntryList& list) const; 98 bool _HasEntry(const char* name, 99 EntryList& list) const; 100 101 bool _FindDirectory(ino_t directory, dev_t device, 102 DirectoryList::iterator& it) const; 103 bool _FindDirectory( 104 const node_ref& directoryNodeRef, 105 DirectoryList::iterator& it) const; 106 bool _FindDirectory(ino_t directory, dev_t device, 107 DirectoryList::iterator& it, 108 const DirectoryList::const_iterator& end) 109 const; 110 bool _FindDirectory( 111 const node_ref& directoryNodeRef, 112 DirectoryList::iterator& it, 113 const DirectoryList::const_iterator& end) 114 const; 115 116 void _AddNewEntry(EntryList& list, 117 add_on_entry_info& info); 118 119 private: 120 DirectoryList fDirectories; 121 EntryList fPendingEntries; 122 }; 123 124 125 }; // namespace Storage 126 }; // namespace BPrivate 127 128 129 using namespace BPrivate::Storage; 130 131 132 #endif // _ADD_ON_MONITOR_HANDLER_H 133