2 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "anbox/input/manager.h"
19 #include "anbox/system_configuration.h"
20 #include "anbox/input/device.h"
21 #include "anbox/runtime.h"
22 #include "anbox/utils.h"
24 #include <boost/format.hpp>
28 Manager::Manager(const std::shared_ptr<Runtime> &runtime) : runtime_(runtime) {
29 const auto dir = SystemConfiguration::instance().input_device_dir();
30 utils::ensure_paths({dir});
32 // The directory is bind-mounted into the container but might have user
33 // permissions only (rwx------). Make sure it is accessible.
34 ::chmod(dir.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
37 Manager::~Manager() {}
39 std::shared_ptr<Device> Manager::create_device() {
40 const auto id = next_id();
41 const auto path = build_device_path(id);
42 auto device = Device::create(path, runtime_);
43 devices_.insert({id, device});
47 std::uint32_t Manager::next_id() {
48 static std::uint32_t next_id = 0;
52 std::string Manager::build_device_path(const std::uint32_t &id) {
53 return (boost::format("%1%/event%2%") % SystemConfiguration::instance().input_device_dir() % id).str();