<div dir="ltr"><div>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.<br>
</div>--Jason<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 19, 2014 at 12:26 PM, Neil Roberts <span dir="ltr"><<a href="mailto:neil@linux.intel.com" target="_blank">neil@linux.intel.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This adds a macro called WL_REQUEST_OPCODE which takes the name of the<br>
struct for the interface and the name of one of its members. It then<br>
calculates the opcode number by dividing the offsetof the member by<br>
the size of a function pointer. This assumes the interface struct only<br>
contains function pointers and that they are in order of the opcodes.<br>
---<br>
src/wayland-util.h | 12 ++++++++++++<br>
1 file changed, 12 insertions(+)<br>
<br>
diff --git a/src/wayland-util.h b/src/wayland-util.h<br>
index fd32826..480a887 100644<br>
--- a/src/wayland-util.h<br>
+++ b/src/wayland-util.h<br>
@@ -73,6 +73,18 @@ struct wl_interface {<br>
const struct wl_message *events;<br>
};<br>
<br>
+/**<br>
+ * Gets the opcode of a request from its interface struct<br>
+ *<br>
+ * Given the name of an interface struct an a request within it this<br>
+ * will return the opcode number. For example it can be used like<br>
+ * this:<br>
+ *<br>
+ * int opcode = WL_REQUEST_OPCODE(wl_region_interface, subtract);<br>
+ */<br>
+#define WL_REQUEST_OPCODE(interface, member) \<br>
+ (offsetof(struct interface, member) / sizeof (void (*) (void)))<br>
+<br>
/** \class wl_list<br>
*<br>
* \brief doubly-linked list<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.0<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div>