xref: /haiku/src/apps/mail/QueryList.h (revision a3e794ae459fec76826407f8ba8c94cd3535f128)
1 /*
2  * Copyright 2015, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef QUERY_LIST_H
6 #define QUERY_LIST_H
7 
8 
9 #include <map>
10 #include <vector>
11 
12 #include <Entry.h>
13 #include <Handler.h>
14 #include <Locker.h>
15 #include <ObjectList.h>
16 #include <Query.h>
17 
18 
19 struct QueryList;
20 
21 
22 class QueryListener {
23 public:
24 	virtual 				~QueryListener();
25 	virtual	void				EntryCreated(QueryList& source,
26 									const entry_ref& ref, ino_t node) = 0;
27 	virtual	void				EntryRemoved(QueryList& source,
28 									const node_ref& nodeRef) = 0;
29 };
30 
31 
32 typedef std::map<node_ref, entry_ref> RefMap;
33 
34 
35 class QueryList : public BHandler, public BLocker {
36 public:
37 								QueryList();
38 	virtual						~QueryList();
39 
40 			status_t			Init(const char* predicate,
41 									BVolume* volume = NULL);
42 
43 			void				AddListener(QueryListener* listener);
44 			void				RemoveListener(QueryListener* listener);
45 
46 			const RefMap&		Entries() const
47 									{ return fRefs; }
48 
49 	virtual	void				MessageReceived(BMessage* message);
50 
51 private:
52 			void				_AddEntry(const entry_ref& ref, ino_t node);
53 			void				_RemoveEntry(const node_ref& nodeRef);
54 			void				_NotifyEntryCreated(const entry_ref& ref,
55 									ino_t node);
56 			void				_NotifyEntryRemoved(const node_ref& nodeRef);
57 			void				_AddVolume(BVolume& volume,
58 									const char* predicate);
59 
60 	static	status_t			_FetchQuery(void* self);
61 			status_t			_FetchQuery();
62 
63 private:
64 	typedef std::vector<thread_id> ThreadVector;
65 	typedef std::vector<BQuery*> QueryVector;
66 
67 			bool				fQuit;
68 			RefMap				fRefs;
69 			QueryVector			fQueries;
70 			QueryVector			fQueryQueue;
71 			ThreadVector		fFetchThreads;
72 			BObjectList<QueryListener> fListeners;
73 };
74 
75 
76 #endif // QUERY_LIST_H
77