Mir

Merge lp:~vanvugt/mir/simplify-single-object-accesses into lp:mir

Proposed by Daniel van Vugt
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 3877
Proposed branch: lp:~vanvugt/mir/simplify-single-object-accesses
Merge into: lp:mir
Diff against target: 278 lines (+42/-89)
6 files modified
src/client/connection_surface_map.cpp (+10/-30)
src/client/connection_surface_map.h (+2/-2)
src/client/rpc/mir_protobuf_rpc_channel.cpp (+17/-23)
src/client/surface_map.h (+2/-4)
tests/unit-tests/client/test_connection_resource_map.cpp (+4/-21)
tests/unit-tests/client/test_protobuf_rpc_channel.cpp (+7/-9)
To merge this branch: bzr merge lp:~vanvugt/mir/simplify-single-object-accesses
Reviewer Review Type Date Requested Status
Mir CI Bot continuous-integration Approve
Alan Griffiths Approve
Review via email: mp+312790@code.launchpad.net

Commit message

Simplify SurfaceMap's single object functions.

Also make them safer and more powerful by replacing raw pointers with
shared pointers. That's the reason I need this - to get a shared
pointer.

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:3874
https://mir-jenkins.ubuntu.com/job/mir-ci/2347/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/3061/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/3127
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/3119
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/3119
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/3119
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/3090
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/3090/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3090
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3090/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/3090
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/3090/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3090
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3090/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3090
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3090/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3090/console

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/2347/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3875
https://mir-jenkins.ubuntu.com/job/mir-ci/2350/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/3065
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/3131
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/3123
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/3123
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/3123
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/3094
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/3094/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3094
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3094/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/3094
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/3094/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3094
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3094/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3094
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3094/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3094
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3094/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/2350/rebuild

review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

I'm none to familiar with this code, but the change in behaviour looks rather drastic.

Before: a ConnectionSurfaceMap mutex is locked using "execute around method" and ownership isn't shared. Any actions on the MirSurface are under lock.

After: ownership is being shared meaning the MirSurface can be accessed without the lock.

Far from being "safer and more powerful" it will require the reviewer to invest significant thought to ensure that the changed behaviour doesn't violate consistency assumptions made elsewhere in the code.

Why is this necessary?

review: Needs Information
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

The assertion that actions were previously under lock is incorrect. See:

21 - lk.unlock();
22 - exec(surface.get());

So this proposal does not change the locking behaviour at all.

I need this because I'm in a situation where I want each MirBufferStream to hold a weak reference to the MirSurface(s) that use it. This is required to implement client-side vsync where the clock to sync the stream's swapping to is dictated by which output the window (MirSurface) is on.

So MirBufferStream (or anything in future) wants to hold a weak_ptr to its MirSurface(s). Presently we can only store raw pointers, which is unsafe because there's no guarantee the toolkit will always destroy its streams before its surfaces. Using a shared_ptr (or weak_ptr in my case) avoids such risk. And as mentioned above the locking semantics are unchanged.

Admittedly I can work around all this and move forward in my other work but it would be a hack. What I propose here is the cleanest solution and a generally nice to have simplification.

It should also be noted this is not a new idea. It's already used in:

174 virtual std::shared_ptr<MirBuffer> buffer(int buffer_id) const = 0;

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> The assertion that actions were previously under lock is incorrect. See:
>
> 21 - lk.unlock();
> 22 - exec(surface.get());
>
> So this proposal does not change the locking behaviour at all.

Yikes! The existing code is confusing: The *point* of execute-around is to run paired operations *around* the invoked code (e.g. start transaction/end transaction).

It is far too easy to make the mistake I did and assume the lock is being held. If we're not holding the lock then either /1/ there's no need for this pattern; or, /2/ releasing the lock before exec() is an existing error.

Either way, this MP doesn't break things.

review: Approve
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://mir-jenkins.ubuntu.com/job/mir-autolanding/855/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/3082/console
    None: https://mir-jenkins.ubuntu.com/job/generic-land-mp/903/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/3149
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/3141
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/3141
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/3141
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/3111
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/3111/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3111
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3111/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/3111
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/3111/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3111
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3111/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3111
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3111/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3111/console

review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :
Revision history for this message
Mir CI Bot (mir-ci-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/client/connection_surface_map.cpp'
--- src/client/connection_surface_map.cpp 2016-12-02 05:05:06 +0000
+++ src/client/connection_surface_map.cpp 2016-12-08 10:07:47 +0000
@@ -26,23 +26,15 @@
26namespace mcl=mir::client;26namespace mcl=mir::client;
27namespace mf=mir::frontend;27namespace mf=mir::frontend;
2828
29void mcl::ConnectionSurfaceMap::with_surface_do(29using mir::client::ConnectionSurfaceMap;
30 mf::SurfaceId surface_id, std::function<void(MirSurface*)> const& exec) const30using mir::frontend::SurfaceId;
31using mir::frontend::BufferStreamId;
32
33std::shared_ptr<MirSurface> ConnectionSurfaceMap::surface(SurfaceId id) const
31{34{
32 std::shared_lock<decltype(guard)> lk(guard);35 std::shared_lock<decltype(guard)> lk(guard);
33 auto const it = surfaces.find(surface_id);36 auto const found = surfaces.find(id);
34 if (it != surfaces.end())37 return found != surfaces.end() ? found->second : nullptr;
35 {
36 auto const surface = it->second;
37 lk.unlock();
38 exec(surface.get());
39 }
40 else
41 {
42 std::stringstream ss;
43 ss << __PRETTY_FUNCTION__ << "executed with non-existent surface ID " << surface_id;
44 BOOST_THROW_EXCEPTION(std::runtime_error(ss.str()));
45 }
46}38}
4739
48void mcl::ConnectionSurfaceMap::insert(mf::SurfaceId surface_id, std::shared_ptr<MirSurface> const& surface)40void mcl::ConnectionSurfaceMap::insert(mf::SurfaceId surface_id, std::shared_ptr<MirSurface> const& surface)
@@ -57,23 +49,11 @@
57 surfaces.erase(surface_id);49 surfaces.erase(surface_id);
58}50}
5951
60void mcl::ConnectionSurfaceMap::with_stream_do(52std::shared_ptr<MirBufferStream> ConnectionSurfaceMap::stream(BufferStreamId id) const
61 mf::BufferStreamId stream_id, std::function<void(MirBufferStream*)> const& exec) const
62{53{
63 std::shared_lock<decltype(stream_guard)> lk(stream_guard);54 std::shared_lock<decltype(stream_guard)> lk(stream_guard);
64 auto const it = streams.find(stream_id);55 auto const found = streams.find(id);
65 if (it != streams.end())56 return found != streams.end() ? found->second : nullptr;
66 {
67 auto const stream = it->second;
68 lk.unlock();
69 exec(stream.get());
70 }
71 else
72 {
73 std::stringstream ss;
74 ss << __PRETTY_FUNCTION__ << "executed with non-existent stream ID " << stream_id;
75 BOOST_THROW_EXCEPTION(std::runtime_error(ss.str()));
76 }
77}57}
7858
79void mcl::ConnectionSurfaceMap::with_all_streams_do(std::function<void(MirBufferStream*)> const& fn) const59void mcl::ConnectionSurfaceMap::with_all_streams_do(std::function<void(MirBufferStream*)> const& fn) const
8060
=== modified file 'src/client/connection_surface_map.h'
--- src/client/connection_surface_map.h 2016-12-02 05:05:06 +0000
+++ src/client/connection_surface_map.h 2016-12-08 10:07:47 +0000
@@ -34,11 +34,11 @@
34class ConnectionSurfaceMap : public SurfaceMap34class ConnectionSurfaceMap : public SurfaceMap
35{35{
36public:36public:
37 void with_surface_do(frontend::SurfaceId surface_id, std::function<void(MirSurface*)> const& exec) const override;37 virtual std::shared_ptr<MirSurface> surface(frontend::SurfaceId) const override;
38 void insert(frontend::SurfaceId surface_id, std::shared_ptr<MirSurface> const& surface);38 void insert(frontend::SurfaceId surface_id, std::shared_ptr<MirSurface> const& surface);
39 void erase(frontend::SurfaceId surface_id);39 void erase(frontend::SurfaceId surface_id);
4040
41 void with_stream_do(frontend::BufferStreamId stream_id, std::function<void(MirBufferStream*)> const& exec) const override;41 virtual std::shared_ptr<MirBufferStream> stream(frontend::BufferStreamId) const override;
42 void with_all_streams_do(std::function<void(MirBufferStream*)> const&) const override;42 void with_all_streams_do(std::function<void(MirBufferStream*)> const&) const override;
4343
44 void insert(frontend::BufferStreamId stream_id, std::shared_ptr<MirBufferStream> const& chain);44 void insert(frontend::BufferStreamId stream_id, std::shared_ptr<MirBufferStream> const& chain);
4545
=== modified file 'src/client/rpc/mir_protobuf_rpc_channel.cpp'
--- src/client/rpc/mir_protobuf_rpc_channel.cpp 2016-12-02 05:05:06 +0000
+++ src/client/rpc/mir_protobuf_rpc_channel.cpp 2016-12-08 10:07:47 +0000
@@ -312,10 +312,9 @@
312 {312 {
313 if (seq.buffer_request().has_id())313 if (seq.buffer_request().has_id())
314 {314 {
315 map->with_stream_do(mf::BufferStreamId(seq.buffer_request().id().value()),315 mf::BufferStreamId stream_id(seq.buffer_request().id().value());
316 [&] (MirBufferStream* receiver) {316 if (auto receiver = map->stream(stream_id))
317 receiver->buffer_available(seq.buffer_request().buffer());317 receiver->buffer_available(seq.buffer_request().buffer());
318 });
319 }318 }
320 319
321 else if (seq.buffer_request().has_operation())320 else if (seq.buffer_request().has_operation())
@@ -372,46 +371,41 @@
372 {371 {
373 rpc_report->event_parsing_succeeded(*e);372 rpc_report->event_parsing_succeeded(*e);
374373
375 auto const send_e = [&e](MirSurface* surface)374 int surface_id = 0;
376 { surface->handle_event(*e); };375 bool is_surface_event = true;
377376
378 switch (e->type())377 switch (e->type())
379 {378 {
380 case mir_event_type_surface:379 case mir_event_type_surface:
381 if (auto map = surface_map.lock())380 surface_id = e->to_surface()->id();
382 map->with_surface_do(mf::SurfaceId(e->to_surface()->id()), send_e);
383 break;381 break;
384
385 case mir_event_type_resize:382 case mir_event_type_resize:
386 if (auto map = surface_map.lock())383 surface_id = e->to_resize()->surface_id();
387 map->with_surface_do(mf::SurfaceId(e->to_resize()->surface_id()), send_e);
388 break;384 break;
389
390 case mir_event_type_orientation:385 case mir_event_type_orientation:
391 if (auto map = surface_map.lock())386 surface_id = e->to_orientation()->surface_id();
392 map->with_surface_do(mf::SurfaceId(e->to_orientation()->surface_id()), send_e);
393 break;387 break;
394
395 case mir_event_type_close_surface:388 case mir_event_type_close_surface:
396 if (auto map = surface_map.lock())389 surface_id = e->to_close_surface()->surface_id();
397 map->with_surface_do(mf::SurfaceId(e->to_close_surface()->surface_id()), send_e);
398 break;390 break;
399 case mir_event_type_keymap:391 case mir_event_type_keymap:
400 if (auto map = surface_map.lock())392 surface_id = e->to_keymap()->surface_id();
401 map->with_surface_do(mf::SurfaceId(e->to_keymap()->surface_id()), send_e);
402 break;393 break;
403 case mir_event_type_surface_output:394 case mir_event_type_surface_output:
404 if (auto map = surface_map.lock())395 surface_id = e->to_surface_output()->surface_id();
405 map->with_surface_do(mf::SurfaceId(e->to_surface_output()->surface_id()), send_e);
406 break;396 break;
407 case mir_event_type_surface_placement:397 case mir_event_type_surface_placement:
408 if (auto map = surface_map.lock())398 surface_id = e->to_surface_placement()->id();
409 map->with_surface_do(mf::SurfaceId(e->to_surface_placement()->id()), send_e);
410 break;399 break;
411
412 default:400 default:
401 is_surface_event = false;
413 event_sink->handle_event(*e);402 event_sink->handle_event(*e);
414 }403 }
404
405 if (is_surface_event)
406 if (auto map = surface_map.lock())
407 if (auto surf = map->surface(mf::SurfaceId(surface_id)))
408 surf->handle_event(*e);
415 }409 }
416 }410 }
417 catch(...)411 catch(...)
418412
=== modified file 'src/client/surface_map.h'
--- src/client/surface_map.h 2016-12-02 05:05:06 +0000
+++ src/client/surface_map.h 2016-12-08 10:07:47 +0000
@@ -40,10 +40,8 @@
40class SurfaceMap40class SurfaceMap
41{41{
42public:42public:
43 virtual void with_surface_do(43 virtual std::shared_ptr<MirSurface> surface(frontend::SurfaceId) const = 0;
44 frontend::SurfaceId surface_id, std::function<void(MirSurface*)> const& exec) const = 0;44 virtual std::shared_ptr<MirBufferStream> stream(frontend::BufferStreamId) const = 0;
45 virtual void with_stream_do(
46 frontend::BufferStreamId stream_id, std::function<void(MirBufferStream*)> const& exec) const = 0;
47 virtual void with_all_streams_do(std::function<void(MirBufferStream*)> const&) const = 0;45 virtual void with_all_streams_do(std::function<void(MirBufferStream*)> const&) const = 0;
48 virtual std::shared_ptr<MirBuffer> buffer(int buffer_id) const = 0;46 virtual std::shared_ptr<MirBuffer> buffer(int buffer_id) const = 0;
49 virtual void insert(int buffer_id, std::shared_ptr<MirBuffer> const& buffer) = 0;47 virtual void insert(int buffer_id, std::shared_ptr<MirBuffer> const& buffer) = 0;
5048
=== modified file 'tests/unit-tests/client/test_connection_resource_map.cpp'
--- tests/unit-tests/client/test_connection_resource_map.cpp 2016-12-02 05:05:06 +0000
+++ tests/unit-tests/client/test_connection_resource_map.cpp 2016-12-08 10:07:47 +0000
@@ -56,15 +56,9 @@
56TEST_F(ConnectionResourceMap, maps_surface_when_surface_inserted)56TEST_F(ConnectionResourceMap, maps_surface_when_surface_inserted)
57{57{
58 using namespace testing;58 using namespace testing;
59 auto surface_called = false;
60 mcl::ConnectionSurfaceMap map;59 mcl::ConnectionSurfaceMap map;
61 map.insert(surface_id, surface);60 map.insert(surface_id, surface);
62 map.with_surface_do(surface_id, [&](MirSurface* surf) {61 EXPECT_EQ(surface, map.surface(surface_id));
63 EXPECT_THAT(surf, Eq(surface.get()));
64 surface_called = true;
65 });
66
67 EXPECT_TRUE(surface_called);
68}62}
6963
70TEST_F(ConnectionResourceMap, removes_surface_when_surface_removed)64TEST_F(ConnectionResourceMap, removes_surface_when_surface_removed)
@@ -73,22 +67,15 @@
73 mcl::ConnectionSurfaceMap map;67 mcl::ConnectionSurfaceMap map;
74 map.insert(surface_id, surface);68 map.insert(surface_id, surface);
75 map.erase(surface_id);69 map.erase(surface_id);
76 EXPECT_THROW({70 EXPECT_FALSE(map.stream(stream_id));
77 map.with_stream_do(stream_id, [](MirBufferStream*){});
78 }, std::runtime_error);
79}71}
8072
81TEST_F(ConnectionResourceMap, maps_streams)73TEST_F(ConnectionResourceMap, maps_streams)
82{74{
83 using namespace testing;75 using namespace testing;
84 auto stream_called = false;
85 mcl::ConnectionSurfaceMap map;76 mcl::ConnectionSurfaceMap map;
86 map.insert(stream_id, stream);77 map.insert(stream_id, stream);
87 map.with_stream_do(stream_id, [&](MirBufferStream* str) {78 EXPECT_EQ(stream, map.stream(stream_id));
88 EXPECT_THAT(str, Eq(stream.get()));
89 stream_called = true;
90 });
91 EXPECT_TRUE(stream_called);
92 map.erase(stream_id);79 map.erase(stream_id);
93}80}
9481
@@ -126,11 +113,7 @@
126 mcl::ConnectionSurfaceMap map;113 mcl::ConnectionSurfaceMap map;
127 map.insert(buffer_id, buffer);114 map.insert(buffer_id, buffer);
128 map.insert(surface_id, surface);115 map.insert(surface_id, surface);
129116 EXPECT_EQ(buffer, map.buffer(buffer_id));
130 map.with_surface_do(surface_id,
131 [this, &map](auto) {
132 EXPECT_THAT(map.buffer(buffer_id), Eq(buffer));
133 });
134}117}
135118
136TEST_F(ConnectionResourceMap, can_insert_retrieve_erase_render_surface)119TEST_F(ConnectionResourceMap, can_insert_retrieve_erase_render_surface)
137120
=== modified file 'tests/unit-tests/client/test_protobuf_rpc_channel.cpp'
--- tests/unit-tests/client/test_protobuf_rpc_channel.cpp 2016-12-02 05:05:06 +0000
+++ tests/unit-tests/client/test_protobuf_rpc_channel.cpp 2016-12-08 10:07:47 +0000
@@ -59,10 +59,8 @@
5959
60struct MockSurfaceMap : mcl::SurfaceMap60struct MockSurfaceMap : mcl::SurfaceMap
61{61{
62 MOCK_CONST_METHOD2(with_surface_do,62 MOCK_CONST_METHOD1(surface, std::shared_ptr<MirSurface>(mir::frontend::SurfaceId));
63 void(mir::frontend::SurfaceId, std::function<void(MirSurface*)> const&));63 MOCK_CONST_METHOD1(stream, std::shared_ptr<MirBufferStream>(mir::frontend::BufferStreamId));
64 MOCK_CONST_METHOD2(with_stream_do,
65 void(mir::frontend::BufferStreamId, std::function<void(MirBufferStream*)> const&));
66 MOCK_CONST_METHOD1(with_all_streams_do,64 MOCK_CONST_METHOD1(with_all_streams_do,
67 void(std::function<void(MirBufferStream*)> const&));65 void(std::function<void(MirBufferStream*)> const&));
68 MOCK_CONST_METHOD1(buffer, std::shared_ptr<mcl::MirBuffer>(int));66 MOCK_CONST_METHOD1(buffer, std::shared_ptr<mcl::MirBuffer>(int));
@@ -74,13 +72,13 @@
74class StubSurfaceMap : public mcl::SurfaceMap72class StubSurfaceMap : public mcl::SurfaceMap
75{73{
76public:74public:
77 void with_surface_do(75 std::shared_ptr<MirSurface> surface(mir::frontend::SurfaceId) const override
78 mir::frontend::SurfaceId, std::function<void(MirSurface*)> const&) const override
79 {76 {
77 return {};
80 }78 }
81 void with_stream_do(79 std::shared_ptr<MirBufferStream> stream(mir::frontend::BufferStreamId) const override
82 mir::frontend::BufferStreamId, std::function<void(MirBufferStream*)> const&) const override
83 {80 {
81 return {};
84 }82 }
85 void with_all_streams_do(std::function<void(MirBufferStream*)> const&) const override83 void with_all_streams_do(std::function<void(MirBufferStream*)> const&) const override
86 {84 {
@@ -796,7 +794,7 @@
796 auto mock_buffer_factory = std::make_shared<MockBufferFactory>();794 auto mock_buffer_factory = std::make_shared<MockBufferFactory>();
797 auto mock_client_buffer = std::make_shared<mtd::MockClientBuffer>();795 auto mock_client_buffer = std::make_shared<mtd::MockClientBuffer>();
798 auto buf = std::make_shared<mcl::Buffer>(buffer_cb, nullptr, buffer_id, mock_client_buffer, nullptr, mir_buffer_usage_software);796 auto buf = std::make_shared<mcl::Buffer>(buffer_cb, nullptr, buffer_id, mock_client_buffer, nullptr, mir_buffer_usage_software);
799 EXPECT_CALL(*stream_map, with_stream_do(mir::frontend::BufferStreamId{stream_id},_))797 EXPECT_CALL(*stream_map, stream(mir::frontend::BufferStreamId{stream_id}))
800 .Times(1);798 .Times(1);
801799
802 auto transport = std::make_unique<NiceMock<MockStreamTransport>>();800 auto transport = std::make_unique<NiceMock<MockStreamTransport>>();

Subscribers

People subscribed via source and target branches