xref: /haiku/src/add-ons/kernel/file_systems/netfs/client/QueryManager.h (revision c90684742e7361651849be4116d0e5de3a817194)
1 // QueryManager.h
2 
3 #ifndef NET_FS_QUERY_MANAGER_H
4 #define NET_FS_QUERY_MANAGER_H
5 
6 #include "Locker.h"
7 #include "QueryIterator.h"
8 
9 class Volume;
10 class VolumeManager;
11 
12 // QueryManager
13 class QueryManager {
14 public:
15 								QueryManager(VolumeManager* volumeManager);
16 								~QueryManager();
17 
18 			status_t			Init();
19 
20 			status_t			AddIterator(QueryIterator* iterator);
21 
22 			status_t			AddSubIterator(
23 									HierarchicalQueryIterator* iterator,
24 									QueryIterator* subIterator);
25 private:
26 			status_t			RemoveSubIterator(
27 									HierarchicalQueryIterator* iterator,
28 									QueryIterator* subIterator);
29 public:
30 // TODO: Remove.
31 
32 			QueryIterator*		GetCurrentSubIterator(
33 									HierarchicalQueryIterator* iterator);
34 			void				NextSubIterator(
35 									HierarchicalQueryIterator* iterator,
36 									QueryIterator* subIterator);
37 private:
38 			void				RewindSubIterator(
39 									HierarchicalQueryIterator* iterator);
40 public:
41 // TODO: Remove.
42 
43 			void				PutIterator(QueryIterator* iterator);
44 
45 			void				VolumeUnmounting(Volume* volume);
46 
47 private:
48 			struct IteratorMap;
49 
50 			Locker				fLock;
51 			VolumeManager*		fVolumeManager;
52 			IteratorMap*		fIterators;
53 };
54 
55 // QueryIteratorPutter
56 class QueryIteratorPutter {
57 public:
58 	QueryIteratorPutter(QueryManager* manager, QueryIterator* iterator)
59 		: fManager(manager),
60 		  fIterator(iterator)
61 	{
62 	}
63 
64 	~QueryIteratorPutter()
65 	{
66 		if (fManager && fIterator)
67 			fManager->PutIterator(fIterator);
68 	}
69 
70 	void Detach()
71 	{
72 		fManager = NULL;
73 		fIterator = NULL;
74 	}
75 
76 private:
77 	QueryManager*	fManager;
78 	QueryIterator*	fIterator;
79 };
80 
81 #endif	// NET_FS_QUERY_MANAGER_H
82