<p dir="ltr">Hi pq,<br>
I'm sorry for replying late.</p>
<p dir="ltr">The reasons why I tried to add are following.<br>
- If a wl_client is able to has a user data, <br>
  a wayland server can use it for storing the client specific data such as security privilege, the result of privilege check, and other things.<br>
  Those kinds of data are the client specific and need to be removed when the client is gone.<br>
In this case, it'll be better to use wl_client' user data as a data storage other than storing those information in the server's data.<br>
- There was a guy who wants to have tyis kind of APIs. (As I remember, he is nicesj.)<br>
- There was a reply for the above request and It seemed positive to me.</p>
<p dir="ltr">If this can be merged into the stream, it'll be good for me and other guys who wants to find this out. :)</p>
<p dir="ltr">Thanks and regards,<br>
Sung-Jin Park<br>
</p>
<div class="gmail_quote">2016. 2. 11. 오후 7:08에 "Pekka Paalanen" <<a href="mailto:ppaalanen@gmail.com">ppaalanen@gmail.com</a>>님이 작성:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I think we should think this a little more.<br>
<br>
There is no absolute requirement to add a user_data member to<br>
wl_client, because you can use a destroy listener to look up your user<br>
data struct. When you attach user data, you also want to always be<br>
notified about wl_client destruction, which means you always have a<br>
destroy listener.<br>
<br>
The downside of using a destroy listener to look up your user data<br>
struct is that it is an O(number of destroy listeners) operation rather<br>
than O(1), but usually that number should be 1 or 2 I think, your user<br>
data destructor included.<br>
<br>
So the first question is, is this really worthwhile?<br>
<br>
For comparison to another related patch, adding the client created<br>
signal is obviously worthwhile, since there is no other sure way to be<br>
notified about new wl_clients.<br>
<br>
Then let's assume user_data for wl_client is worthwhile. The closest<br>
example of a server-side structure with user data is wl_resource.<br>
wl_resource also has an explicit wl_resource_destroy_func_t member, and<br>
the rationale is clear: if you add user data, you want to be able to<br>
tear down the user data at the right time, so you always need a way to<br>
be notified about destruction.<br>
<br>
The second question is, should also wl_client have an explicit user<br>
data destructor function? If yes, you have to add API for it.<br>
<br>
The third question is: do all wl_client objects have the same single<br>
owner?<br>
<br>
The owner problem is particularly visible in the client side with<br>
wl_proxy, which also has a single user data member of type void<br>
pointer. This creates two problems:<br>
<br>
- If wl_proxy should have more than one user data attached, only one of<br>
  them can use the user data member and the others must use the<br>
  destructor trick anyway - oops, wl_proxy does not have a destroy<br>
  signal, but at least wl_client does.<br>
<br>
- It is not always obvious who owns the user data. If there are more<br>
  than one component that assume they own the wl_proxy and its user<br>
  data, then passing the wl_proxy to another component that also<br>
  assumes the same causes the other component to access not the data it<br>
  thinks it gets.<br>
<br>
The latter problem is especially dangerous when an application is<br>
sharing the same connection with multiple toolkits. Both toolkits may<br>
create wl_surface objects and naturally put their own pointer in the<br>
wl_proxy user data field. They also listen for input events, and input<br>
events carry a reference to a wl_surface. Therefore, a toolkit may<br>
receive a wl_proxy with the other toolkit's user data, and crash or<br>
misbehave due to assuming it is its own.<br>
<br>
In the wl_client case, I think the owner issue should be negligible,<br>
there is always one obvious owner for the wl_client and its user data -<br>
or that is what I assume, as I haven't read any other compositor code<br>
than Weston's.<br>
<br>
In summary, while there is technically nothing wrong with this idea per<br>
se, I do wonder if it is a net win.<br>
<br>
I believe that if there is a dedicated user data slot, there should<br>
also be a dedicated destructor function slot for it.<br>
<br>
What do others think? I could go either way.<br>
<br>
<br>
On Wed, 27 Jan 2016 19:34:56 +0900<br>
Sung-Jin Park <<a href="mailto:sj76.park@samsung.com">sj76.park@samsung.com</a>> wrote:<br>
<br>
> Signed-off-by: Sung-Jin Park <<a href="mailto:sj76.park@samsung.com">sj76.park@samsung.com</a>><br>
> ---<br>
>  src/wayland-server-core.h |  6 ++++++<br>
>  src/wayland-server.c      | 13 +++++++++++++<br>
>  2 files changed, 19 insertions(+)<br>
><br>
> diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h<br>
> index e8e1e9c..6990423 100644<br>
> --- a/src/wayland-server-core.h<br>
> +++ b/src/wayland-server-core.h<br>
> @@ -186,6 +186,12 @@ int<br>
>  wl_client_get_fd(struct wl_client *client);<br>
><br>
>  void<br>
> +wl_client_set_user_data(struct wl_client *client, void *data);<br>
> +<br>
> +void *<br>
> +wl_client_get_user_data(struct wl_client *client);<br>
> +<br>
> +void<br>
>  wl_client_add_destroy_listener(struct wl_client *client,<br>
>                              struct wl_listener *listener);<br>
><br>
> diff --git a/src/wayland-server.c b/src/wayland-server.c<br>
> index 6654cd7..e7a6eae 100644<br>
> --- a/src/wayland-server.c<br>
> +++ b/src/wayland-server.c<br>
> @@ -81,6 +81,7 @@ struct wl_client {<br>
>       struct wl_signal destroy_signal;<br>
>       struct ucred ucred;<br>
>       int error;<br>
> +     void *data;<br>
<br>
Please name this user_data.<br>
<br>
>  };<br>
><br>
>  struct wl_display {<br>
> @@ -526,6 +527,18 @@ wl_client_get_fd(struct wl_client *client)<br>
>       return wl_connection_get_fd(client->connection);<br>
>  }<br>
><br>
> +WL_EXPORT void<br>
> +wl_client_set_user_data(struct wl_client *client, void *data)<br>
> +{<br>
> +     client->data = data;<br>
> +}<br>
> +<br>
> +WL_EXPORT void *<br>
> +wl_client_get_user_data(struct wl_client *client)<br>
> +{<br>
> +     return client->data;<br>
> +}<br>
<br>
Documentation is missing.<br>
<br>
> +<br>
>  /** Look up an object in the client name space<br>
>   *<br>
>   * \param client The client object<br>
<br>
Thanks<br>
pq<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="https://lists.freedesktop.org/mailman/listinfo/wayland-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
<br></blockquote></div>