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 <string>
23 #include <sys/types.h>
24 #include <vector>
25 
26 struct wl_client;
27 struct wl_interface;
28 struct wl_resource;
29 
30 #include <wayland-server.h>
31 
32 namespace Wrapland::Server
33 {
34 class Client;
35 class Display;
36 
37 namespace Wayland
38 {
39 class Display;
40 
41 class Client
42 {
43 public:
44     Client(wl_client* wlClient, Server::Client* clientHandle);
45 
46     Client(Client const&) = delete;
47     Client& operator=(Client const&) = delete;
48     Client(Client&&) noexcept = default;
49     Client& operator=(Client&&) noexcept = default;
50 
51     virtual ~Client();
52 
53     void flush();
54     wl_resource* createResource(const wl_interface* interface, uint32_t version, uint32_t id);
55     wl_resource* getResource(uint32_t id);
56 
57     Display* display() const;
58     Server::Client* handle() const;
59 
60     pid_t processId() const;
61     uid_t userId() const;
62     gid_t groupId() const;
63     std::string executablePath() const;
64 
65     wl_client* native() const;
66 
67     void destroy();
68 
69 private:
70     static void destroyListenerCallback(wl_listener* listener, void* data);
71 
72     wl_client* m_client;
73 
74     pid_t m_pid = 0;
75     uid_t m_user = 0;
76     gid_t m_group = 0;
77     std::string m_executablePath;
78 
79     Server::Client* q_ptr;
80 
81     struct DestroyWrapper {
82         Client* client;
83         struct wl_listener listener;
84     };
85     DestroyWrapper m_destroyWrapper;
86 };
87 
88 }
89 }
90