summaryrefslogtreecommitdiff
path: root/src/libcamera/media_object.cpp
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2018-12-26 11:09:35 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-02 12:53:55 +0200
commitd4af90d72901b1c6c2609ea8a3c0da76facf6c2e (patch)
tree348450495041618c944f4673d7bd4eaebabd1878 /src/libcamera/media_object.cpp
parent14291e50b7d9cfbc7bae51f84b97adf44cce6b55 (diff)
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 <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera/media_object.cpp')
-rw-r--r--src/libcamera/media_object.cpp45
1 files changed, 41 insertions, 4 deletions
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 <errno.h>
-#include <fcntl.h>
#include <string.h>
-#include <sys/stat.h>
+#include <unistd.h>
#include <string>
#include <vector>
@@ -213,6 +212,20 @@ void MediaPad::addLink(MediaLink *link)
*/
/**
+ * \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
* \return The list of the entity's pads
@@ -249,11 +262,35 @@ const MediaPad *MediaEntity::getPadById(unsigned int id) const
}
/**
+ * \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)
{
}