1 /+
2  +  Copyright © 2015 Rémi Thebault
3  +
4  +  Permission is hereby granted, free of charge, to any person
5  +  obtaining a copy of this software and associated documentation files
6  +  (the "Software"), to deal in the Software without restriction,
7  +  including without limitation the rights to use, copy, modify, merge,
8  +  publish, distribute, sublicense, and/or sell copies of the Software,
9  +  and to permit persons to whom the Software is furnished to do so,
10  +  subject to the following conditions:
11  +
12  +  The above copyright notice and this permission notice (including the
13  +  next paragraph) shall be included in all copies or substantial
14  +  portions of the Software.
15  +
16  +  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  +  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  +  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  +  NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  +  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  +  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  +  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  +  SOFTWARE.
24  +/
25 module wayland.client.dy_loader;
26 
27 
28 version (Dynamic) {
29 
30     import derelict.util.loader;
31     import wayland.client.util;
32     import wayland.client.core;
33     import ifaces = wayland.client.ifaces;
34     import wayland.client.egl;
35 
36 
37     private __gshared WaylandClientLoader clientLoader;
38     private __gshared WaylandEglLoader eglLoader;
39 
40 
41     enum wld_client_lib_name = "libwayland-client.so";
42 
43     public void loadWaylandClient() {
44         if (clientLoader) return;
45 
46         clientLoader = new WaylandClientLoader(wld_client_lib_name);
47         clientLoader.load();
48     }
49 
50 
51     enum wld_egl_lib_name = "libwayland-egl.so";
52 
53     public void loadWaylandEgl() {
54         if (eglLoader) return;
55 
56         eglLoader = new WaylandEglLoader(wld_egl_lib_name);
57         eglLoader.load();
58     }
59 
60 
61     version (unittest) {
62         shared static this() {
63             loadWaylandClient();
64         }
65     }
66 
67     private class WaylandClientLoader : ifaces.WaylandClientLoader
68     {
69         public this(string libName) {
70             super(libName);
71         }
72 
73         protected override void loadSymbols() {
74 
75             super.loadSymbols();
76 
77             bindFunc( cast( void** )&wl_list_init, "wl_list_init");
78             bindFunc( cast( void** )&wl_list_insert, "wl_list_insert");
79             bindFunc( cast( void** )&wl_list_length, "wl_list_length");
80             bindFunc( cast( void** )&wl_list_empty, "wl_list_empty");
81             bindFunc( cast( void** )&wl_list_remove, "wl_list_remove");
82             bindFunc( cast( void** )&wl_list_insert_list, "wl_list_insert_list");
83 
84             bindFunc( cast( void** )&wl_array_init, "wl_array_init");
85             bindFunc( cast( void** )&wl_array_release, "wl_array_release");
86             bindFunc( cast( void** )&wl_array_add, "wl_array_add");
87             bindFunc( cast( void** )&wl_array_copy, "wl_array_copy");
88 
89             bindFunc( cast( void** )&wl_event_queue_destroy, "wl_event_queue_destroy");
90 
91             bindFunc( cast( void** )&wl_proxy_marshal, "wl_proxy_marshal");
92             bindFunc( cast( void** )&wl_proxy_marshal_array, "wl_proxy_marshal_array");
93             bindFunc( cast( void** )&wl_proxy_create, "wl_proxy_create");
94             bindFunc( cast( void** )&wl_proxy_marshal_constructor, "wl_proxy_marshal_constructor");
95             bindFunc( cast( void** )&wl_proxy_marshal_array_constructor, "wl_proxy_marshal_array_constructor");
96             bindFunc( cast( void** )&wl_proxy_destroy, "wl_proxy_destroy");
97             bindFunc( cast( void** )&wl_proxy_add_listener, "wl_proxy_add_listener");
98             bindFunc( cast( void** )&wl_proxy_get_listener, "wl_proxy_get_listener");
99             bindFunc( cast( void** )&wl_proxy_add_dispatcher, "wl_proxy_add_dispatcher");
100             bindFunc( cast( void** )&wl_proxy_set_user_data, "wl_proxy_set_user_data");
101             bindFunc( cast( void** )&wl_proxy_get_user_data, "wl_proxy_get_user_data");
102             bindFunc( cast( void** )&wl_proxy_get_id, "wl_proxy_get_id");
103             bindFunc( cast( void** )&wl_proxy_get_class, "wl_proxy_get_class");
104             bindFunc( cast( void** )&wl_proxy_set_queue, "wl_proxy_set_queue");
105 
106             bindFunc( cast( void** )&wl_display_connect, "wl_display_connect");
107             bindFunc( cast( void** )&wl_display_connect_to_fd, "wl_display_connect_to_fd");
108             bindFunc( cast( void** )&wl_display_disconnect, "wl_display_disconnect");
109             bindFunc( cast( void** )&wl_display_get_fd, "wl_display_get_fd");
110             bindFunc( cast( void** )&wl_display_dispatch, "wl_display_dispatch");
111             bindFunc( cast( void** )&wl_display_dispatch_queue, "wl_display_dispatch_queue");
112             bindFunc( cast( void** )&wl_display_dispatch_queue_pending, "wl_display_dispatch_queue_pending");
113             bindFunc( cast( void** )&wl_display_dispatch_pending, "wl_display_dispatch_pending");
114             bindFunc( cast( void** )&wl_display_get_error, "wl_display_get_error");
115             bindFunc( cast( void** )&wl_display_get_protocol_error, "wl_display_get_protocol_error");
116             bindFunc( cast( void** )&wl_display_flush, "wl_display_flush");
117             bindFunc( cast( void** )&wl_display_roundtrip_queue, "wl_display_roundtrip_queue");
118             bindFunc( cast( void** )&wl_display_roundtrip, "wl_display_roundtrip");
119             bindFunc( cast( void** )&wl_display_create_queue, "wl_display_create_queue");
120             bindFunc( cast( void** )&wl_display_prepare_read_queue, "wl_display_prepare_read_queue");
121             bindFunc( cast( void** )&wl_display_prepare_read, "wl_display_prepare_read");
122             bindFunc( cast( void** )&wl_display_cancel_read, "wl_display_cancel_read");
123             bindFunc( cast( void** )&wl_display_read_events, "wl_display_read_events");
124 
125             bindFunc( cast( void** )&wl_log_set_handler_client, "wl_log_set_handler_client");
126 
127         }
128     }
129 
130     private class WaylandEglLoader : SharedLibLoader
131     {
132         public this(string libName) {
133             super(libName);
134         }
135 
136         protected override void loadSymbols() {
137 
138             bindFunc( cast( void** )&wl_egl_window_create, "wl_egl_window_create");
139             bindFunc( cast( void** )&wl_egl_window_destroy, "wl_egl_window_destroy");
140             bindFunc( cast( void** )&wl_egl_window_resize, "wl_egl_window_resize");
141             bindFunc( cast( void** )&wl_egl_window_get_attached_size,
142                                     "wl_egl_window_get_attached_size");
143 
144         }
145     }
146 
147 
148 }