{"id":119,"url":"https://patchwork.libcamera.org/api/1.1/patches/119/?format=json","web_url":"https://patchwork.libcamera.org/patch/119/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190101212328.18361-3-laurent.pinchart@ideasonboard.com>","date":"2019-01-01T21:23:27","name":"[libcamera-devel,3/4] libcamera: mediadevice: Reorder functions in declaration order","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"804bf136d1f8d98854cb5271ed9008e7e6142b63","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/119/mbox/","series":[{"id":45,"url":"https://patchwork.libcamera.org/api/1.1/series/45/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=45","date":"2019-01-01T21:23:26","name":"[libcamera-devel,1/4] libcamera: mediadevice: Fix graph parsing error handling","version":1,"mbox":"https://patchwork.libcamera.org/series/45/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/119/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/119/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 58A3160B35\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  1 Jan 2019 22:22:34 +0100 (CET)","from avalon.bb.dnainternet.fi\n\t(dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 447E41173\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  1 Jan 2019 22:22:33 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1546377753;\n\tbh=sa3t6/qnse81eA4bkgYTY1VKOtsQY67ejkpXV05OzMA=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=DBZSMR1hzBkxICjkjGDp+AclGn07+LB6C0T+Vknpo4mAX8ZICUfEJ12w1VpAkPUw7\n\tP9Pk4mEt2PGsOj+q8eg/N/vkCptcqgzdwsHdETCRlOYyYX2vW9W/yiQYidSXLkjpAg\n\tBaHxCozXf7yu8fSiEPxfbuiOp7uO2CPsm1siXF0c=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  1 Jan 2019 23:23:27 +0200","Message-Id":"<20190101212328.18361-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.19.2","In-Reply-To":"<20190101212328.18361-1-laurent.pinchart@ideasonboard.com>","References":"<20190101212328.18361-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 3/4] libcamera: mediadevice: Reorder\n\tfunctions in declaration order","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 01 Jan 2019 21:22:34 -0000"},"content":"In order to simplify navigation in the .cpp file, order functions in the\ndeclaration order in the .h file.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/media_device.cpp | 356 ++++++++++++++++-----------------\n 1 file changed, 178 insertions(+), 178 deletions(-)","diff":"diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex fd5a31746075..4c77d3787391 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -70,38 +70,6 @@ MediaDevice::~MediaDevice()\n \tclear();\n }\n \n-/**\n- * \\fn MediaDevice::driver()\n- * \\brief Retrieve the media device driver name\n- * \\return The name of the kernel driver that handles the MediaDevice\n- */\n-\n-/**\n- * \\fn MediaDevice::devnode()\n- * \\brief Retrieve the media device device node path\n- * \\return The MediaDevice devnode path\n- */\n-\n-/**\n- * \\brief Delete all media objects in the MediaDevice.\n- *\n- * Delete all MediaEntities; entities will then delete their pads,\n- * and each source pad will delete links.\n- *\n- * After this function has been called, the media graph will be unpopulated\n- * and its media objects deleted. The media device has to be populated\n- * before it could be used again.\n- */\n-void MediaDevice::clear()\n-{\n-\tfor (auto const &o : objects_)\n-\t\tdelete o.second;\n-\n-\tobjects_.clear();\n-\tentities_.clear();\n-\tvalid_ = false;\n-}\n-\n /**\n  * \\brief Open a media device and retrieve informations from it\n  *\n@@ -154,152 +122,6 @@ void MediaDevice::close()\n \tfd_ = -1;\n }\n \n-/**\n- * \\fn MediaDevice::entities()\n- * \\brief Retrieve the list of entities in the media graph\n- * \\return The list of MediaEntities registered in the MediaDevice\n- */\n-\n-/*\n- * Add a new object to the global objects pool and fail if the object\n- * has already been registered.\n- */\n-bool MediaDevice::addObject(MediaObject *obj)\n-{\n-\n-\tif (objects_.find(obj->id()) != objects_.end()) {\n-\t\tLOG(Error) << \"Element with id \" << obj->id()\n-\t\t\t   << \" already enumerated.\";\n-\t\treturn false;\n-\t}\n-\n-\tobjects_[obj->id()] = obj;\n-\n-\treturn true;\n-}\n-\n-/*\n- * MediaObject pool lookup by id.\n- */\n-MediaObject *MediaDevice::object(unsigned int id)\n-{\n-\tauto it = objects_.find(id);\n-\treturn (it == objects_.end()) ? nullptr : it->second;\n-}\n-\n-/**\n- * \\brief Return the MediaEntity with name \\a name\n- * \\param name The entity name\n- * \\return The entity with \\a name\n- * \\return nullptr if no entity with \\a name is found\n- */\n-MediaEntity *MediaDevice::getEntityByName(const std::string &name)\n-{\n-\tfor (MediaEntity *e : entities_)\n-\t\tif (e->name() == name)\n-\t\t\treturn e;\n-\n-\treturn nullptr;\n-}\n-\n-bool MediaDevice::populateLinks(const struct media_v2_topology &topology)\n-{\n-\tmedia_v2_link *mediaLinks = reinterpret_cast<media_v2_link *>\n-\t\t\t\t    (topology.ptr_links);\n-\n-\tfor (unsigned int i = 0; i < topology.num_links; ++i) {\n-\t\t/*\n-\t\t * Skip links between entities and interfaces: we only care\n-\t\t * about pad-2-pad links here.\n-\t\t */\n-\t\tif ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) ==\n-\t\t    MEDIA_LNK_FL_INTERFACE_LINK)\n-\t\t\tcontinue;\n-\n-\t\t/* Store references to source and sink pads in the link. */\n-\t\tunsigned int source_id = mediaLinks[i].source_id;\n-\t\tMediaPad *source = dynamic_cast<MediaPad *>\n-\t\t\t\t   (object(source_id));\n-\t\tif (!source) {\n-\t\t\tLOG(Error) << \"Failed to find pad with id: \"\n-\t\t\t\t   << source_id;\n-\t\t\treturn false;\n-\t\t}\n-\n-\t\tunsigned int sink_id = mediaLinks[i].sink_id;\n-\t\tMediaPad *sink = dynamic_cast<MediaPad *>\n-\t\t\t\t (object(sink_id));\n-\t\tif (!sink) {\n-\t\t\tLOG(Error) << \"Failed to find pad with id: \"\n-\t\t\t\t   << sink_id;\n-\t\t\treturn false;\n-\t\t}\n-\n-\t\tMediaLink *link = new MediaLink(&mediaLinks[i], source, sink);\n-\t\tif (!addObject(link)) {\n-\t\t\tdelete link;\n-\t\t\treturn false;\n-\t\t}\n-\n-\t\tsource->addLink(link);\n-\t\tsink->addLink(link);\n-\t}\n-\n-\treturn true;\n-}\n-\n-bool MediaDevice::populatePads(const struct media_v2_topology &topology)\n-{\n-\tmedia_v2_pad *mediaPads = reinterpret_cast<media_v2_pad *>\n-\t\t\t\t  (topology.ptr_pads);\n-\n-\tfor (unsigned int i = 0; i < topology.num_pads; ++i) {\n-\t\tunsigned int entity_id = mediaPads[i].entity_id;\n-\n-\t\t/* Store a reference to this MediaPad in entity. */\n-\t\tMediaEntity *mediaEntity = dynamic_cast<MediaEntity *>\n-\t\t\t\t\t   (object(entity_id));\n-\t\tif (!mediaEntity) {\n-\t\t\tLOG(Error) << \"Failed to find entity with id: \"\n-\t\t\t\t   << entity_id;\n-\t\t\treturn false;\n-\t\t}\n-\n-\t\tMediaPad *pad = new MediaPad(&mediaPads[i], mediaEntity);\n-\t\tif (!addObject(pad)) {\n-\t\t\tdelete pad;\n-\t\t\treturn false;\n-\t\t}\n-\n-\t\tmediaEntity->addPad(pad);\n-\t}\n-\n-\treturn true;\n-}\n-\n-/*\n- * For each entity in the media graph create a MediaEntity and store a\n- * reference in the MediaObject global pool and in the global vector of\n- * entities.\n- */\n-bool MediaDevice::populateEntities(const struct media_v2_topology &topology)\n-{\n-\tmedia_v2_entity *mediaEntities = reinterpret_cast<media_v2_entity *>\n-\t\t\t\t\t (topology.ptr_entities);\n-\n-\tfor (unsigned int i = 0; i < topology.num_entities; ++i) {\n-\t\tMediaEntity *entity = new MediaEntity(&mediaEntities[i]);\n-\t\tif (!addObject(entity)) {\n-\t\t\tdelete entity;\n-\t\t\treturn false;\n-\t\t}\n-\n-\t\tentities_.push_back(entity);\n-\t}\n-\n-\treturn true;\n-}\n-\n /**\n  * \\brief Populate the media graph with media objects\n  *\n@@ -380,15 +202,193 @@ int MediaDevice::populate()\n  * \\return true if the media graph is valid, false otherwise\n  */\n \n+/**\n+ * \\fn MediaDevice::driver()\n+ * \\brief Retrieve the media device driver name\n+ * \\return The name of the kernel driver that handles the MediaDevice\n+ */\n+\n+/**\n+ * \\fn MediaDevice::devnode()\n+ * \\brief Retrieve the media device device node path\n+ * \\return The MediaDevice devnode path\n+ */\n+\n+/**\n+ * \\fn MediaDevice::entities()\n+ * \\brief Retrieve the list of entities in the media graph\n+ * \\return The list of MediaEntities registered in the MediaDevice\n+ */\n+\n+/**\n+ * \\brief Return the MediaEntity with name \\a name\n+ * \\param name The entity name\n+ * \\return The entity with \\a name\n+ * \\return nullptr if no entity with \\a name is found\n+ */\n+MediaEntity *MediaDevice::getEntityByName(const std::string &name)\n+{\n+\tfor (MediaEntity *e : entities_)\n+\t\tif (e->name() == name)\n+\t\t\treturn e;\n+\n+\treturn nullptr;\n+}\n+\n /**\n  * \\var MediaDevice::objects_\n  * \\brief Global map of media objects (entities, pads, links) keyed by their\n  * object id.\n  */\n \n+/*\n+ * MediaObject pool lookup by id.\n+ */\n+MediaObject *MediaDevice::object(unsigned int id)\n+{\n+\tauto it = objects_.find(id);\n+\treturn (it == objects_.end()) ? nullptr : it->second;\n+}\n+\n+/*\n+ * Add a new object to the global objects pool and fail if the object\n+ * has already been registered.\n+ */\n+bool MediaDevice::addObject(MediaObject *obj)\n+{\n+\n+\tif (objects_.find(obj->id()) != objects_.end()) {\n+\t\tLOG(Error) << \"Element with id \" << obj->id()\n+\t\t\t   << \" already enumerated.\";\n+\t\treturn false;\n+\t}\n+\n+\tobjects_[obj->id()] = obj;\n+\n+\treturn true;\n+}\n+\n+/**\n+ * \\brief Delete all media objects in the MediaDevice.\n+ *\n+ * Delete all MediaEntities; entities will then delete their pads,\n+ * and each source pad will delete links.\n+ *\n+ * After this function has been called, the media graph will be unpopulated\n+ * and its media objects deleted. The media device has to be populated\n+ * before it could be used again.\n+ */\n+void MediaDevice::clear()\n+{\n+\tfor (auto const &o : objects_)\n+\t\tdelete o.second;\n+\n+\tobjects_.clear();\n+\tentities_.clear();\n+\tvalid_ = false;\n+}\n+\n /**\n  * \\var MediaDevice::entities_\n  * \\brief Global list of media entities in the media graph\n  */\n \n+/*\n+ * For each entity in the media graph create a MediaEntity and store a\n+ * reference in the MediaObject global pool and in the global vector of\n+ * entities.\n+ */\n+bool MediaDevice::populateEntities(const struct media_v2_topology &topology)\n+{\n+\tmedia_v2_entity *mediaEntities = reinterpret_cast<media_v2_entity *>\n+\t\t\t\t\t (topology.ptr_entities);\n+\n+\tfor (unsigned int i = 0; i < topology.num_entities; ++i) {\n+\t\tMediaEntity *entity = new MediaEntity(&mediaEntities[i]);\n+\t\tif (!addObject(entity)) {\n+\t\t\tdelete entity;\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tentities_.push_back(entity);\n+\t}\n+\n+\treturn true;\n+}\n+\n+bool MediaDevice::populatePads(const struct media_v2_topology &topology)\n+{\n+\tmedia_v2_pad *mediaPads = reinterpret_cast<media_v2_pad *>\n+\t\t\t\t  (topology.ptr_pads);\n+\n+\tfor (unsigned int i = 0; i < topology.num_pads; ++i) {\n+\t\tunsigned int entity_id = mediaPads[i].entity_id;\n+\n+\t\t/* Store a reference to this MediaPad in entity. */\n+\t\tMediaEntity *mediaEntity = dynamic_cast<MediaEntity *>\n+\t\t\t\t\t   (object(entity_id));\n+\t\tif (!mediaEntity) {\n+\t\t\tLOG(Error) << \"Failed to find entity with id: \"\n+\t\t\t\t   << entity_id;\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tMediaPad *pad = new MediaPad(&mediaPads[i], mediaEntity);\n+\t\tif (!addObject(pad)) {\n+\t\t\tdelete pad;\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tmediaEntity->addPad(pad);\n+\t}\n+\n+\treturn true;\n+}\n+\n+bool MediaDevice::populateLinks(const struct media_v2_topology &topology)\n+{\n+\tmedia_v2_link *mediaLinks = reinterpret_cast<media_v2_link *>\n+\t\t\t\t    (topology.ptr_links);\n+\n+\tfor (unsigned int i = 0; i < topology.num_links; ++i) {\n+\t\t/*\n+\t\t * Skip links between entities and interfaces: we only care\n+\t\t * about pad-2-pad links here.\n+\t\t */\n+\t\tif ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) ==\n+\t\t    MEDIA_LNK_FL_INTERFACE_LINK)\n+\t\t\tcontinue;\n+\n+\t\t/* Store references to source and sink pads in the link. */\n+\t\tunsigned int source_id = mediaLinks[i].source_id;\n+\t\tMediaPad *source = dynamic_cast<MediaPad *>\n+\t\t\t\t   (object(source_id));\n+\t\tif (!source) {\n+\t\t\tLOG(Error) << \"Failed to find pad with id: \"\n+\t\t\t\t   << source_id;\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tunsigned int sink_id = mediaLinks[i].sink_id;\n+\t\tMediaPad *sink = dynamic_cast<MediaPad *>\n+\t\t\t\t (object(sink_id));\n+\t\tif (!sink) {\n+\t\t\tLOG(Error) << \"Failed to find pad with id: \"\n+\t\t\t\t   << sink_id;\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tMediaLink *link = new MediaLink(&mediaLinks[i], source, sink);\n+\t\tif (!addObject(link)) {\n+\t\t\tdelete link;\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tsource->addLink(link);\n+\t\tsink->addLink(link);\n+\t}\n+\n+\treturn true;\n+}\n+\n } /* namespace libcamera */\n","prefixes":["libcamera-devel","3/4"]}