xref: /haiku/headers/private/storage/AddOnMonitorHandler.h (revision d01ea8ec63a34e5c78977457f0affc7e27135b74)
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);
649a986950SClemens Zeidler 	virtual	void				EntryRemoved(const char *name, ino_t directory,
652faa1532SStephan Aßmus 									dev_t device, ino_t node);
669a986950SClemens Zeidler 	virtual	void				EntryMoved(const char *name,
67e4644818SClemens Zeidler 									const char *fromName, ino_t fromDirectory,
68e4644818SClemens Zeidler 									ino_t toDirectory, dev_t device,
699a986950SClemens Zeidler 									ino_t node, dev_t nodeDevice);
70*d01ea8ecSClemens Zeidler 	virtual	void				StatChanged(ino_t node, dev_t device,
71*d01ea8ecSClemens Zeidler 									int32 statFields);
72afd1e200Sshatty 
73afd1e200Sshatty private:
74588b796bSClemens Zeidler 			void				_HandlePendingEntries();
752faa1532SStephan Aßmus 			void				_EntryCreated(add_on_entry_info& info);
76afd1e200Sshatty 
772faa1532SStephan Aßmus 			typedef NodeMonitorHandler inherited;
782faa1532SStephan Aßmus 			typedef std::list<add_on_entry_info> EntryList;
792faa1532SStephan Aßmus 
802faa1532SStephan Aßmus 			struct add_on_directory_info {
812faa1532SStephan Aßmus 				node_ref		nref;
822faa1532SStephan Aßmus 				EntryList		entries;
832faa1532SStephan Aßmus 			};
842faa1532SStephan Aßmus 
852faa1532SStephan Aßmus 			typedef std::list<add_on_directory_info> DirectoryList;
862faa1532SStephan Aßmus 
872faa1532SStephan Aßmus 			bool				_FindEntry(const node_ref& entry,
882faa1532SStephan Aßmus 									const EntryList& list,
892faa1532SStephan Aßmus 									EntryList::iterator& it) const;
902faa1532SStephan Aßmus 			bool				_FindEntry(const char* name,
912faa1532SStephan Aßmus 									const EntryList& list,
922faa1532SStephan Aßmus 									EntryList::iterator& it) const;
932faa1532SStephan Aßmus 
942faa1532SStephan Aßmus 			bool				_HasEntry(const node_ref& entry,
952faa1532SStephan Aßmus 									EntryList& list) const;
962faa1532SStephan Aßmus 			bool				_HasEntry(const char* name,
972faa1532SStephan Aßmus 									EntryList& list) const;
982faa1532SStephan Aßmus 
992faa1532SStephan Aßmus 			bool				_FindDirectory(ino_t directory, dev_t device,
1002faa1532SStephan Aßmus 									DirectoryList::iterator& it) const;
1012faa1532SStephan Aßmus 			bool				_FindDirectory(
1022faa1532SStephan Aßmus 									const node_ref& directoryNodeRef,
1032faa1532SStephan Aßmus 									DirectoryList::iterator& it) const;
1042faa1532SStephan Aßmus 			bool				_FindDirectory(ino_t directory, dev_t device,
1052faa1532SStephan Aßmus 									DirectoryList::iterator& it,
1062faa1532SStephan Aßmus 									const DirectoryList::const_iterator& end)
1072faa1532SStephan Aßmus 										const;
1082faa1532SStephan Aßmus 			bool				_FindDirectory(
1092faa1532SStephan Aßmus 									const node_ref& directoryNodeRef,
1102faa1532SStephan Aßmus 									DirectoryList::iterator& it,
1112faa1532SStephan Aßmus 									const DirectoryList::const_iterator& end)
1122faa1532SStephan Aßmus 										const;
1132faa1532SStephan Aßmus 
1142faa1532SStephan Aßmus 			void				_AddNewEntry(EntryList& list,
1152faa1532SStephan Aßmus 									add_on_entry_info& info);
1162faa1532SStephan Aßmus 
1172faa1532SStephan Aßmus private:
1182faa1532SStephan Aßmus 			DirectoryList		fDirectories;
1192faa1532SStephan Aßmus 			EntryList			fPendingEntries;
120afd1e200Sshatty };
121afd1e200Sshatty 
122afd1e200Sshatty 
123afd1e200Sshatty }; // namespace Storage
124afd1e200Sshatty }; // namespace BPrivate
125afd1e200Sshatty 
1262faa1532SStephan Aßmus 
127afd1e200Sshatty using namespace BPrivate::Storage;
128afd1e200Sshatty 
1292faa1532SStephan Aßmus 
130afd1e200Sshatty #endif	// _ADD_ON_MONITOR_HANDLER_H
131