Directory: | ./ |
---|---|
File: | server/wayland/client.cpp |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 56 | 60 | 93.3% |
Branches: | 16 | 34 | 47.1% |
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 | #include "client.h" | ||
21 | #include "../client.h" | ||
22 | #include "../client_p.h" | ||
23 | |||
24 | #include "display.h" | ||
25 | |||
26 | #include <QFileInfo> | ||
27 | |||
28 | #include <wayland-server.h> | ||
29 | |||
30 | namespace Wrapland::Server::Wayland | ||
31 | { | ||
32 | |||
33 | 1176 | Client::Client(wl_client* native, Server::Client* handle) | |
34 | 588 | : native{native} | |
35 | 588 | , handle{handle} | |
36 | 588 | { | |
37 | 588 | m_destroyWrapper.client = this; | |
38 | 588 | m_destroyWrapper.listener.notify = destroyListenerCallback; | |
39 |
1/2✓ Branch 0 taken 588 times.
✗ Branch 1 not taken.
|
588 | wl_client_add_destroy_listener(native, &m_destroyWrapper.listener); |
40 |
1/2✓ Branch 0 taken 588 times.
✗ Branch 1 not taken.
|
588 | wl_client_get_credentials(native, &m_pid, &m_user, &m_group); |
41 | |||
42 | 588 | m_executablePath | |
43 | // Qt types have limited compatibility with modern C++. Remove this clang-tidy exception | ||
44 | // once it is ported to std::string. | ||
45 | // NOLINTNEXTLINE(performance-no-automatic-move) | ||
46 |
8/16✓ Branch 0 taken 588 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 588 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 588 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 588 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 588 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 588 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 588 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 588 times.
|
588 | = QFileInfo(QStringLiteral("/proc/%1/exe").arg(m_pid)).symLinkTarget().toUtf8().constData(); |
47 | 588 | } | |
48 | |||
49 | 588 | Client::~Client() | |
50 | 588 | { | |
51 |
1/2✓ Branch 0 taken 588 times.
✗ Branch 1 not taken.
|
588 | if (native) { |
52 | ✗ | wl_list_remove(&m_destroyWrapper.listener.link); | |
53 | } | ||
54 | 588 | } | |
55 | |||
56 | 58 | Display* Client::display() const | |
57 | { | ||
58 | 58 | return Display::backendCast(handle->display()); | |
59 | } | ||
60 | |||
61 | 510 | void Client::flush() const | |
62 | { | ||
63 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 510 times.
|
510 | if (!native) { |
64 | ✗ | return; | |
65 | } | ||
66 | 510 | wl_client_flush(native); | |
67 | 510 | } | |
68 | |||
69 | 2 | void Client::destroy() const | |
70 | { | ||
71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!native) { |
72 | ✗ | return; | |
73 | } | ||
74 | 2 | wl_client_destroy(native); | |
75 | 2 | } | |
76 | 588 | ||
77 | 1882 | Client* Client::cast_client(Server::Client* client) | |
78 | 588 | { | |
79 | 1294 | return client->d_ptr.get(); | |
80 | } | ||
81 | |||
82 | 588 | Client* Client::create_client(wl_client* wlClient, Display* display) | |
83 | { | ||
84 | // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) | ||
85 |
1/2✓ Branch 0 taken 588 times.
✗ Branch 1 not taken.
|
588 | return (new Server::Client(wlClient, display->handle))->d_ptr.get(); |
86 | } | ||
87 | |||
88 | 588 | void Client::destroyListenerCallback(wl_listener* listener, [[maybe_unused]] void* data) | |
89 | { | ||
90 | // The wl_container_of macro can not be used with auto keyword and in the macro from libwayland | ||
91 | // the alignment is increased. | ||
92 | // Relevant clang-tidy checks are: | ||
93 | // * clang-diagnostic-cast-align | ||
94 | // * cppcoreguidelines-pro-bounds-pointer-arithmetic | ||
95 | // * hicpp-use-auto | ||
96 | // * modernize-use-auto | ||
97 | // NOLINTNEXTLINE | ||
98 | 588 | DestroyWrapper* wrapper = wl_container_of(listener, wrapper, listener); | |
99 | 588 | auto client = wrapper->client; | |
100 | |||
101 | 588 | wl_list_remove(&client->m_destroyWrapper.listener.link); | |
102 | 588 | client->native = nullptr; | |
103 | 588 | Q_EMIT client->handle->disconnected(client->handle); | |
104 |
1/2✓ Branch 0 taken 588 times.
✗ Branch 1 not taken.
|
588 | delete client->handle; |
105 | 588 | } | |
106 | |||
107 | wl_resource* | ||
108 | 4137 | Client::createResource(wl_interface const* interface, uint32_t version, uint32_t id) const | |
109 | { | ||
110 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4137 times.
|
4137 | if (!native) { |
111 | ✗ | return nullptr; | |
112 | } | ||
113 | 4137 | return wl_resource_create(native, interface, static_cast<int>(version), id); | |
114 | 4137 | } | |
115 | |||
116 | 1 | gid_t Client::groupId() const | |
117 | { | ||
118 | 1 | return m_group; | |
119 | } | ||
120 | |||
121 | 1 | pid_t Client::processId() const | |
122 | { | ||
123 | 1 | return m_pid; | |
124 | } | ||
125 | |||
126 | 1 | uid_t Client::userId() const | |
127 | { | ||
128 | 1 | return m_user; | |
129 | } | ||
130 | |||
131 | 1 | std::string Client::executablePath() const | |
132 | { | ||
133 | 1 | return m_executablePath; | |
134 | } | ||
135 | |||
136 | 3 | std::string Client::security_context_app_id() const | |
137 | { | ||
138 | 3 | return m_security_context_app_id; | |
139 | } | ||
140 | |||
141 | 1 | void Client::set_security_context_app_id(std::string const& id) | |
142 | { | ||
143 | 1 | m_security_context_app_id = id; | |
144 | 1 | } | |
145 | |||
146 | } | ||
147 |