[PATCH wayland] server: add helper functions for wl_global

Derek Foreman derekf at osg.samsung.com
Mon Feb 23 09:26:33 PST 2015


I think \return should be used to document the return values.

After that,

Reviewed-by: Derek Foreman <derekf at osg.samsung.com>

On 23/02/15 11:22 AM, Jonny Lamb wrote:
> The intention here is to be able to find an existing wl_global using
> some search parameters and then get some information about it.
> ---
>  src/wayland-server.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/wayland-server.h |  4 ++++
>  2 files changed, 62 insertions(+)
> 
> diff --git a/src/wayland-server.c b/src/wayland-server.c
> index 0558634..035b9f0 100644
> --- a/src/wayland-server.c
> +++ b/src/wayland-server.c
> @@ -945,6 +945,64 @@ wl_global_destroy(struct wl_global *global)
>  	free(global);
>  }
>  
> +/** Get the data associated with the wl_global
> + *
> + * \param global The wl_global object
> + *
> + * This function returns the data associated with the wl_global.
> + *
> + * \memberof wl_global
> + */
> +WL_EXPORT void *
> +wl_global_get_data(struct wl_global *global)
> +{
> +	return global->data;
> +}
> +
> +/** Find a wl_global given search parameters
> + *
> + * \param display The display object
> + * \param interface The interface to match, or NULL
> + * \param version The version to match, or 0
> + * \param data The user data to match, or NULL
> + * \param bind The function used to bind the object, or NULL
> + *
> + * The global list of a wl_display is not public so this function helps in
> + * finding a specific wl_global based on the parameters. Parameters can be
> + * missing for a broader search (NULL for interface, data, and bind, and 0 for
> + * version) but at least one must be present or no result will be returned.
> + *
> + * If no matching wl_global is found, NULL is returned.
> + *
> + * \memberof wl_global
> + */
> +WL_EXPORT struct wl_global *
> +wl_global_find(struct wl_display *display,
> +	const struct wl_interface *interface, uint32_t version,
> +	void *data, wl_global_bind_func_t bind)
> +{
> +	struct wl_global *global;
> +
> +	/* return with nothing if we have no search parameters */
> +	if (interface == NULL && version == 0 && data == NULL && bind == NULL)
> +		return NULL;
> +
> +	wl_list_for_each(global, &display->global_list, link) {
> +		if (interface != NULL && global->interface != interface)
> +			continue;
> +		if (version != 0 && global->version != version)
> +			continue;
> +		if (data != NULL && global->data != data)
> +			continue;
> +		if (bind != NULL && global->bind != bind)
> +			continue;
> +
> +		return global;
> +	}
> +
> +	return NULL;
> +}
> +
>  /** Get the current serial number
>   *
>   * \param display The display object
> diff --git a/src/wayland-server.h b/src/wayland-server.h
> index af2f03d..05449dc 100644
> --- a/src/wayland-server.h
> +++ b/src/wayland-server.h
> @@ -113,6 +113,10 @@ struct wl_global *wl_global_create(struct wl_display *display,
>  				   int version,
>  				   void *data, wl_global_bind_func_t bind);
>  void wl_global_destroy(struct wl_global *global);
> +void *wl_global_get_data(struct wl_global *global);
> +struct wl_global *wl_global_find(struct wl_display *display,
> +	const struct wl_interface *interface, uint32_t version,
> +	void *data, wl_global_bind_func_t bind);
>  
>  struct wl_client *wl_client_create(struct wl_display *display, int fd);
>  void wl_client_destroy(struct wl_client *client);
> 



More information about the wayland-devel mailing list