[libcamera-devel,3/4] libcamera: mediadevice: Reorder functions in declaration order

Message ID 20190101212328.18361-3-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel,1/4] libcamera: mediadevice: Fix graph parsing error handling
Related show

Commit Message

Laurent Pinchart Jan. 1, 2019, 9:23 p.m. UTC
In order to simplify navigation in the .cpp file, order functions in the
declaration order in the .h file.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/media_device.cpp | 356 ++++++++++++++++-----------------
 1 file changed, 178 insertions(+), 178 deletions(-)

Comments

Kieran Bingham Jan. 1, 2019, 10:07 p.m. UTC | #1
Hi Laurent,

On 01/01/2019 21:23, Laurent Pinchart wrote:
> In order to simplify navigation in the .cpp file, order functions in the
> declaration order in the .h file.
> 

I'll not look this over as I would expect it to be a zero-code-change.

As long as that assumption is correct,

Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>


> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/libcamera/media_device.cpp | 356 ++++++++++++++++-----------------
>  1 file changed, 178 insertions(+), 178 deletions(-)
> 
> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
> index fd5a31746075..4c77d3787391 100644
> --- a/src/libcamera/media_device.cpp
> +++ b/src/libcamera/media_device.cpp
> @@ -70,38 +70,6 @@ MediaDevice::~MediaDevice()
>  	clear();
>  }
>  
> -/**
> - * \fn MediaDevice::driver()
> - * \brief Retrieve the media device driver name
> - * \return The name of the kernel driver that handles the MediaDevice
> - */
> -
> -/**
> - * \fn MediaDevice::devnode()
> - * \brief Retrieve the media device device node path
> - * \return The MediaDevice devnode path
> - */
> -
> -/**
> - * \brief Delete all media objects in the MediaDevice.
> - *
> - * Delete all MediaEntities; entities will then delete their pads,
> - * and each source pad will delete links.
> - *
> - * After this function has been called, the media graph will be unpopulated
> - * and its media objects deleted. The media device has to be populated
> - * before it could be used again.
> - */
> -void MediaDevice::clear()
> -{
> -	for (auto const &o : objects_)
> -		delete o.second;
> -
> -	objects_.clear();
> -	entities_.clear();
> -	valid_ = false;
> -}
> -
>  /**
>   * \brief Open a media device and retrieve informations from it
>   *
> @@ -154,152 +122,6 @@ void MediaDevice::close()
>  	fd_ = -1;
>  }
>  
> -/**
> - * \fn MediaDevice::entities()
> - * \brief Retrieve the list of entities in the media graph
> - * \return The list of MediaEntities registered in the MediaDevice
> - */
> -
> -/*
> - * Add a new object to the global objects pool and fail if the object
> - * has already been registered.
> - */
> -bool MediaDevice::addObject(MediaObject *obj)
> -{
> -
> -	if (objects_.find(obj->id()) != objects_.end()) {
> -		LOG(Error) << "Element with id " << obj->id()
> -			   << " already enumerated.";
> -		return false;
> -	}
> -
> -	objects_[obj->id()] = obj;
> -
> -	return true;
> -}
> -
> -/*
> - * MediaObject pool lookup by id.
> - */
> -MediaObject *MediaDevice::object(unsigned int id)
> -{
> -	auto it = objects_.find(id);
> -	return (it == objects_.end()) ? nullptr : it->second;
> -}
> -
> -/**
> - * \brief Return the MediaEntity with name \a name
> - * \param name The entity name
> - * \return The entity with \a name
> - * \return nullptr if no entity with \a name is found
> - */
> -MediaEntity *MediaDevice::getEntityByName(const std::string &name)
> -{
> -	for (MediaEntity *e : entities_)
> -		if (e->name() == name)
> -			return e;
> -
> -	return nullptr;
> -}
> -
> -bool MediaDevice::populateLinks(const struct media_v2_topology &topology)
> -{
> -	media_v2_link *mediaLinks = reinterpret_cast<media_v2_link *>
> -				    (topology.ptr_links);
> -
> -	for (unsigned int i = 0; i < topology.num_links; ++i) {
> -		/*
> -		 * Skip links between entities and interfaces: we only care
> -		 * about pad-2-pad links here.
> -		 */
> -		if ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) ==
> -		    MEDIA_LNK_FL_INTERFACE_LINK)
> -			continue;
> -
> -		/* Store references to source and sink pads in the link. */
> -		unsigned int source_id = mediaLinks[i].source_id;
> -		MediaPad *source = dynamic_cast<MediaPad *>
> -				   (object(source_id));
> -		if (!source) {
> -			LOG(Error) << "Failed to find pad with id: "
> -				   << source_id;
> -			return false;
> -		}
> -
> -		unsigned int sink_id = mediaLinks[i].sink_id;
> -		MediaPad *sink = dynamic_cast<MediaPad *>
> -				 (object(sink_id));
> -		if (!sink) {
> -			LOG(Error) << "Failed to find pad with id: "
> -				   << sink_id;
> -			return false;
> -		}
> -
> -		MediaLink *link = new MediaLink(&mediaLinks[i], source, sink);
> -		if (!addObject(link)) {
> -			delete link;
> -			return false;
> -		}
> -
> -		source->addLink(link);
> -		sink->addLink(link);
> -	}
> -
> -	return true;
> -}
> -
> -bool MediaDevice::populatePads(const struct media_v2_topology &topology)
> -{
> -	media_v2_pad *mediaPads = reinterpret_cast<media_v2_pad *>
> -				  (topology.ptr_pads);
> -
> -	for (unsigned int i = 0; i < topology.num_pads; ++i) {
> -		unsigned int entity_id = mediaPads[i].entity_id;
> -
> -		/* Store a reference to this MediaPad in entity. */
> -		MediaEntity *mediaEntity = dynamic_cast<MediaEntity *>
> -					   (object(entity_id));
> -		if (!mediaEntity) {
> -			LOG(Error) << "Failed to find entity with id: "
> -				   << entity_id;
> -			return false;
> -		}
> -
> -		MediaPad *pad = new MediaPad(&mediaPads[i], mediaEntity);
> -		if (!addObject(pad)) {
> -			delete pad;
> -			return false;
> -		}
> -
> -		mediaEntity->addPad(pad);
> -	}
> -
> -	return true;
> -}
> -
> -/*
> - * For each entity in the media graph create a MediaEntity and store a
> - * reference in the MediaObject global pool and in the global vector of
> - * entities.
> - */
> -bool MediaDevice::populateEntities(const struct media_v2_topology &topology)
> -{
> -	media_v2_entity *mediaEntities = reinterpret_cast<media_v2_entity *>
> -					 (topology.ptr_entities);
> -
> -	for (unsigned int i = 0; i < topology.num_entities; ++i) {
> -		MediaEntity *entity = new MediaEntity(&mediaEntities[i]);
> -		if (!addObject(entity)) {
> -			delete entity;
> -			return false;
> -		}
> -
> -		entities_.push_back(entity);
> -	}
> -
> -	return true;
> -}
> -
>  /**
>   * \brief Populate the media graph with media objects
>   *
> @@ -380,15 +202,193 @@ int MediaDevice::populate()
>   * \return true if the media graph is valid, false otherwise
>   */
>  
> +/**
> + * \fn MediaDevice::driver()
> + * \brief Retrieve the media device driver name
> + * \return The name of the kernel driver that handles the MediaDevice
> + */
> +
> +/**
> + * \fn MediaDevice::devnode()
> + * \brief Retrieve the media device device node path
> + * \return The MediaDevice devnode path
> + */
> +
> +/**
> + * \fn MediaDevice::entities()
> + * \brief Retrieve the list of entities in the media graph
> + * \return The list of MediaEntities registered in the MediaDevice
> + */
> +
> +/**
> + * \brief Return the MediaEntity with name \a name
> + * \param name The entity name
> + * \return The entity with \a name
> + * \return nullptr if no entity with \a name is found
> + */
> +MediaEntity *MediaDevice::getEntityByName(const std::string &name)
> +{
> +	for (MediaEntity *e : entities_)
> +		if (e->name() == name)
> +			return e;
> +
> +	return nullptr;
> +}
> +
>  /**
>   * \var MediaDevice::objects_
>   * \brief Global map of media objects (entities, pads, links) keyed by their
>   * object id.
>   */
>  
> +/*
> + * MediaObject pool lookup by id.
> + */
> +MediaObject *MediaDevice::object(unsigned int id)
> +{
> +	auto it = objects_.find(id);
> +	return (it == objects_.end()) ? nullptr : it->second;
> +}
> +
> +/*
> + * Add a new object to the global objects pool and fail if the object
> + * has already been registered.
> + */
> +bool MediaDevice::addObject(MediaObject *obj)
> +{
> +
> +	if (objects_.find(obj->id()) != objects_.end()) {
> +		LOG(Error) << "Element with id " << obj->id()
> +			   << " already enumerated.";
> +		return false;
> +	}
> +
> +	objects_[obj->id()] = obj;
> +
> +	return true;
> +}
> +
> +/**
> + * \brief Delete all media objects in the MediaDevice.
> + *
> + * Delete all MediaEntities; entities will then delete their pads,
> + * and each source pad will delete links.
> + *
> + * After this function has been called, the media graph will be unpopulated
> + * and its media objects deleted. The media device has to be populated
> + * before it could be used again.
> + */
> +void MediaDevice::clear()
> +{
> +	for (auto const &o : objects_)
> +		delete o.second;
> +
> +	objects_.clear();
> +	entities_.clear();
> +	valid_ = false;
> +}
> +
>  /**
>   * \var MediaDevice::entities_
>   * \brief Global list of media entities in the media graph
>   */
>  
> +/*
> + * For each entity in the media graph create a MediaEntity and store a
> + * reference in the MediaObject global pool and in the global vector of
> + * entities.
> + */
> +bool MediaDevice::populateEntities(const struct media_v2_topology &topology)
> +{
> +	media_v2_entity *mediaEntities = reinterpret_cast<media_v2_entity *>
> +					 (topology.ptr_entities);
> +
> +	for (unsigned int i = 0; i < topology.num_entities; ++i) {
> +		MediaEntity *entity = new MediaEntity(&mediaEntities[i]);
> +		if (!addObject(entity)) {
> +			delete entity;
> +			return false;
> +		}
> +
> +		entities_.push_back(entity);
> +	}
> +
> +	return true;
> +}
> +
> +bool MediaDevice::populatePads(const struct media_v2_topology &topology)
> +{
> +	media_v2_pad *mediaPads = reinterpret_cast<media_v2_pad *>
> +				  (topology.ptr_pads);
> +
> +	for (unsigned int i = 0; i < topology.num_pads; ++i) {
> +		unsigned int entity_id = mediaPads[i].entity_id;
> +
> +		/* Store a reference to this MediaPad in entity. */
> +		MediaEntity *mediaEntity = dynamic_cast<MediaEntity *>
> +					   (object(entity_id));
> +		if (!mediaEntity) {
> +			LOG(Error) << "Failed to find entity with id: "
> +				   << entity_id;
> +			return false;
> +		}
> +
> +		MediaPad *pad = new MediaPad(&mediaPads[i], mediaEntity);
> +		if (!addObject(pad)) {
> +			delete pad;
> +			return false;
> +		}
> +
> +		mediaEntity->addPad(pad);
> +	}
> +
> +	return true;
> +}
> +
> +bool MediaDevice::populateLinks(const struct media_v2_topology &topology)
> +{
> +	media_v2_link *mediaLinks = reinterpret_cast<media_v2_link *>
> +				    (topology.ptr_links);
> +
> +	for (unsigned int i = 0; i < topology.num_links; ++i) {
> +		/*
> +		 * Skip links between entities and interfaces: we only care
> +		 * about pad-2-pad links here.
> +		 */
> +		if ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) ==
> +		    MEDIA_LNK_FL_INTERFACE_LINK)
> +			continue;
> +
> +		/* Store references to source and sink pads in the link. */
> +		unsigned int source_id = mediaLinks[i].source_id;
> +		MediaPad *source = dynamic_cast<MediaPad *>
> +				   (object(source_id));
> +		if (!source) {
> +			LOG(Error) << "Failed to find pad with id: "
> +				   << source_id;
> +			return false;
> +		}
> +
> +		unsigned int sink_id = mediaLinks[i].sink_id;
> +		MediaPad *sink = dynamic_cast<MediaPad *>
> +				 (object(sink_id));
> +		if (!sink) {
> +			LOG(Error) << "Failed to find pad with id: "
> +				   << sink_id;
> +			return false;
> +		}
> +
> +		MediaLink *link = new MediaLink(&mediaLinks[i], source, sink);
> +		if (!addObject(link)) {
> +			delete link;
> +			return false;
> +		}
> +
> +		source->addLink(link);
> +		sink->addLink(link);
> +	}
> +
> +	return true;
> +}
> +
>  } /* namespace libcamera */
>

Patch

diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
index fd5a31746075..4c77d3787391 100644
--- a/src/libcamera/media_device.cpp
+++ b/src/libcamera/media_device.cpp
@@ -70,38 +70,6 @@  MediaDevice::~MediaDevice()
 	clear();
 }
 
-/**
- * \fn MediaDevice::driver()
- * \brief Retrieve the media device driver name
- * \return The name of the kernel driver that handles the MediaDevice
- */
-
-/**
- * \fn MediaDevice::devnode()
- * \brief Retrieve the media device device node path
- * \return The MediaDevice devnode path
- */
-
-/**
- * \brief Delete all media objects in the MediaDevice.
- *
- * Delete all MediaEntities; entities will then delete their pads,
- * and each source pad will delete links.
- *
- * After this function has been called, the media graph will be unpopulated
- * and its media objects deleted. The media device has to be populated
- * before it could be used again.
- */
-void MediaDevice::clear()
-{
-	for (auto const &o : objects_)
-		delete o.second;
-
-	objects_.clear();
-	entities_.clear();
-	valid_ = false;
-}
-
 /**
  * \brief Open a media device and retrieve informations from it
  *
@@ -154,152 +122,6 @@  void MediaDevice::close()
 	fd_ = -1;
 }
 
-/**
- * \fn MediaDevice::entities()
- * \brief Retrieve the list of entities in the media graph
- * \return The list of MediaEntities registered in the MediaDevice
- */
-
-/*
- * Add a new object to the global objects pool and fail if the object
- * has already been registered.
- */
-bool MediaDevice::addObject(MediaObject *obj)
-{
-
-	if (objects_.find(obj->id()) != objects_.end()) {
-		LOG(Error) << "Element with id " << obj->id()
-			   << " already enumerated.";
-		return false;
-	}
-
-	objects_[obj->id()] = obj;
-
-	return true;
-}
-
-/*
- * MediaObject pool lookup by id.
- */
-MediaObject *MediaDevice::object(unsigned int id)
-{
-	auto it = objects_.find(id);
-	return (it == objects_.end()) ? nullptr : it->second;
-}
-
-/**
- * \brief Return the MediaEntity with name \a name
- * \param name The entity name
- * \return The entity with \a name
- * \return nullptr if no entity with \a name is found
- */
-MediaEntity *MediaDevice::getEntityByName(const std::string &name)
-{
-	for (MediaEntity *e : entities_)
-		if (e->name() == name)
-			return e;
-
-	return nullptr;
-}
-
-bool MediaDevice::populateLinks(const struct media_v2_topology &topology)
-{
-	media_v2_link *mediaLinks = reinterpret_cast<media_v2_link *>
-				    (topology.ptr_links);
-
-	for (unsigned int i = 0; i < topology.num_links; ++i) {
-		/*
-		 * Skip links between entities and interfaces: we only care
-		 * about pad-2-pad links here.
-		 */
-		if ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) ==
-		    MEDIA_LNK_FL_INTERFACE_LINK)
-			continue;
-
-		/* Store references to source and sink pads in the link. */
-		unsigned int source_id = mediaLinks[i].source_id;
-		MediaPad *source = dynamic_cast<MediaPad *>
-				   (object(source_id));
-		if (!source) {
-			LOG(Error) << "Failed to find pad with id: "
-				   << source_id;
-			return false;
-		}
-
-		unsigned int sink_id = mediaLinks[i].sink_id;
-		MediaPad *sink = dynamic_cast<MediaPad *>
-				 (object(sink_id));
-		if (!sink) {
-			LOG(Error) << "Failed to find pad with id: "
-				   << sink_id;
-			return false;
-		}
-
-		MediaLink *link = new MediaLink(&mediaLinks[i], source, sink);
-		if (!addObject(link)) {
-			delete link;
-			return false;
-		}
-
-		source->addLink(link);
-		sink->addLink(link);
-	}
-
-	return true;
-}
-
-bool MediaDevice::populatePads(const struct media_v2_topology &topology)
-{
-	media_v2_pad *mediaPads = reinterpret_cast<media_v2_pad *>
-				  (topology.ptr_pads);
-
-	for (unsigned int i = 0; i < topology.num_pads; ++i) {
-		unsigned int entity_id = mediaPads[i].entity_id;
-
-		/* Store a reference to this MediaPad in entity. */
-		MediaEntity *mediaEntity = dynamic_cast<MediaEntity *>
-					   (object(entity_id));
-		if (!mediaEntity) {
-			LOG(Error) << "Failed to find entity with id: "
-				   << entity_id;
-			return false;
-		}
-
-		MediaPad *pad = new MediaPad(&mediaPads[i], mediaEntity);
-		if (!addObject(pad)) {
-			delete pad;
-			return false;
-		}
-
-		mediaEntity->addPad(pad);
-	}
-
-	return true;
-}
-
-/*
- * For each entity in the media graph create a MediaEntity and store a
- * reference in the MediaObject global pool and in the global vector of
- * entities.
- */
-bool MediaDevice::populateEntities(const struct media_v2_topology &topology)
-{
-	media_v2_entity *mediaEntities = reinterpret_cast<media_v2_entity *>
-					 (topology.ptr_entities);
-
-	for (unsigned int i = 0; i < topology.num_entities; ++i) {
-		MediaEntity *entity = new MediaEntity(&mediaEntities[i]);
-		if (!addObject(entity)) {
-			delete entity;
-			return false;
-		}
-
-		entities_.push_back(entity);
-	}
-
-	return true;
-}
-
 /**
  * \brief Populate the media graph with media objects
  *
@@ -380,15 +202,193 @@  int MediaDevice::populate()
  * \return true if the media graph is valid, false otherwise
  */
 
+/**
+ * \fn MediaDevice::driver()
+ * \brief Retrieve the media device driver name
+ * \return The name of the kernel driver that handles the MediaDevice
+ */
+
+/**
+ * \fn MediaDevice::devnode()
+ * \brief Retrieve the media device device node path
+ * \return The MediaDevice devnode path
+ */
+
+/**
+ * \fn MediaDevice::entities()
+ * \brief Retrieve the list of entities in the media graph
+ * \return The list of MediaEntities registered in the MediaDevice
+ */
+
+/**
+ * \brief Return the MediaEntity with name \a name
+ * \param name The entity name
+ * \return The entity with \a name
+ * \return nullptr if no entity with \a name is found
+ */
+MediaEntity *MediaDevice::getEntityByName(const std::string &name)
+{
+	for (MediaEntity *e : entities_)
+		if (e->name() == name)
+			return e;
+
+	return nullptr;
+}
+
 /**
  * \var MediaDevice::objects_
  * \brief Global map of media objects (entities, pads, links) keyed by their
  * object id.
  */
 
+/*
+ * MediaObject pool lookup by id.
+ */
+MediaObject *MediaDevice::object(unsigned int id)
+{
+	auto it = objects_.find(id);
+	return (it == objects_.end()) ? nullptr : it->second;
+}
+
+/*
+ * Add a new object to the global objects pool and fail if the object
+ * has already been registered.
+ */
+bool MediaDevice::addObject(MediaObject *obj)
+{
+
+	if (objects_.find(obj->id()) != objects_.end()) {
+		LOG(Error) << "Element with id " << obj->id()
+			   << " already enumerated.";
+		return false;
+	}
+
+	objects_[obj->id()] = obj;
+
+	return true;
+}
+
+/**
+ * \brief Delete all media objects in the MediaDevice.
+ *
+ * Delete all MediaEntities; entities will then delete their pads,
+ * and each source pad will delete links.
+ *
+ * After this function has been called, the media graph will be unpopulated
+ * and its media objects deleted. The media device has to be populated
+ * before it could be used again.
+ */
+void MediaDevice::clear()
+{
+	for (auto const &o : objects_)
+		delete o.second;
+
+	objects_.clear();
+	entities_.clear();
+	valid_ = false;
+}
+
 /**
  * \var MediaDevice::entities_
  * \brief Global list of media entities in the media graph
  */
 
+/*
+ * For each entity in the media graph create a MediaEntity and store a
+ * reference in the MediaObject global pool and in the global vector of
+ * entities.
+ */
+bool MediaDevice::populateEntities(const struct media_v2_topology &topology)
+{
+	media_v2_entity *mediaEntities = reinterpret_cast<media_v2_entity *>
+					 (topology.ptr_entities);
+
+	for (unsigned int i = 0; i < topology.num_entities; ++i) {
+		MediaEntity *entity = new MediaEntity(&mediaEntities[i]);
+		if (!addObject(entity)) {
+			delete entity;
+			return false;
+		}
+
+		entities_.push_back(entity);
+	}
+
+	return true;
+}
+
+bool MediaDevice::populatePads(const struct media_v2_topology &topology)
+{
+	media_v2_pad *mediaPads = reinterpret_cast<media_v2_pad *>
+				  (topology.ptr_pads);
+
+	for (unsigned int i = 0; i < topology.num_pads; ++i) {
+		unsigned int entity_id = mediaPads[i].entity_id;
+
+		/* Store a reference to this MediaPad in entity. */
+		MediaEntity *mediaEntity = dynamic_cast<MediaEntity *>
+					   (object(entity_id));
+		if (!mediaEntity) {
+			LOG(Error) << "Failed to find entity with id: "
+				   << entity_id;
+			return false;
+		}
+
+		MediaPad *pad = new MediaPad(&mediaPads[i], mediaEntity);
+		if (!addObject(pad)) {
+			delete pad;
+			return false;
+		}
+
+		mediaEntity->addPad(pad);
+	}
+
+	return true;
+}
+
+bool MediaDevice::populateLinks(const struct media_v2_topology &topology)
+{
+	media_v2_link *mediaLinks = reinterpret_cast<media_v2_link *>
+				    (topology.ptr_links);
+
+	for (unsigned int i = 0; i < topology.num_links; ++i) {
+		/*
+		 * Skip links between entities and interfaces: we only care
+		 * about pad-2-pad links here.
+		 */
+		if ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) ==
+		    MEDIA_LNK_FL_INTERFACE_LINK)
+			continue;
+
+		/* Store references to source and sink pads in the link. */
+		unsigned int source_id = mediaLinks[i].source_id;
+		MediaPad *source = dynamic_cast<MediaPad *>
+				   (object(source_id));
+		if (!source) {
+			LOG(Error) << "Failed to find pad with id: "
+				   << source_id;
+			return false;
+		}
+
+		unsigned int sink_id = mediaLinks[i].sink_id;
+		MediaPad *sink = dynamic_cast<MediaPad *>
+				 (object(sink_id));
+		if (!sink) {
+			LOG(Error) << "Failed to find pad with id: "
+				   << sink_id;
+			return false;
+		}
+
+		MediaLink *link = new MediaLink(&mediaLinks[i], source, sink);
+		if (!addObject(link)) {
+			delete link;
+			return false;
+		}
+
+		source->addLink(link);
+		sink->addLink(link);
+	}
+
+	return true;
+}
+
 } /* namespace libcamera */