libcamera: request: Add operator<<()

With the recent addition of operator<<() in most libcamera core classes
to replace usage of the toString() function the Request class was left
behind.

Add operator<<() for the Request class and reimplement toString().

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Jacopo Mondi 2022-06-03 11:30:25 +02:00
parent 38e427f605
commit 161d24377c
3 changed files with 24 additions and 8 deletions

View file

@ -44,6 +44,7 @@ public:
private:
friend class PipelineHandler;
friend std::ostream &operator<<(std::ostream &out, const Request &r);
void doCancelRequest();
void emitPrepareCompleted();

View file

@ -9,6 +9,7 @@
#include <map>
#include <memory>
#include <ostream>
#include <stdint.h>
#include <string>
#include <unordered_set>
@ -75,4 +76,6 @@ private:
Status status_;
};
std::ostream &operator<<(std::ostream &out, const Request &r);
} /* namespace libcamera */

View file

@ -582,16 +582,28 @@ bool Request::hasPendingBuffers() const
std::string Request::toString() const
{
std::stringstream ss;
/* Pending, Completed, Cancelled(X). */
static const char *statuses = "PCX";
/* Example Output: Request(55:P:1/2:6523524) */
ss << "Request(" << sequence() << ":" << statuses[status_] << ":"
<< _d()->pending_.size() << "/" << bufferMap_.size() << ":"
<< cookie_ << ")";
ss << *this;
return ss.str();
}
/**
* \brief Insert a text representation of a Request into an output stream
* \param[in] out The output stream
* \param[in] r The Request
* \return The output stream \a out
*/
std::ostream &operator<<(std::ostream &out, const Request &r)
{
/* Pending, Completed, Cancelled(X). */
static const char *statuses = "PCX";
/* Example Output: Request(55:P:1/2:6523524) */
out << "Request(" << r.sequence() << ":" << statuses[r.status()] << ":"
<< r._d()->pending_.size() << "/" << r.buffers().size() << ":"
<< r.cookie() << ")";
return out;
}
} /* namespace libcamera */