Merge lp:~alan-griffiths/mir/dlopen-graphicsplatform into lp:~mir-team/mir/trunk
- dlopen-graphicsplatform
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Kevin DuBois |
Approved revision: | no longer in the source branch. |
Merged at revision: | 767 |
Proposed branch: | lp:~alan-griffiths/mir/dlopen-graphicsplatform |
Merge into: | lp:~mir-team/mir/trunk |
Diff against target: |
514 lines (+260/-24) 16 files modified
CMakeLists.txt (+1/-1) debian/libmirserver0.install (+1/-0) examples/render_to_fb.cpp (+4/-1) include/server/mir/graphics/platform.h (+4/-4) include/server/mir/shared_library.h (+55/-0) src/server/CMakeLists.txt (+3/-1) src/server/default_server_configuration.cpp (+5/-7) src/server/graphics/CMakeLists.txt (+2/-1) src/server/graphics/android/CMakeLists.txt (+5/-2) src/server/graphics/android/android_platform.cpp (+3/-3) src/server/graphics/gbm/CMakeLists.txt (+4/-3) src/server/graphics/gbm/gbm_platform.cpp (+1/-1) src/server/shared_library.cpp (+55/-0) tests/integration-tests/CMakeLists.txt (+1/-0) tests/unit-tests/CMakeLists.txt (+2/-0) tests/unit-tests/shared_library_test.cpp (+114/-0) |
To merge this branch: | bzr merge lp:~alan-griffiths/mir/dlopen-graphicsplatform |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Kevin DuBois (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Alexandros Frantzis (community) | Approve | ||
Review via email: mp+170797@code.launchpad.net |
Commit message
graphics, config: Dynamically load the graphics platform
Description of the change
graphics, config: Dynamically load the graphics platform
Will follow up with MP to make the library configurable
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:772
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:773
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:774
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2013-06-19 09:57:32 +0000 | |||
3 | +++ CMakeLists.txt 2013-06-21 15:26:27 +0000 | |||
4 | @@ -42,7 +42,7 @@ | |||
5 | 42 | include (cmake/PrePush.cmake) | 42 | include (cmake/PrePush.cmake) |
6 | 43 | 43 | ||
7 | 44 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Werror -Wall -pedantic -Wextra -fPIC") | 44 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Werror -Wall -pedantic -Wextra -fPIC") |
9 | 45 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++0x -Werror -Wall -fno-strict-aliasing -pedantic -Wnon-virtual-dtor -Wextra -fPIC") | 45 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++0x -Werror -Wall -fno-strict-aliasing -pedantic -Wnon-virtual-dtor -Wextra -fPIC -Wno-return-type-c-linkage") |
10 | 46 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") | 46 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") |
11 | 47 | 47 | ||
12 | 48 | ##################################################################### | 48 | ##################################################################### |
13 | 49 | 49 | ||
14 | === modified file 'debian/libmirserver0.install' | |||
15 | --- debian/libmirserver0.install 2013-05-22 10:24:51 +0000 | |||
16 | +++ debian/libmirserver0.install 2013-06-21 15:26:27 +0000 | |||
17 | @@ -1,2 +1,3 @@ | |||
18 | 1 | usr/lib/libmirserver.so.* | 1 | usr/lib/libmirserver.so.* |
19 | 2 | usr/lib/libmirplatformgraphics.so* | ||
20 | 2 | usr/lib/libmirserverlttng.so | 3 | usr/lib/libmirserverlttng.so |
21 | 3 | 4 | ||
22 | === modified file 'examples/render_to_fb.cpp' | |||
23 | --- examples/render_to_fb.cpp 2013-06-20 02:16:09 +0000 | |||
24 | +++ examples/render_to_fb.cpp 2013-06-21 15:26:27 +0000 | |||
25 | @@ -16,6 +16,7 @@ | |||
26 | 16 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> | 16 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> |
27 | 17 | */ | 17 | */ |
28 | 18 | 18 | ||
29 | 19 | #include "mir/shared_library.h" | ||
30 | 19 | #include "mir/graphics/platform.h" | 20 | #include "mir/graphics/platform.h" |
31 | 20 | #include "mir/graphics/display.h" | 21 | #include "mir/graphics/display.h" |
32 | 21 | #include "mir/graphics/display_buffer.h" | 22 | #include "mir/graphics/display_buffer.h" |
33 | @@ -56,8 +57,10 @@ | |||
34 | 56 | sigaction(SIGINT, &sa, NULL); | 57 | sigaction(SIGINT, &sa, NULL); |
35 | 57 | sigaction(SIGTERM, &sa, NULL); | 58 | sigaction(SIGTERM, &sa, NULL); |
36 | 58 | 59 | ||
37 | 60 | mir::SharedLibrary libmirplatformgraphics("libmirplatformgraphics.so"); | ||
38 | 59 | auto logger = std::make_shared<ml::DumbConsoleLogger>(); | 61 | auto logger = std::make_shared<ml::DumbConsoleLogger>(); |
40 | 60 | auto platform = mg::create_platform(std::make_shared<mo::ProgramOption>(), std::make_shared<ml::DisplayReport>(logger)); | 62 | auto report = std::make_shared<ml::DisplayReport>(logger); |
41 | 63 | auto platform = libmirplatformgraphics.load_function<mg::CreatePlatform>("create_platform")(std::make_shared<mo::ProgramOption>(), report); | ||
42 | 61 | auto display = platform->create_display(); | 64 | auto display = platform->create_display(); |
43 | 62 | 65 | ||
44 | 63 | mir::draw::glAnimationBasic gl_animation; | 66 | mir::draw::glAnimationBasic gl_animation; |
45 | 64 | 67 | ||
46 | === modified file 'include/server/mir/graphics/platform.h' | |||
47 | --- include/server/mir/graphics/platform.h 2013-06-20 23:34:40 +0000 | |||
48 | +++ include/server/mir/graphics/platform.h 2013-06-21 15:26:27 +0000 | |||
49 | @@ -101,7 +101,7 @@ | |||
50 | 101 | */ | 101 | */ |
51 | 102 | virtual void fill_ipc_package(std::shared_ptr<compositor::BufferIPCPacker> const& packer, | 102 | virtual void fill_ipc_package(std::shared_ptr<compositor::BufferIPCPacker> const& packer, |
52 | 103 | std::shared_ptr<compositor::Buffer> const& buffer) const = 0; | 103 | std::shared_ptr<compositor::Buffer> const& buffer) const = 0; |
54 | 104 | 104 | ||
55 | 105 | /** | 105 | /** |
56 | 106 | * Creates the in-process client support object. | 106 | * Creates the in-process client support object. |
57 | 107 | */ | 107 | */ |
58 | @@ -109,7 +109,7 @@ | |||
59 | 109 | }; | 109 | }; |
60 | 110 | 110 | ||
61 | 111 | /** | 111 | /** |
63 | 112 | * Creates and returns a new graphics platform. | 112 | * Function prototype used to return a new graphics platform. |
64 | 113 | * | 113 | * |
65 | 114 | * \param [in] options options to use for this platform | 114 | * \param [in] options options to use for this platform |
66 | 115 | * \param [in] report the object to use to report interesting events from the display subsystem | 115 | * \param [in] report the object to use to report interesting events from the display subsystem |
67 | @@ -118,8 +118,8 @@ | |||
68 | 118 | * | 118 | * |
69 | 119 | * \ingroup platform_enablement | 119 | * \ingroup platform_enablement |
70 | 120 | */ | 120 | */ |
73 | 121 | std::shared_ptr<Platform> create_platform(std::shared_ptr<options::Option> const& options, std::shared_ptr<DisplayReport> const& report); | 121 | extern "C" typedef std::shared_ptr<Platform>(*CreatePlatform)(std::shared_ptr<options::Option> const& options, std::shared_ptr<DisplayReport> const& report); |
74 | 122 | 122 | extern "C" std::shared_ptr<Platform> create_platform (std::shared_ptr<options::Option> const& options, std::shared_ptr<DisplayReport> const& report); | |
75 | 123 | } | 123 | } |
76 | 124 | } | 124 | } |
77 | 125 | 125 | ||
78 | 126 | 126 | ||
79 | === added file 'include/server/mir/shared_library.h' | |||
80 | --- include/server/mir/shared_library.h 1970-01-01 00:00:00 +0000 | |||
81 | +++ include/server/mir/shared_library.h 2013-06-21 15:26:27 +0000 | |||
82 | @@ -0,0 +1,55 @@ | |||
83 | 1 | /* | ||
84 | 2 | * Copyright © 2013 Canonical Ltd. | ||
85 | 3 | * | ||
86 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
87 | 5 | * under the terms of the GNU General Public License version 3, | ||
88 | 6 | * as published by the Free Software Foundation. | ||
89 | 7 | * | ||
90 | 8 | * This program is distributed in the hope that it will be useful, | ||
91 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
92 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
93 | 11 | * GNU General Public License for more details. | ||
94 | 12 | * | ||
95 | 13 | * You should have received a copy of the GNU General Public License | ||
96 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
97 | 15 | * | ||
98 | 16 | * Authored by: Alan Griffiths <alan@octopull.co.uk> | ||
99 | 17 | */ | ||
100 | 18 | |||
101 | 19 | #ifndef MIR_SHARED_LIBRARY_H_ | ||
102 | 20 | #define MIR_SHARED_LIBRARY_H_ | ||
103 | 21 | |||
104 | 22 | #include <string> | ||
105 | 23 | |||
106 | 24 | namespace mir | ||
107 | 25 | { | ||
108 | 26 | class SharedLibrary | ||
109 | 27 | { | ||
110 | 28 | public: | ||
111 | 29 | explicit SharedLibrary(char const* library_name); | ||
112 | 30 | explicit SharedLibrary(std::string const& library_name); | ||
113 | 31 | ~SharedLibrary(); | ||
114 | 32 | |||
115 | 33 | template<typename FunctionPtr> | ||
116 | 34 | FunctionPtr load_function(char const* function_name) const | ||
117 | 35 | { | ||
118 | 36 | FunctionPtr result{}; | ||
119 | 37 | (void*&)result = load_symbol(function_name); | ||
120 | 38 | return result; | ||
121 | 39 | } | ||
122 | 40 | |||
123 | 41 | template<typename FunctionPtr> | ||
124 | 42 | FunctionPtr load_function(std::string const& function_name) const | ||
125 | 43 | { | ||
126 | 44 | return load_function<FunctionPtr>(function_name.c_str()); | ||
127 | 45 | } | ||
128 | 46 | private: | ||
129 | 47 | void* const so; | ||
130 | 48 | void* load_symbol(char const* function_name) const; | ||
131 | 49 | SharedLibrary(SharedLibrary const&) = delete; | ||
132 | 50 | SharedLibrary& operator=(SharedLibrary const&) = delete; | ||
133 | 51 | }; | ||
134 | 52 | } | ||
135 | 53 | |||
136 | 54 | |||
137 | 55 | #endif /* MIR_SHARED_LIBRARY_H_ */ | ||
138 | 0 | 56 | ||
139 | === modified file 'src/server/CMakeLists.txt' | |||
140 | --- src/server/CMakeLists.txt 2013-06-03 08:14:01 +0000 | |||
141 | +++ src/server/CMakeLists.txt 2013-06-21 15:26:27 +0000 | |||
142 | @@ -28,6 +28,7 @@ | |||
143 | 28 | display_server.cpp | 28 | display_server.cpp |
144 | 29 | default_server_configuration.cpp | 29 | default_server_configuration.cpp |
145 | 30 | asio_main_loop.cpp | 30 | asio_main_loop.cpp |
146 | 31 | shared_library.cpp | ||
147 | 31 | ) | 32 | ) |
148 | 32 | 33 | ||
149 | 33 | set(MIRSERVER_LINKAGE SHARED) | 34 | set(MIRSERVER_LINKAGE SHARED) |
150 | @@ -50,9 +51,10 @@ | |||
151 | 50 | ) | 51 | ) |
152 | 51 | 52 | ||
153 | 52 | list(APPEND MIRSERVER_LINKS | 53 | list(APPEND MIRSERVER_LINKS |
154 | 53 | mirplatformgraphics | ||
155 | 54 | mirprotobuf | 54 | mirprotobuf |
156 | 55 | 3rd_party | 55 | 3rd_party |
157 | 56 | ${EGL_LDFLAGS} ${EGL_LIBRARIES} | ||
158 | 57 | ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES} | ||
159 | 56 | ) | 58 | ) |
160 | 57 | 59 | ||
161 | 58 | if(${MIRSERVER_LINKAGE} STREQUAL SHARED) | 60 | if(${MIRSERVER_LINKAGE} STREQUAL SHARED) |
162 | 59 | 61 | ||
163 | === modified file 'src/server/default_server_configuration.cpp' | |||
164 | --- src/server/default_server_configuration.cpp 2013-06-20 23:34:12 +0000 | |||
165 | +++ src/server/default_server_configuration.cpp 2013-06-21 15:26:27 +0000 | |||
166 | @@ -19,6 +19,7 @@ | |||
167 | 19 | #include "mir/default_server_configuration.h" | 19 | #include "mir/default_server_configuration.h" |
168 | 20 | #include "mir/abnormal_exit.h" | 20 | #include "mir/abnormal_exit.h" |
169 | 21 | #include "mir/asio_main_loop.h" | 21 | #include "mir/asio_main_loop.h" |
170 | 22 | #include "mir/shared_library.h" | ||
171 | 22 | 23 | ||
172 | 23 | #include "mir/options/program_option.h" | 24 | #include "mir/options/program_option.h" |
173 | 24 | #include "mir/compositor/buffer_allocation_strategy.h" | 25 | #include "mir/compositor/buffer_allocation_strategy.h" |
174 | @@ -290,18 +291,15 @@ | |||
175 | 290 | }); | 291 | }); |
176 | 291 | } | 292 | } |
177 | 292 | 293 | ||
178 | 294 | |||
179 | 293 | std::shared_ptr<mg::Platform> mir::DefaultServerConfiguration::the_graphics_platform() | 295 | std::shared_ptr<mg::Platform> mir::DefaultServerConfiguration::the_graphics_platform() |
180 | 294 | { | 296 | { |
181 | 295 | return graphics_platform( | 297 | return graphics_platform( |
182 | 296 | [this]() | 298 | [this]() |
183 | 297 | { | 299 | { |
191 | 298 | // TODO I doubt we need the extra level of indirection provided by | 300 | static SharedLibrary libmirplatformgraphics("libmirplatformgraphics.so"); |
192 | 299 | // mg::create_platform() - we just need to move the implementation | 301 | static auto create_platform = libmirplatformgraphics.load_function<mg::CreatePlatform>("create_platform"); |
193 | 300 | // of DefaultServerConfiguration::the_graphics_platform() to the | 302 | return create_platform(the_options(), the_display_report()); |
187 | 301 | // graphics libraries. | ||
188 | 302 | // Alternatively, if we want to dynamically load the graphics library | ||
189 | 303 | // then this would be the place to do that. | ||
190 | 304 | return mg::create_platform(the_options(), the_display_report()); | ||
194 | 305 | }); | 303 | }); |
195 | 306 | } | 304 | } |
196 | 307 | 305 | ||
197 | 308 | 306 | ||
198 | === modified file 'src/server/graphics/CMakeLists.txt' | |||
199 | --- src/server/graphics/CMakeLists.txt 2013-06-14 18:24:09 +0000 | |||
200 | +++ src/server/graphics/CMakeLists.txt 2013-06-21 15:26:27 +0000 | |||
201 | @@ -32,5 +32,6 @@ | |||
202 | 32 | mirlogging | 32 | mirlogging |
203 | 33 | 33 | ||
204 | 34 | ${MIR_COMMON_PLATFORM_LIBRARIES} | 34 | ${MIR_COMMON_PLATFORM_LIBRARIES} |
206 | 35 | ${GLESv2_LIBRARIES} | 35 | ${EGL_LDFLAGS} ${EGL_LIBRARIES} |
207 | 36 | ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES} | ||
208 | 36 | ) | 37 | ) |
209 | 37 | 38 | ||
210 | === modified file 'src/server/graphics/android/CMakeLists.txt' | |||
211 | --- src/server/graphics/android/CMakeLists.txt 2013-05-21 21:43:25 +0000 | |||
212 | +++ src/server/graphics/android/CMakeLists.txt 2013-06-21 15:26:27 +0000 | |||
213 | @@ -5,7 +5,7 @@ | |||
214 | 5 | ) | 5 | ) |
215 | 6 | 6 | ||
216 | 7 | add_library( | 7 | add_library( |
218 | 8 | mirplatformgraphics STATIC | 8 | mirplatformgraphics SHARED |
219 | 9 | 9 | ||
220 | 10 | android_platform.cpp | 10 | android_platform.cpp |
221 | 11 | android_buffer_allocator.cpp | 11 | android_buffer_allocator.cpp |
222 | @@ -33,9 +33,12 @@ | |||
223 | 33 | 33 | ||
224 | 34 | target_link_libraries( | 34 | target_link_libraries( |
225 | 35 | mirplatformgraphics | 35 | mirplatformgraphics |
227 | 36 | mircompositor | 36 | mirserver |
228 | 37 | mirsharedandroid | ||
229 | 37 | 38 | ||
230 | 38 | ${LIBHARDWARE_LIBRARIES} | 39 | ${LIBHARDWARE_LIBRARIES} |
231 | 39 | ${EGL_LDFLAGS} ${EGL_LIBRARIES} | 40 | ${EGL_LDFLAGS} ${EGL_LIBRARIES} |
232 | 40 | ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES} | 41 | ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES} |
233 | 41 | ) | 42 | ) |
234 | 43 | |||
235 | 44 | install(TARGETS mirplatformgraphics LIBRARY DESTINATION lib) | ||
236 | 42 | 45 | ||
237 | === modified file 'src/server/graphics/android/android_platform.cpp' | |||
238 | --- src/server/graphics/android/android_platform.cpp 2013-06-20 23:34:40 +0000 | |||
239 | +++ src/server/graphics/android/android_platform.cpp 2013-06-21 15:26:27 +0000 | |||
240 | @@ -86,11 +86,11 @@ | |||
241 | 86 | for(auto i=0; i<buffer_handle->numFds; i++) | 86 | for(auto i=0; i<buffer_handle->numFds; i++) |
242 | 87 | { | 87 | { |
243 | 88 | packer->pack_fd(buffer_handle->data[offset++]); | 88 | packer->pack_fd(buffer_handle->data[offset++]); |
245 | 89 | } | 89 | } |
246 | 90 | for(auto i=0; i<buffer_handle->numInts; i++) | 90 | for(auto i=0; i<buffer_handle->numInts; i++) |
247 | 91 | { | 91 | { |
248 | 92 | packer->pack_data(buffer_handle->data[offset++]); | 92 | packer->pack_data(buffer_handle->data[offset++]); |
250 | 93 | } | 93 | } |
251 | 94 | 94 | ||
252 | 95 | packer->pack_stride(buffer->stride()); | 95 | packer->pack_stride(buffer->stride()); |
253 | 96 | } | 96 | } |
254 | @@ -100,7 +100,7 @@ | |||
255 | 100 | return std::make_shared<mga::InternalClient>(); | 100 | return std::make_shared<mga::InternalClient>(); |
256 | 101 | } | 101 | } |
257 | 102 | 102 | ||
259 | 103 | std::shared_ptr<mg::Platform> mg::create_platform(std::shared_ptr<mo::Option> const& /*options*/, std::shared_ptr<DisplayReport> const& display_report) | 103 | extern "C" std::shared_ptr<mg::Platform> mg::create_platform(std::shared_ptr<mo::Option> const& /*options*/, std::shared_ptr<DisplayReport> const& display_report) |
260 | 104 | { | 104 | { |
261 | 105 | return std::make_shared<mga::AndroidPlatform>(display_report); | 105 | return std::make_shared<mga::AndroidPlatform>(display_report); |
262 | 106 | } | 106 | } |
263 | 107 | 107 | ||
264 | === modified file 'src/server/graphics/gbm/CMakeLists.txt' | |||
265 | --- src/server/graphics/gbm/CMakeLists.txt 2013-06-05 20:36:34 +0000 | |||
266 | +++ src/server/graphics/gbm/CMakeLists.txt 2013-06-21 15:26:27 +0000 | |||
267 | @@ -11,7 +11,7 @@ | |||
268 | 11 | 11 | ||
269 | 12 | 12 | ||
270 | 13 | add_library( | 13 | add_library( |
272 | 14 | mirplatformgraphics STATIC | 14 | mirplatformgraphics SHARED |
273 | 15 | 15 | ||
274 | 16 | gbm_platform.cpp | 16 | gbm_platform.cpp |
275 | 17 | gbm_buffer_allocator.cpp | 17 | gbm_buffer_allocator.cpp |
276 | @@ -34,11 +34,12 @@ | |||
277 | 34 | 34 | ||
278 | 35 | target_link_libraries( | 35 | target_link_libraries( |
279 | 36 | mirplatformgraphics | 36 | mirplatformgraphics |
282 | 37 | mircompositor | 37 | mirserver |
281 | 38 | mirlogging | ||
283 | 39 | 38 | ||
284 | 40 | ${DRM_LDFLAGS} ${DRM_LIBRARIES} | 39 | ${DRM_LDFLAGS} ${DRM_LIBRARIES} |
285 | 41 | ${GBM_LDFLAGS} ${GBM_LIBRARIES} | 40 | ${GBM_LDFLAGS} ${GBM_LIBRARIES} |
286 | 42 | ${EGL_LDFLAGS} ${EGL_LIBRARIES} | 41 | ${EGL_LDFLAGS} ${EGL_LIBRARIES} |
287 | 43 | ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES} | 42 | ${GLESv2_LDFLAGS} ${GLESv2_LIBRARIES} |
288 | 44 | ) | 43 | ) |
289 | 44 | |||
290 | 45 | install(TARGETS mirplatformgraphics LIBRARY DESTINATION lib) | ||
291 | 45 | 46 | ||
292 | === modified file 'src/server/graphics/gbm/gbm_platform.cpp' | |||
293 | --- src/server/graphics/gbm/gbm_platform.cpp 2013-06-20 23:34:40 +0000 | |||
294 | +++ src/server/graphics/gbm/gbm_platform.cpp 2013-06-21 15:26:27 +0000 | |||
295 | @@ -144,7 +144,7 @@ | |||
296 | 144 | return std::make_shared<mgg::InternalClient>(internal_native_display); | 144 | return std::make_shared<mgg::InternalClient>(internal_native_display); |
297 | 145 | } | 145 | } |
298 | 146 | 146 | ||
300 | 147 | std::shared_ptr<mg::Platform> mg::create_platform(std::shared_ptr<mo::Option> const& options, std::shared_ptr<DisplayReport> const& report) | 147 | extern "C" std::shared_ptr<mg::Platform> mg::create_platform(std::shared_ptr<mo::Option> const& options, std::shared_ptr<DisplayReport> const& report) |
301 | 148 | { | 148 | { |
302 | 149 | auto real_fops = std::make_shared<RealVTFileOperations>(); | 149 | auto real_fops = std::make_shared<RealVTFileOperations>(); |
303 | 150 | auto vt = std::make_shared<mgg::LinuxVirtualTerminal>(real_fops, options->get("vt", 0), report); | 150 | auto vt = std::make_shared<mgg::LinuxVirtualTerminal>(real_fops, options->get("vt", 0), report); |
304 | 151 | 151 | ||
305 | === added file 'src/server/shared_library.cpp' | |||
306 | --- src/server/shared_library.cpp 1970-01-01 00:00:00 +0000 | |||
307 | +++ src/server/shared_library.cpp 2013-06-21 15:26:27 +0000 | |||
308 | @@ -0,0 +1,55 @@ | |||
309 | 1 | /* | ||
310 | 2 | * Copyright © 2013 Canonical Ltd. | ||
311 | 3 | * | ||
312 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
313 | 5 | * under the terms of the GNU General Public License version 3, | ||
314 | 6 | * as published by the Free Software Foundation. | ||
315 | 7 | * | ||
316 | 8 | * This program is distributed in the hope that it will be useful, | ||
317 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
318 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
319 | 11 | * GNU General Public License for more details. | ||
320 | 12 | * | ||
321 | 13 | * You should have received a copy of the GNU General Public License | ||
322 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
323 | 15 | * | ||
324 | 16 | * Authored by: Alan Griffiths <alan@octopull.co.uk> | ||
325 | 17 | */ | ||
326 | 18 | |||
327 | 19 | #include "mir/shared_library.h" | ||
328 | 20 | |||
329 | 21 | #include <boost/throw_exception.hpp> | ||
330 | 22 | #include <boost/exception/info.hpp> | ||
331 | 23 | |||
332 | 24 | #include <dlfcn.h> | ||
333 | 25 | |||
334 | 26 | #include <stdexcept> | ||
335 | 27 | |||
336 | 28 | mir::SharedLibrary::SharedLibrary(char const* library_name) : | ||
337 | 29 | so(dlopen(library_name, RTLD_NOW)) | ||
338 | 30 | { | ||
339 | 31 | if (!so) | ||
340 | 32 | { | ||
341 | 33 | BOOST_THROW_EXCEPTION(std::runtime_error(dlerror())); | ||
342 | 34 | } | ||
343 | 35 | } | ||
344 | 36 | |||
345 | 37 | mir::SharedLibrary::SharedLibrary(std::string const& library_name) : | ||
346 | 38 | SharedLibrary(library_name.c_str()) {} | ||
347 | 39 | |||
348 | 40 | mir::SharedLibrary::~SharedLibrary() | ||
349 | 41 | { | ||
350 | 42 | dlclose(so); | ||
351 | 43 | } | ||
352 | 44 | |||
353 | 45 | void* mir::SharedLibrary::load_symbol(char const* function_name) const | ||
354 | 46 | { | ||
355 | 47 | if (void* result = dlsym(so, function_name)) | ||
356 | 48 | { | ||
357 | 49 | return result; | ||
358 | 50 | } | ||
359 | 51 | else | ||
360 | 52 | { | ||
361 | 53 | BOOST_THROW_EXCEPTION(std::runtime_error(dlerror())); | ||
362 | 54 | } | ||
363 | 55 | } | ||
364 | 0 | 56 | ||
365 | === modified file 'tests/integration-tests/CMakeLists.txt' | |||
366 | --- tests/integration-tests/CMakeLists.txt 2013-05-30 03:50:54 +0000 | |||
367 | +++ tests/integration-tests/CMakeLists.txt 2013-06-21 15:26:27 +0000 | |||
368 | @@ -47,6 +47,7 @@ | |||
369 | 47 | mir-test-cucumber | 47 | mir-test-cucumber |
370 | 48 | 48 | ||
371 | 49 | mirserver | 49 | mirserver |
372 | 50 | mirplatformgraphics | ||
373 | 50 | mirclient | 51 | mirclient |
374 | 51 | mirdraw | 52 | mirdraw |
375 | 52 | mirtestdraw | 53 | mirtestdraw |
376 | 53 | 54 | ||
377 | === modified file 'tests/unit-tests/CMakeLists.txt' | |||
378 | --- tests/unit-tests/CMakeLists.txt 2013-05-20 15:55:48 +0000 | |||
379 | +++ tests/unit-tests/CMakeLists.txt 2013-06-21 15:26:27 +0000 | |||
380 | @@ -6,6 +6,7 @@ | |||
381 | 6 | 6 | ||
382 | 7 | test_gmock_fixes.cpp | 7 | test_gmock_fixes.cpp |
383 | 8 | test_asio_main_loop.cpp | 8 | test_asio_main_loop.cpp |
384 | 9 | shared_library_test.cpp | ||
385 | 9 | ) | 10 | ) |
386 | 10 | 11 | ||
387 | 11 | add_subdirectory(options/) | 12 | add_subdirectory(options/) |
388 | @@ -29,6 +30,7 @@ | |||
389 | 29 | 30 | ||
390 | 30 | mirclient | 31 | mirclient |
391 | 31 | mirserver | 32 | mirserver |
392 | 33 | mirplatformgraphics | ||
393 | 32 | mirdraw | 34 | mirdraw |
394 | 33 | mirtestdraw | 35 | mirtestdraw |
395 | 34 | mirlogging | 36 | mirlogging |
396 | 35 | 37 | ||
397 | === added file 'tests/unit-tests/shared_library_test.cpp' | |||
398 | --- tests/unit-tests/shared_library_test.cpp 1970-01-01 00:00:00 +0000 | |||
399 | +++ tests/unit-tests/shared_library_test.cpp 2013-06-21 15:26:27 +0000 | |||
400 | @@ -0,0 +1,114 @@ | |||
401 | 1 | /* | ||
402 | 2 | * Copyright © 2013 Canonical Ltd. | ||
403 | 3 | * | ||
404 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
405 | 5 | * under the terms of the GNU General Public License version 3, | ||
406 | 6 | * as published by the Free Software Foundation. | ||
407 | 7 | * | ||
408 | 8 | * This program is distributed in the hope that it will be useful, | ||
409 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
410 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
411 | 11 | * GNU General Public License for more details. | ||
412 | 12 | * | ||
413 | 13 | * You should have received a copy of the GNU General Public License | ||
414 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
415 | 15 | * | ||
416 | 16 | * Authored by: Alan Griffiths <alan@octopull.co.uk> | ||
417 | 17 | */ | ||
418 | 18 | |||
419 | 19 | #include "mir/shared_library.h" | ||
420 | 20 | |||
421 | 21 | #include <gtest/gtest.h> | ||
422 | 22 | |||
423 | 23 | #include <boost/exception/diagnostic_information.hpp> | ||
424 | 24 | |||
425 | 25 | #include <stdexcept> | ||
426 | 26 | |||
427 | 27 | namespace | ||
428 | 28 | { | ||
429 | 29 | class HasSubstring | ||
430 | 30 | { | ||
431 | 31 | public: | ||
432 | 32 | HasSubstring(char const* substring) : substring(substring) {} | ||
433 | 33 | |||
434 | 34 | friend::testing::AssertionResult operator,(std::string const& target, HasSubstring const& match) | ||
435 | 35 | { | ||
436 | 36 | if (std::string::npos != target.find(match.substring)) | ||
437 | 37 | return ::testing::AssertionSuccess(); | ||
438 | 38 | else | ||
439 | 39 | return ::testing::AssertionFailure() << | ||
440 | 40 | "The target:\n\"" << target << "\"\n" | ||
441 | 41 | "Does not contain:\n\"" << match.substring << "\""; | ||
442 | 42 | } | ||
443 | 43 | |||
444 | 44 | private: | ||
445 | 45 | char const* const substring; | ||
446 | 46 | |||
447 | 47 | HasSubstring(HasSubstring const&) = delete; | ||
448 | 48 | HasSubstring& operator=(HasSubstring const&) = delete; | ||
449 | 49 | }; | ||
450 | 50 | |||
451 | 51 | #define EXPECT_THAT(target, condition) EXPECT_TRUE((target, condition)) | ||
452 | 52 | |||
453 | 53 | char const* const nonexistent_library = "nonexistent_library"; | ||
454 | 54 | char const* const existing_library = "libmirplatformgraphics.so"; | ||
455 | 55 | char const* const nonexistent_function = "nonexistent_library"; | ||
456 | 56 | char const* const existing_function = "create_platform"; | ||
457 | 57 | } | ||
458 | 58 | |||
459 | 59 | TEST(SharedLibrary, load_nonexistent_library_fails) | ||
460 | 60 | { | ||
461 | 61 | EXPECT_THROW({ mir::SharedLibrary nonexistent(nonexistent_library); }, std::runtime_error); | ||
462 | 62 | } | ||
463 | 63 | |||
464 | 64 | TEST(SharedLibrary, load_nonexistent_library_fails_with_useful_info) | ||
465 | 65 | { | ||
466 | 66 | try | ||
467 | 67 | { | ||
468 | 68 | mir::SharedLibrary nonexistent(nonexistent_library); | ||
469 | 69 | } | ||
470 | 70 | catch (std::exception const& error) | ||
471 | 71 | { | ||
472 | 72 | auto info = boost::diagnostic_information(error); | ||
473 | 73 | |||
474 | 74 | EXPECT_THAT(info, HasSubstring("cannot open shared object")) << "What went wrong"; | ||
475 | 75 | EXPECT_THAT(info, HasSubstring(nonexistent_library)) << "Name of library"; | ||
476 | 76 | } | ||
477 | 77 | } | ||
478 | 78 | |||
479 | 79 | TEST(SharedLibrary, load_valid_library_works) | ||
480 | 80 | { | ||
481 | 81 | mir::SharedLibrary existing(existing_library); | ||
482 | 82 | } | ||
483 | 83 | |||
484 | 84 | TEST(SharedLibrary, load_nonexistent_function_fails) | ||
485 | 85 | { | ||
486 | 86 | mir::SharedLibrary existing(existing_library); | ||
487 | 87 | |||
488 | 88 | EXPECT_THROW({ existing.load_function<void(*)()>(nonexistent_function); }, std::runtime_error); | ||
489 | 89 | } | ||
490 | 90 | |||
491 | 91 | TEST(SharedLibrary, load_nonexistent_function_fails_with_useful_info) | ||
492 | 92 | { | ||
493 | 93 | mir::SharedLibrary existing(existing_library); | ||
494 | 94 | |||
495 | 95 | try | ||
496 | 96 | { | ||
497 | 97 | existing.load_function<void(*)()>(nonexistent_function); | ||
498 | 98 | } | ||
499 | 99 | catch (std::exception const& error) | ||
500 | 100 | { | ||
501 | 101 | auto info = boost::diagnostic_information(error); | ||
502 | 102 | |||
503 | 103 | EXPECT_THAT(info, HasSubstring("undefined symbol")) << "What went wrong"; | ||
504 | 104 | EXPECT_THAT(info, HasSubstring(existing_library)) << "Name of library"; | ||
505 | 105 | EXPECT_THAT(info, HasSubstring(nonexistent_function)) << "Name of function"; | ||
506 | 106 | } | ||
507 | 107 | } | ||
508 | 108 | |||
509 | 109 | TEST(SharedLibrary, load_valid_function_works) | ||
510 | 110 | { | ||
511 | 111 | mir::SharedLibrary existing(existing_library); | ||
512 | 112 | existing.load_function<void(*)()>(existing_function); | ||
513 | 113 | } | ||
514 | 114 |
Looks good, and works just fine locally.