Directory: | ./ |
---|---|
File: | server/wayland/send.h |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 15 | 15 | 100.0% |
Branches: | 4 | 8 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /******************************************************************** | ||
2 | Copyright © 2020 Roman Gilg <subdiff@gmail.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||
8 | later version accepted by the membership of KDE e.V. (or its | ||
9 | successor approved by the membership of KDE e.V.), which shall | ||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | |||
12 | This library is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Lesser General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | ||
20 | #pragma once | ||
21 | |||
22 | #include <tuple> | ||
23 | |||
24 | #include <wayland-server.h> | ||
25 | |||
26 | namespace Wrapland::Server::Wayland | ||
27 | { | ||
28 | |||
29 | template<auto sender, uint32_t min_version = 0, typename... Args> | ||
30 | 4394 | void send(wl_resource* resource, uint32_t version, Args&&... args) | |
31 | { | ||
32 | if constexpr (min_version <= 1) { | ||
33 | 3556 | sender(resource, args...); | |
34 | } else { | ||
35 |
4/8✗ Branch 0 not taken.
✓ Branch 1 taken 630 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 200 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
838 | if (version >= min_version) { |
36 | 838 | sender(resource, args...); | |
37 | 838 | } | |
38 | } | ||
39 | 4394 | } | |
40 | |||
41 | template<auto sender, uint32_t min_version, typename Tuple, std::size_t... Indices> | ||
42 | 183 | void send_tuple_impl(wl_resource* resource, | |
43 | uint32_t version, | ||
44 | Tuple&& tuple, | ||
45 | [[maybe_unused]] std::index_sequence<Indices...> indices) | ||
46 | { | ||
47 | 183 | send<sender, min_version>(resource, version, std::get<Indices>(tuple)...); | |
48 | 183 | } | |
49 | |||
50 | template<auto sender, uint32_t min_version = 0, typename... Args> | ||
51 | 183 | void send_tuple(wl_resource* resource, uint32_t version, std::tuple<Args...>&& tuple) | |
52 | { | ||
53 | 183 | auto constexpr size = std::tuple_size_v<std::decay_t<decltype(tuple)>>; | |
54 | 183 | auto constexpr indices = std::make_index_sequence<size>{}; | |
55 | 183 | send_tuple_impl<sender, min_version>( | |
56 | 183 | resource, version, std::forward<decltype(tuple)>(tuple), indices); | |
57 | 183 | } | |
58 | |||
59 | } | ||
60 |