2
* Copyright © 2014-2015 Canonical Ltd.
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,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
19
#include "stub_input_platform.h"
21
#include "mir/input/input_device_registry.h"
22
#include "mir/dispatch/action_queue.h"
23
#include "mir/module_deleter.h"
27
namespace mtf = mir_test_framework;
28
namespace mi = mir::input;
30
mtf::StubInputPlatform::StubInputPlatform(
31
std::shared_ptr<mi::InputDeviceRegistry> const& input_device_registry)
32
: platform_queue{mir::make_module_ptr<mir::dispatch::ActionQueue>()},
33
registry(input_device_registry)
35
stub_input_platform = this;
38
mtf::StubInputPlatform::~StubInputPlatform()
41
stub_input_platform = nullptr;
44
void mtf::StubInputPlatform::start()
46
for (auto const& dev : device_store)
48
auto device = dev.lock();
49
registry->add_device(device);
54
std::shared_ptr<mir::dispatch::Dispatchable> mtf::StubInputPlatform::dispatchable()
56
return platform_queue;
59
void mtf::StubInputPlatform::stop()
63
void mtf::StubInputPlatform::add(std::shared_ptr<mir::input::InputDevice> const& dev)
65
if (!stub_input_platform)
67
device_store.push_back(dev);
71
stub_input_platform->platform_queue->enqueue(
72
[registry=stub_input_platform->registry,dev]
74
registry->add_device(dev);
78
void mtf::StubInputPlatform::remove(std::shared_ptr<mir::input::InputDevice> const& dev)
80
if (!stub_input_platform)
81
BOOST_THROW_EXCEPTION(std::runtime_error("No stub input platform available"));
83
stub_input_platform->platform_queue->enqueue(
84
[registry=stub_input_platform->registry,dev]
86
registry->remove_device(dev);
90
mtf::StubInputPlatform* mtf::StubInputPlatform::stub_input_platform = nullptr;
91
std::vector<std::weak_ptr<mir::input::InputDevice>> mtf::StubInputPlatform::device_store;