no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / third_party / wayland-proxy / wayland-proxy.h
blob657563b569af160573e6e0b3107d8ab4e56b4d27
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef _wayland_proxy_h_
7 #define _wayland_proxy_h_
9 #include <poll.h>
10 #include <vector>
11 #include <fcntl.h>
12 #include <atomic>
13 #include <memory>
15 class ProxiedConnection;
17 class WaylandProxy {
18 public:
19 static std::unique_ptr<WaylandProxy> Create();
21 // Launch an application with Wayland proxy set
22 bool RunChildApplication(char* argv[]);
24 // Run proxy as part of already running application
25 // and set Wayland proxy display for it.
26 bool RunThread();
28 // Set original Wayland display env variable and clear
29 // proxy display file.
30 void RestoreWaylandDisplay();
32 static void SetVerbose(bool aVerbose);
34 ~WaylandProxy();
36 private:
37 bool Init();
38 void Run();
40 void SetWaylandProxyDisplay();
41 static void* RunProxyThread(WaylandProxy* aProxy);
42 bool CheckWaylandDisplay(const char* aWaylandDisplay);
44 bool SetupWaylandDisplays();
45 bool StartProxyServer();
46 bool IsChildAppTerminated();
48 bool PollConnections();
49 bool ProcessConnections();
51 void Info(const char* aFormat, ...);
52 void Warning(const char* aOperation);
53 void Error(const char* aOperation);
54 void ErrorPlain(const char* aFormat, ...);
56 private:
57 // List of all Compositor <-> Application connections
58 std::vector<std::unique_ptr<ProxiedConnection>> mConnections;
59 int mProxyServerSocket = -1;
60 pid_t mApplicationPID = 0;
61 std::atomic<bool> mThreadRunning = false;
62 pthread_t mThread;
64 // sockaddr_un has hardcoded max len of sun_path
65 static constexpr int sMaxDisplayNameLen = 108;
66 // Name of Wayland display provided by compositor
67 char mWaylandDisplay[sMaxDisplayNameLen];
68 // Name of Wayland display provided by us
69 char mWaylandProxy[sMaxDisplayNameLen];
72 #endif // _wayland_proxy_h_