@@ -10,32 +10,29 @@ void SurfaceProvider::loadHybridMethods() {
10
10
registerHybridMethod (" getSurface" , &SurfaceProvider::getSurfaceOrNull, this );
11
11
}
12
12
13
- Listener SurfaceProvider::addOnSurfaceChangedListener (margelo:: SurfaceProvider::Callback callback) {
13
+ Listener SurfaceProvider::addOnSurfaceChangedListener (SurfaceProvider::Callback callback) {
14
14
std::unique_lock lock (_mutex);
15
15
16
- _callbacks.push_back (std::move (callback));
17
- return Listener ([]() {
18
- // TODO: Find a safe way to remove this listener from the vector.
19
- });
16
+ return _listeners.add (std::move (callback));
20
17
}
21
18
22
19
void SurfaceProvider::onSurfaceCreated (std::shared_ptr<Surface> surface) {
23
20
std::unique_lock lock (_mutex);
24
- for (const auto & listener : _callbacks ) {
21
+ for (const auto & listener : _listeners. getListeners () ) {
25
22
listener.onSurfaceCreated (surface);
26
23
}
27
24
}
28
25
29
26
void SurfaceProvider::onSurfaceChanged (std::shared_ptr<Surface> surface, int width, int height) {
30
27
std::unique_lock lock (_mutex);
31
- for (const auto & listener : _callbacks ) {
28
+ for (const auto & listener : _listeners. getListeners () ) {
32
29
listener.onSurfaceSizeChanged (surface, width, height);
33
30
}
34
31
}
35
32
36
33
void SurfaceProvider::onSurfaceDestroyed (std::shared_ptr<Surface> surface) {
37
34
std::unique_lock lock (_mutex);
38
- for (const auto & listener : _callbacks ) {
35
+ for (const auto & listener : _listeners. getListeners () ) {
39
36
listener.onSurfaceDestroyed (surface);
40
37
}
41
38
}
0 commit comments