xref: /haiku/headers/os/storage/Query.h (revision bb24170e40e943e21fbe6160f67d0a2b29fd3b01)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //---------------------------------------------------------------------
5 /*!
6 	\file Query.h
7 	BQuery interface declaration.
8 */
9 
10 #ifndef _QUERY_H
11 #define _QUERY_H
12 
13 #include <EntryList.h>
14 #include <Messenger.h>
15 #include <OS.h>
16 #include <SupportDefs.h>
17 
18 #include <StorageDefs.Private.h>
19 
20 class BVolume;
21 struct entry_ref;
22 
23 namespace BPrivate {
24 	namespace Storage {
25 		class QueryNode;
26 		class QueryStack;
27 		class QueryTree;
28 	};
29 };
30 
31 typedef enum {
32 	B_INVALID_OP	= 0,
33 	B_EQ,
34 	B_GT,
35 	B_GE,
36 	B_LT,
37 	B_LE,
38 	B_NE,
39 	B_CONTAINS,
40 	B_BEGINS_WITH,
41 	B_ENDS_WITH,
42 	B_AND			= 0x101,
43 	B_OR,
44 	B_NOT,
45 	_B_RESERVED_OP_	= 0x100000
46 } query_op;
47 
48 /*!
49 	\class BQuery
50 	\brief Represents a live or non-live file system query
51 
52 	Provides an interface for creating file system queries. Implements
53 	the BEntryList for iterating through the found entries.
54 
55 	\author <a href='mailto:bonefish@users.sf.net'>Ingo Weinhold</a>
56 
57 	\version 0.0.0
58 */
59 class BQuery : public BEntryList {
60 public:
61 	BQuery();
62 	virtual ~BQuery();
63 
64 	status_t Clear();
65 
66 	status_t PushAttr(const char *attrName);
67 	status_t PushOp(query_op op);
68 
69 	status_t PushUInt32(uint32 value);
70 	status_t PushInt32(int32 value);
71 	status_t PushUInt64(uint64 value);
72 	status_t PushInt64(int64 value);
73 	status_t PushFloat(float value);
74 	status_t PushDouble(double value);
75 	status_t PushString(const char *value, bool caseInsensitive = false);
76 	status_t PushDate(const char *date);
77 
78 	status_t SetVolume(const BVolume *volume);
79 	status_t SetPredicate(const char *expression);
80 	status_t SetTarget(BMessenger messenger);
81 
82 	bool IsLive() const;
83 
84 	status_t GetPredicate(char *buffer, size_t length);
85 	status_t GetPredicate(BString *predicate);
86 	size_t PredicateLength();
87 
88 	dev_t TargetDevice() const;
89 
90 	status_t Fetch();
91 
92 	// BEntryList interface
93 	virtual status_t GetNextEntry(BEntry *entry, bool traverse = false);
94 	virtual status_t GetNextRef(entry_ref *ref);
95 	virtual int32 GetNextDirents(struct dirent *buf, size_t length,
96 								 int32 count = INT_MAX);
97 	virtual status_t Rewind();
98 	virtual int32 CountEntries();
99 
100 private:
101 	bool _HasFetched() const;
102 	status_t _PushNode(BPrivate::Storage::QueryNode *node, bool deleteOnError);
103 	status_t _SetPredicate(const char *expression);
104 	status_t _EvaluateStack();
105 
106 	// FBC
107 	virtual void _ReservedQuery1();
108 	virtual void _ReservedQuery2();
109 	virtual void _ReservedQuery3();
110 	virtual void _ReservedQuery4();
111 	virtual void _ReservedQuery5();
112 	virtual void _ReservedQuery6();
113 
114 private:
115 	int32		_reservedData[4];	// FBC
116 	BPrivate::Storage::QueryStack *fStack;
117 	char		*fPredicate;
118 	dev_t		fDevice;
119 	bool		fLive;
120 	port_id		fPort;
121 	long		fToken;
122 	BPrivate::Storage::FileDescriptor fQueryFd;
123 };
124 
125 #endif	// _QUERY_H
126 
127 
128