BQuery: Add SetFlags() method.

It can be used to set flags on the query, same as fs_open_query()'s
flags parameter.

fLive had 3 bytes of padding after it, so this doesn't break ABI.
This commit is contained in:
Augustin Cavalier
2025-04-30 17:18:16 -04:00
parent 7e740f61ac
commit d26ab46206
2 changed files with 16 additions and 9 deletions
+2 -1
View File
@@ -63,6 +63,7 @@ public:
status_t SetVolume(const BVolume* volume); status_t SetVolume(const BVolume* volume);
status_t SetPredicate(const char* expression); status_t SetPredicate(const char* expression);
status_t SetTarget(BMessenger messenger); status_t SetTarget(BMessenger messenger);
void SetFlags(uint32 flags);
bool IsLive() const; bool IsLive() const;
@@ -102,7 +103,7 @@ private:
BPrivate::Storage::QueryStack* fStack; BPrivate::Storage::QueryStack* fStack;
char* fPredicate; char* fPredicate;
dev_t fDevice; dev_t fDevice;
bool fLive; uint32 fFlags;
port_id fPort; port_id fPort;
long fToken; long fToken;
int fQueryFd; int fQueryFd;
+14 -8
View File
@@ -39,7 +39,7 @@ BQuery::BQuery()
fStack(NULL), fStack(NULL),
fPredicate(NULL), fPredicate(NULL),
fDevice((dev_t)B_ERROR), fDevice((dev_t)B_ERROR),
fLive(false), fFlags(0),
fPort(B_ERROR), fPort(B_ERROR),
fToken(0), fToken(0),
fQueryFd(-1) fQueryFd(-1)
@@ -71,7 +71,7 @@ BQuery::Clear()
fPredicate = NULL; fPredicate = NULL;
// reset the other parameters // reset the other parameters
fDevice = (dev_t)B_ERROR; fDevice = (dev_t)B_ERROR;
fLive = false; fFlags = 0;
fPort = B_ERROR; fPort = B_ERROR;
fToken = 0; fToken = 0;
return error; return error;
@@ -226,17 +226,23 @@ BQuery::SetTarget(BMessenger messenger)
fPort = messengerPrivate.Port(); fPort = messengerPrivate.Port();
fToken = (messengerPrivate.IsPreferredTarget() fToken = (messengerPrivate.IsPreferredTarget()
? -1 : messengerPrivate.Token()); ? -1 : messengerPrivate.Token());
fLive = true;
} }
return error; return error;
} }
void
BQuery::SetFlags(uint32 flags)
{
fFlags = flags;
}
// Gets whether the query associated with this object is live. // Gets whether the query associated with this object is live.
bool bool
BQuery::IsLive() const BQuery::IsLive() const
{ {
return fLive; return fPort >= 0;
} }
@@ -310,14 +316,14 @@ BQuery::Fetch()
BString parsedPredicate; BString parsedPredicate;
_ParseDates(parsedPredicate); _ParseDates(parsedPredicate);
fQueryFd = _kern_open_query(fDevice, parsedPredicate.String(), fQueryFd = _kern_open_query(fDevice,
parsedPredicate.Length(), fLive ? B_LIVE_QUERY : 0, fPort, fToken); parsedPredicate.String(), parsedPredicate.Length(),
fFlags | ((fPort >= 0) ? B_LIVE_QUERY : 0),
fPort, fToken);
if (fQueryFd < 0) if (fQueryFd < 0)
return fQueryFd; return fQueryFd;
// set close on exec flag
fcntl(fQueryFd, F_SETFD, FD_CLOEXEC); fcntl(fQueryFd, F_SETFD, FD_CLOEXEC);
return B_OK; return B_OK;
} }