Skip to contentSkip to conversation

Print information on given entity only

PATCH In review Sakari Ailus 2 participants 12 messages Sep 13, 2016 – Sep 15, 2016 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

cover Print information on given entity only

Hi,

These patches add the ability to media-ctl to print information on a given entity only. That's sometimes handy.

Signature · 2 lines
Regards,
Sakari
#3 lore raw

PATCH 2/2 media-ctl: Print information related to a single entity

Add an optional argument to the -p option that allows printing all information related to a given entity. This may be handy sometimes if only a single entity is of interest and there are many entities.

---
 utils/media-ctl/media-ctl.c | 26 +++++++++++++++-----------
 utils/media-ctl/options.c   |  9 ++++++---
 utils/media-ctl/options.h   |  1 +
 3 files changed, 22 insertions(+), 14 deletions(-)
utils/media-ctl/media-ctl.c +15 -11
index 0499008..fdd2449 100644
@@ -504,14 +504,6 @@ static void media_print_topology_text(struct media_device *media)
 			media, media_get_entity(media, i));
 }
 
-void media_print_topology(struct media_device *media, int dot)
-{
-	if (dot)
-		media_print_topology_dot(media);
-	else
-		media_print_topology_text(media);
-}
-
 int main(int argc, char **argv)
 {
 	struct media_device *media;
@@ -611,9 +603,21 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (media_opts.print || media_opts.print_dot) {
-		media_print_topology(media, media_opts.print_dot);
-		printf("\n");
+	if (media_opts.print_dot) {
+		media_print_topology_dot(media);
+	} else if (media_opts.print_entity) {
+		struct media_entity *entity = NULL;
+
+		entity = media_get_entity_by_name(media,
+						  media_opts.print_entity);
+		if (entity == NULL) {
+			printf("Entity '%s' not found\n",
+			       media_opts.print_entity);
+			goto out;
+		}
+		media_print_topology_text_entity(media, entity);
+	} else if (media_opts.print) {
+		media_print_topology_text(media);
 	}
 
 	if (media_opts.reset) {
utils/media-ctl/options.c +6 -3
index a288a1b..3352626 100644
@@ -51,7 +51,9 @@ static void usage(const char *argv0)
 	printf("-i, --interactive	Modify links interactively\n");
 	printf("-l, --links links	Comma-separated list of link descriptors to setup\n");
 	printf("    --known-mbus-fmts	List known media bus formats and their numeric values\n");
-	printf("-p, --print-topology	Print the device topology\n");
+	printf("-p, --print-topology [name] Print the device topology\n");
+	printf("			If entity name is specified, information to that entity\n");
+	printf("			only is printed.\n");
 	printf("    --print-dot		Print the device topology as a dot graph\n");
 	printf("-r, --reset		Reset all links to inactive\n");
 	printf("-v, --verbose		Be verbose\n");
@@ -109,7 +111,7 @@ static struct option opts[] = {
 	{"links", 1, 0, 'l'},
 	{"known-mbus-fmts", 0, 0, OPT_LIST_KNOWN_MBUS_FMTS},
 	{"print-dot", 0, 0, OPT_PRINT_DOT},
-	{"print-topology", 0, 0, 'p'},
+	{"print-topology", 2, 0, 'p'},
 	{"reset", 0, 0, 'r'},
 	{"verbose", 0, 0, 'v'},
 	{ },
@@ -146,7 +148,7 @@ int parse_cmdline(int argc, char **argv)
 	}
 
 	/* parse options */
-	while ((opt = getopt_long(argc, argv, "d:e:f:hil:prvV:",
+	while ((opt = getopt_long(argc, argv, "d:e:f:hil:p::rvV:",
 				  opts, NULL)) != -1) {
 		switch (opt) {
 		case 'd':
@@ -182,6 +184,7 @@ int parse_cmdline(int argc, char **argv)
 
 		case 'p':
 			media_opts.print = 1;
+			media_opts.print_entity = optarg;
 			break;
 
 		case 'r':
utils/media-ctl/options.h +1 -0
index 9b5f314..ff9dfdf 100644
@@ -30,6 +30,7 @@ struct media_options
 		     print_dot:1,
 		     reset:1,
 		     verbose:1;
+	const char *print_entity;
 	const char *entity;
 	const char *formats;
 	const char *links;
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 media-ctl: Split off printing information related to a single entity

In reply to Sakari Ailus

As a result, a function that can be used to print information on a given entity only is provided.

---
 utils/media-ctl/media-ctl.c | 93 ++++++++++++++++++++++++---------------------
 1 file changed, 49 insertions(+), 44 deletions(-)
utils/media-ctl/media-ctl.c +49 -44
index 2f049c6..0499008 100644
@@ -436,67 +436,72 @@ static void media_print_pad_text(struct media_entity *entity,
 		v4l2_subdev_print_subdev_dv(entity);
 }
 
-static void media_print_topology_text(struct media_device *media)
+static void media_print_topology_text_entity(struct media_device *media,
+					     struct media_entity *entity)
 {
 	static const struct flag_name link_flags[] = {
 		{ MEDIA_LNK_FL_ENABLED, "ENABLED" },
 		{ MEDIA_LNK_FL_IMMUTABLE, "IMMUTABLE" },
 		{ MEDIA_LNK_FL_DYNAMIC, "DYNAMIC" },
 	};
-
-	unsigned int nents = media_get_entities_count(media);
-	unsigned int i, j, k;
+	const struct media_entity_desc *info = media_entity_get_info(entity);
+	const char *devname = media_entity_get_devname(entity);
+	unsigned int num_links = media_entity_get_links_count(entity);
+	unsigned int j, k;
 	unsigned int padding;
 
-	printf("Device topology\n");
-
-	for (i = 0; i < nents; ++i) {
-		struct media_entity *entity = media_get_entity(media, i);
-		const struct media_entity_desc *info = media_entity_get_info(entity);
-		const char *devname = media_entity_get_devname(entity);
-		unsigned int num_links = media_entity_get_links_count(entity);
-
-		padding = printf("- entity %u: ", info->id);
-		printf("%s (%u pad%s, %u link%s)\n", info->name,
-			info->pads, info->pads > 1 ? "s" : "",
-			num_links, num_links > 1 ? "s" : "");
-		printf("%*ctype %s subtype %s flags %x\n", padding, ' ',
-			media_entity_type_to_string(info->type),
-			media_entity_subtype_to_string(info->type),
-			info->flags);
-		if (devname)
-			printf("%*cdevice node name %s\n", padding, ' ', devname);
+	padding = printf("- entity %u: ", info->id);
+	printf("%s (%u pad%s, %u link%s)\n", info->name,
+	       info->pads, info->pads > 1 ? "s" : "",
+	       num_links, num_links > 1 ? "s" : "");
+	printf("%*ctype %s subtype %s flags %x\n", padding, ' ',
+	       media_entity_type_to_string(info->type),
+	       media_entity_subtype_to_string(info->type),
+	       info->flags);
+	if (devname)
+		printf("%*cdevice node name %s\n", padding, ' ', devname);
 
-		for (j = 0; j < info->pads; j++) {
-			const struct media_pad *pad = media_entity_get_pad(entity, j);
+	for (j = 0; j < info->pads; j++) {
+		const struct media_pad *pad = media_entity_get_pad(entity, j);
 
-			printf("\tpad%u: %s\n", j, media_pad_type_to_string(pad->flags));
+		printf("\tpad%u: %s\n", j, media_pad_type_to_string(pad->flags));
 
-			media_print_pad_text(entity, pad);
+		media_print_pad_text(entity, pad);
 
-			for (k = 0; k < num_links; k++) {
-				const struct media_link *link = media_entity_get_link(entity, k);
-				const struct media_pad *source = link->source;
-				const struct media_pad *sink = link->sink;
+		for (k = 0; k < num_links; k++) {
+			const struct media_link *link = media_entity_get_link(entity, k);
+			const struct media_pad *source = link->source;
+			const struct media_pad *sink = link->sink;
 
-				if (source->entity == entity && source->index == j)
-					printf("\t\t-> \"%s\":%u [",
-						media_entity_get_info(sink->entity)->name,
-						sink->index);
-				else if (sink->entity == entity && sink->index == j)
-					printf("\t\t<- \"%s\":%u [",
-						media_entity_get_info(source->entity)->name,
-						source->index);
-				else
-					continue;
+			if (source->entity == entity && source->index == j)
+				printf("\t\t-> \"%s\":%u [",
+				       media_entity_get_info(sink->entity)->name,
+				       sink->index);
+			else if (sink->entity == entity && sink->index == j)
+				printf("\t\t<- \"%s\":%u [",
+				       media_entity_get_info(source->entity)->name,
+				       source->index);
+			else
+				continue;
 
-				print_flags(link_flags, ARRAY_SIZE(link_flags), link->flags);
+			print_flags(link_flags, ARRAY_SIZE(link_flags), link->flags);
 
-				printf("]\n");
-			}
+			printf("]\n");
 		}
-		printf("\n");
 	}
+	printf("\n");
+}
+
+static void media_print_topology_text(struct media_device *media)
+{
+	unsigned int nents = media_get_entities_count(media);
+	unsigned int i;
+
+	printf("Device topology\n");
+
+	for (i = 0; i < nents; ++i)
+		media_print_topology_text_entity(
+			media, media_get_entity(media, i));
 }
 
 void media_print_topology(struct media_device *media, int dot)
Signature · 1 line
2.7.4
Acked-by on v1 1/2
#2 lore raw

Re: [v4l-utils PATCH 1/2] media-ctl: Split off printing information related to a single entity

Hi Sakari,

Thank you for the patch.

Quoted 4 lines · On Tuesday 13 Sep 2016 11:28:15 Sakari Ailus wrote:

As a result, a function that can be used to print information on a given entity only is provided.

Quoted 3 lines
---
 utils/media-ctl/media-ctl.c | 93 +++++++++++++++++++++---------------------
 1 file changed, 49 insertions(+), 44 deletions(-)
Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw

Re: [v4l-utils PATCH 2/2] media-ctl: Print information related to a single entity

In reply to Sakari Ailus

Hi Sakari,

Thank you for the patch. This is a feature I've often thought would be useful.

Quoted 3 lines · On Tuesday 13 Sep 2016 11:28:16 Sakari Ailus wrote:

Add an optional argument to the -p option that allows printing all information related to a given entity. This may be handy sometimes if only a single entity is of interest and there are many entities.

Would it make sense to instead reuse the -e argument ? If both -p and -e are specified, print entity information for the entity referenced by -e. If only - p or -e are specified, operate as we do today.

Quoted 56 lines
---
 utils/media-ctl/media-ctl.c | 26 +++++++++++++++-----------
 utils/media-ctl/options.c   |  9 ++++++---
 utils/media-ctl/options.h   |  1 +
 3 files changed, 22 insertions(+), 14 deletions(-)
utils/media-ctl/media-ctl.c +15 -11
index 0499008..fdd2449 100644
@@ -504,14 +504,6 @@ static void media_print_topology_text(struct
 media_device *media) media, media_get_entity(media, i));
 }
 
-void media_print_topology(struct media_device *media, int dot)
-{
-	if (dot)
-		media_print_topology_dot(media);
-	else
-		media_print_topology_text(media);
-}
-
 int main(int argc, char **argv)
 {
 	struct media_device *media;
@@ -611,9 +603,21 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (media_opts.print || media_opts.print_dot) {
-		media_print_topology(media, media_opts.print_dot);
-		printf("\n");
+	if (media_opts.print_dot) {
+		media_print_topology_dot(media);
+	} else if (media_opts.print_entity) {
+		struct media_entity *entity = NULL;
+
+		entity = media_get_entity_by_name(media,
+						  media_opts.print_entity);
+		if (entity == NULL) {
+			printf("Entity '%s' not found\n",
+			       media_opts.print_entity);
+			goto out;
+		}
+		media_print_topology_text_entity(media, entity);
+	} else if (media_opts.print) {
+		media_print_topology_text(media);
 	}
 
 	if (media_opts.reset) {
utils/media-ctl/options.c +0 -0
index a288a1b..3352626 100644

utils/media-ctl/options.c static void usage(const char *argv0) · line 59

Quoted 10 lines
utils/media-ctl/options.c +3 -1
@@ -51,7 +51,9 @@ static void usage(const char *argv0)
 	printf("-i, --interactive	Modify links interactively\n");
 	printf("-l, --links links	Comma-separated list of link
 descriptors to setup\n");
 	printf("    --known-mbus-fmts	List known media bus formats and
 their numeric values\n");
-	printf("-p, --print-topology	Print the device topology\n");
+	printf("-p, --print-topology [name] Print the device topology\n");
+	printf("			If entity name is specified,
 information to that entity\n");
+	printf("			only is printed.\n");

I'd wrap this to make lines a bit shorter, and perhaps write it as

printf("-p, --print-topology [name]\n);
printf(" Print the device topology. If name\n");
printf(" is specified, print information for\n");
printf(" the named entity only.\n);

Or if you go by my proposal above,

printf("-p, --print-topology Print the device topology. If an entity\n");
printf(" is specified through the -e option, print\n");
printf(" information for that entity only.\n);

Quoted 1 line

printf(" --print-dot Print the device topology as a dot

graph\n");

Quoted 40 lines
utils/media-ctl/options.c +3 -2
 	printf("-r, --reset		Reset all links to inactive\n");
 	printf("-v, --verbose		Be verbose\n");
@@ -109,7 +111,7 @@ static struct option opts[] = {
 	{"links", 1, 0, 'l'},
 	{"known-mbus-fmts", 0, 0, OPT_LIST_KNOWN_MBUS_FMTS},
 	{"print-dot", 0, 0, OPT_PRINT_DOT},
-	{"print-topology", 0, 0, 'p'},
+	{"print-topology", 2, 0, 'p'},
 	{"reset", 0, 0, 'r'},
 	{"verbose", 0, 0, 'v'},
 	{ },
@@ -146,7 +148,7 @@ int parse_cmdline(int argc, char **argv)
 	}
 
 	/* parse options */
-	while ((opt = getopt_long(argc, argv, "d:e:f:hil:prvV:",
+	while ((opt = getopt_long(argc, argv, "d:e:f:hil:p::rvV:",
 				  opts, NULL)) != -1) {
 		switch (opt) {
 		case 'd':
@@ -182,6 +184,7 @@ int parse_cmdline(int argc, char **argv)
 
 		case 'p':
 			media_opts.print = 1;
+			media_opts.print_entity = optarg;
 			break;
 
 		case 'r':
utils/media-ctl/options.h +1 -0
index 9b5f314..ff9dfdf 100644
@@ -30,6 +30,7 @@ struct media_options
 		     print_dot:1,
 		     reset:1,
 		     verbose:1;
+	const char *print_entity;
 	const char *entity;
 	const char *formats;
 	const char *links;
Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw

PATCH 2/2 media-ctl: Print information related to a single entity

Add an optional argument to the -p option that allows printing all information related to a given entity. This may be handy sometimes if only a single entity is of interest and there are many entities.

---
 utils/media-ctl/media-ctl.c | 33 +++++++++++++++------------------
 utils/media-ctl/options.c   |  2 ++
 2 files changed, 17 insertions(+), 18 deletions(-)
utils/media-ctl/media-ctl.c +15 -18
index 0499008..109cc11 100644
@@ -504,19 +504,11 @@ static void media_print_topology_text(struct media_device *media)
 			media, media_get_entity(media, i));
 }
 
-void media_print_topology(struct media_device *media, int dot)
-{
-	if (dot)
-		media_print_topology_dot(media);
-	else
-		media_print_topology_text(media);
-}
-
 int main(int argc, char **argv)
 {
 	struct media_device *media;
+	struct media_entity *entity = NULL;
 	int ret = -1;
-	const char *devname;
 
 	if (parse_cmdline(argc, argv))
 		return EXIT_FAILURE;
@@ -562,17 +554,11 @@ int main(int argc, char **argv)
 	}
 
 	if (media_opts.entity) {
-		struct media_entity *entity;
-
 		entity = media_get_entity_by_name(media, media_opts.entity);
 		if (entity == NULL) {
 			printf("Entity '%s' not found\n", media_opts.entity);
 			goto out;
 		}
-
-		devname = media_entity_get_devname(entity);
-		if (devname)
-			printf("%s\n", devname);
 	}
 
 	if (media_opts.fmt_pad) {
@@ -611,9 +597,20 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (media_opts.print || media_opts.print_dot) {
-		media_print_topology(media, media_opts.print_dot);
-		printf("\n");
+	if (media_opts.print_dot) {
+		media_print_topology_dot(media);
+	} else if (media_opts.print) {
+		if (entity) {
+			media_print_topology_text_entity(media, entity);
+		} else {
+			media_print_topology_text(media);
+		}
+	} else if (entity) {
+		const char *devname;
+
+		devname = media_entity_get_devname(entity);
+		if (devname)
+			printf("%s\n", devname);
 	}
 
 	if (media_opts.reset) {
utils/media-ctl/options.c +2 -0
index a288a1b..304a86c 100644
@@ -52,6 +52,8 @@ static void usage(const char *argv0)
 	printf("-l, --links links	Comma-separated list of link descriptors to setup\n");
 	printf("    --known-mbus-fmts	List known media bus formats and their numeric values\n");
 	printf("-p, --print-topology	Print the device topology\n");
+	printf("			If entity name is specified using -e option, information\n");
+	printf("			related to that entity only is printed.\n");
 	printf("    --print-dot		Print the device topology as a dot graph\n");
 	printf("-r, --reset		Reset all links to inactive\n");
 	printf("-v, --verbose		Be verbose\n");
Signature · 1 line
2.7.4
#6 lore raw

PATCH 2/2 media-ctl: Print information related to a single entity

In reply to Laurent Pinchart

Add a possibility to printing all information related to a given entity by using both -p and -e options. This may be handy sometimes if only a single entity is of interest and there are many entities.

---
Fixed the commit message as well.

 utils/media-ctl/media-ctl.c | 33 +++++++++++++++------------------
 utils/media-ctl/options.c   |  2 ++
 2 files changed, 17 insertions(+), 18 deletions(-)
utils/media-ctl/media-ctl.c +15 -18
index 0499008..109cc11 100644
@@ -504,19 +504,11 @@ static void media_print_topology_text(struct media_device *media)
 			media, media_get_entity(media, i));
 }
 
-void media_print_topology(struct media_device *media, int dot)
-{
-	if (dot)
-		media_print_topology_dot(media);
-	else
-		media_print_topology_text(media);
-}
-
 int main(int argc, char **argv)
 {
 	struct media_device *media;
+	struct media_entity *entity = NULL;
 	int ret = -1;
-	const char *devname;
 
 	if (parse_cmdline(argc, argv))
 		return EXIT_FAILURE;
@@ -562,17 +554,11 @@ int main(int argc, char **argv)
 	}
 
 	if (media_opts.entity) {
-		struct media_entity *entity;
-
 		entity = media_get_entity_by_name(media, media_opts.entity);
 		if (entity == NULL) {
 			printf("Entity '%s' not found\n", media_opts.entity);
 			goto out;
 		}
-
-		devname = media_entity_get_devname(entity);
-		if (devname)
-			printf("%s\n", devname);
 	}
 
 	if (media_opts.fmt_pad) {
@@ -611,9 +597,20 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (media_opts.print || media_opts.print_dot) {
-		media_print_topology(media, media_opts.print_dot);
-		printf("\n");
+	if (media_opts.print_dot) {
+		media_print_topology_dot(media);
+	} else if (media_opts.print) {
+		if (entity) {
+			media_print_topology_text_entity(media, entity);
+		} else {
+			media_print_topology_text(media);
+		}
+	} else if (entity) {
+		const char *devname;
+
+		devname = media_entity_get_devname(entity);
+		if (devname)
+			printf("%s\n", devname);
 	}
 
 	if (media_opts.reset) {
utils/media-ctl/options.c +2 -0
index a288a1b..304a86c 100644
@@ -52,6 +52,8 @@ static void usage(const char *argv0)
 	printf("-l, --links links	Comma-separated list of link descriptors to setup\n");
 	printf("    --known-mbus-fmts	List known media bus formats and their numeric values\n");
 	printf("-p, --print-topology	Print the device topology\n");
+	printf("			If entity name is specified using -e option, information\n");
+	printf("			related to that entity only is printed.\n");
 	printf("    --print-dot		Print the device topology as a dot graph\n");
 	printf("-r, --reset		Reset all links to inactive\n");
 	printf("-v, --verbose		Be verbose\n");
Signature · 1 line
2.7.4
#7 lore raw

Re: [v4l-utils PATCH v1.2 2/2] media-ctl: Print information related to a single entity

Hi Sakari,

Thank you for the patch.

Quoted 60 lines · On Wednesday 14 Sep 2016 17:29:39 Sakari Ailus wrote:

Add a possibility to printing all information related to a given entity by using both -p and -e options. This may be handy sometimes if only a single entity is of interest and there are many entities.

---
Fixed the commit message as well.

 utils/media-ctl/media-ctl.c | 33 +++++++++++++++------------------
 utils/media-ctl/options.c   |  2 ++
 2 files changed, 17 insertions(+), 18 deletions(-)
utils/media-ctl/media-ctl.c +1 -16
index 0499008..109cc11 100644
@@ -504,19 +504,11 @@ static void media_print_topology_text(struct
 media_device *media) media, media_get_entity(media, i));
 }
 
-void media_print_topology(struct media_device *media, int dot)
-{
-	if (dot)
-		media_print_topology_dot(media);
-	else
-		media_print_topology_text(media);
-}
-
 int main(int argc, char **argv)
 {
 	struct media_device *media;
+	struct media_entity *entity = NULL;
 	int ret = -1;
-	const char *devname;
 
 	if (parse_cmdline(argc, argv))
 		return EXIT_FAILURE;
@@ -562,17 +554,11 @@ int main(int argc, char **argv)
 	}
 
 	if (media_opts.entity) {
-		struct media_entity *entity;
-
 		entity = media_get_entity_by_name(media, media_opts.entity);
 		if (entity == NULL) {
 			printf("Entity '%s' not found\n", media_opts.entity);
 			goto out;
 		}
-
-		devname = media_entity_get_devname(entity);
-		if (devname)
-			printf("%s\n", devname);
 	}
 
 	if (media_opts.fmt_pad) {
@@ -611,9 +597,20 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (media_opts.print || media_opts.print_dot) {

utils/media-ctl/media-ctl.c int main(int argc, char **argv) · line 607

Quoted 10 lines
utils/media-ctl/media-ctl.c +8 -2
-		media_print_topology(media, media_opts.print_dot);
-		printf("\n");
+	if (media_opts.print_dot) {
+		media_print_topology_dot(media);
+	} else if (media_opts.print) {
+		if (entity) {
+			media_print_topology_text_entity(media, entity);
+		} else {
+			media_print_topology_text(media);
+		}

You could remove the curly braces here.

Quoted 14 lines
utils/media-ctl/media-ctl.c +6 -0
+	} else if (entity) {
+		const char *devname;
+
+		devname = media_entity_get_devname(entity);
+		if (devname)
+			printf("%s\n", devname);
 	}
 
 	if (media_opts.reset) {
utils/media-ctl/options.c +0 -0
index a288a1b..304a86c 100644

utils/media-ctl/options.c static void usage(const char *argv0) · line 52

Quoted 1 line
utils/media-ctl/options.c +0 -0
@@ -52,6 +52,8 @@ static void usage(const char *argv0)
 	printf("-l, --links links	Comma-separated list of link 

descriptors to

Quoted 1 line

setup\n"); printf(" --known-mbus-fmts List known media bus formats

and

Quoted 1 line

their numeric values\n"); printf("-p, --print-topology Print the

device

utils/media-ctl/options.c

Quoted 2 lines

topology\n");

utils/media-ctl/options.c +1 -0
+	printf("			If entity name is specified using -e 

option, information\n");

utils/media-ctl/options.c

Quoted 1 line
utils/media-ctl/options.c +1 -0
+	printf("			related to that entity only is 

printed.\n");

Nitpicking, was anything wrong with

printf("-p, --print-topology    Print the device topology. If an entity\n");
printf("                        is specified through the -e option, print\n");
printf("                        information for that entity only.\n);

? I think the help text looks more natural when using articles :-)

Quoted 1 line

printf(" --print-dot Print the device topology as a dot

graph\n");

Quoted 2 lines
utils/media-ctl/options.c +0 -0
 	printf("-r, --reset		Reset all links to inactive\n");
 	printf("-v, --verbose		Be verbose\n");
Signature · 3 lines
Regards,

Laurent Pinchart
#8 lore raw

Re: [v4l-utils PATCH v1.2 2/2] media-ctl: Print information related to a single entity

Quoted 64 lines · Laurent Pinchart

Hi Sakari,

Thank you for the patch.

Quoted 59 lines · On Wednesday 14 Sep 2016 17:29:39 Sakari Ailus wrote:

Add a possibility to printing all information related to a given entity by using both -p and -e options. This may be handy sometimes if only a single entity is of interest and there are many entities.

---
Fixed the commit message as well.

 utils/media-ctl/media-ctl.c | 33 +++++++++++++++------------------
 utils/media-ctl/options.c   |  2 ++
 2 files changed, 17 insertions(+), 18 deletions(-)
utils/media-ctl/media-ctl.c +1 -15
index 0499008..109cc11 100644
@@ -504,19 +504,11 @@ static void media_print_topology_text(struct
 media_device *media) media, media_get_entity(media, i));
 }
 
-void media_print_topology(struct media_device *media, int dot)
-{
-	if (dot)
-		media_print_topology_dot(media);
-	else
-		media_print_topology_text(media);
-}
-
 int main(int argc, char **argv)
 {
 	struct media_device *media;
+	struct media_entity *entity = NULL;
 	int ret = -1;
-	const char *devname;
 
 	if (parse_cmdline(argc, argv))
 		return EXIT_FAILURE;
@@ -562,17 +554,11 @@ int main(int argc, char **argv)
 	}
 
 	if (media_opts.entity) {
-		struct media_entity *entity;
-
 		entity = media_get_entity_by_name(media, media_opts.entity);
 		if (entity == NULL) {
 			printf("Entity '%s' not found\n", media_opts.entity);
 			goto out;
 		}
-
-		devname = media_entity_get_devname(entity);
-		if (devname)
-			printf("%s\n", devname);
 	}
 
 	if (media_opts.fmt_pad) {
@@ -611,9 +597,20 @@ int main(int argc, char **argv)
 		}
 	}
 
Quoted 13 lines

utils/media-ctl/media-ctl.c int main(int argc, char **argv) · line 607

Quoted 11 lines
utils/media-ctl/media-ctl.c +8 -3
-	if (media_opts.print || media_opts.print_dot) {
-		media_print_topology(media, media_opts.print_dot);
-		printf("\n");
+	if (media_opts.print_dot) {
+		media_print_topology_dot(media);
+	} else if (media_opts.print) {
+		if (entity) {
+			media_print_topology_text_entity(media, entity);
+		} else {
+			media_print_topology_text(media);
+		}

You could remove the curly braces here.

Will fix.

Quoted 24 lines
Quoted 15 lines
utils/media-ctl/media-ctl.c +6 -0
+	} else if (entity) {
+		const char *devname;
+
+		devname = media_entity_get_devname(entity);
+		if (devname)
+			printf("%s\n", devname);
 	}
 
 	if (media_opts.reset) {
utils/media-ctl/options.c +0 -0
index a288a1b..304a86c 100644

utils/media-ctl/options.c static void usage(const char *argv0) · line 52

Quoted 1 line
utils/media-ctl/options.c +0 -0
@@ -52,6 +52,8 @@ static void usage(const char *argv0)
 	printf("-l, --links links	Comma-separated list of link 

descriptors to

Quoted 1 line

setup\n"); printf(" --known-mbus-fmts List known media bus formats

and

Quoted 1 line

their numeric values\n"); printf("-p, --print-topology Print the

device

utils/media-ctl/options.c

Quoted 2 lines

topology\n");

utils/media-ctl/options.c +1 -0
+	printf("			If entity name is specified using -e 

option, information\n");

Quoted 8 lines

utils/media-ctl/options.c

Quoted 1 line
utils/media-ctl/options.c +1 -0
+	printf("			related to that entity only is 

printed.\n");

Nitpicking, was anything wrong with

printf("-p, --print-topology    Print the device topology. If an entity\n");
printf("                        is specified through the -e option, print\n");
printf("                        information for that entity only.\n);

Not necessarily, but I missed that part of your reply. I'll replace it.

Quoted 2 lines

? I think the help text looks more natural when using articles :-)

The message was still clear, wasn't it? :-D

Quoted 6 lines
Quoted 2 lines

printf(" --print-dot Print the device topology as a dot

graph\n");

Quoted 2 lines
utils/media-ctl/options.c +0 -0
 	printf("-r, --reset		Reset all links to inactive\n");
 	printf("-v, --verbose		Be verbose\n");
Signature · 4 lines
Cheers,

Sakari Ailus
[email protected]
#9 lore raw

PATCH 2/2 media-ctl: Print information related to a single entity

In reply to Laurent Pinchart

Add a possibility to printing all information related to a given entity by using both -p and -e options. This may be handy sometimes if only a single entity is of interest and there are many entities.

---
 utils/media-ctl/media-ctl.c | 32 ++++++++++++++------------------
 utils/media-ctl/options.c   |  4 +++-
 2 files changed, 17 insertions(+), 19 deletions(-)
utils/media-ctl/media-ctl.c +14 -18
index 0499008..b60d297 100644
@@ -504,19 +504,11 @@ static void media_print_topology_text(struct media_device *media)
 			media, media_get_entity(media, i));
 }
 
-void media_print_topology(struct media_device *media, int dot)
-{
-	if (dot)
-		media_print_topology_dot(media);
-	else
-		media_print_topology_text(media);
-}
-
 int main(int argc, char **argv)
 {
 	struct media_device *media;
+	struct media_entity *entity = NULL;
 	int ret = -1;
-	const char *devname;
 
 	if (parse_cmdline(argc, argv))
 		return EXIT_FAILURE;
@@ -562,17 +554,11 @@ int main(int argc, char **argv)
 	}
 
 	if (media_opts.entity) {
-		struct media_entity *entity;
-
 		entity = media_get_entity_by_name(media, media_opts.entity);
 		if (entity == NULL) {
 			printf("Entity '%s' not found\n", media_opts.entity);
 			goto out;
 		}
-
-		devname = media_entity_get_devname(entity);
-		if (devname)
-			printf("%s\n", devname);
 	}
 
 	if (media_opts.fmt_pad) {
@@ -611,9 +597,19 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (media_opts.print || media_opts.print_dot) {
-		media_print_topology(media, media_opts.print_dot);
-		printf("\n");
+	if (media_opts.print_dot) {
+		media_print_topology_dot(media);
+	} else if (media_opts.print) {
+		if (entity)
+			media_print_topology_text_entity(media, entity);
+		else
+			media_print_topology_text(media);
+	} else if (entity) {
+		const char *devname;
+
+		devname = media_entity_get_devname(entity);
+		if (devname)
+			printf("%s\n", devname);
 	}
 
 	if (media_opts.reset) {
utils/media-ctl/options.c +3 -1
index a288a1b..77d1a51 100644
@@ -51,7 +51,9 @@ static void usage(const char *argv0)
 	printf("-i, --interactive	Modify links interactively\n");
 	printf("-l, --links links	Comma-separated list of link descriptors to setup\n");
 	printf("    --known-mbus-fmts	List known media bus formats and their numeric values\n");
-	printf("-p, --print-topology	Print the device topology\n");
+	printf("-p, --print-topology	Print the device topology. If an entity\n");
+	printf("			is specified through the -e option, print\n");
+	printf("			information for that entity only.\n);
 	printf("    --print-dot		Print the device topology as a dot graph\n");
 	printf("-r, --reset		Reset all links to inactive\n");
 	printf("-v, --verbose		Be verbose\n");
Signature · 1 line
2.7.4
Reviewed-by on v1 2/2
#10 lore raw

Re: [v4l-utils PATCH v1.3 2/2] media-ctl: Print information related to a single entity

Hi Sakari,

Thank you for the patch.

Quoted 5 lines · On Thursday 15 Sep 2016 09:40:39 Sakari Ailus wrote:

Add a possibility to printing all information related to a given entity by using both -p and -e options. This may be handy sometimes if only a single entity is of interest and there are many entities.

Quoted 76 lines
---
 utils/media-ctl/media-ctl.c | 32 ++++++++++++++------------------
 utils/media-ctl/options.c   |  4 +++-
 2 files changed, 17 insertions(+), 19 deletions(-)
utils/media-ctl/media-ctl.c +14 -18
index 0499008..b60d297 100644
@@ -504,19 +504,11 @@ static void media_print_topology_text(struct
 media_device *media) media, media_get_entity(media, i));
 }
 
-void media_print_topology(struct media_device *media, int dot)
-{
-	if (dot)
-		media_print_topology_dot(media);
-	else
-		media_print_topology_text(media);
-}
-
 int main(int argc, char **argv)
 {
 	struct media_device *media;
+	struct media_entity *entity = NULL;
 	int ret = -1;
-	const char *devname;
 
 	if (parse_cmdline(argc, argv))
 		return EXIT_FAILURE;
@@ -562,17 +554,11 @@ int main(int argc, char **argv)
 	}
 
 	if (media_opts.entity) {
-		struct media_entity *entity;
-
 		entity = media_get_entity_by_name(media, media_opts.entity);
 		if (entity == NULL) {
 			printf("Entity '%s' not found\n", media_opts.entity);
 			goto out;
 		}
-
-		devname = media_entity_get_devname(entity);
-		if (devname)
-			printf("%s\n", devname);
 	}
 
 	if (media_opts.fmt_pad) {
@@ -611,9 +597,19 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (media_opts.print || media_opts.print_dot) {
-		media_print_topology(media, media_opts.print_dot);
-		printf("\n");
+	if (media_opts.print_dot) {
+		media_print_topology_dot(media);
+	} else if (media_opts.print) {
+		if (entity)
+			media_print_topology_text_entity(media, entity);
+		else
+			media_print_topology_text(media);
+	} else if (entity) {
+		const char *devname;
+
+		devname = media_entity_get_devname(entity);
+		if (devname)
+			printf("%s\n", devname);
 	}
 
 	if (media_opts.reset) {
utils/media-ctl/options.c +0 -0
index a288a1b..77d1a51 100644

utils/media-ctl/options.c static void usage(const char *argv0) · line 52

Quoted 2 lines
utils/media-ctl/options.c +0 -0
@@ -51,7 +51,9 @@ static void usage(const char *argv0)
 	printf("-i, --interactive	Modify links interactively\n");
 	printf("-l, --links links	Comma-separated list of link 

descriptors to

Quoted 1 line

setup\n"); printf(" --known-mbus-fmts List known media bus formats

and

Quoted 1 line

their numeric values\n"); - printf("-p, --print-topology Print the

device

utils/media-ctl/options.c

Quoted 2 lines

topology\n");

utils/media-ctl/options.c +1 -0
+	printf("-p, --print-topology	Print the device topology. If an 

entity\n");

utils/media-ctl/options.c

Quoted 1 line
utils/media-ctl/options.c +1 -0
+	printf("			is specified through the -e option, 

print\n");

utils/media-ctl/options.c

Quoted 2 lines
utils/media-ctl/options.c +1 -0
+	printf("			information for that entity only.\n);
 	printf("    --print-dot		Print the device topology as a dot 

graph\n");

Quoted 2 lines
utils/media-ctl/options.c +0 -0
 	printf("-r, --reset		Reset all links to inactive\n");
 	printf("-v, --verbose		Be verbose\n");
Signature · 3 lines
Regards,

Laurent Pinchart