client: Keep track of proxy validity and number of reference holders

When events are queued, the associated proxy objects (target proxy and
potentially closure argument proxies) are verified being valid. However,
as any event may destroy some proxy object, validity needs to be
verified again before dispatching. Before this change this was done by
again looking up the object via the display object map, but that did not
work because a delete_id event could be dispatched out-of-order if it
was queued in another queue, causing the object map to either have a new
proxy object with the same id or none at all, had it been destroyed in
an earlier event in the queue.

Instead, make wl_proxy reference counted and increase the reference
counter of every object associated with an event when it is queued. In
wl_proxy_destroy() set a flag saying the proxy has been destroyed by the
application and only free the proxy if the reference counter reaches
zero after decreasing it.

Before dispatching, verify that a proxy object still is valid by
checking that the flag set in wl_proxy_destroy() has not been set. When
dequeuing the event, all associated proxy objects are dereferenced and
free:ed if the reference counter reaches zero. As proxy reference counter
is initiated to 1, when dispatching an event it can never reach zero
without having the destroyed flag set.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
tests: Add queue test case

Check that after a callback removes a proxy that most likely will have
several events queued up with the same target proxy, no more callbacks
are invoked.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
tests: Use a pipe for synchronization to avoid potential deadlock

Using signals in the previous way could potentially lead to dead locks
if the SIGCONT was signalled before a listener was registered.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
tests: Add out of order delete_id queue tests

Verify that when receiving the first of two synchronization callback
events, destroying the second one doesn't cause any errors even if the
delete_id event is handled out of order.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
doc: doxygen: Interpret the first line comment as the brief

Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
doc: Auto-generate API methods and classes documentation

There's work to do still for giving a prettier style on the documentation, for
instance splitting paragraphs correctly and printing the detailed description
of the methods as well.

Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
doc: Remove unused css and xslt for the protocol

This was added previously (commit 015c42e1) when we didn't have docbook
formatted documentation. Now it became quite useless.

Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
doc: Set publican to quiet mode

Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
doc: Update .gitignore

Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
doc: Fix incorrectly formatted section header

https://bugs.freedesktop.org/show_bug.cgi?id=56719

Reported-by: Petr Gladkikh <PetrGlad@gmail.com>
Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
client: Fix source comment typos
protocol: Add summary description for wl_data_device_manager
protocol: Fix copy and paste summary
Fix distcheck by adding back protocol/Makefile.am

5909dddc78573774bd3a93c280831a7d18d82994 removed protocol/Makefile.am
which meant protocol/wayland.xml no longer got included in the tarball.
Add back protocol/Makefile.am and configure.ac bits and add protocol to
subdirs in Makefile.am to fix this.
doc: Fix out-of-source build so distcheck works again

The amount of generated files and hacks over hacks in the doc/ directory
is getting out of hand and we need a better solution.  For now, just get
distcheck back to working.
configure.ac: Bump version to 1.0.1
debug: Allow WAYLAND_DEBUG=server/client for server/client side only debug

By default the server will dump protocol for both the server and its
clients when run with WAYLAND_DEBUG=1.  That's still the case, but it now
also understands WAYLAND_DEBUG=client or WAYLAND_DEBUG=server, which
will only enable debug dumping on either client or server side.
client: Add an entry point for dispatching a queue without blocking

On the client side EGL, all the wl_buffer.release events need to be
processed before buffer allocation, otherwise a third buffer might
be allocated unnecessarily. However, the buffer allocation should
not block in the case no event was received. In order to do that, a
non-blocking queue dispatch function is needed.
doc: Fix typos

Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
client: Don't cancel a roundtrip when any event is received

Since wl_display_dispatch() returns the number of processed events or -1
on error, only cancel the roundtrip if an -1 is returned.

This also fixes a potential memory corruption bug happening when
wl_display_roundtrip() does an early return and the callback later
writes to the then out of scope stack allocated `done' parameter.

Introduced by 33b7637b4500a682018b503837b8aca9afae36f2.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>