wayland: bump required version to 1.10
[mesa-waffle.git] / src / waffle / wayland / wayland_wrapper.c
blob06fa3364d8209e9a85d08c20d3efa96ce8adfa7d
1 // Copyright 2015 Emil Velikov
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // - Redistributions of source code must retain the above copyright notice, this
9 // list of conditions and the following disclaimer.
11 // - Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 /// @file
27 /// @brief Wrappers for Wayland-client functions
28 ///
29 /// Many of the wayland functions are defined as static inline within the
30 /// public headers. In order to avoid the static(link-time) dependency, we
31 /// provide the required symbols with this file.
32 ///
33 /// This is achieved by declaring wrapper functions, around which we define the
34 /// needed (base) wayland ones. After that we include the public header, at
35 /// which point the pre-processor/compiler will use our defines.
36 ///
37 /// Each wrapper is initialised via dlsym to retrieve the relevant symbol from
38 /// the library libwayland-client.so.0
41 #include <stdbool.h>
42 #include <dlfcn.h>
44 #include "wcore_error.h"
46 #include "wayland_wrapper.h"
48 // dlopen handle for libwayland-client.so.0
49 static void *dl_wl_client;
51 static const char *libwl_client_filename = "libwayland-client.so.0";
53 bool
54 wayland_wrapper_teardown(void)
56 bool ok = true;
57 int error;
59 if (dl_wl_client) {
60 error = dlclose(dl_wl_client);
61 if (error) {
62 ok &= false;
63 wcore_errorf(WAFFLE_ERROR_UNKNOWN,
64 "dlclose(\"%s\") failed: %s",
65 libwl_client_filename, dlerror());
69 return ok;
72 bool
73 wayland_wrapper_init(void)
75 bool ok = true;
77 dl_wl_client = dlopen(libwl_client_filename, RTLD_LAZY | RTLD_LOCAL);
78 if (!dl_wl_client) {
79 wcore_errorf(WAFFLE_ERROR_FATAL,
80 "dlopen(\"%s\") failed: %s",
81 libwl_client_filename, dlerror());
82 ok = false;
83 goto error;
86 #define RETRIEVE_WL_CLIENT_SYMBOL(S) \
87 wfl_##S = (__typeof__(wfl_##S))dlsym(dl_wl_client, #S); \
88 if (!wfl_##S) { \
89 wcore_errorf(WAFFLE_ERROR_FATAL, \
90 "dlsym(\"%s\", \"" #S "\") failed: %s", \
91 libwl_client_filename, dlerror()); \
92 ok = false; \
93 goto error; \
96 RETRIEVE_WL_CLIENT_SYMBOL(wl_compositor_interface);
97 RETRIEVE_WL_CLIENT_SYMBOL(wl_registry_interface);
98 RETRIEVE_WL_CLIENT_SYMBOL(wl_shell_interface);
99 RETRIEVE_WL_CLIENT_SYMBOL(wl_shell_surface_interface);
100 RETRIEVE_WL_CLIENT_SYMBOL(wl_surface_interface);
102 RETRIEVE_WL_CLIENT_SYMBOL(wl_display_connect);
103 RETRIEVE_WL_CLIENT_SYMBOL(wl_display_disconnect);
104 RETRIEVE_WL_CLIENT_SYMBOL(wl_display_roundtrip);
105 RETRIEVE_WL_CLIENT_SYMBOL(wl_proxy_destroy);
106 RETRIEVE_WL_CLIENT_SYMBOL(wl_proxy_add_listener);
107 RETRIEVE_WL_CLIENT_SYMBOL(wl_proxy_marshal);
108 RETRIEVE_WL_CLIENT_SYMBOL(wl_proxy_marshal_constructor);
109 RETRIEVE_WL_CLIENT_SYMBOL(wl_proxy_marshal_constructor_versioned);
110 #undef RETRIEVE_WL_CLIENT_SYMBOL
112 error:
113 // On failure the caller of wayland_wrapper_init will trigger it's own
114 // destruction which will execute wayland_wrapper_teardown.
115 return ok;