xref: /haiku/headers/private/storage/AddOnMonitorHandler.h (revision 916be2df3c26f589bd422d22230f921e51e69bae)
1ab428535SAxel Dörfler /*
2*916be2dfSJohn Scipione  * Copyright 2004-2013, 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 
48*916be2dfSJohn Scipione 			status_t			AddAddOnDirectories(const char* leafPath = "");
49*916be2dfSJohn Scipione 
50afd1e200Sshatty protected:
512faa1532SStephan Aßmus 	// hooks for sub-class
522faa1532SStephan Aßmus 	virtual	void				AddOnCreated(
532faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
542faa1532SStephan Aßmus 	virtual	void				AddOnEnabled(
552faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
562faa1532SStephan Aßmus 	virtual	void				AddOnDisabled(
572faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
582faa1532SStephan Aßmus 									// name field will be invalid!
592faa1532SStephan Aßmus 	virtual	void				AddOnRemoved(
602faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
612faa1532SStephan Aßmus 									// name field will be invalid!
62afd1e200Sshatty 
63afd1e200Sshatty protected:
64afd1e200Sshatty 	virtual	void				EntryCreated(const char* name, ino_t directory,
65afd1e200Sshatty 									dev_t device, ino_t node);
669a986950SClemens Zeidler 	virtual	void				EntryRemoved(const char *name, ino_t directory,
672faa1532SStephan Aßmus 									dev_t device, ino_t node);
689a986950SClemens Zeidler 	virtual	void				EntryMoved(const char *name,
69e4644818SClemens Zeidler 									const char *fromName, ino_t fromDirectory,
70e4644818SClemens Zeidler 									ino_t toDirectory, dev_t device,
719a986950SClemens Zeidler 									ino_t node, dev_t nodeDevice);
72d01ea8ecSClemens Zeidler 	virtual	void				StatChanged(ino_t node, dev_t device,
73d01ea8ecSClemens Zeidler 									int32 statFields);
74afd1e200Sshatty 
75afd1e200Sshatty private:
76588b796bSClemens Zeidler 			void				_HandlePendingEntries();
772faa1532SStephan Aßmus 			void				_EntryCreated(add_on_entry_info& info);
78afd1e200Sshatty 
792faa1532SStephan Aßmus 			typedef NodeMonitorHandler inherited;
802faa1532SStephan Aßmus 			typedef std::list<add_on_entry_info> EntryList;
812faa1532SStephan Aßmus 
822faa1532SStephan Aßmus 			struct add_on_directory_info {
832faa1532SStephan Aßmus 				node_ref		nref;
842faa1532SStephan Aßmus 				EntryList		entries;
852faa1532SStephan Aßmus 			};
862faa1532SStephan Aßmus 
872faa1532SStephan Aßmus 			typedef std::list<add_on_directory_info> DirectoryList;
882faa1532SStephan Aßmus 
892faa1532SStephan Aßmus 			bool				_FindEntry(const node_ref& entry,
902faa1532SStephan Aßmus 									const EntryList& list,
912faa1532SStephan Aßmus 									EntryList::iterator& it) const;
922faa1532SStephan Aßmus 			bool				_FindEntry(const char* name,
932faa1532SStephan Aßmus 									const EntryList& list,
942faa1532SStephan Aßmus 									EntryList::iterator& it) const;
952faa1532SStephan Aßmus 
962faa1532SStephan Aßmus 			bool				_HasEntry(const node_ref& entry,
972faa1532SStephan Aßmus 									EntryList& list) const;
982faa1532SStephan Aßmus 			bool				_HasEntry(const char* name,
992faa1532SStephan Aßmus 									EntryList& list) const;
1002faa1532SStephan Aßmus 
1012faa1532SStephan Aßmus 			bool				_FindDirectory(ino_t directory, dev_t device,
1022faa1532SStephan Aßmus 									DirectoryList::iterator& it) const;
1032faa1532SStephan Aßmus 			bool				_FindDirectory(
1042faa1532SStephan Aßmus 									const node_ref& directoryNodeRef,
1052faa1532SStephan Aßmus 									DirectoryList::iterator& it) const;
1062faa1532SStephan Aßmus 			bool				_FindDirectory(ino_t directory, dev_t device,
1072faa1532SStephan Aßmus 									DirectoryList::iterator& it,
1082faa1532SStephan Aßmus 									const DirectoryList::const_iterator& end)
1092faa1532SStephan Aßmus 										const;
1102faa1532SStephan Aßmus 			bool				_FindDirectory(
1112faa1532SStephan Aßmus 									const node_ref& directoryNodeRef,
1122faa1532SStephan Aßmus 									DirectoryList::iterator& it,
1132faa1532SStephan Aßmus 									const DirectoryList::const_iterator& end)
1142faa1532SStephan Aßmus 										const;
1152faa1532SStephan Aßmus 
1162faa1532SStephan Aßmus 			void				_AddNewEntry(EntryList& list,
1172faa1532SStephan Aßmus 									add_on_entry_info& info);
1182faa1532SStephan Aßmus 
1192faa1532SStephan Aßmus private:
1202faa1532SStephan Aßmus 			DirectoryList		fDirectories;
1212faa1532SStephan Aßmus 			EntryList			fPendingEntries;
122afd1e200Sshatty };
123afd1e200Sshatty 
124afd1e200Sshatty 
125afd1e200Sshatty }; // namespace Storage
126afd1e200Sshatty }; // namespace BPrivate
127afd1e200Sshatty 
1282faa1532SStephan Aßmus 
129afd1e200Sshatty using namespace BPrivate::Storage;
130afd1e200Sshatty 
1312faa1532SStephan Aßmus 
132afd1e200Sshatty #endif	// _ADD_ON_MONITOR_HANDLER_H
133