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_
15 class ProxiedConnection
;
17 typedef void (*CompositorCrashHandler
)();
19 #define WAYLAND_PROXY_ENABLED (1 << 0)
20 #define WAYLAND_PROXY_DISABLED (1 << 1)
21 #define WAYLAND_PROXY_RUN_FAILED (1 << 2)
22 #define WAYLAND_PROXY_TERMINATED (1 << 3)
23 #define WAYLAND_PROXY_CONNECTION_ADDED (1 << 4)
24 #define WAYLAND_PROXY_CONNECTION_REMOVED (1 << 5)
25 #define WAYLAND_PROXY_APP_TERMINATED (1 << 6)
26 #define WAYLAND_PROXY_APP_CONNECTION_FAILED (1 << 7)
27 #define WAYLAND_PROXY_COMPOSITOR_ATTACHED (1 << 8)
28 #define WAYLAND_PROXY_COMPOSITOR_CONNECTION_FAILED (1 << 9)
29 #define WAYLAND_PROXY_COMPOSITOR_SOCKET_FAILED (1 << 10)
33 static std::unique_ptr
<WaylandProxy
> Create();
35 // Launch an application with Wayland proxy set
36 bool RunChildApplication(char* argv
[]);
38 // Run proxy as part of already running application
39 // and set Wayland proxy display for it.
42 // Set original Wayland display env variable and clear
43 // proxy display file.
44 void RestoreWaylandDisplay();
46 static void SetVerbose(bool aVerbose
);
47 static void SetCompositorCrashHandler(CompositorCrashHandler aCrashHandler
);
48 static void CompositorCrashed();
49 static void AddState(unsigned aState
);
50 static const char* GetState();
58 void SetWaylandProxyDisplay();
59 static void* RunProxyThread(WaylandProxy
* aProxy
);
60 bool CheckWaylandDisplay(const char* aWaylandDisplay
);
62 bool SetupWaylandDisplays();
63 bool StartProxyServer();
64 bool IsChildAppTerminated();
66 bool PollConnections();
67 bool ProcessConnections();
69 void Info(const char* aFormat
, ...);
70 void Warning(const char* aOperation
);
71 void Error(const char* aOperation
);
72 void ErrorPlain(const char* aFormat
, ...);
74 void CheckCompositor();
77 // List of all Compositor <-> Application connections
78 std::vector
<std::unique_ptr
<ProxiedConnection
>> mConnections
;
79 int mProxyServerSocket
= -1;
80 pid_t mApplicationPID
= 0;
81 std::atomic
<bool> mThreadRunning
= false;
84 // sockaddr_un has hardcoded max len of sun_path
85 static constexpr int sMaxDisplayNameLen
= 108;
86 // Name of Wayland display provided by compositor
87 char mWaylandDisplay
[sMaxDisplayNameLen
];
88 // Name of Wayland display provided by us
89 char mWaylandProxy
[sMaxDisplayNameLen
];
91 static CompositorCrashHandler sCompositorCrashHandler
;
92 static std::atomic
<unsigned> sProxyStateFlags
;
95 #endif // _wayland_proxy_h_