[PATCH wayland] client: add wl_proxy_get_class()
Pekka Paalanen
ppaalanen at gmail.com
Tue Feb 26 05:31:46 PST 2013
On Tue, 26 Feb 2013 15:19:44 +0200
Pekka Paalanen <ppaalanen at gmail.com> wrote:
> This is a useful shorthand for client application debugging macros,
> since you can ask the object class from the object itself.
>
> Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
> ---
> src/wayland-client.c | 12 ++++++++++++
> src/wayland-client.h | 1 +
> 2 files changed, 13 insertions(+)
>
> diff --git a/src/wayland-client.c b/src/wayland-client.c
> index 785f4ee..935e5f1 100644
> --- a/src/wayland-client.c
> +++ b/src/wayland-client.c
> @@ -1127,6 +1127,18 @@ wl_proxy_get_id(struct wl_proxy *proxy)
> return proxy->object.id;
> }
>
> +/** Get the interface name (class) of a proxy object
> + *
> + * \param proxy The proxy object
> + * \return The interface name of the object associated with the proxy
> + *
> + * \memberof wl_proxy
> + */
> +WL_EXPORT const char *
> +wl_proxy_get_class(struct wl_proxy *proxy)
> +{
> + return proxy->object.interface->name;
> +}
>
> /** Assign a proxy to an event queue
> *
> diff --git a/src/wayland-client.h b/src/wayland-client.h
> index 8b1fd0d..578fa7e 100644
> --- a/src/wayland-client.h
> +++ b/src/wayland-client.h
> @@ -131,6 +131,7 @@ int wl_proxy_add_listener(struct wl_proxy *proxy,
> void wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data);
> void *wl_proxy_get_user_data(struct wl_proxy *proxy);
> uint32_t wl_proxy_get_id(struct wl_proxy *proxy);
> +const char *wl_proxy_get_class(struct wl_proxy *proxy);
> void wl_proxy_set_queue(struct wl_proxy *proxy, struct wl_event_queue *queue);
>
> #include "wayland-client-protocol.h"
With this, I can do the following in a client:
static void
debug_print(void *proxy, int line, const char *func, const char *fmt, ...)
__attribute__ ((format (printf, 4, 5)));
static void
debug_print(void *proxy, int line, const char *func, const char *fmt, ...)
{
va_list ap;
struct timeval tv;
gettimeofday(&tv, NULL);
fprintf(stderr, "%8ld.%03ld ",
(long)tv.tv_sec & 0xffff, (long)tv.tv_usec / 1000);
if (proxy)
fprintf(stderr, "%s@%d ",
wl_proxy_get_class(proxy), wl_proxy_get_id(proxy));
/*fprintf(stderr, __FILE__ ":%d:%s ", line, func);*/
fprintf(stderr, "%s ", func);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
#define DBG(fmt, ...) \
debug_print(NULL, __LINE__, __func__, fmt, ##__VA_ARGS__)
#define DBG_OBJ(obj, fmt, ...) \
debug_print(obj, __LINE__, __func__, fmt, ##__VA_ARGS__)
Thanks,
pq
More information about the wayland-devel
mailing list