xref: /haiku/headers/private/storage/AddOnMonitorHandler.h (revision 9a98695072d7707188e5c6a2ecac39f0a50f3659)
1ab428535SAxel Dörfler /*
22faa1532SStephan Aßmus  * Copyright 2004-2010, Haiku, Inc. All rights reserved.
3ab428535SAxel Dörfler  * Distributed under the terms of the MIT License.
4ab428535SAxel Dörfler  */
5afd1e200Sshatty #ifndef _ADD_ON_MONITOR_HANDLER_H
6afd1e200Sshatty #define _ADD_ON_MONITOR_HANDLER_H
7afd1e200Sshatty 
82faa1532SStephan Aßmus 
9afd1e200Sshatty #include <list>
10ab428535SAxel Dörfler 
11afd1e200Sshatty #include "NodeMonitorHandler.h"
12afd1e200Sshatty 
13ab428535SAxel Dörfler 
14afd1e200Sshatty namespace BPrivate {
15afd1e200Sshatty namespace Storage {
16afd1e200Sshatty 
172faa1532SStephan Aßmus 
18afd1e200Sshatty struct add_on_entry_info {
19afd1e200Sshatty 	char name[B_FILE_NAME_LENGTH];
20afd1e200Sshatty 	node_ref nref;
21afd1e200Sshatty 	node_ref dir_nref;
222faa1532SStephan Aßmus 	node_ref addon_nref;
23afd1e200Sshatty };
24afd1e200Sshatty 
25afd1e200Sshatty 
26afd1e200Sshatty class AddOnMonitorHandler : public NodeMonitorHandler {
27afd1e200Sshatty public:
28ab428535SAxel Dörfler 								AddOnMonitorHandler(const char* name = NULL);
29afd1e200Sshatty 	virtual						~AddOnMonitorHandler();
30afd1e200Sshatty 
312faa1532SStephan Aßmus 	virtual	void				MessageReceived(BMessage* message);
32afd1e200Sshatty 
332faa1532SStephan Aßmus 	// Supply the add-on directories here, in the order you want them checked.
342faa1532SStephan Aßmus 	// Add-ons in directories added earlier will shadow add-ons in directories
352faa1532SStephan Aßmus 	// added later, if they share the same file name. If an add-on is removed
362faa1532SStephan Aßmus 	// from or renamed in a directory and it has previously shadowed another
372faa1532SStephan Aßmus 	// add-on, the previously shadowed add-on shall become enabled
382faa1532SStephan Aßmus 	// (AddOnEnabled()). If an add-on appears in a directory, or is renamed,
392faa1532SStephan Aßmus 	// it can cause another add-on to become disabled, if it has the same name.
402faa1532SStephan Aßmus 	// Note that directories are not watched recursively, and all entries
412faa1532SStephan Aßmus 	// are reported as add-ons regardless of their node type (files,
422faa1532SStephan Aßmus 	// directories, symlinks).
43588b796bSClemens Zeidler 	// If sync is true all pending add-on entries are handled immediately.
44588b796bSClemens Zeidler 	// Including entries from other directories.
45588b796bSClemens Zeidler 	virtual	status_t			AddDirectory(const node_ref* nref,
46588b796bSClemens Zeidler 									bool sync = false);
47afd1e200Sshatty 
48afd1e200Sshatty protected:
492faa1532SStephan Aßmus 	// hooks for sub-class
502faa1532SStephan Aßmus 	virtual	void				AddOnCreated(
512faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
522faa1532SStephan Aßmus 	virtual	void				AddOnEnabled(
532faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
542faa1532SStephan Aßmus 	virtual	void				AddOnDisabled(
552faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
562faa1532SStephan Aßmus 									// name field will be invalid!
572faa1532SStephan Aßmus 	virtual	void				AddOnRemoved(
582faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
592faa1532SStephan Aßmus 									// name field will be invalid!
60afd1e200Sshatty 
61afd1e200Sshatty protected:
62afd1e200Sshatty 	virtual	void				EntryCreated(const char* name, ino_t directory,
63afd1e200Sshatty 									dev_t device, ino_t node);
64*9a986950SClemens Zeidler 	virtual	void				EntryRemoved(const char *name, ino_t directory,
652faa1532SStephan Aßmus 									dev_t device, ino_t node);
66*9a986950SClemens Zeidler 	virtual	void				EntryMoved(const char *name,
67*9a986950SClemens Zeidler 									const char *fromName, ino_t from_directory,
68*9a986950SClemens Zeidler 									ino_t to_directory, dev_t device,
69*9a986950SClemens Zeidler 									ino_t node, dev_t nodeDevice);
702faa1532SStephan Aßmus 	virtual	void				StatChanged(ino_t node, dev_t device);
71afd1e200Sshatty 
72afd1e200Sshatty private:
73588b796bSClemens Zeidler 			void				_HandlePendingEntries();
742faa1532SStephan Aßmus 			void				_EntryCreated(add_on_entry_info& info);
75afd1e200Sshatty 
762faa1532SStephan Aßmus 			typedef NodeMonitorHandler inherited;
772faa1532SStephan Aßmus 			typedef std::list<add_on_entry_info> EntryList;
782faa1532SStephan Aßmus 
792faa1532SStephan Aßmus 			struct add_on_directory_info {
802faa1532SStephan Aßmus 				node_ref		nref;
812faa1532SStephan Aßmus 				EntryList		entries;
822faa1532SStephan Aßmus 			};
832faa1532SStephan Aßmus 
842faa1532SStephan Aßmus 			typedef std::list<add_on_directory_info> DirectoryList;
852faa1532SStephan Aßmus 
862faa1532SStephan Aßmus 			bool				_FindEntry(const node_ref& entry,
872faa1532SStephan Aßmus 									const EntryList& list,
882faa1532SStephan Aßmus 									EntryList::iterator& it) const;
892faa1532SStephan Aßmus 			bool				_FindEntry(const char* name,
902faa1532SStephan Aßmus 									const EntryList& list,
912faa1532SStephan Aßmus 									EntryList::iterator& it) const;
922faa1532SStephan Aßmus 
932faa1532SStephan Aßmus 			bool				_HasEntry(const node_ref& entry,
942faa1532SStephan Aßmus 									EntryList& list) const;
952faa1532SStephan Aßmus 			bool				_HasEntry(const char* name,
962faa1532SStephan Aßmus 									EntryList& list) const;
972faa1532SStephan Aßmus 
982faa1532SStephan Aßmus 			bool				_FindDirectory(ino_t directory, dev_t device,
992faa1532SStephan Aßmus 									DirectoryList::iterator& it) const;
1002faa1532SStephan Aßmus 			bool				_FindDirectory(
1012faa1532SStephan Aßmus 									const node_ref& directoryNodeRef,
1022faa1532SStephan Aßmus 									DirectoryList::iterator& it) const;
1032faa1532SStephan Aßmus 			bool				_FindDirectory(ino_t directory, dev_t device,
1042faa1532SStephan Aßmus 									DirectoryList::iterator& it,
1052faa1532SStephan Aßmus 									const DirectoryList::const_iterator& end)
1062faa1532SStephan Aßmus 										const;
1072faa1532SStephan Aßmus 			bool				_FindDirectory(
1082faa1532SStephan Aßmus 									const node_ref& directoryNodeRef,
1092faa1532SStephan Aßmus 									DirectoryList::iterator& it,
1102faa1532SStephan Aßmus 									const DirectoryList::const_iterator& end)
1112faa1532SStephan Aßmus 										const;
1122faa1532SStephan Aßmus 
1132faa1532SStephan Aßmus 			void				_AddNewEntry(EntryList& list,
1142faa1532SStephan Aßmus 									add_on_entry_info& info);
1152faa1532SStephan Aßmus 
1162faa1532SStephan Aßmus private:
1172faa1532SStephan Aßmus 			DirectoryList		fDirectories;
1182faa1532SStephan Aßmus 			EntryList			fPendingEntries;
119afd1e200Sshatty };
120afd1e200Sshatty 
121afd1e200Sshatty 
122afd1e200Sshatty }; // namespace Storage
123afd1e200Sshatty }; // namespace BPrivate
124afd1e200Sshatty 
1252faa1532SStephan Aßmus 
126afd1e200Sshatty using namespace BPrivate::Storage;
127afd1e200Sshatty 
1282faa1532SStephan Aßmus 
129afd1e200Sshatty #endif	// _ADD_ON_MONITOR_HANDLER_H
130