[libcamera-devel] [PATCH 1/3] libcamera: request: Mark metadata() and controls() as const

Laurent Pinchart laurent.pinchart at ideasonboard.com
Thu Dec 10 19:32:19 CET 2020


Hi Jacopo,

On Thu, Dec 10, 2020 at 10:43:08AM +0100, Jacopo Mondi wrote:
> On Thu, Dec 10, 2020 at 09:35:16AM +0000, Kieran Bingham wrote:
> > On 09/12/2020 17:35, Jacopo Mondi wrote:
> > > Mark the metadata() and controls() operations as const function to make
> > > it possible to retrieve them from const Request instances.
> >
> > Is this accurate? How do applications set controls on the request if
> > it's const? (before queueing it)
> 
> Probably from a 'const Request' you should only be able to get a
> 'const ControlList &' ?

Yes, otherwise the user of a const Request would be allowed to modify
the controls and metadata stored in the request, which isn't nice.
There's no issue having both

	ControlList &metadata() { return *metadata_; }
	const ControlList &metadata() const { return *metadata_; }

This however means duplicating the documentation I'm afraid, but we can
use copydoc. See ControlValue::data().

> > Or is that done somewhere else?
> >
> > Metadata certainly seems like it should be const though...
> 
> Happy to drop the const for controls(). I added it there expecting
> some questions :)

Up to you. I don't expect there would be lots of use cases for accessing
controls in a const request, but who knows ?

> > > Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
> > > ---
> > >  include/libcamera/request.h | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/include/libcamera/request.h b/include/libcamera/request.h
> > > index 655b1324bae8..1a89622ab989 100644
> > > --- a/include/libcamera/request.h
> > > +++ b/include/libcamera/request.h
> > > @@ -45,8 +45,8 @@ public:
> > >
> > >  	void reuse(ReuseFlag flags = Default);
> > >
> > > -	ControlList &controls() { return *controls_; }
> > > -	ControlList &metadata() { return *metadata_; }
> > > +	ControlList &controls() const { return *controls_; }
> > > +	ControlList &metadata() const { return *metadata_; }
> > >  	const BufferMap &buffers() const { return bufferMap_; }
> > >  	int addBuffer(const Stream *stream, FrameBuffer *buffer);
> > >  	FrameBuffer *findBuffer(const Stream *stream) const;

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list