* Cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31710 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-07-23 09:45:54 +00:00
parent 664683a7d2
commit 8315ac2417
2 changed files with 141 additions and 147 deletions
+12 -13
View File
@@ -1,23 +1,19 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//---------------------------------------------------------------------
/*!
\file Query.h
BQuery interface declaration.
/*
* Copyright 2002-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _QUERY_H
#define _QUERY_H
#include <EntryList.h>
#include <Messenger.h>
#include <OS.h>
#include <SupportDefs.h>
class BVolume;
struct entry_ref;
namespace BPrivate {
namespace Storage {
class QueryNode;
@@ -43,6 +39,7 @@ typedef enum {
_B_RESERVED_OP_ = 0x100000
} query_op;
/*!
\class BQuery
\brief Represents a live or non-live file system query
@@ -70,7 +67,8 @@ public:
status_t PushInt64(int64 value);
status_t PushFloat(float value);
status_t PushDouble(double value);
status_t PushString(const char *value, bool caseInsensitive = false);
status_t PushString(const char* value,
bool caseInsensitive = false);
status_t PushDate(const char* date);
status_t SetVolume(const BVolume* volume);
@@ -90,14 +88,15 @@ public:
// BEntryList interface
virtual status_t GetNextEntry(BEntry* entry, bool traverse = false);
virtual status_t GetNextRef(entry_ref* ref);
virtual int32 GetNextDirents(struct dirent *buf, size_t length,
virtual int32 GetNextDirents(struct dirent* buffer, size_t length,
int32 count = INT_MAX);
virtual status_t Rewind();
virtual int32 CountEntries();
private:
bool _HasFetched() const;
status_t _PushNode(BPrivate::Storage::QueryNode *node, bool deleteOnError);
status_t _PushNode(BPrivate::Storage::QueryNode* node,
bool deleteOnError);
status_t _SetPredicate(const char* expression);
status_t _EvaluateStack();
@@ -110,7 +109,6 @@ private:
virtual void _QwertyQuery6();
private:
int32 _reservedData[4]; // FBC
BPrivate::Storage::QueryStack* fStack;
char* fPredicate;
dev_t fDevice;
@@ -118,6 +116,7 @@ private:
port_id fPort;
long fToken;
int fQueryFd;
int32 _reservedData[4];
};
#endif // _QUERY_H
+60 -65
View File
@@ -1,20 +1,23 @@
//----------------------------------------------------------------------
// This software is part of the Haiku distribution and is covered
// by the MIT license.
//---------------------------------------------------------------------
/*!
\file Query.cpp
BQuery implementation.
/*
* Copyright 2002-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Tyler Dauwalder
* Ingo Weinhold
* Axel Dörfler, [email protected].
*/
#include <Query.h>
#include <fcntl.h>
#include <new>
#include <parsedate.h>
#include <time.h>
#include <Entry.h>
#include <fs_query.h>
#include <Query.h>
#include <parsedate.h>
#include <Volume.h>
#include <MessengerPrivate.h>
@@ -26,13 +29,12 @@
using namespace std;
using namespace BPrivate::Storage;
// BQuery
// constructor
/*! \brief Creates an uninitialized BQuery.
*/
BQuery::BQuery()
: BEntryList(),
:
BEntryList(),
fStack(NULL),
fPredicate(NULL),
fDevice((dev_t)B_ERROR),
@@ -43,7 +45,7 @@ BQuery::BQuery()
{
}
// destructor
/*! \brief Frees all resources associated with the object.
*/
BQuery::~BQuery()
@@ -51,7 +53,7 @@ BQuery::~BQuery()
Clear();
}
// Clear
/*! \brief Resets the object to a uninitialized state.
\return \c B_OK
*/
@@ -77,7 +79,7 @@ BQuery::Clear()
return error;
}
// PushAttr
/*! \brief Pushes an attribute name onto the BQuery's predicate stack.
\param attrName the attribute name
\return
@@ -98,7 +100,7 @@ BQuery::PushAttr(const char *attrName)
return _PushNode(new(nothrow) AttributeNode(attrName), true);
}
// PushOp
/*! \brief Pushes an operator onto the BQuery's predicate stack.
\param op the code representing the operator
\return
@@ -141,7 +143,7 @@ BQuery::PushOp(query_op op)
return error;
}
// PushUInt32
/*! \brief Pushes a uint32 value onto the BQuery's predicate stack.
\param value the value
\return
@@ -162,7 +164,7 @@ BQuery::PushUInt32(uint32 value)
return _PushNode(new(nothrow) UInt32ValueNode(value), true);
}
// PushInt32
/*! \brief Pushes an int32 value onto the BQuery's predicate stack.
\param value the value
\return
@@ -183,7 +185,7 @@ BQuery::PushInt32(int32 value)
return _PushNode(new(nothrow) Int32ValueNode(value), true);
}
// PushUInt64
/*! \brief Pushes a uint64 value onto the BQuery's predicate stack.
\param value the value
\return
@@ -204,7 +206,7 @@ BQuery::PushUInt64(uint64 value)
return _PushNode(new(nothrow) UInt64ValueNode(value), true);
}
// PushInt64
/*! \brief Pushes an int64 value onto the BQuery's predicate stack.
\param value the value
\return
@@ -225,7 +227,7 @@ BQuery::PushInt64(int64 value)
return _PushNode(new(nothrow) Int64ValueNode(value), true);
}
// PushFloat
/*! \brief Pushes a float value onto the BQuery's predicate stack.
\param value the value
\return
@@ -246,7 +248,7 @@ BQuery::PushFloat(float value)
return _PushNode(new(nothrow) FloatValueNode(value), true);
}
// PushDouble
/*! \brief Pushes a double value onto the BQuery's predicate stack.
\param value the value
\return
@@ -267,7 +269,7 @@ BQuery::PushDouble(double value)
return _PushNode(new(nothrow) DoubleValueNode(value), true);
}
// PushString
/*! \brief Pushes a string value onto the BQuery's predicate stack.
\param value the value
\param caseInsensitive \c true, if the case of the string should be
@@ -290,7 +292,7 @@ BQuery::PushString(const char *value, bool caseInsensitive)
return _PushNode(new(nothrow) StringNode(value, caseInsensitive), true);
}
// PushDate
/*! \brief Pushes a date value onto the BQuery's predicate stack.
The supplied date can be any string understood by the POSIX function
parsedate().
@@ -308,20 +310,13 @@ BQuery::PushString(const char *value, bool caseInsensitive)
status_t
BQuery::PushDate(const char* date)
{
status_t error = (date ? B_OK : B_BAD_VALUE);
if (error == B_OK) {
time_t t;
time(&t);
t = parsedate(date, t);
if (t < 0)
error = B_BAD_VALUE;
}
if (error == B_OK)
error = _PushNode(new(nothrow) DateNode(date), true);
return error;
if (date == NULL || !date[0] || parsedate(date, time(NULL)) < 0)
return B_BAD_VALUE;
return _PushNode(new(nothrow) DateNode(date), true);
}
// SetVolume
/*! \brief Sets the BQuery's volume.
A query is restricted to one volume. This method sets this volume. It
fails, if called after Fetch(). To reuse a BQuery object it has to be
@@ -334,19 +329,20 @@ BQuery::PushDate(const char *date)
status_t
BQuery::SetVolume(const BVolume* volume)
{
status_t error = (volume ? B_OK : B_BAD_VALUE);
if (error == B_OK && _HasFetched())
error = B_NOT_ALLOWED;
if (error == B_OK) {
if (volume == NULL)
return B_BAD_VALUE;
if (_HasFetched())
return B_NOT_ALLOWED;
if (volume->InitCheck() == B_OK)
fDevice = volume->Device();
else
fDevice = (dev_t)B_ERROR;
}
return error;
return B_OK;
}
// SetPredicate
/*! \brief Sets the BQuery's predicate.
A predicate can be set either using this method or constructing one on
the predicate stack. The two methods can not be mixed. The letter one
@@ -370,7 +366,7 @@ BQuery::SetPredicate(const char *expression)
return error;
}
// SetTarget
/*! \brief Sets the BQuery's target and makes the query live.
The query update messages are sent to the specified target. They might
roll in immediately after calling Fetch().
@@ -397,7 +393,7 @@ BQuery::SetTarget(BMessenger messenger)
return error;
}
// IsLive
/*! \brief Returns whether the query associated with this object is live.
\return \c true, if the query is live, \c false otherwise
*/
@@ -407,7 +403,7 @@ BQuery::IsLive() const
return fLive;
}
// GetPredicate
/*! \brief Returns the BQuery's predicate.
Regardless of whether the predicate has been constructed using the
predicate stack or set via SetPredicate(), this method returns a
@@ -437,7 +433,7 @@ BQuery::GetPredicate(char *buffer, size_t length)
return error;
}
// GetPredicate
/*! \brief Returns the BQuery's predicate.
Regardless of whether the predicate has been constructed using the
predicate stack or set via SetPredicate(), this method returns a
@@ -464,7 +460,7 @@ BQuery::GetPredicate(BString *predicate)
return error;
}
// PredicateLength
/*! \brief Returns the length of the BQuery's predicate string.
Regardless of whether the predicate has been constructed using the
predicate stack or set via SetPredicate(), this method returns the length
@@ -487,11 +483,10 @@ BQuery::PredicateLength()
return size;
}
// TargetDevice
/*! \brief Returns the device ID identifying the BQuery's volume.
\return the device ID of the BQuery's volume or \c B_NO_INIT, if the
volume isn't set.
*/
dev_t
BQuery::TargetDevice() const
@@ -499,7 +494,7 @@ BQuery::TargetDevice() const
return fDevice;
}
// Fetch
/*! \brief Tells the BQuery to start fetching entries satisfying the predicate.
After Fetch() has been called GetNextEntry(), GetNextRef() and
GetNextDirents() can be used to retrieve the enties. Live query updates
@@ -535,9 +530,9 @@ BQuery::Fetch()
}
// BEntryList interface
// #pragma mark - BEntryList interface
// GetNextEntry
/*! \brief Returns the BQuery's next entry as a BEntry.
Places the next entry in the list in \a entry, traversing symlinks if
\a traverse is \c true.
@@ -565,7 +560,7 @@ BQuery::GetNextEntry(BEntry *entry, bool traverse)
return error;
}
// GetNextRef
/*! \brief Returns the BQuery's next entry as an entry_ref.
Places an entry_ref to the next entry in the list into \a ref.
\param ref a pointer to an entry_ref to be filled in with the data of the
@@ -604,7 +599,7 @@ BQuery::GetNextRef(entry_ref *ref)
return error;
}
// GetNextDirents
/*! \brief Returns the BQuery's next entries as dirent structures.
Reads a number of entries into the array of dirent structures pointed to by
\a buf. Reads as many but no more than \a count entries, as many entries as
@@ -622,16 +617,16 @@ BQuery::GetNextRef(entry_ref *ref)
- \c B_FILE_ERROR: Fetch() has not been called before.
*/
int32
BQuery::GetNextDirents(struct dirent *buf, size_t length, int32 count)
BQuery::GetNextDirents(struct dirent* buffer, size_t length, int32 count)
{
if (!buf)
if (!buffer)
return B_BAD_VALUE;
if (!_HasFetched())
return B_FILE_ERROR;
return _kern_read_dir(fQueryFd, buf, length, count);
return _kern_read_dir(fQueryFd, buffer, length, count);
}
// Rewind
/*! \brief Rewinds the entry list back to the first entry.
Unlike R5 Haiku implements this method for BQuery.
@@ -648,7 +643,7 @@ BQuery::Rewind()
return _kern_rewind_dir(fQueryFd);
}
// CountEntries
/*! \brief Unimplemented method of the BEntryList interface.
\return 0.
*/
@@ -658,7 +653,7 @@ BQuery::CountEntries()
return B_ERROR;
}
// _HasFetched
/*! Returns whether Fetch() has already been called on this object.
\return \c true, if Fetch() has successfully been invoked, \c false
otherwise.
@@ -666,10 +661,10 @@ BQuery::CountEntries()
bool
BQuery::_HasFetched() const
{
return (fQueryFd >= 0);
return fQueryFd >= 0;
}
// _PushNode
/*! \brief Pushs a node onto the predicate stack.
If the stack has not been allocate until this time, this method does
allocate it.
@@ -705,7 +700,7 @@ BQuery::_PushNode(QueryNode *node, bool deleteOnError)
return error;
}
// _SetPredicate
/*! \brief Helper method to set the BQuery's predicate.
It is not checked whether Fetch() has already been invoked.
\param predicate the predicate string
@@ -731,7 +726,7 @@ BQuery::_SetPredicate(const char *expression)
return error;
}
// _EvaluateStack
/*! Evaluates the query's predicate stack.
The method does nothing (and returns \c B_OK), if the stack is \c NULL.
If the stack is non-null and Fetch() has already been called, the method