libcamera: pipeline: Refuse to substitute camera data

Once a pipeline-specific data has been associated with a camera, refuse
to update it in order to avoid invalidating the previously set
reference, which might still be owned by the caller.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Jacopo Mondi 2019-01-25 17:40:18 +01:00
parent a2bdf51ed6
commit 529704d1ab

View file

@ -212,19 +212,20 @@ CameraData *PipelineHandler::cameraData(const Camera *camera)
* information with \a camera. Ownership of \a data is transferred to
* the PipelineHandler.
*
* If pipeline-specific data has already been associated with the camera by a
* previous call to this method, is it replaced by \a data and the previous data
* are deleted, rendering all references to them invalid.
* Pipeline-specific data can only be set once. Any attempt to call
* this method after the first one with the same camera won't change
* the pipeline-specific data.
*
* The data can be retrieved by pipeline handlers using the cameraData() method.
*/
void PipelineHandler::setCameraData(const Camera *camera,
std::unique_ptr<CameraData> data)
{
if (cameraData_.count(camera))
LOG(Pipeline, Debug)
<< "Replacing data associated with "
<< camera->name();
if (cameraData_.find(camera) != cameraData_.end()) {
LOG(Pipeline, Error)
<< "Replacing data associated with a camera is forbidden";
return;
}
cameraData_[camera] = std::move(data);
}