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