Skip to content

Introduce client message observers

Lloyd Pique requested to merge lpique/wayland:client_message_observer into main

Client message observers are very much like the server protocol logging callbacks added in commit 450f06e2, except they are for the client, and they include a "discarded_reason" code for events that were undeliverable.

The primary use case and motivation of the client observer interface is to allow the client code to log someplace other than stderr if it wants. In my case I would want to log to the Android logcat service, to go along with other higher-level messages from the client.

The existing protocol-logger-test.c was refactored and extended to cover the various client observer cases, as they are also useful in tests, and to demonstrate how to use the client observer API for logging, replicating the logging done by wayland-client.c when debug_client is set.

This logging required a potentially unsafe cast. For the arguments passed to both the server and client logging interfaces, the "args[i].o" is an opaque wl_object* type. To get more useful information (object id, class name) to replicate the details printed by wl_closure_print, this needed to be cast to a wl_resource* (server) or wl_proxy* (client). To make this conversion safer, one of the patches adds a wl_resource_from_object() helper function, and a separate one adds a wl_proxy_from_object() helper function.

Along the way I also found that server created interfaces, such as the wl_data_offer created by the wl_data_device::data_offer event, would leak if the event wasn't listened for, or if the receiving interface was destroyed before dispatch occurred. The final patch in this chain fixes that, and adjusts the expectations of the tests which caught the leak, as it also detects a different reason for the event being discarded.

Merge request reports