From d4af90d72901b1c6c2609ea8a3c0da76facf6c2e Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Wed, 26 Dec 2018 11:09:35 +0100 Subject: libcamera: media_device: Create entities with major and minor numbers Extend the MediaEntity object with device node major and minor numbers, and retrieve them from the media graph using interfaces. They will be used by the DeviceEnumerator to retrieve the devnode path. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart --- src/libcamera/media_object.cpp | 45 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'src/libcamera/media_object.cpp') diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp index b64dcc3c..581e1c08 100644 --- a/src/libcamera/media_object.cpp +++ b/src/libcamera/media_object.cpp @@ -6,9 +6,8 @@ */ #include -#include #include -#include +#include #include #include @@ -212,6 +211,20 @@ void MediaPad::addLink(MediaLink *link) * \return The entity name */ +/** + * \fn MediaEntity::major() + * \brief Retrieve the major number of the interface associated with the entity + * \return The interface major number, or 0 if the entity isn't associated with + * an interface + */ + +/** + * \fn MediaEntity::minor() + * \brief Retrieve the minor number of the interface associated with the entity + * \return The interface minor number, or 0 if the entity isn't associated with + * an interface + */ + /** * \fn MediaEntity::pads() * \brief Retrieve all pads of the entity @@ -248,12 +261,36 @@ const MediaPad *MediaEntity::getPadById(unsigned int id) const return nullptr; } +/** + * \brief Set the path to the device node for the associated interface + * \param devnode The interface device node path associated with this entity + * \return 0 on success, or a negative error code if the device node can't be + * accessed + */ +int MediaEntity::setDeviceNode(const std::string &devnode) +{ + /* Make sure the device node can be accessed. */ + int ret = ::access(devnode.c_str(), R_OK | W_OK); + if (ret < 0) { + ret = -errno; + LOG(Error) << "Device node " << devnode << " can't be accessed: " + << strerror(-ret); + return ret; + } + + return 0; +} + /** * \brief Construct a MediaEntity * \param entity The media entity kernel data + * \param major The major number of the entity associated interface + * \param minor The minor number of the entity associated interface */ -MediaEntity::MediaEntity(const struct media_v2_entity *entity) - : MediaObject(entity->id), name_(entity->name) +MediaEntity::MediaEntity(const struct media_v2_entity *entity, + unsigned int major, unsigned int minor) + : MediaObject(entity->id), name_(entity->name), + major_(major), minor_(minor) { } -- cgit v1.2.1