libcamera: camera: Add acquire() and release()
Exclusive access must be obtained before performing operations that change the device state. Define an internal flag to track ownership and provide a means of protecting functions that change device configuration. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
51d442d5a1
commit
ff96eb2ebb
2 changed files with 43 additions and 1 deletions
|
@ -29,6 +29,9 @@ public:
|
|||
|
||||
Signal<Camera *> disconnected;
|
||||
|
||||
int acquire();
|
||||
void release();
|
||||
|
||||
private:
|
||||
Camera(PipelineHandler *pipe, const std::string &name);
|
||||
~Camera();
|
||||
|
@ -38,6 +41,8 @@ private:
|
|||
|
||||
std::shared_ptr<PipelineHandler> pipe_;
|
||||
std::string name_;
|
||||
|
||||
bool acquired_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
|
|
@ -102,12 +102,14 @@ const std::string &Camera::name() const
|
|||
*/
|
||||
|
||||
Camera::Camera(PipelineHandler *pipe, const std::string &name)
|
||||
: pipe_(pipe->shared_from_this()), name_(name)
|
||||
: pipe_(pipe->shared_from_this()), name_(name), acquired_(false)
|
||||
{
|
||||
}
|
||||
|
||||
Camera::~Camera()
|
||||
{
|
||||
if (acquired_)
|
||||
LOG(Camera, Error) << "Removing camera while still in use";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,4 +129,39 @@ void Camera::disconnect()
|
|||
disconnected.emit(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Acquire the camera device for exclusive access
|
||||
*
|
||||
* After opening the device with open(), exclusive access must be obtained
|
||||
* before performing operations that change the device state. This function is
|
||||
* not blocking, if the device has already been acquired (by the same or another
|
||||
* process) the -EBUSY error code is returned.
|
||||
*
|
||||
* Once exclusive access isn't needed anymore, the device should be released
|
||||
* with a call to the release() function.
|
||||
*
|
||||
* \todo Implement exclusive access across processes.
|
||||
*
|
||||
* \return 0 on success or a negative error code on error.
|
||||
*/
|
||||
int Camera::acquire()
|
||||
{
|
||||
if (acquired_)
|
||||
return -EBUSY;
|
||||
|
||||
acquired_ = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Release exclusive access to the camera device
|
||||
*
|
||||
* Releasing the camera device allows other users to acquire exclusive access
|
||||
* with the acquire() function.
|
||||
*/
|
||||
void Camera::release()
|
||||
{
|
||||
acquired_ = false;
|
||||
}
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue