[PATCH 3/4] Add a macro to get the opcode number of a request given the interface

Jason Ekstrand jason at jlekstrand.net
Mon May 19 13:15:53 PDT 2014


Ooh, I like this.  I thought about having wayland-scanner emit more
#defines, but this works rather nicely.  One question: do we want it in
wayland-util or wayland-server?  Putting it in wayland-util exposes it
client-side as well.
--Jason


On Mon, May 19, 2014 at 12:26 PM, Neil Roberts <neil at linux.intel.com> wrote:

> This adds a macro called WL_REQUEST_OPCODE which takes the name of the
> struct for the interface and the name of one of its members. It then
> calculates the opcode number by dividing the offsetof the member by
> the size of a function pointer. This assumes the interface struct only
> contains function pointers and that they are in order of the opcodes.
> ---
>  src/wayland-util.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/src/wayland-util.h b/src/wayland-util.h
> index fd32826..480a887 100644
> --- a/src/wayland-util.h
> +++ b/src/wayland-util.h
> @@ -73,6 +73,18 @@ struct wl_interface {
>         const struct wl_message *events;
>  };
>
> +/**
> + * Gets the opcode of a request from its interface struct
> + *
> + * Given the name of an interface struct an a request within it this
> + * will return the opcode number. For example it can be used like
> + * this:
> + *
> + * int opcode = WL_REQUEST_OPCODE(wl_region_interface, subtract);
> + */
> +#define WL_REQUEST_OPCODE(interface, member) \
> +       (offsetof(struct interface, member) / sizeof (void (*) (void)))
> +
>  /** \class wl_list
>   *
>   * \brief doubly-linked list
> --
> 1.9.0
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20140519/9c3c4a71/attachment.html>


More information about the wayland-devel mailing list