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 <n...@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@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/wayland-devel >
_______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel