diff mbox

[1/3] modetest: introduce get_prop_info() for getting property id and type

Message ID 1440570108-17354-1-git-send-email-human.hwang@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Hyungwon Hwang Aug. 26, 2015, 6:21 a.m. UTC
Modetest gets the property name from user to set it. So the name must be
converted to its id. Until now, this is done in the set_property(). But to
support atomic modeset in modetest, this logic should be separated from the
fuction, because atomic modeset and legacy modeset use different IOCTLs.

Signed-off-by: Hyungwon Hwang <human.hwang@samsung.com>
---
 tests/modetest/modetest.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

Comments

Emil Velikov Sept. 1, 2015, 11:41 p.m. UTC | #1
On 26 August 2015 at 07:21, Hyungwon Hwang <human.hwang@samsung.com> wrote:
> Modetest gets the property name from user to set it. So the name must be
> converted to its id. Until now, this is done in the set_property(). But to
> support atomic modeset in modetest, this logic should be separated from the
> fuction, because atomic modeset and legacy modeset use different IOCTLs.
>
> Signed-off-by: Hyungwon Hwang <human.hwang@samsung.com>
> ---
>  tests/modetest/modetest.c | 31 +++++++++++++++++++++----------
>  1 file changed, 21 insertions(+), 10 deletions(-)
>
> diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
> index 43bd06f..b7f6d32 100644
> --- a/tests/modetest/modetest.c
> +++ b/tests/modetest/modetest.c
> @@ -866,12 +866,11 @@ struct property_arg {
>         uint64_t value;
>  };
>
> -static void set_property(struct device *dev, struct property_arg *p)
> +static int get_prop_info(struct resources *resources, struct property_arg *p,
> +                                                               char *obj_type)
Strictly speaking you don't need the struct device > struct resources
change here.
But if you prefer doing so, keep the const qualifier for obj_type.

>  {
>         drmModeObjectProperties *props = NULL;
>         drmModePropertyRes **props_info = NULL;
> -       const char *obj_type;
> -       int ret;
>         int i;
>
...

> +static void set_property(struct device *dev, struct property_arg *p)
> +{
> +       int ret;
> +       char *obj_type = NULL;
> +
Drop the initializer and constify.

-Emil
diff mbox

Patch

diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
index 43bd06f..b7f6d32 100644
--- a/tests/modetest/modetest.c
+++ b/tests/modetest/modetest.c
@@ -866,12 +866,11 @@  struct property_arg {
 	uint64_t value;
 };
 
-static void set_property(struct device *dev, struct property_arg *p)
+static int get_prop_info(struct resources *resources, struct property_arg *p,
+								char *obj_type)
 {
 	drmModeObjectProperties *props = NULL;
 	drmModePropertyRes **props_info = NULL;
-	const char *obj_type;
-	int ret;
 	int i;
 
 	p->obj_type = 0;
@@ -884,27 +883,27 @@  static void set_property(struct device *dev, struct property_arg *p)
 			if (obj->type->type##_id != p->obj_id)			\
 				continue;					\
 			p->obj_type = DRM_MODE_OBJECT_##Type;			\
-			obj_type = #Type;					\
+			obj_type = (char *)#Type;				\
 			props = obj->props;					\
 			props_info = obj->props_info;				\
 		}								\
 	} while(0)								\
 
-	find_object(dev->resources, res, crtc, CRTC);
+	find_object(resources, res, crtc, CRTC);
 	if (p->obj_type == 0)
-		find_object(dev->resources, res, connector, CONNECTOR);
+		find_object(resources, res, connector, CONNECTOR);
 	if (p->obj_type == 0)
-		find_object(dev->resources, plane_res, plane, PLANE);
+		find_object(resources, plane_res, plane, PLANE);
 	if (p->obj_type == 0) {
 		fprintf(stderr, "Object %i not found, can't set property\n",
 			p->obj_id);
-			return;
+			return -1;
 	}
 
 	if (!props) {
 		fprintf(stderr, "%s %i has no properties\n",
 			obj_type, p->obj_id);
-		return;
+		return -1;
 	}
 
 	for (i = 0; i < (int)props->count_props; ++i) {
@@ -917,11 +916,23 @@  static void set_property(struct device *dev, struct property_arg *p)
 	if (i == (int)props->count_props) {
 		fprintf(stderr, "%s %i has no %s property\n",
 			obj_type, p->obj_id, p->name);
-		return;
+		return -1;
 	}
 
 	p->prop_id = props->props[i];
 
+	return 0;
+}
+
+static void set_property(struct device *dev, struct property_arg *p)
+{
+	int ret;
+	char *obj_type = NULL;
+
+	ret = get_prop_info(dev->resources, p, obj_type);
+	if (ret < 0)
+		return;
+
 	ret = drmModeObjectSetProperty(dev->fd, p->obj_id, p->obj_type,
 				       p->prop_id, p->value);
 	if (ret < 0)