1 /**************************************************************************
3 * Copyright 2020 Samsung Electronics co., Ltd. All Rights Reserved.
5 * Contact: SooChan Lim <sc1.lim@samsung.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
29 #include "mockcompositor.h"
33 logger_func(void *user_data, enum wl_protocol_logger_type type,
34 const struct wl_protocol_logger_message *message)
36 //Compositor *c = static_cast<Compositor *>(user_data);
38 std::cout << "res:" << wl_resource_get_class(message->resource) << " "
39 << "op:" << message->message_opcode << " "
40 << "name:" << message->message->name << "\n";
44 Compositor::Compositor()
45 : display(wl_display_create()),
46 loop(wl_display_get_event_loop(display)),
47 logger(wl_display_add_protocol_logger(display, logger_func, this))
51 ret = wl_display_add_socket(display, "test-ds-tizen");
53 ds_err("wl_display_add_socket() filed.");
55 ret = wl_display_init_shm(display);
57 ds_err("wl_display_init_shm() filed.");
59 compositor = ds_compositor_create(display);
60 if (compositor == nullptr)
61 ds_err("ds_compositor_create() filed.");
64 Compositor::~Compositor ()
66 wl_list *clients = wl_display_get_client_list(display);
67 wl_client *client = nullptr;
69 wl_client_for_each(client, clients) {
70 wl_client_destroy(client);
73 wl_protocol_logger_destroy(logger);
74 wl_display_destroy(display);
77 void Compositor::DispatchEvents()
79 /* flush any pending client events */
80 wl_display_flush_clients(display);
81 /* dispatch any pending main loop events */
82 wl_event_loop_dispatch(loop, 0);
85 MockCompositor::MockCompositor()
88 th = std::thread([this](){
92 // mockcompositor is ready
97 // mockcompositor process the events in every 40 milliseconds
98 std::this_thread::sleep_for(std::chrono::milliseconds(40));
103 // wait until the child thread(mockcompositor) is ready
105 std::unique_lock<std::mutex> lock(m);
106 cv.wait(lock, [this]{return ready;});
110 MockCompositor::MockCompositor(ds_test_setup_func_t setup_func, void *data)
111 : compositor(nullptr)
113 th = std::thread([this, setup_func, data](){
117 // call test setup_function
120 // mockcompositor is ready
125 // mockcompositor process the events in every 40 milliseconds
126 std::this_thread::sleep_for(std::chrono::milliseconds(40));
132 // wait until the child thread(mockcompositor) is ready
134 std::unique_lock<std::mutex> lock(m);
135 cv.wait(lock, [this]{return ready;});
139 MockCompositor::~MockCompositor() {
140 // finish the child thread(mockcompositor).
145 void MockCompositor::Process()
147 std::lock_guard<std::mutex> lock(m);
148 compositor->DispatchEvents();
151 struct wl_display *MockCompositor::GetWlDisplay()
153 return this->compositor->display;