@@ -27,31 +27,29 @@ namespace mtf = mir_test_framework;
27
27
namespace mi = mir::input;
28
28
29
29
mtf::StubInputPlatform::StubInputPlatform (
30
- std::shared_ptr<mi::InputDeviceRegistry> const & input_device_registry)
30
+ std::shared_ptr<mi::InputDeviceRegistry> const & input_device_registry,
31
+ std::shared_ptr<DeviceStore> const & device_store)
31
32
: platform_dispatchable{std::make_shared<mir::dispatch::MultiplexingDispatchable>()},
32
33
platform_queue{std::make_shared<mir::dispatch::ActionQueue>()},
33
- registry (input_device_registry)
34
+ registry (input_device_registry),
35
+ device_store(device_store)
34
36
{
35
- stub_input_platform = this ;
36
37
platform_dispatchable->add_watch (platform_queue);
37
38
}
38
39
39
40
mtf::StubInputPlatform::~StubInputPlatform ()
40
41
{
41
- std::lock_guard lk{device_store_guard};
42
- device_store.clear ();
43
- stub_input_platform = nullptr ;
42
+ device_store->clear ();
44
43
}
45
44
46
45
void mtf::StubInputPlatform::start ()
47
46
{
48
- std::lock_guard lk{device_store_guard};
49
- for (auto const & dev : device_store)
47
+ device_store->foreach_device ([&](auto const & dev)
50
48
{
51
49
auto device = dev.lock ();
52
50
if (device)
53
51
registry->add_device (device);
54
- }
52
+ });
55
53
}
56
54
57
55
std::shared_ptr<mir::dispatch::Dispatchable> mtf::StubInputPlatform::dispatchable ()
@@ -61,13 +59,12 @@ std::shared_ptr<mir::dispatch::Dispatchable> mtf::StubInputPlatform::dispatchabl
61
59
62
60
void mtf::StubInputPlatform::stop ()
63
61
{
64
- std::lock_guard lk{device_store_guard};
65
- for (auto const & dev : device_store)
62
+ device_store->foreach_device ([&](auto const & dev)
66
63
{
67
64
auto device = dev.lock ();
68
65
if (device)
69
66
registry->remove_device (device);
70
- }
67
+ });
71
68
}
72
69
73
70
void mtf::StubInputPlatform::pause_for_config ()
@@ -80,61 +77,28 @@ void mtf::StubInputPlatform::continue_after_config()
80
77
81
78
void mtf::StubInputPlatform::add (std::shared_ptr<mir::input::InputDevice> const & dev)
82
79
{
83
- auto input_platform = stub_input_platform.load ();
84
- if (!input_platform)
85
- {
86
- std::lock_guard lk{device_store_guard};
87
- device_store.push_back (dev);
88
- return ;
89
- }
90
-
91
- input_platform->platform_queue ->enqueue (
92
- [registry=input_platform->registry ,dev]
80
+ platform_queue->enqueue (
81
+ [registry=registry,dev]
93
82
{
94
83
registry->add_device (dev);
95
84
});
96
85
}
97
86
98
87
void mtf::StubInputPlatform::remove (std::shared_ptr<mir::input::InputDevice> const & dev)
99
88
{
100
- auto input_platform = stub_input_platform.load ();
101
- if (!input_platform)
102
- BOOST_THROW_EXCEPTION (std::runtime_error (" No stub input platform available" ));
103
-
104
- std::lock_guard lk{device_store_guard};
105
- device_store.erase (
106
- std::remove_if (begin (device_store),
107
- end (device_store),
108
- [dev](auto weak_dev)
109
- {
110
- return (weak_dev.lock () == dev);
111
- }),
112
- end (device_store));
113
- input_platform->platform_queue ->enqueue (
114
- [ registry = input_platform->registry , dev ]
89
+ platform_queue->enqueue (
90
+ [ registry = registry, dev ]
115
91
{
116
92
registry->remove_device (dev);
117
93
});
118
94
}
119
95
120
96
void mtf::StubInputPlatform::register_dispatchable (std::shared_ptr<mir::dispatch::Dispatchable> const & queue)
121
97
{
122
- auto input_platform = stub_input_platform.load ();
123
- if (!input_platform)
124
- BOOST_THROW_EXCEPTION (std::runtime_error (" No stub input platform available" ));
125
-
126
- input_platform->platform_dispatchable ->add_watch (queue);
98
+ platform_dispatchable->add_watch (queue);
127
99
}
128
100
129
101
void mtf::StubInputPlatform::unregister_dispatchable (std::shared_ptr<mir::dispatch::Dispatchable> const & queue)
130
102
{
131
- auto input_platform = stub_input_platform.load ();
132
- if (!input_platform)
133
- BOOST_THROW_EXCEPTION (std::runtime_error (" No stub input platform available" ));
134
-
135
- input_platform->platform_dispatchable ->remove_watch (queue);
103
+ platform_dispatchable->remove_watch (queue);
136
104
}
137
-
138
- std::atomic<mtf::StubInputPlatform*> mtf::StubInputPlatform::stub_input_platform{nullptr };
139
- std::vector<std::weak_ptr<mir::input::InputDevice>> mtf::StubInputPlatform::device_store;
140
- std::mutex mtf::StubInputPlatform::device_store_guard;
0 commit comments