22 #include "waylandgateway.h" 28 constexpr
const char *WaylandGateway::ENABLED_FIELD;
29 constexpr
const char *WaylandGateway::SOCKET_FILE_NAME;
30 constexpr
const char *WaylandGateway::WAYLAND_RUNTIME_DIR_VARIABLE_NAME;
32 WaylandGateway::WaylandGateway(std::shared_ptr<ContainerAbstractInterface> container) :
33 Gateway(ID, container, true ),
35 m_activatedOnce(false)
39 WaylandGateway::~WaylandGateway()
45 bool configValue =
false;
48 log_error() <<
"Key " << ENABLED_FIELD <<
" missing or not bool in json configuration";
53 m_enabled = configValue;
59 bool WaylandGateway::activateGateway()
62 log_info() <<
"Wayland gateway disabled";
70 if (m_enabled && m_activatedOnce) {
71 log_info() <<
"Ignoring redundant activation";
75 bool hasWayland =
false;
76 std::string dir = Glib::getenv(WAYLAND_RUNTIME_DIR_VARIABLE_NAME, hasWayland);
78 log_error() <<
"Should enable wayland gateway, but " << WAYLAND_RUNTIME_DIR_VARIABLE_NAME <<
" is not defined";
82 std::shared_ptr<ContainerAbstractInterface> container =
getContainer();
84 log_info() <<
"enabling Wayland gateway. Socket dir:" << dir;
85 std::string pathInHost = buildPath(dir, SOCKET_FILE_NAME);
86 std::string pathInContainer = buildPath(
"/gateways", SOCKET_FILE_NAME);
88 if (!container->bindMountInContainer(pathInHost, pathInContainer,
false)) {
89 log_error() <<
"Could not bind mount the wayland socket into the container";
93 std::string socketDir = parentPath(pathInContainer);
94 container->setEnvironmentVariable(WAYLAND_RUNTIME_DIR_VARIABLE_NAME, socketDir);
96 m_activatedOnce =
true;
101 bool WaylandGateway::teardownGateway()
bool readConfigElement(const json_t *element)
Gateway specific parsing of config elements.
std::shared_ptr< ContainerAbstractInterface > getContainer()
Get a handle to the associated container.
Developers guide to adding a config item:
static bool read(const json_t *element, const char *key, std::string &result)
Reads a string from a JSON Object.