[libcamera-devel] [PATCH v3 04/11] libcamera: request: Add a toString()

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri Mar 26 03:08:43 CET 2021


Hi Kieran,

Thank you for the patch.


On Thu, Mar 25, 2021 at 01:42:24PM +0000, Kieran Bingham wrote:
> Provide a toString helper to assist in printing Request state
> for debug and logging contexts.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
>  include/libcamera/request.h |  3 +++
>  src/libcamera/request.cpp   | 30 +++++++++++++++++++++++++++---
>  2 files changed, 30 insertions(+), 3 deletions(-)
> 
> diff --git a/include/libcamera/request.h b/include/libcamera/request.h
> index cd5a24741f8a..4cf5ff3f7d3b 100644
> --- a/include/libcamera/request.h
> +++ b/include/libcamera/request.h
> @@ -10,6 +10,7 @@
>  #include <map>
>  #include <memory>
>  #include <stdint.h>
> +#include <string>
>  #include <unordered_set>
>  
>  #include <libcamera/class.h>
> @@ -56,6 +57,8 @@ public:
>  
>  	bool hasPendingBuffers() const { return !pending_.empty(); }
>  
> +	std::string toString() const;
> +
>  private:
>  	LIBCAMERA_DISABLE_COPY(Request)
>  
> diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp
> index fc16b148a599..7b7ef6814686 100644
> --- a/src/libcamera/request.cpp
> +++ b/src/libcamera/request.cpp
> @@ -8,6 +8,7 @@
>  #include <libcamera/request.h>
>  
>  #include <map>
> +#include <sstream>
>  
>  #include <libcamera/buffer.h>
>  #include <libcamera/camera.h>
> @@ -261,6 +262,16 @@ FrameBuffer *Request::findBuffer(const Stream *stream) const
>   * otherwise
>   */
>  
> +/**
> + * \fn Request::toString()
> + * \brief Generate a string representation of the Request internals
> + *
> + * This function facilitates debugging of Request state while it is used
> + * internally within libcamera.
> + *
> + * \return A string representing the current state of the request
> + */
> +

Any reason why this isn't move below, just above the function ?

>  /**
>   * \brief Complete a queued request
>   *
> @@ -275,9 +286,7 @@ void Request::complete()
>  
>  	status_ = cancelled_ ? RequestCancelled : RequestComplete;
>  
> -	LOG(Request, Debug)
> -		<< "Request has completed - cookie: " << cookie_
> -		<< (cancelled_ ? " [Cancelled]" : "");
> +	LOG(Request, Debug) << toString();
>  
>  	LIBCAMERA_TRACEPOINT(request_complete, this);
>  }
> @@ -310,4 +319,19 @@ bool Request::completeBuffer(FrameBuffer *buffer)
>  	return !hasPendingBuffers();
>  }
>  
> +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_] << ":"

s/Request /Request/

Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

> +	   << pending_.size() << "/" << bufferMap_.size() << ":"
> +	   << cookie_ << ")";
> +
> +	return ss.str();
> +}
> +
>  } /* namespace libcamera */

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list