mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-21 15:53:54 +03:00
py: Use UniqueFD
Use UniqueFD to automate the eventfd lifetime management. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
f814b1b6a9
commit
f4933ee77f
2 changed files with 6 additions and 14 deletions
|
@ -29,25 +29,17 @@ PyCameraManager::PyCameraManager()
|
||||||
throw std::system_error(errno, std::generic_category(),
|
throw std::system_error(errno, std::generic_category(),
|
||||||
"Failed to create eventfd");
|
"Failed to create eventfd");
|
||||||
|
|
||||||
eventFd_ = fd;
|
eventFd_ = UniqueFD(fd);
|
||||||
|
|
||||||
int ret = cameraManager_->start();
|
int ret = cameraManager_->start();
|
||||||
if (ret) {
|
if (ret)
|
||||||
close(fd);
|
|
||||||
eventFd_ = -1;
|
|
||||||
throw std::system_error(-ret, std::generic_category(),
|
throw std::system_error(-ret, std::generic_category(),
|
||||||
"Failed to start CameraManager");
|
"Failed to start CameraManager");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PyCameraManager::~PyCameraManager()
|
PyCameraManager::~PyCameraManager()
|
||||||
{
|
{
|
||||||
LOG(Python, Debug) << "~PyCameraManager()";
|
LOG(Python, Debug) << "~PyCameraManager()";
|
||||||
|
|
||||||
if (eventFd_ != -1) {
|
|
||||||
close(eventFd_);
|
|
||||||
eventFd_ = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
py::list PyCameraManager::cameras()
|
py::list PyCameraManager::cameras()
|
||||||
|
@ -95,7 +87,7 @@ void PyCameraManager::writeFd()
|
||||||
{
|
{
|
||||||
uint64_t v = 1;
|
uint64_t v = 1;
|
||||||
|
|
||||||
size_t s = write(eventFd_, &v, 8);
|
size_t s = write(eventFd_.get(), &v, 8);
|
||||||
/*
|
/*
|
||||||
* We should never fail, and have no simple means to manage the error,
|
* We should never fail, and have no simple means to manage the error,
|
||||||
* so let's log a fatal error.
|
* so let's log a fatal error.
|
||||||
|
@ -108,7 +100,7 @@ void PyCameraManager::readFd()
|
||||||
{
|
{
|
||||||
uint8_t buf[8];
|
uint8_t buf[8];
|
||||||
|
|
||||||
if (read(eventFd_, buf, 8) != 8)
|
if (read(eventFd_.get(), buf, 8) != 8)
|
||||||
throw std::system_error(errno, std::generic_category());
|
throw std::system_error(errno, std::generic_category());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
|
|
||||||
static const std::string &version() { return CameraManager::version(); }
|
static const std::string &version() { return CameraManager::version(); }
|
||||||
|
|
||||||
int eventFd() const { return eventFd_; }
|
int eventFd() const { return eventFd_.get(); }
|
||||||
|
|
||||||
std::vector<pybind11::object> getReadyRequests();
|
std::vector<pybind11::object> getReadyRequests();
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ public:
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<CameraManager> cameraManager_;
|
std::unique_ptr<CameraManager> cameraManager_;
|
||||||
|
|
||||||
int eventFd_ = -1;
|
UniqueFD eventFd_;
|
||||||
std::mutex completedRequestsMutex_;
|
std::mutex completedRequestsMutex_;
|
||||||
std::vector<Request *> completedRequests_;
|
std::vector<Request *> completedRequests_;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue