mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-21 11:25:08 +03:00
v4l2: v4l2_camera_file: Store file description
Create a string that describe the file from the path and file descriptor. This will be used in log messages to clearly identify which file an operation is related to. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
This commit is contained in:
parent
43c86fb0c6
commit
07d5fff29c
3 changed files with 37 additions and 3 deletions
|
@ -7,20 +7,46 @@
|
|||
|
||||
#include "v4l2_camera_file.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
#include "v4l2_camera_proxy.h"
|
||||
|
||||
using namespace libcamera;
|
||||
|
||||
V4L2CameraFile::V4L2CameraFile(int efd, bool nonBlocking, V4L2CameraProxy *proxy)
|
||||
V4L2CameraFile::V4L2CameraFile(int dirfd, const char *path, int efd,
|
||||
bool nonBlocking, V4L2CameraProxy *proxy)
|
||||
: proxy_(proxy), nonBlocking_(nonBlocking), efd_(efd),
|
||||
priority_(V4L2_PRIORITY_DEFAULT)
|
||||
{
|
||||
proxy_->open(this);
|
||||
|
||||
if (path[0] != '/') {
|
||||
if (dirfd == AT_FDCWD) {
|
||||
char *cwd = getcwd(nullptr, 0);
|
||||
if (cwd) {
|
||||
description_ = std::string(cwd) + "/";
|
||||
free(cwd);
|
||||
} else {
|
||||
description_ = std::string("(unreachable)/");
|
||||
}
|
||||
} else {
|
||||
description_ = "(dirfd:" + std::to_string(dirfd) + ")/";
|
||||
}
|
||||
}
|
||||
|
||||
description_ += std::string(path) + " (fd:" + std::to_string(efd) + ")";
|
||||
}
|
||||
|
||||
V4L2CameraFile::~V4L2CameraFile()
|
||||
{
|
||||
proxy_->close(this);
|
||||
}
|
||||
|
||||
const std::string &V4L2CameraFile::description() const
|
||||
{
|
||||
return description_;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
class V4L2CameraProxy;
|
||||
|
@ -14,7 +16,8 @@ class V4L2CameraProxy;
|
|||
class V4L2CameraFile
|
||||
{
|
||||
public:
|
||||
V4L2CameraFile(int efd, bool nonBlocking, V4L2CameraProxy *proxy);
|
||||
V4L2CameraFile(int dirfd, const char *path, int efd, bool nonBlocking,
|
||||
V4L2CameraProxy *proxy);
|
||||
~V4L2CameraFile();
|
||||
|
||||
V4L2CameraProxy *proxy() const { return proxy_; }
|
||||
|
@ -25,9 +28,12 @@ public:
|
|||
enum v4l2_priority priority() const { return priority_; }
|
||||
void setPriority(enum v4l2_priority priority) { priority_ = priority; }
|
||||
|
||||
const std::string &description() const;
|
||||
|
||||
private:
|
||||
V4L2CameraProxy *proxy_;
|
||||
|
||||
std::string description_;
|
||||
bool nonBlocking_;
|
||||
int efd_;
|
||||
enum v4l2_priority priority_;
|
||||
|
|
|
@ -156,7 +156,9 @@ int V4L2CompatManager::openat(int dirfd, const char *path, int oflag, mode_t mod
|
|||
return efd;
|
||||
|
||||
V4L2CameraProxy *proxy = proxies_[ret].get();
|
||||
files_.emplace(efd, std::make_shared<V4L2CameraFile>(efd, oflag & O_NONBLOCK, proxy));
|
||||
files_.emplace(efd, std::make_shared<V4L2CameraFile>(dirfd, path, efd,
|
||||
oflag & O_NONBLOCK,
|
||||
proxy));
|
||||
|
||||
LOG(V4L2Compat, Debug) << "Opened " << path << " -> fd " << efd;
|
||||
return efd;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue