libcamera: camera_manager: Make the class a singleton
There can only be a single camera manager instance in the application. Creating it as a singleton helps avoiding mistakes. It also allows the camera manager to be used as a storage of global data, such as the future event dispatcher. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
@@ -161,4 +161,19 @@ Camera *CameraManager::get(const std::string &name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieve the camera manager instance
|
||||
*
|
||||
* The CameraManager is a singleton and can't be constructed manually. This
|
||||
* function shall instead be used to retrieve the single global instance of the
|
||||
* manager.
|
||||
*
|
||||
* \return The camera manager instance
|
||||
*/
|
||||
CameraManager *CameraManager::instance()
|
||||
{
|
||||
static CameraManager manager;
|
||||
return &manager;
|
||||
}
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
||||
Reference in New Issue
Block a user