[libcamera-devel] [PATCH v2] libcamera: request: Add operator<<()
Kieran Bingham
kieran.bingham at ideasonboard.com
Mon Jun 6 14:01:18 CEST 2022
Quoting Jacopo Mondi via libcamera-devel (2022-06-04 10:24:22)
> 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 at jmondi.org>
Looks fine to me.
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
>
> ---
> v2:
> - reimplement toString() using operator<<
>
> ---
> include/libcamera/internal/request.h | 1 +
> include/libcamera/request.h | 3 +++
> src/libcamera/request.cpp | 20 ++++++++++++++++----
> 3 files changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/include/libcamera/internal/request.h b/include/libcamera/internal/request.h
> index 1f2499896e23..9dadd6c60361 100644
> --- a/include/libcamera/internal/request.h
> +++ b/include/libcamera/internal/request.h
> @@ -44,6 +44,7 @@ public:
>
> private:
> friend class PipelineHandler;
> + friend std::ostream &operator<<(std::ostream &out, const Request &r);
>
> void doCancelRequest();
> void emitPrepareCompleted();
> diff --git a/include/libcamera/request.h b/include/libcamera/request.h
> index 1eb537e9b09b..dffde1536cad 100644
> --- a/include/libcamera/request.h
> +++ b/include/libcamera/request.h
> @@ -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 */
> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp
> index 5704972d86af..51d74b294d38 100644
> --- a/src/libcamera/request.cpp
> +++ b/src/libcamera/request.cpp
> @@ -582,16 +582,28 @@ bool Request::hasPendingBuffers() const
> std::string Request::toString() const
> {
> std::stringstream ss;
> + 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) */
> - ss << "Request(" << sequence() << ":" << statuses[status_] << ":"
> - << _d()->pending_.size() << "/" << bufferMap_.size() << ":"
> - << cookie_ << ")";
> + out << "Request(" << r.sequence() << ":" << statuses[r.status()] << ":"
> + << r._d()->pending_.size() << "/" << r.buffers().size() << ":"
> + << r.cookie() << ")";
>
> - return ss.str();
> + return out;
> }
>
> } /* namespace libcamera */
> --
> 2.35.1
>
More information about the libcamera-devel
mailing list