qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 01/20] qdev: add print_options callback
  2011-02-02 20:28 [Qemu-devel] [PATCH 00/20] usb-ccid (v16) Alon Levy
@ 2011-02-02 20:28 ` Alon Levy
  2011-02-03 16:39   ` Anthony Liguori
  0 siblings, 1 reply; 5+ messages in thread
From: Alon Levy @ 2011-02-02 20:28 UTC (permalink / raw)
  To: qemu-devel

another callback added to PropertyInfo, for later use by PROP_TYPE_ENUM.
Allows printing of runtime computed options when doing:
 qemu -device foo,?
---
 hw/qdev.c |   10 +++++++++-
 hw/qdev.h |    1 +
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index c7fec44..0b2ad3d 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -187,7 +187,15 @@ int qdev_device_help(QemuOpts *opts)
         if (!prop->info->parse) {
             continue;           /* no way to set it, don't show */
         }
-        error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
+        if (prop->info->print_options) {
+            char buf[256];
+            int ret;
+            ret = prop->info->print_options(info, prop, buf, sizeof(buf) - 3);
+            error_printf("%s.%s=%s%s\n", info->name, prop->name, buf,
+                ret == sizeof(buf) - 3 ? "..." : "" );
+        } else {
+            error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
+        }
     }
     return 1;
 }
diff --git a/hw/qdev.h b/hw/qdev.h
index 9808f85..fa3221b 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -109,6 +109,7 @@ struct PropertyInfo {
     enum PropertyType type;
     int (*parse)(DeviceState *dev, Property *prop, const char *str);
     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
+    int (*print_options)(DeviceInfo *info, Property *prop, char *dest, size_t len);
     void (*free)(DeviceState *dev, Property *prop);
 };
 
-- 
1.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 01/20] qdev: add print_options callback
@ 2011-02-02 21:46 Alon Levy
  2011-02-03 10:21 ` Alon Levy
  0 siblings, 1 reply; 5+ messages in thread
From: Alon Levy @ 2011-02-02 21:46 UTC (permalink / raw)
  To: qemu-devel

another callback added to PropertyInfo, for later use by PROP_TYPE_ENUM.
Allows printing of runtime computed options when doing:
 qemu -device foo,?
---
 hw/qdev.c |   10 +++++++++-
 hw/qdev.h |    1 +
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index c7fec44..0b2ad3d 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -187,7 +187,15 @@ int qdev_device_help(QemuOpts *opts)
         if (!prop->info->parse) {
             continue;           /* no way to set it, don't show */
         }
-        error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
+        if (prop->info->print_options) {
+            char buf[256];
+            int ret;
+            ret = prop->info->print_options(info, prop, buf, sizeof(buf) - 3);
+            error_printf("%s.%s=%s%s\n", info->name, prop->name, buf,
+                ret == sizeof(buf) - 3 ? "..." : "" );
+        } else {
+            error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
+        }
     }
     return 1;
 }
diff --git a/hw/qdev.h b/hw/qdev.h
index 9808f85..fa3221b 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -109,6 +109,7 @@ struct PropertyInfo {
     enum PropertyType type;
     int (*parse)(DeviceState *dev, Property *prop, const char *str);
     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
+    int (*print_options)(DeviceInfo *info, Property *prop, char *dest, size_t len);
     void (*free)(DeviceState *dev, Property *prop);
 };
 
-- 
1.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 01/20] qdev: add print_options callback
  2011-02-02 21:46 [Qemu-devel] [PATCH 01/20] qdev: add print_options callback Alon Levy
@ 2011-02-03 10:21 ` Alon Levy
  0 siblings, 0 replies; 5+ messages in thread
From: Alon Levy @ 2011-02-03 10:21 UTC (permalink / raw)
  To: qemu-devel

Please ignore, duplicate of 01/20 already on the list. It took so long for
01/20 to appear on the list that I thought it was lost.

Alon

On Wed, Feb 02, 2011 at 11:46:07PM +0200, Alon Levy wrote:
> another callback added to PropertyInfo, for later use by PROP_TYPE_ENUM.
> Allows printing of runtime computed options when doing:
>  qemu -device foo,?
> ---
>  hw/qdev.c |   10 +++++++++-
>  hw/qdev.h |    1 +
>  2 files changed, 10 insertions(+), 1 deletions(-)
> 
> diff --git a/hw/qdev.c b/hw/qdev.c
> index c7fec44..0b2ad3d 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -187,7 +187,15 @@ int qdev_device_help(QemuOpts *opts)
>          if (!prop->info->parse) {
>              continue;           /* no way to set it, don't show */
>          }
> -        error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
> +        if (prop->info->print_options) {
> +            char buf[256];
> +            int ret;
> +            ret = prop->info->print_options(info, prop, buf, sizeof(buf) - 3);
> +            error_printf("%s.%s=%s%s\n", info->name, prop->name, buf,
> +                ret == sizeof(buf) - 3 ? "..." : "" );
> +        } else {
> +            error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
> +        }
>      }
>      return 1;
>  }
> diff --git a/hw/qdev.h b/hw/qdev.h
> index 9808f85..fa3221b 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -109,6 +109,7 @@ struct PropertyInfo {
>      enum PropertyType type;
>      int (*parse)(DeviceState *dev, Property *prop, const char *str);
>      int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
> +    int (*print_options)(DeviceInfo *info, Property *prop, char *dest, size_t len);
>      void (*free)(DeviceState *dev, Property *prop);
>  };
>  
> -- 
> 1.7.4
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 01/20] qdev: add print_options callback
  2011-02-02 20:28 ` [Qemu-devel] [PATCH 01/20] qdev: add print_options callback Alon Levy
@ 2011-02-03 16:39   ` Anthony Liguori
  2011-02-03 20:54     ` Alon Levy
  0 siblings, 1 reply; 5+ messages in thread
From: Anthony Liguori @ 2011-02-03 16:39 UTC (permalink / raw)
  To: Alon Levy; +Cc: qemu-devel

On 02/02/2011 02:28 PM, Alon Levy wrote:
> another callback added to PropertyInfo, for later use by PROP_TYPE_ENUM.
> Allows printing of runtime computed options when doing:
>   qemu -device foo,?
> ---
>   hw/qdev.c |   10 +++++++++-
>   hw/qdev.h |    1 +
>   2 files changed, 10 insertions(+), 1 deletions(-)
>
> diff --git a/hw/qdev.c b/hw/qdev.c
> index c7fec44..0b2ad3d 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -187,7 +187,15 @@ int qdev_device_help(QemuOpts *opts)
>           if (!prop->info->parse) {
>               continue;           /* no way to set it, don't show */
>           }
> -        error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
> +        if (prop->info->print_options) {
> +            char buf[256];
> +            int ret;
> +            ret = prop->info->print_options(info, prop, buf, sizeof(buf) - 3);
> +            error_printf("%s.%s=%s%s\n", info->name, prop->name, buf,
> +                ret == sizeof(buf) - 3 ? "..." : "" );
> +        } else {
> +            error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
> +        }
>       }
>       return 1;
>   }
> diff --git a/hw/qdev.h b/hw/qdev.h
> index 9808f85..fa3221b 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -109,6 +109,7 @@ struct PropertyInfo {
>       enum PropertyType type;
>       int (*parse)(DeviceState *dev, Property *prop, const char *str);
>       int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
> +    int (*print_options)(DeviceInfo *info, Property *prop, char *dest, size_t len);
>    

I'm not clear what the different between print and print_options is and 
why two callbacks are needed.  Can you explain and comments to the patch 
clarifying why two interfaces are needed.  Even better would be if one 
interface could handle it.

Regards,

Anthony Liguori


>       void (*free)(DeviceState *dev, Property *prop);
>   };
>
>    

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 01/20] qdev: add print_options callback
  2011-02-03 16:39   ` Anthony Liguori
@ 2011-02-03 20:54     ` Alon Levy
  0 siblings, 0 replies; 5+ messages in thread
From: Alon Levy @ 2011-02-03 20:54 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

On Thu, Feb 03, 2011 at 10:39:40AM -0600, Anthony Liguori wrote:
> On 02/02/2011 02:28 PM, Alon Levy wrote:
> >another callback added to PropertyInfo, for later use by PROP_TYPE_ENUM.
> >Allows printing of runtime computed options when doing:
> >  qemu -device foo,?
> >---
> >  hw/qdev.c |   10 +++++++++-
> >  hw/qdev.h |    1 +
> >  2 files changed, 10 insertions(+), 1 deletions(-)
> >
> >diff --git a/hw/qdev.c b/hw/qdev.c
> >index c7fec44..0b2ad3d 100644
> >--- a/hw/qdev.c
> >+++ b/hw/qdev.c
> >@@ -187,7 +187,15 @@ int qdev_device_help(QemuOpts *opts)
> >          if (!prop->info->parse) {
> >              continue;           /* no way to set it, don't show */
> >          }
> >-        error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
> >+        if (prop->info->print_options) {
> >+            char buf[256];
> >+            int ret;
> >+            ret = prop->info->print_options(info, prop, buf, sizeof(buf) - 3);
> >+            error_printf("%s.%s=%s%s\n", info->name, prop->name, buf,
> >+                ret == sizeof(buf) - 3 ? "..." : "" );
> >+        } else {
> >+            error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
> >+        }
> >      }
> >      return 1;
> >  }
> >diff --git a/hw/qdev.h b/hw/qdev.h
> >index 9808f85..fa3221b 100644
> >--- a/hw/qdev.h
> >+++ b/hw/qdev.h
> >@@ -109,6 +109,7 @@ struct PropertyInfo {
> >      enum PropertyType type;
> >      int (*parse)(DeviceState *dev, Property *prop, const char *str);
> >      int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
> >+    int (*print_options)(DeviceInfo *info, Property *prop, char *dest, size_t len);
> 
> I'm not clear what the different between print and print_options is
> and why two callbacks are needed.  Can you explain and comments to

There is a difference in usage - the existing print is called when we do info during
execution, it shows the status of the device. print_options is given a DeviceInfo
and not a DeviceState and responds with the list we print for a command line invocation:
"qemu -device foo,? ", It is used to allow possible options that depend on available
runtime libraries or other resources. It also allows relatively easy implementation for
data that could be known at compile time, like names for enums, used by the next patches.

> the patch clarifying why two interfaces are needed.  Even better
> would be if one interface could handle it.
> 
> Regards,
> 
> Anthony Liguori
> 
> 
> >      void (*free)(DeviceState *dev, Property *prop);
> >  };
> >
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-02-03 20:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-02 21:46 [Qemu-devel] [PATCH 01/20] qdev: add print_options callback Alon Levy
2011-02-03 10:21 ` Alon Levy
  -- strict thread matches above, loose matches on Subject: below --
2011-02-02 20:28 [Qemu-devel] [PATCH 00/20] usb-ccid (v16) Alon Levy
2011-02-02 20:28 ` [Qemu-devel] [PATCH 01/20] qdev: add print_options callback Alon Levy
2011-02-03 16:39   ` Anthony Liguori
2011-02-03 20:54     ` Alon Levy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).