xref: /haiku/headers/private/storage/AddOnMonitorHandler.h (revision 2faa1532f8de1520d3f5a33ecc607fce8b1d5a41)
1ab428535SAxel Dörfler /*
2*2faa1532SStephan 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 
8*2faa1532SStephan Aßmus 
9afd1e200Sshatty #include <list>
10ab428535SAxel Dörfler 
11afd1e200Sshatty #include "NodeMonitorHandler.h"
12afd1e200Sshatty 
13ab428535SAxel Dörfler 
14afd1e200Sshatty namespace BPrivate {
15afd1e200Sshatty namespace Storage {
16afd1e200Sshatty 
17*2faa1532SStephan Aßmus 
18afd1e200Sshatty struct add_on_entry_info {
19afd1e200Sshatty 	char name[B_FILE_NAME_LENGTH];
20afd1e200Sshatty 	node_ref nref;
21afd1e200Sshatty 	node_ref dir_nref;
22*2faa1532SStephan 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 
31*2faa1532SStephan Aßmus 	virtual	void				MessageReceived(BMessage* message);
32afd1e200Sshatty 
33*2faa1532SStephan Aßmus 	// Supply the add-on directories here, in the order you want them checked.
34*2faa1532SStephan Aßmus 	// Add-ons in directories added earlier will shadow add-ons in directories
35*2faa1532SStephan Aßmus 	// added later, if they share the same file name. If an add-on is removed
36*2faa1532SStephan Aßmus 	// from or renamed in a directory and it has previously shadowed another
37*2faa1532SStephan Aßmus 	// add-on, the previously shadowed add-on shall become enabled
38*2faa1532SStephan Aßmus 	// (AddOnEnabled()). If an add-on appears in a directory, or is renamed,
39*2faa1532SStephan Aßmus 	// it can cause another add-on to become disabled, if it has the same name.
40*2faa1532SStephan Aßmus 	// Note that directories are not watched recursively, and all entries
41*2faa1532SStephan Aßmus 	// are reported as add-ons regardless of their node type (files,
42*2faa1532SStephan Aßmus 	// directories, symlinks).
43afd1e200Sshatty 	virtual	status_t			AddDirectory(const node_ref* nref);
44afd1e200Sshatty 
45afd1e200Sshatty protected:
46*2faa1532SStephan Aßmus 	// hooks for sub-class
47*2faa1532SStephan Aßmus 	virtual	void				AddOnCreated(
48*2faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
49*2faa1532SStephan Aßmus 	virtual	void				AddOnEnabled(
50*2faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
51*2faa1532SStephan Aßmus 	virtual	void				AddOnDisabled(
52*2faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
53*2faa1532SStephan Aßmus 									// name field will be invalid!
54*2faa1532SStephan Aßmus 	virtual	void				AddOnRemoved(
55*2faa1532SStephan Aßmus 									const add_on_entry_info* entryInfo);
56*2faa1532SStephan Aßmus 									// name field will be invalid!
57afd1e200Sshatty 
58afd1e200Sshatty protected:
59afd1e200Sshatty 	virtual	void				EntryCreated(const char* name, ino_t directory,
60afd1e200Sshatty 									dev_t device, ino_t node);
61*2faa1532SStephan Aßmus 	virtual	void				EntryRemoved(ino_t directory, dev_t device,
62*2faa1532SStephan Aßmus 									ino_t node);
63*2faa1532SStephan Aßmus 	virtual	void				EntryMoved(const char* name,
64*2faa1532SStephan Aßmus 									ino_t fromDirectory, ino_t toDirectory,
65*2faa1532SStephan Aßmus 									dev_t device, ino_t node);
66*2faa1532SStephan Aßmus 	virtual	void				StatChanged(ino_t node, dev_t device);
67afd1e200Sshatty 
68afd1e200Sshatty private:
69ca5e0241SRene Gollent 			void				_HandlePulse();
70*2faa1532SStephan Aßmus 			void				_EntryCreated(add_on_entry_info& info);
71afd1e200Sshatty 
72*2faa1532SStephan Aßmus 			typedef NodeMonitorHandler inherited;
73*2faa1532SStephan Aßmus 			typedef std::list<add_on_entry_info> EntryList;
74*2faa1532SStephan Aßmus 
75*2faa1532SStephan Aßmus 			struct add_on_directory_info {
76*2faa1532SStephan Aßmus 				node_ref		nref;
77*2faa1532SStephan Aßmus 				EntryList		entries;
78*2faa1532SStephan Aßmus 			};
79*2faa1532SStephan Aßmus 
80*2faa1532SStephan Aßmus 			typedef std::list<add_on_directory_info> DirectoryList;
81*2faa1532SStephan Aßmus 
82*2faa1532SStephan Aßmus 			bool				_FindEntry(const node_ref& entry,
83*2faa1532SStephan Aßmus 									const EntryList& list,
84*2faa1532SStephan Aßmus 									EntryList::iterator& it) const;
85*2faa1532SStephan Aßmus 			bool				_FindEntry(const char* name,
86*2faa1532SStephan Aßmus 									const EntryList& list,
87*2faa1532SStephan Aßmus 									EntryList::iterator& it) const;
88*2faa1532SStephan Aßmus 
89*2faa1532SStephan Aßmus 			bool				_HasEntry(const node_ref& entry,
90*2faa1532SStephan Aßmus 									EntryList& list) const;
91*2faa1532SStephan Aßmus 			bool				_HasEntry(const char* name,
92*2faa1532SStephan Aßmus 									EntryList& list) const;
93*2faa1532SStephan Aßmus 
94*2faa1532SStephan Aßmus 			bool				_FindDirectory(ino_t directory, dev_t device,
95*2faa1532SStephan Aßmus 									DirectoryList::iterator& it) const;
96*2faa1532SStephan Aßmus 			bool				_FindDirectory(
97*2faa1532SStephan Aßmus 									const node_ref& directoryNodeRef,
98*2faa1532SStephan Aßmus 									DirectoryList::iterator& it) const;
99*2faa1532SStephan Aßmus 			bool				_FindDirectory(ino_t directory, dev_t device,
100*2faa1532SStephan Aßmus 									DirectoryList::iterator& it,
101*2faa1532SStephan Aßmus 									const DirectoryList::const_iterator& end)
102*2faa1532SStephan Aßmus 										const;
103*2faa1532SStephan Aßmus 			bool				_FindDirectory(
104*2faa1532SStephan Aßmus 									const node_ref& directoryNodeRef,
105*2faa1532SStephan Aßmus 									DirectoryList::iterator& it,
106*2faa1532SStephan Aßmus 									const DirectoryList::const_iterator& end)
107*2faa1532SStephan Aßmus 										const;
108*2faa1532SStephan Aßmus 
109*2faa1532SStephan Aßmus 			void				_AddNewEntry(EntryList& list,
110*2faa1532SStephan Aßmus 									add_on_entry_info& info);
111*2faa1532SStephan Aßmus 
112*2faa1532SStephan Aßmus private:
113*2faa1532SStephan Aßmus 			DirectoryList		fDirectories;
114*2faa1532SStephan Aßmus 			EntryList			fPendingEntries;
115afd1e200Sshatty };
116afd1e200Sshatty 
117afd1e200Sshatty 
118afd1e200Sshatty }; // namespace Storage
119afd1e200Sshatty }; // namespace BPrivate
120afd1e200Sshatty 
121*2faa1532SStephan Aßmus 
122afd1e200Sshatty using namespace BPrivate::Storage;
123afd1e200Sshatty 
124*2faa1532SStephan Aßmus 
125afd1e200Sshatty #endif	// _ADD_ON_MONITOR_HANDLER_H
126