Mir

Merge lp:~brandontschaefer/mir/mir-event-union-to-struct into lp:mir

Proposed by Brandon Schaefer
Status: Merged
Approved by: Alberto Aguirre
Approved revision: no longer in the source branch.
Merged at revision: 3429
Proposed branch: lp:~brandontschaefer/mir/mir-event-union-to-struct
Merge into: lp:mir
Diff against target: 2818 lines (+902/-598)
31 files modified
include/client/mir_toolkit/events/event.h (+1/-1)
src/client/event.cpp (+15/-20)
src/client/events/CMakeLists.txt (+0/-1)
src/client/events/event_builders.cpp (+100/-73)
src/client/events/make_empty_event.cpp (+0/-42)
src/client/events/make_empty_event.h (+0/-32)
src/client/events/serialization.cpp (+2/-81)
src/client/input/android/event_conversion_helpers.cpp (+4/-3)
src/client/input/input_event.cpp (+39/-89)
src/client/input/xkb_mapper.cpp (+1/-1)
src/client/rpc/mir_protobuf_rpc_channel.cpp (+6/-6)
src/common/CMakeLists.txt (+2/-0)
src/common/events/CMakeLists.txt (+29/-0)
src/common/events/event_private.cpp (+395/-0)
src/common/symbols.map (+20/-0)
src/include/common/mir/events/event_private.h (+94/-61)
src/server/graphics/nested/display_buffer.cpp (+5/-5)
src/server/input/android/input_sender.cpp (+3/-3)
src/server/input/default_event_builder.cpp (+3/-2)
src/server/input/key_repeat_dispatcher.cpp (+8/-17)
src/server/input/surface_input_dispatcher.cpp (+12/-12)
src/server/input/validator.cpp (+13/-13)
tests/unit-tests/client/input/test_android_input_receiver.cpp (+14/-12)
tests/unit-tests/client/input/test_xkb_mapper.cpp (+1/-1)
tests/unit-tests/client/test_event_distributor.cpp (+4/-4)
tests/unit-tests/input/test_input_event.cpp (+41/-41)
tests/unit-tests/input/test_surface_input_dispatcher.cpp (+3/-3)
tests/unit-tests/input/test_validator.cpp (+34/-34)
tests/unit-tests/scene/test_application_session.cpp (+32/-33)
tests/unit-tests/scene/test_surface.cpp (+2/-2)
tests/unit-tests/scene/test_surface_impl.cpp (+19/-6)
To merge this branch: bzr merge lp:~brandontschaefer/mir/mir-event-union-to-struct
Reviewer Review Type Date Requested Status
Cemil Azizoglu (community) Approve
Mir CI Bot continuous-integration Approve
Alberto Aguirre (community) Approve
Review via email: mp+290093@code.launchpad.net

Commit message

Move away from union MirEvents to a structure based MirEvent.

Description of the change

Move away from union MirEvents to a structure based MirEvent.

Need to double check we do not break ABI when we move from typedef union MirEvent --> struct

This is the first of three other branches.

Branch order:
1) Union to Struct for MirEvents
2) MirEvents to encapsulation with getter/setter functions instead of direct access
3) Capnproto support

Instead of this:
https://code.launchpad.net/~brandontschaefer/mir/capnproto-event/+merge/289076
https://code.launchpad.net/~brandontschaefer/mir/capnproto-event/+merge/289076/comments/739742

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

FAILED: Continuous integration, rev:3401
https://mir-jenkins.ubuntu.com/job/mir-ci/653/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/595/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/632
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/624
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/624
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/605
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/605/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/605
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/605/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/605/console
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/605/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/605
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/605/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/605
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/605/artifact/output/*zip*/output.zip

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

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

FAILED: Continuous integration, rev:3403
https://mir-jenkins.ubuntu.com/job/mir-ci/654/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/596/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/633
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/625
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/625
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/606
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/606/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/606
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/606/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/606/console
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/606/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/606
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/606/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/606
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/606/artifact/output/*zip*/output.zip

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

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

PASSED: Continuous integration, rev:3403
https://mir-jenkins.ubuntu.com/job/mir-ci/656/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/598
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/635
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/627
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/627
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/608
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/608/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/608
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/608/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/608
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/608/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/608
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/608/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/608
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/608/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

+MirInputEvent* MirEvent::to_input()
1318 +{
1319 + return reinterpret_cast<MirInputEvent*>(this);
1320 +}

And all other to_xxx methods can all use static_cast

review: Needs Fixing
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

1113 +template<typename T>
1114 +mir::EventUPtr deserialize_from(std::string const& bytes)
1121 +
1122 +template<typename T>
1123 +std::string serialize_from(MirEvent const* ev)
1130 +
1131 +template<typename T>
1132 +MirEvent* deep_copy(MirEvent const* ev)
1133 +{

Maybe a commend that T needs to be TriviallyCopyable?

Or if you can swing it:
static_assert(std::is_trivially_copyable<T>{}, "");

Which won't work for the libstdc++ version in the vivid+overlay...

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

1229 + auto event = new MirKeymapEvent;
...
1233 + if (stream_size < minimal_event_size)
1234 + BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
...
1240 + if (stream_size < minimal_event_size)
1241 + BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));

"event" can leak if you throw (like in 1234 and 1241)

review: Needs Fixing
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Theres __has_trivial_copy

https://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html

Which ill use for now vs checking #defines then using is_trivially_copy as this shouldnt be in the code base that long... we shall hope :).

Everything else fixed!

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

LGTM

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

PASSED: Continuous integration, rev:3404
https://mir-jenkins.ubuntu.com/job/mir-ci/657/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/601
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/638
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/630
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/630
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/611
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/611/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/611
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/611/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/611
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/611/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/611
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/611/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/611
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/611/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

mirevents binary object should be part of mircommon lib - it should not be added separately to mirserver and mirclient.

review: Needs Fixing
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Fixed

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

FAILED: Continuous integration, rev:3405
https://mir-jenkins.ubuntu.com/job/mir-ci/673/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/625/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/662
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/654
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/654
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/635
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/635/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/635
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/635/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/635/console
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/635/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/635
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/635/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/635
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/635/artifact/output/*zip*/output.zip

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

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

FAILED: Continuous integration, rev:3405
https://mir-jenkins.ubuntu.com/job/mir-ci/675/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/627/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/664
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/656
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/656
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/637
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/637/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/637/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/637
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/637/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/637
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/637/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/637
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/637/artifact/output/*zip*/output.zip

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

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

PASSED: Continuous integration, rev:3406
https://mir-jenkins.ubuntu.com/job/mir-ci/677/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/629
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/666
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/658
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/658
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/639
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/639/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/639
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/639/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/639
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/639/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/639
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/639/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/639
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/639/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

Thanks for doing this step. Much easier to review since it does one thing only.

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/client/mir_toolkit/events/event.h'
2--- include/client/mir_toolkit/events/event.h 2016-03-23 06:39:56 +0000
3+++ include/client/mir_toolkit/events/event.h 2016-03-28 23:13:38 +0000
4@@ -60,7 +60,7 @@
5
6 typedef struct MirCookie MirCookie;
7
8-typedef union MirEvent MirEvent;
9+typedef struct MirEvent MirEvent;
10
11 #ifdef __cplusplus
12 }
13
14=== modified file 'src/client/event.cpp'
15--- src/client/event.cpp 2016-01-29 08:18:22 +0000
16+++ src/client/event.cpp 2016-03-28 23:13:38 +0000
17@@ -95,63 +95,63 @@
18 abort();
19 }
20
21- return reinterpret_cast<MirInputEvent const*>(ev);
22+ return ev->to_input();
23 }
24
25 MirSurfaceEvent const* mir_event_get_surface_event(MirEvent const* ev)
26 {
27 expect_event_type(ev, mir_event_type_surface);
28
29- return &ev->surface;
30+ return ev->to_surface();
31 }
32
33 MirResizeEvent const* mir_event_get_resize_event(MirEvent const* ev)
34 {
35 expect_event_type(ev, mir_event_type_resize);
36
37- return &ev->resize;
38+ return ev->to_resize();
39 }
40
41 MirPromptSessionEvent const* mir_event_get_prompt_session_event(MirEvent const* ev)
42 {
43 expect_event_type(ev, mir_event_type_prompt_session_state_change);
44
45- return &ev->prompt_session;
46+ return ev->to_prompt_session();
47 }
48
49 MirOrientationEvent const* mir_event_get_orientation_event(MirEvent const* ev)
50 {
51 expect_event_type(ev, mir_event_type_orientation);
52
53- return &ev->orientation;
54+ return ev->to_orientation();
55 }
56
57 MirCloseSurfaceEvent const* mir_event_get_close_surface_event(MirEvent const* ev)
58 {
59 expect_event_type(ev, mir_event_type_close_surface);
60
61- return &ev->close_surface;
62+ return ev->to_close_surface();
63 }
64
65 MirKeymapEvent const* mir_event_get_keymap_event(MirEvent const* ev)
66 {
67 expect_event_type(ev, mir_event_type_keymap);
68
69- return &ev->keymap;
70+ return ev->to_keymap();
71 }
72
73 MirInputConfigurationEvent const* mir_event_get_input_configuration_event(MirEvent const* ev)
74 {
75 expect_event_type(ev, mir_event_type_input_configuration);
76
77- return &ev->input_configuration;
78+ return ev->to_input_configuration();
79 }
80
81 MirSurfaceOutputEvent const* mir_event_get_surface_output_event(MirEvent const* ev)
82 {
83 expect_event_type(ev, mir_event_type_surface_output);
84
85- return &ev->surface_output;
86+ return ev->to_surface_output();
87 }
88
89 /* Surface event accessors */
90@@ -267,20 +267,15 @@
91 // a ref count ref is implemented as copy.
92 MirEvent const* mir_event_ref(MirEvent const* ev)
93 {
94- MirEvent *new_ev = new MirEvent;
95- memcpy(new_ev, ev, sizeof(MirEvent));
96-
97- if (mir_event_get_type(new_ev) == mir_event_type_keymap)
98- {
99- // malloc to match xkbcommons allocation behavior
100- auto buffer = static_cast<char*>(malloc(new_ev->keymap.size));
101- std::memcpy(buffer, ev->keymap.buffer, new_ev->keymap.size);
102- new_ev->keymap.buffer = buffer;
103- }
104- return new_ev;
105+ return ev->clone();
106 }
107
108 void mir_event_unref(MirEvent const* ev)
109 {
110+ if (mir_event_get_type(ev) == mir_event_type_keymap)
111+ {
112+ std::free(const_cast<char*>(ev->to_keymap()->buffer));
113+ }
114+
115 delete const_cast<MirEvent*>(ev);
116 }
117
118=== modified file 'src/client/events/CMakeLists.txt'
119--- src/client/events/CMakeLists.txt 2016-01-22 16:40:15 +0000
120+++ src/client/events/CMakeLists.txt 2016-03-28 23:13:38 +0000
121@@ -17,7 +17,6 @@
122 list(APPEND MIR_CLIENT_SOURCES
123 ${CMAKE_CURRENT_SOURCE_DIR}/event_builders.cpp
124 ${CMAKE_CURRENT_SOURCE_DIR}/serialization.cpp
125- ${CMAKE_CURRENT_SOURCE_DIR}/make_empty_event.cpp
126 )
127
128 set(MIR_CLIENT_SOURCES ${MIR_CLIENT_SOURCES} PARENT_SCOPE)
129
130=== modified file 'src/client/events/event_builders.cpp'
131--- src/client/events/event_builders.cpp 2016-01-29 08:18:22 +0000
132+++ src/client/events/event_builders.cpp 2016-03-28 23:13:38 +0000
133@@ -20,8 +20,6 @@
134
135 #include "mir/log.h"
136
137-#include "make_empty_event.h"
138-
139 #include "mir/events/event_builders.h"
140 #include "mir/events/event_private.h"
141 #include "mir/cookie/blob.h"
142@@ -56,56 +54,77 @@
143
144 return blob;
145 }
146+
147+template <class T>
148+T* new_event()
149+{
150+ T* t = new T;
151+ memset(t, 0, sizeof(T));
152+
153+ return t;
154+}
155+
156+template <class T>
157+mir::EventUPtr make_uptr_event(T* e)
158+{
159+ return mir::EventUPtr(e, ([](MirEvent* e) { delete reinterpret_cast<T*>(e); }));
160+}
161+
162 }
163
164 mir::EventUPtr mev::make_event(mf::SurfaceId const& surface_id, MirOrientation orientation)
165 {
166- auto e = make_empty_event();
167+ auto e = new_event<MirOrientationEvent>();
168
169 e->type = mir_event_type_orientation;
170- e->orientation.surface_id = surface_id.as_value();
171- e->orientation.direction = orientation;
172- return e;
173+ e->surface_id = surface_id.as_value();
174+ e->direction = orientation;
175+
176+ return make_uptr_event(e);
177 }
178
179 mir::EventUPtr mev::make_event(MirPromptSessionState state)
180 {
181- auto e = make_empty_event();
182+ auto e = new_event<MirPromptSessionEvent>();
183
184 e->type = mir_event_type_prompt_session_state_change;
185- e->prompt_session.new_state = state;
186- return e;
187+ e->new_state = state;
188+
189+ return make_uptr_event(e);
190 }
191
192 mir::EventUPtr mev::make_event(mf::SurfaceId const& surface_id, geom::Size const& size)
193 {
194- auto e = make_empty_event();
195+ auto e = new_event<MirResizeEvent>();
196
197 e->type = mir_event_type_resize;
198- e->resize.surface_id = surface_id.as_value();
199- e->resize.width = size.width.as_int();
200- e->resize.height = size.height.as_int();
201- return e;
202+ e->surface_id = surface_id.as_value();
203+ e->width = size.width.as_int();
204+ e->height = size.height.as_int();
205+
206+ return make_uptr_event(e);
207 }
208
209 mir::EventUPtr mev::make_event(mf::SurfaceId const& surface_id, MirSurfaceAttrib attribute, int value)
210 {
211- auto e = make_empty_event();
212+ auto e = new_event<MirSurfaceEvent>();
213
214 e->type = mir_event_type_surface;
215- e->surface.id = surface_id.as_value();
216- e->surface.attrib = attribute;
217- e->surface.value = value;
218- return e;
219+ e->id = surface_id.as_value();
220+ e->attrib = attribute;
221+ e->value = value;
222+
223+ return make_uptr_event(e);
224 }
225
226 mir::EventUPtr mev::make_event(mf::SurfaceId const& surface_id)
227 {
228- auto e = make_empty_event();
229+ auto e = new_event<MirCloseSurfaceEvent>();
230
231 e->type = mir_event_type_close_surface;
232- e->close_surface.surface_id = surface_id.as_value();
233- return e;
234+ e->surface_id = surface_id.as_value();
235+
236+ return make_uptr_event(e);
237 }
238
239 mir::EventUPtr mev::make_event(
240@@ -115,16 +134,16 @@
241 MirFormFactor form_factor,
242 uint32_t output_id)
243 {
244- auto e = make_empty_event();
245+ auto e = new_event<MirSurfaceOutputEvent>();
246
247 e->type = mir_event_type_surface_output;
248- e->surface_output.surface_id = surface_id.as_value();
249- e->surface_output.dpi = dpi;
250- e->surface_output.scale = scale;
251- e->surface_output.form_factor = form_factor;
252- e->surface_output.output_id = output_id;
253+ e->surface_id = surface_id.as_value();
254+ e->dpi = dpi;
255+ e->scale = scale;
256+ e->form_factor = form_factor;
257+ e->output_id = output_id;
258
259- return e;
260+ return make_uptr_event(e);
261 }
262
263 namespace
264@@ -162,20 +181,19 @@
265 std::vector<uint8_t> const& cookie, MirKeyboardAction action, xkb_keysym_t key_code,
266 int scan_code, MirInputEventModifiers modifiers)
267 {
268- auto e = make_empty_event();
269+ auto e = new_event<MirKeyboardEvent>();
270
271 e->type = mir_event_type_key;
272- auto& kev = e->key;
273- kev.device_id = device_id;
274- kev.source_id = AINPUT_SOURCE_KEYBOARD;
275- kev.event_time = timestamp;
276- kev.cookie = vector_to_cookie_as_blob(cookie);
277- kev.action = action;
278- kev.key_code = key_code;
279- kev.scan_code = scan_code;
280- kev.modifiers = modifiers;
281+ e->device_id = device_id;
282+ e->source_id = AINPUT_SOURCE_KEYBOARD;
283+ e->event_time = timestamp;
284+ e->cookie = vector_to_cookie_as_blob(cookie);
285+ e->action = action;
286+ e->key_code = key_code;
287+ e->scan_code = scan_code;
288+ e->modifiers = modifiers;
289
290- return e;
291+ return make_uptr_event(e);
292 }
293
294 void mev::set_modifier(MirEvent& event, MirInputEventModifiers modifiers)
295@@ -184,13 +202,13 @@
296 {
297 case mir_event_type_key:
298 {
299- auto& kev = event.key;
300+ auto& kev = *event.to_input()->to_keyboard();
301 kev.modifiers = modifiers;
302 break;
303 }
304 case mir_event_type_motion:
305 {
306- auto& mev = event.motion;
307+ auto& mev = *event.to_input()->to_motion();
308 mev.modifiers = modifiers;
309 break;
310 }
311@@ -202,22 +220,22 @@
312 void mev::set_cursor_position(MirEvent& event, mir::geometry::Point const& pos)
313 {
314 if (event.type != mir_event_type_motion &&
315- event.motion.source_id != AINPUT_SOURCE_MOUSE &&
316- event.motion.pointer_count == 1)
317+ event.to_input()->to_motion()->source_id != AINPUT_SOURCE_MOUSE &&
318+ event.to_input()->to_motion()->pointer_count == 1)
319 BOOST_THROW_EXCEPTION(std::invalid_argument("Cursor position is only valid for pointer events."));
320
321- event.motion.pointer_coordinates[0].x = pos.x.as_float();
322- event.motion.pointer_coordinates[0].y = pos.y.as_float();
323+ event.to_input()->to_motion()->pointer_coordinates[0].x = pos.x.as_float();
324+ event.to_input()->to_motion()->pointer_coordinates[0].y = pos.y.as_float();
325 }
326
327 void mev::set_button_state(MirEvent& event, MirPointerButtons button_state)
328 {
329 if (event.type != mir_event_type_motion &&
330- event.motion.source_id != AINPUT_SOURCE_MOUSE &&
331- event.motion.pointer_count == 1)
332+ event.to_input()->to_motion()->source_id != AINPUT_SOURCE_MOUSE &&
333+ event.to_input()->to_motion()->pointer_count == 1)
334 BOOST_THROW_EXCEPTION(std::invalid_argument("Cursor position is only valid for pointer events."));
335
336- event.motion.buttons = button_state;
337+ event.to_input()->to_motion()->buttons = button_state;
338 }
339
340 // Deprecated version with uint64_t mac
341@@ -239,17 +257,16 @@
342 mir::EventUPtr mev::make_event(MirInputDeviceId device_id, std::chrono::nanoseconds timestamp,
343 std::vector<uint8_t> const& cookie, MirInputEventModifiers modifiers)
344 {
345- auto e = make_empty_event();
346+ auto e = new_event<MirMotionEvent>();
347
348 e->type = mir_event_type_motion;
349- auto& mev = e->motion;
350- mev.device_id = device_id;
351- mev.event_time = timestamp;
352- mev.cookie = vector_to_cookie_as_blob(cookie);
353- mev.modifiers = modifiers;
354- mev.source_id = AINPUT_SOURCE_TOUCHSCREEN;
355+ e->device_id = device_id;
356+ e->event_time = timestamp;
357+ e->cookie = vector_to_cookie_as_blob(cookie);
358+ e->modifiers = modifiers;
359+ e->source_id = AINPUT_SOURCE_TOUCHSCREEN;
360
361- return e;
362+ return make_uptr_event(e);
363 }
364
365 // Deprecated version with uint64_t mac
366@@ -270,8 +287,8 @@
367 MirTouchTooltype tooltype, float x_axis_value, float y_axis_value,
368 float pressure_value, float touch_major_value, float touch_minor_value, float size_value)
369 {
370- auto& mev = event.motion;
371- auto& pc = mev.pointer_coordinates[mev.pointer_count++];
372+ auto mev = event.to_input()->to_motion();
373+ auto& pc = mev->pointer_coordinates[mev->pointer_count++];
374 pc.id = touch_id;
375 pc.tool_type = tooltype;
376 pc.x = x_axis_value;
377@@ -290,10 +307,10 @@
378 float hscroll_value, float vscroll_value,
379 float relative_x_value, float relative_y_value)
380 {
381- auto e = make_empty_event();
382+ auto e = new_event<MirMotionEvent>();
383
384 e->type = mir_event_type_motion;
385- auto& mev = e->motion;
386+ auto& mev = *e->to_input()->to_motion();
387 mev.device_id = device_id;
388 mev.event_time = timestamp;
389 mev.cookie = vector_to_cookie_as_blob(cookie);
390@@ -311,7 +328,7 @@
391 pc.hscroll = hscroll_value;
392 pc.vscroll = vscroll_value;
393
394- return e;
395+ return make_uptr_event(e);
396 }
397
398 // Deprecated version with uint64_t mac
399@@ -365,7 +382,17 @@
400 mir::EventUPtr mev::make_event(mf::SurfaceId const& surface_id, MirInputDeviceId id, std::string const& model,
401 std::string const& layout, std::string const& variant, std::string const& options)
402 {
403- auto e = make_empty_event();
404+ auto e = new_event<MirKeymapEvent>();
405+ auto ep = mir::EventUPtr(e, [](MirEvent* e) {
406+ // xkbcommon creates the keymap through malloc
407+ if (e && e->type == mir_event_type_keymap)
408+ {
409+ auto keymap = e->to_keymap();
410+ std::free(const_cast<char*>(keymap->buffer));
411+ }
412+
413+ delete e;
414+ });
415
416 auto ctx = mi::make_unique_context();
417 auto map = mi::make_unique_keymap(ctx.get(), model, layout, variant, options);
418@@ -374,23 +401,23 @@
419 BOOST_THROW_EXCEPTION(std::runtime_error("failed to assemble keymap from given parameters"));
420
421 e->type = mir_event_type_keymap;
422- e->keymap.surface_id = surface_id.as_value();
423- e->keymap.device_id = id;
424+ e->surface_id = surface_id.as_value();
425+ e->device_id = id;
426 // TODO consider caching compiled keymaps
427- e->keymap.buffer = xkb_keymap_get_as_string(map.get(), XKB_KEYMAP_FORMAT_TEXT_V1);
428- e->keymap.size = strlen(e->keymap.buffer);
429+ e->buffer = xkb_keymap_get_as_string(map.get(), XKB_KEYMAP_FORMAT_TEXT_V1);
430+ e->size = strlen(e->to_keymap()->buffer);
431
432- return e;
433+ return ep;
434 }
435
436 mir::EventUPtr mev::make_event(MirInputConfigurationAction action, MirInputDeviceId id, std::chrono::nanoseconds time)
437 {
438- auto e = make_empty_event();
439+ auto e = new_event<MirInputConfigurationEvent>();
440
441 e->type = mir_event_type_input_configuration;
442- e->input_configuration.action = action;
443- e->input_configuration.when = time;
444- e->input_configuration.id = id;
445+ e->action = action;
446+ e->when = time;
447+ e->id = id;
448
449- return e;
450+ return make_uptr_event(e);
451 }
452
453=== removed file 'src/client/events/make_empty_event.cpp'
454--- src/client/events/make_empty_event.cpp 2016-01-22 16:40:15 +0000
455+++ src/client/events/make_empty_event.cpp 1970-01-01 00:00:00 +0000
456@@ -1,42 +0,0 @@
457-/*
458- * Copyright © 2016 Canonical Ltd.
459- *
460- * This program is free software: you can redistribute it and/or modify it
461- * under the terms of the GNU Lesser General Public License version 3,
462- * as published by the Free Software Foundation.
463- *
464- * This program is distributed in the hope that it will be useful,
465- * but WITHOUT ANY WARRANTY; without even the implied warranty of
466- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
467- * GNU Lesser General Public License for more details.
468- *
469- * You should have received a copy of the GNU Lesser General Public License
470- * along with this program. If not, see <http://www.gnu.org/licenses/>.
471- *
472- * Author: Andreas Pokorny <andreas.pokorny@canonical.com>
473- */
474-
475-#include "make_empty_event.h"
476-#include "mir/events/event_private.h"
477-
478-#include <cstring>
479-#include <cstdlib>
480-
481-namespace mev = mir::events;
482-namespace
483-{
484- void delete_event(MirEvent *e)
485- {
486- // xkbcommon creates the keymap through malloc
487- if (e && e->type == mir_event_type_keymap)
488- std::free(const_cast<char*>(e->keymap.buffer));
489- delete e;
490- }
491-}
492-
493-mir::EventUPtr mev::make_empty_event()
494-{
495- auto e = new MirEvent;
496- std::memset(e, 0, sizeof (MirEvent));
497- return mir::EventUPtr(e, delete_event);
498-}
499
500=== removed file 'src/client/events/make_empty_event.h'
501--- src/client/events/make_empty_event.h 2016-01-22 16:40:15 +0000
502+++ src/client/events/make_empty_event.h 1970-01-01 00:00:00 +0000
503@@ -1,32 +0,0 @@
504-/*
505- * Copyright © 2016 Canonical Ltd.
506- *
507- * This program is free software: you can redistribute it and/or modify it
508- * under the terms of the GNU Lesser General Public License version 3,
509- * as published by the Free Software Foundation.
510- *
511- * This program is distributed in the hope that it will be useful,
512- * but WITHOUT ANY WARRANTY; without even the implied warranty of
513- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
514- * GNU Lesser General Public License for more details.
515- *
516- * You should have received a copy of the GNU Lesser General Public License
517- * along with this program. If not, see <http://www.gnu.org/licenses/>.
518- *
519- * Author: Andreas Pokorny <andreas.pokorny@canonical.com>
520- */
521-
522-#ifndef MIR_EVENTS_MAKE_EMPTY_EVENTS_H_
523-#define MIR_EVENTS_MAKE_EMPTY_EVENTS_H_
524-
525-#include "mir/events/event_builders.h"
526-
527-namespace mir
528-{
529-namespace events
530-{
531-mir::EventUPtr make_empty_event();
532-}
533-}
534-
535-#endif
536
537=== modified file 'src/client/events/serialization.cpp'
538--- src/client/events/serialization.cpp 2016-01-22 16:40:15 +0000
539+++ src/client/events/serialization.cpp 2016-03-28 23:13:38 +0000
540@@ -16,96 +16,17 @@
541 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
542 */
543
544-#include "make_empty_event.h"
545 #include "mir/events/serialization.h"
546 #include "mir/events/event_private.h"
547
548-#include <boost/throw_exception.hpp>
549-#include <cstring>
550-
551 namespace mev = mir::events;
552
553-namespace
554-{
555-template<typename Data>
556-char const* consume(char const* pos, Data& data)
557-{
558- std::memcpy(&data, pos, sizeof data);
559- return pos + sizeof data;
560-}
561-
562-template<typename Data>
563-void encode(std::string& encoded, Data const& data)
564-{
565- encoded.append(reinterpret_cast<char const*>(&data), sizeof data);
566-}
567-}
568-
569 std::string mev::serialize_event(MirEvent const& event)
570 {
571- auto type = mir_event_get_type(&event);
572-
573- switch (type)
574- {
575- case mir_event_type_keymap:
576- {
577- std::string encoded;
578- auto const& keymap = event.keymap;
579- encoded.reserve(sizeof event.type +
580- sizeof keymap.surface_id +
581- sizeof keymap.device_id +
582- sizeof keymap.size +
583- keymap.size);
584- encode(encoded, event.type);
585- encode(encoded, keymap.surface_id);
586- encode(encoded, keymap.device_id);
587- encode(encoded, keymap.size);
588- encoded.append(keymap.buffer, keymap.size);
589- return encoded;
590- }
591- default:
592- return {reinterpret_cast<char const*>(&event), sizeof event};
593- }
594+ return MirEvent::serialize(&event);
595 }
596
597 mir::EventUPtr mev::deserialize_event(std::string const& raw)
598 {
599- auto ev = make_empty_event();
600- auto& event = *ev;
601- auto minimal_event_size = sizeof event.type;
602- auto const stream_size = raw.size();
603- if (stream_size < minimal_event_size)
604- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
605-
606- char const* pos = consume(raw.data(), event.type);
607-
608- switch (event.type)
609- {
610- case mir_event_type_keymap:
611- {
612- auto& keymap = event.keymap;
613- minimal_event_size += sizeof keymap.surface_id + sizeof keymap.device_id + sizeof keymap.size;
614-
615- if (stream_size < minimal_event_size)
616- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
617- pos = consume(pos, keymap.surface_id);
618- pos = consume(pos, keymap.device_id);
619- pos = consume(pos, keymap.size);
620-
621- minimal_event_size += keymap.size;
622-
623- if (stream_size < minimal_event_size)
624- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
625-
626- auto buffer = static_cast<char*>(malloc(keymap.size));
627- std::memcpy(buffer, pos, keymap.size);
628- keymap.buffer = buffer;
629- break;
630- }
631- default:
632- consume(raw.data(), event);
633- break;
634- }
635-
636- return ev;
637+ return MirEvent::deserialize(raw);
638 }
639
640=== modified file 'src/client/input/android/event_conversion_helpers.cpp'
641--- src/client/input/android/event_conversion_helpers.cpp 2016-03-23 06:39:56 +0000
642+++ src/client/input/android/event_conversion_helpers.cpp 2016-03-28 23:13:38 +0000
643@@ -201,7 +201,7 @@
644 int32_t mia::extract_masked_android_action_from(MirEvent const& ev)
645 {
646 int index_with_action = -1;
647- auto const& mev = ev.motion;
648+ auto const& mev = *ev.to_input()->to_motion();
649
650 for (unsigned i = 0; i < mev.pointer_count; i++)
651 {
652@@ -275,10 +275,11 @@
653
654 int32_t mia::extract_android_action_from(MirEvent const& event)
655 {
656- if (mia::android_source_id_is_pointer_device(event.motion.source_id))
657+ auto& mev = *event.to_input()->to_motion();
658+ if (mia::android_source_id_is_pointer_device(mev.source_id))
659 {
660 return mia::android_pointer_action_from_mir(
661- static_cast<MirPointerAction>(event.motion.pointer_coordinates[0].action), event.motion.buttons);
662+ static_cast<MirPointerAction>(mev.pointer_coordinates[0].action), mev.buttons);
663 }
664 else
665 {
666
667=== modified file 'src/client/input/input_event.cpp'
668--- src/client/input/input_event.cpp 2016-03-23 06:39:56 +0000
669+++ src/client/input/input_event.cpp 2016-03-28 23:13:38 +0000
670@@ -33,16 +33,6 @@
671
672 namespace
673 {
674-void expect_old_event_type(MirEvent const* ev, MirEventType t)
675-{
676- if (ev->type != t)
677- {
678- mir::log_critical("Expected " + mir::event_type_to_string(t) + " but event is of type " +
679- mir::event_type_to_string(ev->type));
680- abort();
681- }
682-}
683-
684 std::string input_event_type_to_string(MirInputEventType input_event_type)
685 {
686 switch (input_event_type)
687@@ -84,25 +74,6 @@
688 AINPUT_SOURCE_ANY = 0xffffff00
689 };
690
691-MirEvent const* old_ev_from_new(MirInputEvent const* ev)
692-{
693- return reinterpret_cast<MirEvent const*>(ev);
694-}
695-
696-MirMotionEvent const& old_mev_from_new(MirTouchEvent const* ev)
697-{
698- auto old_ev = reinterpret_cast<MirEvent const*>(ev);
699- expect_old_event_type(old_ev, mir_event_type_motion);
700- return old_ev->motion;
701-}
702-
703-MirMotionEvent const& old_mev_from_new(MirPointerEvent const* ev)
704-{
705- auto old_ev = reinterpret_cast<MirEvent const*>(ev);
706- expect_old_event_type(old_ev, mir_event_type_motion);
707- return old_ev->motion;
708-}
709-
710 // Differentiate between MirTouchEvents and MirPointerEvents based on old device class
711 MirInputEventType type_from_device_class(int32_t source_class)
712 {
713@@ -122,20 +93,18 @@
714
715 MirInputEventType mir_input_event_get_type(MirInputEvent const* ev)
716 {
717- auto old_ev = old_ev_from_new(ev);
718-
719- if (old_ev->type != mir_event_type_key && old_ev->type != mir_event_type_motion)
720+ if (ev->type != mir_event_type_key && ev->type != mir_event_type_motion)
721 {
722- mir::log_critical("expected input event but event was of type " + mir::event_type_to_string(old_ev->type));
723+ mir::log_critical("expected input event but event was of type " + mir::event_type_to_string(ev->type));
724 abort();
725 }
726
727- switch (old_ev->type)
728+ switch (ev->type)
729 {
730 case mir_event_type_key:
731 return mir_input_event_type_key;
732 case mir_event_type_motion:
733- return type_from_device_class(old_ev->motion.source_id);
734+ return type_from_device_class(ev->to_motion()->source_id);
735 default:
736 abort();
737 }
738@@ -143,20 +112,18 @@
739
740 MirInputDeviceId mir_input_event_get_device_id(MirInputEvent const* ev)
741 {
742- auto old_ev = old_ev_from_new(ev);
743-
744- if(mir_event_get_type(old_ev) != mir_event_type_input)
745+ if(mir_event_get_type(ev) != mir_event_type_input)
746 {
747- mir::log_critical("expected input event but event was of type " + mir::event_type_to_string(old_ev->type));
748+ mir::log_critical("expected input event but event was of type " + mir::event_type_to_string(ev->type));
749 abort();
750 }
751
752- switch (old_ev->type)
753+ switch (ev->type)
754 {
755 case mir_event_type_motion:
756- return old_ev->motion.device_id;
757+ return ev->to_motion()->device_id;
758 case mir_event_type_key:
759- return old_ev->key.device_id;
760+ return ev->to_keyboard()->device_id;
761 default:
762 abort();
763 }
764@@ -164,19 +131,18 @@
765
766 int64_t mir_input_event_get_event_time(MirInputEvent const* ev)
767 {
768- auto old_ev = old_ev_from_new(ev);
769- if(mir_event_get_type(old_ev) != mir_event_type_input)
770+ if(mir_event_get_type(ev) != mir_event_type_input)
771 {
772- mir::log_critical("expected input event but event was of type " + mir::event_type_to_string(old_ev->type));
773+ mir::log_critical("expected input event but event was of type " + mir::event_type_to_string(ev->type));
774 abort();
775 }
776
777- switch (old_ev->type)
778+ switch (ev->type)
779 {
780 case mir_event_type_motion:
781- return old_ev->motion.event_time.count();
782+ return ev->to_motion()->event_time.count();
783 case mir_event_type_key:
784- return old_ev->key.event_time.count();
785+ return ev->to_keyboard()->event_time.count();
786 default:
787 abort();
788 }
789@@ -234,8 +200,7 @@
790
791 MirInputEventModifiers mir_touch_event_modifiers(MirTouchEvent const* tev)
792 {
793- auto const& old_mev = old_mev_from_new(tev);
794- return old_mev.modifiers;
795+ return tev->to_motion()->modifiers;
796 }
797
798 MirTouchEvent const* mir_input_event_get_touch_event(MirInputEvent const* ev)
799@@ -252,62 +217,53 @@
800
801 unsigned int mir_touch_event_point_count(MirTouchEvent const* event)
802 {
803- auto const& old_mev = reinterpret_cast<MirEvent const*>(event)->motion;
804- return old_mev.pointer_count;
805+ return event->to_motion()->pointer_count;
806 }
807
808 MirTouchId mir_touch_event_id(MirTouchEvent const* event, size_t touch_index)
809 {
810- auto const& old_mev = old_mev_from_new(event);
811-
812- if (touch_index >= old_mev.pointer_count)
813+ if (touch_index >= event->to_motion()->pointer_count)
814 {
815 mir::log_critical("touch index is greater than pointer count");
816 abort();
817 }
818
819- return old_mev.pointer_coordinates[touch_index].id;
820+ return event->to_motion()->pointer_coordinates[touch_index].id;
821 }
822
823 MirTouchAction mir_touch_event_action(MirTouchEvent const* event, size_t touch_index)
824 {
825- auto const& old_mev = old_mev_from_new(event);
826-
827- if(touch_index > old_mev.pointer_count)
828+ if(touch_index > event->to_motion()->pointer_count)
829 {
830 mir::log_critical("touch index is greater than pointer count");
831 abort();
832 }
833
834- return static_cast<MirTouchAction>(old_mev.pointer_coordinates[touch_index].action);
835+ return static_cast<MirTouchAction>(event->to_motion()->pointer_coordinates[touch_index].action);
836 }
837
838 MirTouchTooltype mir_touch_event_tooltype(MirTouchEvent const* event,
839 size_t touch_index)
840 {
841- auto const& old_mev = old_mev_from_new(event);
842-
843- if(touch_index > old_mev.pointer_count)
844+ if(touch_index > event->to_motion()->pointer_count)
845 {
846 mir::log_critical("touch index is greater than pointer count");
847 abort();
848 }
849
850- return old_mev.pointer_coordinates[touch_index].tool_type;
851+ return event->to_motion()->pointer_coordinates[touch_index].tool_type;
852 }
853
854 float mir_touch_event_axis_value(MirTouchEvent const* event,
855 size_t touch_index, MirTouchAxis axis)
856 {
857- auto const& old_mev = old_mev_from_new(event);
858-
859- if(touch_index > old_mev.pointer_count)
860+ if(touch_index > event->to_motion()->pointer_count)
861 {
862 mir::log_critical("touch index is greater than pointer count");
863 abort();
864 }
865
866- auto const& old_pc = old_mev.pointer_coordinates[touch_index];
867+ auto const& old_pc = event->to_motion()->pointer_coordinates[touch_index];
868 switch (axis)
869 {
870 case mir_touch_axis_x:
871@@ -343,46 +299,42 @@
872
873 MirInputEventModifiers mir_pointer_event_modifiers(MirPointerEvent const* pev)
874 {
875- auto const& old_mev = old_mev_from_new(pev);
876- return old_mev.modifiers;
877+ return pev->to_motion()->modifiers;
878 }
879
880 MirPointerAction mir_pointer_event_action(MirPointerEvent const* pev)
881 {
882- auto const& old_mev = old_mev_from_new(pev);
883- return static_cast<MirPointerAction>(old_mev.pointer_coordinates[0].action);
884+ return static_cast<MirPointerAction>(pev->to_motion()->pointer_coordinates[0].action);
885 }
886
887 bool mir_pointer_event_button_state(MirPointerEvent const* pev,
888 MirPointerButton button)
889 {
890- auto const& old_mev = old_mev_from_new(pev);
891- return old_mev.buttons & button;
892+ return pev->to_motion()->buttons & button;
893 }
894
895 MirPointerButtons mir_pointer_event_buttons(MirPointerEvent const* pev)
896 {
897- auto const& old_mev = old_mev_from_new(pev);
898- return old_mev.buttons;
899+ return pev->to_motion()->buttons;
900 }
901
902 float mir_pointer_event_axis_value(MirPointerEvent const* pev, MirPointerAxis axis)
903 {
904- auto const& old_mev = old_mev_from_new(pev);
905+ auto mev = pev->to_motion();
906 switch (axis)
907 {
908 case mir_pointer_axis_x:
909- return old_mev.pointer_coordinates[0].x;
910+ return mev->pointer_coordinates[0].x;
911 case mir_pointer_axis_y:
912- return old_mev.pointer_coordinates[0].y;
913+ return mev->pointer_coordinates[0].y;
914 case mir_pointer_axis_relative_x:
915- return old_mev.pointer_coordinates[0].dx;
916+ return mev->pointer_coordinates[0].dx;
917 case mir_pointer_axis_relative_y:
918- return old_mev.pointer_coordinates[0].dy;
919+ return mev->pointer_coordinates[0].dy;
920 case mir_pointer_axis_vscroll:
921- return old_mev.pointer_coordinates[0].vscroll;
922+ return mev->pointer_coordinates[0].vscroll;
923 case mir_pointer_axis_hscroll:
924- return old_mev.pointer_coordinates[0].hscroll;
925+ return mev->pointer_coordinates[0].hscroll;
926 default:
927 mir::log_critical("Invalid axis enumeration " + std::to_string(axis));
928 abort();
929@@ -432,17 +384,15 @@
930
931 MirCookie const* mir_input_event_get_cookie(MirInputEvent const* iev) try
932 {
933- auto const ev = old_ev_from_new(iev);
934-
935- switch (ev->type)
936+ switch (iev->type)
937 {
938 case mir_event_type_motion:
939- return new MirCookie(ev->motion.cookie);
940+ return new MirCookie(iev->to_motion()->cookie);
941 case mir_event_type_key:
942- return new MirCookie(ev->key.cookie);
943+ return new MirCookie(iev->to_keyboard()->cookie);
944 default:
945 {
946- mir::log_critical("expected a key or motion events, type was: " + mir::event_type_to_string(ev->type));
947+ mir::log_critical("expected a key or motion events, type was: " + mir::event_type_to_string(iev->type));
948 abort();
949 }
950 }
951
952=== modified file 'src/client/input/xkb_mapper.cpp'
953--- src/client/input/xkb_mapper.cpp 2016-01-29 08:18:22 +0000
954+++ src/client/input/xkb_mapper.cpp 2016-03-28 23:13:38 +0000
955@@ -103,7 +103,7 @@
956 {
957 std::lock_guard<std::mutex> lg(guard);
958
959- auto& key_ev = ev.key;
960+ auto& key_ev = *ev.to_input()->to_keyboard();
961
962 xkb_key_direction direction = XKB_KEY_DOWN;
963
964
965=== modified file 'src/client/rpc/mir_protobuf_rpc_channel.cpp'
966--- src/client/rpc/mir_protobuf_rpc_channel.cpp 2016-03-23 06:39:56 +0000
967+++ src/client/rpc/mir_protobuf_rpc_channel.cpp 2016-03-28 23:13:38 +0000
968@@ -346,30 +346,30 @@
969 {
970 case mir_event_type_surface:
971 if (auto map = surface_map.lock())
972- map->with_surface_do(mf::SurfaceId(e->surface.id), send_e);
973+ map->with_surface_do(mf::SurfaceId(e->to_surface()->id), send_e);
974 break;
975
976 case mir_event_type_resize:
977 if (auto map = surface_map.lock())
978- map->with_surface_do(mf::SurfaceId(e->resize.surface_id), send_e);
979+ map->with_surface_do(mf::SurfaceId(e->to_resize()->surface_id), send_e);
980 break;
981
982 case mir_event_type_orientation:
983 if (auto map = surface_map.lock())
984- map->with_surface_do(mf::SurfaceId(e->orientation.surface_id), send_e);
985+ map->with_surface_do(mf::SurfaceId(e->to_orientation()->surface_id), send_e);
986 break;
987
988 case mir_event_type_close_surface:
989 if (auto map = surface_map.lock())
990- map->with_surface_do(mf::SurfaceId(e->close_surface.surface_id), send_e);
991+ map->with_surface_do(mf::SurfaceId(e->to_close_surface()->surface_id), send_e);
992 break;
993 case mir_event_type_keymap:
994 if (auto map = surface_map.lock())
995- map->with_surface_do(mf::SurfaceId(e->keymap.surface_id), send_e);
996+ map->with_surface_do(mf::SurfaceId(e->to_keymap()->surface_id), send_e);
997 break;
998 case mir_event_type_surface_output:
999 if (auto map = surface_map.lock())
1000- map->with_surface_do(mf::SurfaceId(e->surface_output.surface_id), send_e);
1001+ map->with_surface_do(mf::SurfaceId(e->to_surface_output()->surface_id), send_e);
1002 break;
1003 default:
1004 event_sink->handle_event(*e);
1005
1006=== modified file 'src/common/CMakeLists.txt'
1007--- src/common/CMakeLists.txt 2016-01-29 08:18:22 +0000
1008+++ src/common/CMakeLists.txt 2016-03-28 23:13:38 +0000
1009@@ -6,6 +6,7 @@
1010
1011 add_subdirectory(fd)
1012 add_subdirectory(geometry)
1013+add_subdirectory(events)
1014 add_subdirectory(logging)
1015 add_subdirectory(report/lttng)
1016 add_subdirectory(env)
1017@@ -16,6 +17,7 @@
1018 add_subdirectory(fatal)
1019
1020 list(APPEND MIR_COMMON_SOURCES
1021+ $<TARGET_OBJECTS:mirevents>
1022 $<TARGET_OBJECTS:mirtime>
1023 $<TARGET_OBJECTS:mirfatal>
1024 $<TARGET_OBJECTS:android-input-common>
1025
1026=== added directory 'src/common/events'
1027=== added file 'src/common/events/CMakeLists.txt'
1028--- src/common/events/CMakeLists.txt 1970-01-01 00:00:00 +0000
1029+++ src/common/events/CMakeLists.txt 2016-03-28 23:13:38 +0000
1030@@ -0,0 +1,29 @@
1031+# Copyright © 2016 Canonical Ltd.
1032+#
1033+# This program is free software: you can redistribute it and/or modify it
1034+# under the terms of the GNU Lesser General Public License version 3,
1035+# as published by the Free Software Foundation.
1036+#
1037+# This program is distributed in the hope that it will be useful,
1038+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1039+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1040+# GNU Lesser General Public License for more details.
1041+#
1042+# You should have received a copy of the GNU Lesser General Public License
1043+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1044+#
1045+# Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
1046+
1047+set(EVENT_SOURCES
1048+ event_private.cpp
1049+)
1050+
1051+add_library(
1052+ mirevents OBJECT
1053+ ${EVENT_SOURCES}
1054+)
1055+
1056+include_directories(
1057+ ${PROJECT_SOURCE_DIR}/include/client
1058+ ${PROJECT_SOURCE_DIR}/src/include/cookie
1059+)
1060
1061=== added file 'src/common/events/event_private.cpp'
1062--- src/common/events/event_private.cpp 1970-01-01 00:00:00 +0000
1063+++ src/common/events/event_private.cpp 2016-03-28 23:13:38 +0000
1064@@ -0,0 +1,395 @@
1065+/*
1066+ * Copyright © 2016 Canonical Ltd.
1067+ *
1068+ * This program is free software: you can redistribute it and/or modify it
1069+ * under the terms of the GNU Lesser General Public License version 3,
1070+ * as published by the Free Software Foundation.
1071+ *
1072+ * This program is distributed in the hope that it will be useful,
1073+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1074+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1075+ * GNU Lesser General Public License for more details.
1076+ *
1077+ * You should have received a copy of the GNU Lesser General Public License
1078+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1079+ *
1080+ * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
1081+ */
1082+
1083+#include "mir/events/event_private.h"
1084+
1085+#include <cstring>
1086+
1087+#include <boost/throw_exception.hpp>
1088+
1089+//TODO Temp functions until we move to capnproto which will do this for us!
1090+namespace
1091+{
1092+void delete_keymap_event(MirEvent* e)
1093+{
1094+ if (e && e->to_keymap()->buffer)
1095+ {
1096+ std::free(const_cast<char*>(e->to_keymap()->buffer));
1097+ }
1098+
1099+ delete e;
1100+}
1101+
1102+// consume/encode needed for keymap!
1103+template<typename Data>
1104+char const* consume(char const* pos, Data& data)
1105+{
1106+ std::memcpy(&data, pos, sizeof data);
1107+ return pos + sizeof data;
1108+}
1109+
1110+template<typename Data>
1111+void encode(std::string& encoded, Data const& data)
1112+{
1113+ encoded.append(reinterpret_cast<char const*>(&data), sizeof data);
1114+}
1115+
1116+template<typename T>
1117+void assert_type_is_trivially_copyable()
1118+{
1119+#if __GNUC__ >= 5
1120+ static_assert(std::is_trivially_copyable<T>::value, "");
1121+#else
1122+ static_assert(__has_trivial_copy(T), "");
1123+#endif
1124+}
1125+
1126+// T needs to be trivially copyable
1127+// vivid wont allow a std::is_trivially_copyable
1128+template<typename T>
1129+mir::EventUPtr deserialize_from(std::string const& bytes)
1130+{
1131+ assert_type_is_trivially_copyable<T>();
1132+
1133+ T* t = new T;
1134+ memcpy(t, bytes.data(), bytes.size());
1135+
1136+ return mir::EventUPtr(t, [](MirEvent* e) { delete e; });
1137+}
1138+
1139+template<typename T>
1140+std::string serialize_from(MirEvent const* ev)
1141+{
1142+ assert_type_is_trivially_copyable<T>();
1143+
1144+ std::string encoded_bytes;
1145+ encoded_bytes.append(reinterpret_cast<char const*>(ev), sizeof(T));
1146+
1147+ return encoded_bytes;
1148+}
1149+
1150+template<typename T>
1151+MirEvent* deep_copy(MirEvent const* ev)
1152+{
1153+ assert_type_is_trivially_copyable<T>();
1154+
1155+ T* t = new T;
1156+ memcpy(t, ev, sizeof(T));
1157+
1158+ return t;
1159+}
1160+}
1161+
1162+MirEvent* MirEvent::clone() const
1163+{
1164+ switch (type)
1165+ {
1166+ case mir_event_type_key:
1167+ return deep_copy<MirKeyboardEvent>(this);
1168+ case mir_event_type_motion:
1169+ return deep_copy<MirMotionEvent>(this);
1170+ case mir_event_type_surface:
1171+ return deep_copy<MirSurfaceEvent>(this);
1172+ case mir_event_type_resize:
1173+ return deep_copy<MirResizeEvent>(this);
1174+ case mir_event_type_prompt_session_state_change:
1175+ return deep_copy<MirPromptSessionEvent>(this);
1176+ case mir_event_type_orientation:
1177+ return deep_copy<MirOrientationEvent>(this);
1178+ case mir_event_type_close_surface:
1179+ return deep_copy<MirCloseSurfaceEvent>(this);
1180+ case mir_event_type_input_configuration:
1181+ return deep_copy<MirInputConfigurationEvent>(this);
1182+ case mir_event_type_surface_output:
1183+ return deep_copy<MirSurfaceOutputEvent>(this);
1184+ case mir_event_type_keymap:
1185+ return to_keymap()->clone();
1186+ case mir_event_type_input:
1187+ default:
1188+ break;
1189+ }
1190+
1191+ BOOST_THROW_EXCEPTION(std::runtime_error("Failed to clone event"));
1192+}
1193+
1194+MirEvent* MirKeymapEvent::clone() const
1195+{
1196+ auto new_ev = deep_copy<MirKeymapEvent>(this);
1197+ auto keymap = new_ev->to_keymap();
1198+
1199+ // malloc to match xkbcommons allocation behavior
1200+ auto buffer = static_cast<char*>(malloc(keymap->size));
1201+ std::memcpy(buffer, keymap->buffer, keymap->size);
1202+ keymap->buffer = buffer;
1203+
1204+ return new_ev;
1205+}
1206+
1207+mir::EventUPtr MirEvent::deserialize(std::string const& bytes)
1208+{
1209+ // Just getting the type from the raw bytes, discard after
1210+ MirEvent event;
1211+ auto minimal_event_size = sizeof event.type;
1212+ auto const stream_size = bytes.size();
1213+ if (stream_size < minimal_event_size)
1214+ BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
1215+
1216+ consume(bytes.data(), event.type);
1217+
1218+ switch (event.type)
1219+ {
1220+ case mir_event_type_key:
1221+ return deserialize_from<MirKeyboardEvent>(bytes);
1222+ case mir_event_type_motion:
1223+ return deserialize_from<MirMotionEvent>(bytes);
1224+ case mir_event_type_surface:
1225+ return deserialize_from<MirSurfaceEvent>(bytes);
1226+ case mir_event_type_resize:
1227+ return deserialize_from<MirResizeEvent>(bytes);
1228+ case mir_event_type_prompt_session_state_change:
1229+ return deserialize_from<MirPromptSessionEvent>(bytes);
1230+ case mir_event_type_orientation:
1231+ return deserialize_from<MirOrientationEvent>(bytes);
1232+ case mir_event_type_close_surface:
1233+ return deserialize_from<MirCloseSurfaceEvent>(bytes);
1234+ case mir_event_type_input_configuration:
1235+ return deserialize_from<MirInputConfigurationEvent>(bytes);
1236+ case mir_event_type_surface_output:
1237+ return deserialize_from<MirSurfaceOutputEvent>(bytes);
1238+ case mir_event_type_keymap:
1239+ return MirKeymapEvent::deserialize(bytes);
1240+ case mir_event_type_input:
1241+ default:
1242+ break;
1243+ }
1244+
1245+ BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
1246+}
1247+
1248+// Edge case where we have handle the char* buffer manually!
1249+mir::EventUPtr MirKeymapEvent::deserialize(std::string const& bytes)
1250+{
1251+ auto event = mir::EventUPtr(new MirKeymapEvent, delete_keymap_event);
1252+ auto& keymap = *event->to_keymap();
1253+ auto minimal_event_size = sizeof event->type;
1254+ auto const stream_size = bytes.size();
1255+ if (stream_size < minimal_event_size)
1256+ BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
1257+
1258+ char const* pos = consume(bytes.data(), event->type);
1259+
1260+ minimal_event_size += sizeof keymap.surface_id + sizeof keymap.device_id + sizeof keymap.size;
1261+
1262+ if (stream_size < minimal_event_size)
1263+ BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
1264+ pos = consume(pos, keymap.surface_id);
1265+ pos = consume(pos, keymap.device_id);
1266+ pos = consume(pos, keymap.size);
1267+
1268+ minimal_event_size += keymap.size;
1269+
1270+ if (stream_size < minimal_event_size)
1271+ BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
1272+
1273+ auto buffer = static_cast<char*>(std::malloc(keymap.size));
1274+ std::memcpy(buffer, pos, keymap.size);
1275+ keymap.buffer = buffer;
1276+
1277+ return event;
1278+}
1279+
1280+std::string MirEvent::serialize(MirEvent const* event)
1281+{
1282+ switch (event->type)
1283+ {
1284+ case mir_event_type_key:
1285+ return serialize_from<MirKeyboardEvent>(event);
1286+ case mir_event_type_motion:
1287+ return serialize_from<MirMotionEvent>(event);
1288+ case mir_event_type_surface:
1289+ return serialize_from<MirSurfaceEvent>(event);
1290+ case mir_event_type_resize:
1291+ return serialize_from<MirResizeEvent>(event);
1292+ case mir_event_type_prompt_session_state_change:
1293+ return serialize_from<MirPromptSessionEvent>(event);
1294+ case mir_event_type_orientation:
1295+ return serialize_from<MirOrientationEvent>(event);
1296+ case mir_event_type_close_surface:
1297+ return serialize_from<MirCloseSurfaceEvent>(event);
1298+ case mir_event_type_input_configuration:
1299+ return serialize_from<MirInputConfigurationEvent>(event);
1300+ case mir_event_type_surface_output:
1301+ return serialize_from<MirSurfaceOutputEvent>(event);
1302+ case mir_event_type_keymap:
1303+ return MirKeymapEvent::serialize(event);
1304+ case mir_event_type_input:
1305+ default:
1306+ break;
1307+ }
1308+
1309+ BOOST_THROW_EXCEPTION(std::runtime_error("Failed to serialize event"));
1310+}
1311+
1312+// Edge case where we have handle the char* buffer manually!
1313+std::string MirKeymapEvent::serialize(MirEvent const* event)
1314+{
1315+ std::string encoded;
1316+ auto keymap = event->to_keymap();
1317+ encoded.reserve(sizeof event->type +
1318+ sizeof keymap->surface_id +
1319+ sizeof keymap->device_id +
1320+ sizeof keymap->size +
1321+ keymap->size);
1322+ encode(encoded, event->type);
1323+ encode(encoded, keymap->surface_id);
1324+ encode(encoded, keymap->device_id);
1325+ encode(encoded, keymap->size);
1326+ encoded.append(keymap->buffer, keymap->size);
1327+
1328+ return encoded;
1329+}
1330+
1331+MirInputEvent* MirEvent::to_input()
1332+{
1333+ return static_cast<MirInputEvent*>(this);
1334+}
1335+
1336+MirInputEvent const* MirEvent::to_input() const
1337+{
1338+ return static_cast<MirInputEvent const*>(this);
1339+}
1340+
1341+MirInputConfigurationEvent* MirEvent::to_input_configuration()
1342+{
1343+ return static_cast<MirInputConfigurationEvent*>(this);
1344+}
1345+
1346+MirInputConfigurationEvent const* MirEvent::to_input_configuration() const
1347+{
1348+ return static_cast<MirInputConfigurationEvent const*>(this);
1349+}
1350+
1351+MirSurfaceEvent* MirEvent::to_surface()
1352+{
1353+ return static_cast<MirSurfaceEvent*>(this);
1354+}
1355+
1356+MirSurfaceEvent const* MirEvent::to_surface() const
1357+{
1358+ return static_cast<MirSurfaceEvent const*>(this);
1359+}
1360+
1361+MirResizeEvent* MirEvent::to_resize()
1362+{
1363+ return static_cast<MirResizeEvent*>(this);
1364+}
1365+
1366+MirResizeEvent const* MirEvent::to_resize() const
1367+{
1368+ return static_cast<MirResizeEvent const*>(this);
1369+}
1370+
1371+MirPromptSessionEvent* MirEvent::to_prompt_session()
1372+{
1373+ return static_cast<MirPromptSessionEvent*>(this);
1374+}
1375+
1376+MirPromptSessionEvent const* MirEvent::to_prompt_session() const
1377+{
1378+ return static_cast<MirPromptSessionEvent const*>(this);
1379+}
1380+
1381+MirOrientationEvent* MirEvent::to_orientation()
1382+{
1383+ return static_cast<MirOrientationEvent*>(this);
1384+}
1385+
1386+MirOrientationEvent const* MirEvent::to_orientation() const
1387+{
1388+ return static_cast<MirOrientationEvent const*>(this);
1389+}
1390+
1391+MirCloseSurfaceEvent* MirEvent::to_close_surface()
1392+{
1393+ return static_cast<MirCloseSurfaceEvent*>(this);
1394+}
1395+
1396+MirCloseSurfaceEvent const* MirEvent::to_close_surface() const
1397+{
1398+ return static_cast<MirCloseSurfaceEvent const*>(this);
1399+}
1400+
1401+MirKeymapEvent* MirEvent::to_keymap()
1402+{
1403+ return static_cast<MirKeymapEvent*>(this);
1404+}
1405+
1406+MirKeymapEvent const* MirEvent::to_keymap() const
1407+{
1408+ return static_cast<MirKeymapEvent const*>(this);
1409+}
1410+
1411+MirSurfaceOutputEvent* MirEvent::to_surface_output()
1412+{
1413+ return static_cast<MirSurfaceOutputEvent*>(this);
1414+}
1415+
1416+MirSurfaceOutputEvent const* MirEvent::to_surface_output() const
1417+{
1418+ return static_cast<MirSurfaceOutputEvent const*>(this);
1419+}
1420+
1421+MirKeyboardEvent* MirInputEvent::to_keyboard()
1422+{
1423+ return static_cast<MirKeyboardEvent*>(this);
1424+}
1425+
1426+MirKeyboardEvent const* MirInputEvent::to_keyboard() const
1427+{
1428+ return static_cast<MirKeyboardEvent const*>(this);
1429+}
1430+
1431+MirMotionEvent* MirInputEvent::to_motion()
1432+{
1433+ return static_cast<MirMotionEvent*>(this);
1434+}
1435+
1436+MirMotionEvent const* MirInputEvent::to_motion() const
1437+{
1438+ return static_cast<MirMotionEvent const*>(this);
1439+}
1440+
1441+MirTouchEvent* MirMotionEvent::to_touch()
1442+{
1443+ return static_cast<MirTouchEvent*>(this);
1444+}
1445+
1446+MirTouchEvent const* MirMotionEvent::to_touch() const
1447+{
1448+ return static_cast<MirTouchEvent const*>(this);
1449+}
1450+
1451+MirPointerEvent* MirMotionEvent::to_pointer()
1452+{
1453+ return static_cast<MirPointerEvent*>(this);
1454+}
1455+
1456+MirPointerEvent const* MirMotionEvent::to_pointer() const
1457+{
1458+ return static_cast<MirPointerEvent const*>(this);
1459+}
1460
1461=== modified file 'src/common/symbols.map'
1462--- src/common/symbols.map 2016-03-23 06:39:56 +0000
1463+++ src/common/symbols.map 2016-03-28 23:13:38 +0000
1464@@ -218,3 +218,23 @@
1465 mir::select_libraries_for_path*;
1466 };
1467 } MIR_COMMON_5v19; # <- Note Mir 0.19.0 used the wrong syntax
1468+
1469+MIR_COMMON_unreleased {
1470+ global:
1471+ extern "C++" {
1472+ MirEvent::to_surface*;
1473+ MirEvent::to_resize*;
1474+ MirEvent::to_orientation*;
1475+ MirEvent::to_close_surface*;
1476+ MirEvent::to_keymap*;
1477+ MirEvent::to_input*;
1478+ MirEvent::to_prompt_session*;
1479+ MirEvent::serialize*;
1480+ MirEvent::deserialize*;
1481+ MirEvent::clone*;
1482+ MirInputEvent::to_keyboard*;
1483+ MirInputEvent::to_motion*;
1484+ MirMotionEvent::to_touch*;
1485+ MirMotionEvent::to_pointer*;
1486+ };
1487+} MIR_COMMON_0.19.1;
1488
1489=== modified file 'src/include/common/mir/events/event_private.h'
1490--- src/include/common/mir/events/event_private.h 2016-01-29 08:18:22 +0000
1491+++ src/include/common/mir/events/event_private.h 2016-03-28 23:13:38 +0000
1492@@ -31,27 +31,78 @@
1493 #include "mir_toolkit/common.h"
1494 #include "mir/cookie/blob.h"
1495
1496+#include "mir/events/event_builders.h"
1497+
1498 #include <xkbcommon/xkbcommon.h>
1499 #include <array>
1500 #include <chrono>
1501
1502-#ifdef __cplusplus
1503-/**
1504- * \addtogroup mir_toolkit
1505- * @{
1506- */
1507-extern "C" {
1508-#endif
1509 /* TODO: To the moon. */
1510 #define MIR_INPUT_EVENT_MAX_POINTER_COUNT 16
1511
1512+typedef struct MirMotionEvent MirMotionEvent;
1513+
1514+struct MirEvent
1515+{
1516+ MirEventType type;
1517+
1518+ MirInputEvent* to_input();
1519+ MirInputEvent const* to_input() const;
1520+
1521+ MirInputConfigurationEvent* to_input_configuration();
1522+ MirInputConfigurationEvent const* to_input_configuration() const;
1523+
1524+ MirSurfaceEvent* to_surface();
1525+ MirSurfaceEvent const* to_surface() const;
1526+
1527+ MirResizeEvent* to_resize();
1528+ MirResizeEvent const* to_resize() const;
1529+
1530+ MirPromptSessionEvent* to_prompt_session();
1531+ MirPromptSessionEvent const* to_prompt_session() const;
1532+
1533+ MirOrientationEvent* to_orientation();
1534+ MirOrientationEvent const* to_orientation() const;
1535+
1536+ MirCloseSurfaceEvent* to_close_surface();
1537+ MirCloseSurfaceEvent const* to_close_surface() const;
1538+
1539+ MirKeymapEvent* to_keymap();
1540+ MirKeymapEvent const* to_keymap() const;
1541+
1542+ MirSurfaceOutputEvent* to_surface_output();
1543+ MirSurfaceOutputEvent const* to_surface_output() const;
1544+
1545+ MirEvent* clone() const;
1546+
1547+ static mir::EventUPtr deserialize(std::string const& bytes);
1548+ static std::string serialize(MirEvent const* event);
1549+
1550+protected:
1551+ MirEvent() = default;
1552+ MirEvent(MirEvent const& event) = default;
1553+ MirEvent& operator=(MirEvent const& event) = default;
1554+};
1555+
1556+struct MirInputEvent : MirEvent
1557+{
1558+ MirKeyboardEvent* to_keyboard();
1559+ MirKeyboardEvent const* to_keyboard() const;
1560+
1561+ MirMotionEvent* to_motion();
1562+ MirMotionEvent const* to_motion() const;
1563+
1564+protected:
1565+ MirInputEvent() = default;
1566+ MirInputEvent(MirInputEvent const& event) = default;
1567+ MirInputEvent& operator=(MirInputEvent const& event) = default;
1568+};
1569+
1570 // PRIVATE
1571 // Direct access to MirKeyboardEvent is deprecated. Please use mir_event_get_input_event
1572 // and the mir_input_event* family of functions.
1573-struct MirKeyboardEvent
1574+struct MirKeyboardEvent : MirInputEvent
1575 {
1576- MirEventType type;
1577-
1578 int32_t device_id;
1579 int32_t source_id;
1580 MirKeyboardAction action;
1581@@ -64,7 +115,7 @@
1582 mir::cookie::Blob cookie;
1583 };
1584
1585-typedef struct
1586+struct MirMotionPointer
1587 {
1588 int id;
1589 float x;
1590@@ -83,15 +134,13 @@
1591 // TODO: We would like to store this as a MirTouchAction but we still encode pointer actions
1592 // here as well.
1593 int action;
1594-} MirMotionPointer;
1595+};
1596
1597 // PRIVATE
1598 // Direct access to MirMotionEvent is deprecated. Please use mir_event_get_input_event
1599 // and the mir_input_event* family of functions.
1600-typedef struct
1601+struct MirMotionEvent : MirInputEvent
1602 {
1603- MirEventType type;
1604-
1605 int32_t device_id;
1606 int32_t source_id;
1607
1608@@ -105,71 +154,76 @@
1609 MirMotionPointer pointer_coordinates[MIR_INPUT_EVENT_MAX_POINTER_COUNT];
1610 /* "_coordinates" is a misnomer here because there's plenty more info than
1611 just coordinates, but renaming it accurately would be an API break */
1612-} MirMotionEvent;
1613+
1614+ MirTouchEvent* to_touch();
1615+ MirTouchEvent const* to_touch() const;
1616+
1617+ MirPointerEvent* to_pointer();
1618+ MirPointerEvent const* to_pointer() const;
1619+};
1620+
1621+// These are left empty as they are just aliases for a MirMotionEvent,
1622+// but nice to be implicit cast to the base class
1623+struct MirTouchEvent : MirMotionEvent
1624+{
1625+};
1626+
1627+struct MirPointerEvent : MirMotionEvent
1628+{
1629+};
1630
1631-struct MirInputConfigurationEvent
1632+struct MirInputConfigurationEvent : MirEvent
1633 {
1634- MirEventType type;
1635-
1636 MirInputConfigurationAction action;
1637 std::chrono::nanoseconds when;
1638 MirInputDeviceId id;
1639 };
1640
1641-struct MirSurfaceEvent
1642+struct MirSurfaceEvent : MirEvent
1643 {
1644- MirEventType type;
1645-
1646 int id;
1647 MirSurfaceAttrib attrib;
1648 int value;
1649 };
1650
1651-struct MirResizeEvent
1652+struct MirResizeEvent : MirEvent
1653 {
1654- MirEventType type;
1655-
1656 int surface_id;
1657 int width;
1658 int height;
1659 };
1660
1661-struct MirPromptSessionEvent
1662+struct MirPromptSessionEvent : MirEvent
1663 {
1664- MirEventType type;
1665-
1666 MirPromptSessionState new_state;
1667 };
1668
1669-struct MirOrientationEvent
1670+struct MirOrientationEvent : MirEvent
1671 {
1672- MirEventType type;
1673-
1674 int surface_id;
1675 MirOrientation direction;
1676 };
1677
1678-struct MirCloseSurfaceEvent
1679+struct MirCloseSurfaceEvent : MirEvent
1680 {
1681- MirEventType type;
1682-
1683 int surface_id;
1684 };
1685
1686-struct MirKeymapEvent
1687+struct MirKeymapEvent : MirEvent
1688 {
1689- MirEventType type;
1690-
1691 int surface_id;
1692 MirInputDeviceId device_id;
1693 char const* buffer;
1694 size_t size;
1695+
1696+ /* FIXME Need to handle the special case of Keymap events due to char const* buffer */
1697+ static mir::EventUPtr deserialize(std::string const& bytes);
1698+ static std::string serialize(MirEvent const* event);
1699+ MirEvent* clone() const;
1700 };
1701
1702-struct MirSurfaceOutputEvent
1703+struct MirSurfaceOutputEvent : MirEvent
1704 {
1705- MirEventType type;
1706-
1707 int surface_id;
1708 int dpi;
1709 float scale;
1710@@ -177,25 +231,4 @@
1711 uint32_t output_id;
1712 };
1713
1714-// Access to MirEvent is deprecated
1715-union MirEvent
1716-{
1717- MirEventType type;
1718- MirKeyboardEvent key;
1719- MirMotionEvent motion;
1720- MirSurfaceEvent surface;
1721- MirResizeEvent resize;
1722- MirPromptSessionEvent prompt_session;
1723- MirOrientationEvent orientation;
1724- MirCloseSurfaceEvent close_surface;
1725- MirKeymapEvent keymap;
1726- MirInputConfigurationEvent input_configuration;
1727- MirSurfaceOutputEvent surface_output;
1728-};
1729-
1730-#ifdef __cplusplus
1731-}
1732-/**@}*/
1733-#endif
1734-
1735 #endif /* MIR_COMMON_EVENT_PRIVATE_H_ */
1736
1737=== modified file 'src/server/graphics/nested/display_buffer.cpp'
1738--- src/server/graphics/nested/display_buffer.cpp 2016-01-29 08:18:22 +0000
1739+++ src/server/graphics/nested/display_buffer.cpp 2016-03-28 23:13:38 +0000
1740@@ -111,17 +111,17 @@
1741
1742 if (event.type == mir_event_type_motion)
1743 {
1744- auto my_event = event;
1745+ MirMotionEvent my_event = *event.to_input()->to_motion();
1746 auto iev = mir_event_get_input_event(&my_event);
1747
1748 if (mir_input_event_get_type(iev) == mir_input_event_type_pointer)
1749 {
1750- auto& motion = my_event.motion;
1751+ auto motion = my_event.to_input()->to_motion();
1752
1753- for (size_t i = 0; i != motion.pointer_count; ++i)
1754+ for (size_t i = 0; i != motion->pointer_count; ++i)
1755 {
1756- motion.pointer_coordinates[i].x += area.top_left.x.as_float();
1757- motion.pointer_coordinates[i].y += area.top_left.y.as_float();
1758+ motion->pointer_coordinates[i].x += area.top_left.x.as_float();
1759+ motion->pointer_coordinates[i].y += area.top_left.y.as_float();
1760 }
1761
1762 auto pev = mir_input_event_get_pointer_event(iev);
1763
1764=== modified file 'src/server/input/android/input_sender.cpp'
1765--- src/server/input/android/input_sender.cpp 2016-03-23 06:39:56 +0000
1766+++ src/server/input/android/input_sender.cpp 2016-03-28 23:13:38 +0000
1767@@ -247,7 +247,7 @@
1768 mir_keyboard_event_scan_code(key_event),
1769 mia::android_modifiers_from_mir(mir_keyboard_event_modifiers(key_event)),
1770 repeat_count,
1771- event.key.cookie,
1772+ event.to_input()->to_keyboard()->cookie,
1773 event_time,
1774 event_time);
1775 }
1776@@ -324,7 +324,7 @@
1777 ret = publisher.publishMotionEvent(seq, mir_input_event_get_device_id(input_event), AINPUT_SOURCE_TOUCHSCREEN,
1778 state_change.android_action, flags, edge_flags,
1779 mia::android_modifiers_from_mir(mir_touch_event_modifiers(touch)),
1780- button_state, x_offset, y_offset, x_precision, y_precision, event.motion.cookie,
1781+ button_state, x_offset, y_offset, x_precision, y_precision, event.to_input()->to_motion()->cookie,
1782 event_time, event_time, contacts_in_event, properties, coords);
1783 }
1784
1785@@ -361,7 +361,7 @@
1786 mia::android_pointer_action_from_mir(mir_pointer_event_action(pointer), mir_pointer_event_buttons(pointer)),
1787 flags, edge_flags, mia::android_modifiers_from_mir(mir_pointer_event_modifiers(pointer)),
1788 mia::android_pointer_buttons_from_mir(mir_pointer_event_buttons(pointer)), x_offset, y_offset, x_precision,
1789- y_precision, event.motion.cookie, event_time, event_time, 1, &pointer_properties, &pointer_coord);
1790+ y_precision, event.to_input()->to_motion()->cookie, event_time, event_time, 1, &pointer_properties, &pointer_coord);
1791 }
1792
1793
1794
1795=== modified file 'src/server/input/default_event_builder.cpp'
1796--- src/server/input/default_event_builder.cpp 2016-01-29 08:18:22 +0000
1797+++ src/server/input/default_event_builder.cpp 2016-03-28 23:13:38 +0000
1798@@ -53,9 +53,10 @@
1799 {
1800 if (action == mir_touch_action_up || action == mir_touch_action_down)
1801 {
1802- auto const cookie = cookie_authority->make_cookie(event.motion.event_time.count());
1803+ auto mev = event.to_input()->to_motion();
1804+ auto const cookie = cookie_authority->make_cookie(mev->event_time.count());
1805 auto const serialized_cookie = cookie->serialize();
1806- std::copy_n(std::begin(serialized_cookie), event.motion.cookie.size(), std::begin(event.motion.cookie));
1807+ std::copy_n(std::begin(serialized_cookie), mev->cookie.size(), std::begin(mev->cookie));
1808 }
1809
1810 me::add_touch(event, touch_id, action, tooltype, x_axis_value, y_axis_value, pressure_value, touch_major_value,
1811
1812=== modified file 'src/server/input/key_repeat_dispatcher.cpp'
1813--- src/server/input/key_repeat_dispatcher.cpp 2016-03-23 06:39:56 +0000
1814+++ src/server/input/key_repeat_dispatcher.cpp 2016-03-28 23:13:38 +0000
1815@@ -114,16 +114,6 @@
1816 return next_dispatcher->dispatch(event);
1817 }
1818
1819-namespace
1820-{
1821-MirEvent copy_to_repeat_ev(MirKeyboardEvent const* kev)
1822-{
1823- MirEvent repeat_ev(*reinterpret_cast<MirEvent const*>(kev));
1824- repeat_ev.key.action = mir_keyboard_action_repeat;
1825- return repeat_ev;
1826-}
1827-}
1828-
1829 // Returns true if the original event has been handled, that is ::dispatch should not pass it on.
1830 bool mi::KeyRepeatDispatcher::handle_key_input(MirInputDeviceId id, MirKeyboardEvent const* kev)
1831 {
1832@@ -146,25 +136,26 @@
1833 }
1834 case mir_keyboard_action_down:
1835 {
1836- MirEvent ev = copy_to_repeat_ev(kev);
1837+ MirKeyboardEvent new_kev = *kev;
1838+ new_kev.action = mir_keyboard_action_repeat;
1839
1840 auto it = device_state.repeat_alarms_by_scancode.find(scan_code);
1841 if (it != device_state.repeat_alarms_by_scancode.end())
1842 {
1843 // When we receive a duplicated down we just replace the action
1844- next_dispatcher->dispatch(ev);
1845+ next_dispatcher->dispatch(new_kev);
1846 return true;
1847 }
1848 auto& capture_alarm = device_state.repeat_alarms_by_scancode[scan_code];
1849- std::shared_ptr<mir::time::Alarm> alarm = alarm_factory->create_alarm([this, &capture_alarm, ev]() mutable
1850+ std::shared_ptr<mir::time::Alarm> alarm = alarm_factory->create_alarm([this, &capture_alarm, new_kev]() mutable
1851 {
1852 std::lock_guard<std::mutex> lg(repeat_state_mutex);
1853
1854- ev.key.event_time = std::chrono::steady_clock::now().time_since_epoch();
1855- auto const cookie = cookie_authority->make_cookie(ev.key.event_time.count());
1856+ new_kev.event_time = std::chrono::steady_clock::now().time_since_epoch();
1857+ auto const cookie = cookie_authority->make_cookie(new_kev.event_time.count());
1858 auto const serialized_cookie = cookie->serialize();
1859- std::copy_n(std::begin(serialized_cookie), ev.key.cookie.size(), std::begin(ev.key.cookie));
1860- next_dispatcher->dispatch(ev);
1861+ std::copy_n(std::begin(serialized_cookie), new_kev.cookie.size(), std::begin(new_kev.cookie));
1862+ next_dispatcher->dispatch(new_kev);
1863
1864 capture_alarm->reschedule_in(repeat_delay);
1865 });
1866
1867=== modified file 'src/server/input/surface_input_dispatcher.cpp'
1868--- src/server/input/surface_input_dispatcher.cpp 2016-01-29 08:18:22 +0000
1869+++ src/server/input/surface_input_dispatcher.cpp 2016-03-28 23:13:38 +0000
1870@@ -73,18 +73,18 @@
1871 template <typename T>
1872 void deliver(std::shared_ptr<mi::Surface> const& surface, T const* ev)
1873 {
1874- MirEvent to_deliver;
1875- to_deliver = *reinterpret_cast<MirEvent const*>(ev);
1876-
1877+ T to_deliver = *ev;
1878+
1879 if (to_deliver.type == mir_event_type_motion)
1880 {
1881 auto sx = surface->input_bounds().top_left.x.as_int();
1882 auto sy = surface->input_bounds().top_left.y.as_int();
1883
1884- for (unsigned i = 0; i < to_deliver.motion.pointer_count; i++)
1885+ auto mev = to_deliver.to_input()->to_motion();
1886+ for (unsigned i = 0; i < mev->pointer_count; i++)
1887 {
1888- to_deliver.motion.pointer_coordinates[i].x -= sx;
1889- to_deliver.motion.pointer_coordinates[i].y -= sy;
1890+ mev->pointer_coordinates[i].x -= sx;
1891+ mev->pointer_coordinates[i].y -= sy;
1892 }
1893 }
1894 surface->consume(&to_deliver);
1895@@ -173,7 +173,7 @@
1896
1897 if (!focus_surface_key_state.handle_event(id, kev))
1898 return false;
1899-
1900+
1901 deliver(strong_focus, kev);
1902
1903 return true;
1904@@ -216,10 +216,8 @@
1905 MirPointerEvent const* pev,
1906 MirPointerAction action)
1907 {
1908- auto iev = (MirInputEvent const*)pev;
1909-
1910- deliver(surface, &*mev::make_event(mir_input_event_get_device_id(iev),
1911- std::chrono::nanoseconds(mir_input_event_get_event_time(iev)),
1912+ auto event = mev::make_event(mir_input_event_get_device_id(pev),
1913+ std::chrono::nanoseconds(mir_input_event_get_event_time(pev)),
1914 std::vector<uint8_t>{},
1915 mir_pointer_event_modifiers(pev),
1916 action, mir_pointer_event_buttons(pev),
1917@@ -228,7 +226,9 @@
1918 mir_pointer_event_axis_value(pev,mir_pointer_axis_hscroll),
1919 mir_pointer_event_axis_value(pev,mir_pointer_axis_vscroll),
1920 mir_pointer_event_axis_value(pev, mir_pointer_axis_relative_x),
1921- mir_pointer_event_axis_value(pev, mir_pointer_axis_relative_y)));
1922+ mir_pointer_event_axis_value(pev, mir_pointer_axis_relative_y));
1923+
1924+ deliver(surface, event->to_input()->to_motion());;
1925 }
1926
1927 mi::SurfaceInputDispatcher::PointerInputState& mi::SurfaceInputDispatcher::ensure_pointer_state(MirInputDeviceId id)
1928
1929=== modified file 'src/server/input/validator.cpp'
1930--- src/server/input/validator.cpp 2016-01-29 08:18:22 +0000
1931+++ src/server/input/validator.cpp 2016-03-28 23:13:38 +0000
1932@@ -64,8 +64,8 @@
1933
1934 mir::EventUPtr copy_event(MirTouchEvent const* ev)
1935 {
1936- MirEvent *ret = new MirEvent;
1937- memcpy(ret, ev, sizeof(MirEvent));
1938+ MirTouchEvent* ret = new MirTouchEvent;
1939+ memcpy(ret, ev, sizeof(MirTouchEvent));
1940 return make_event_uptr(ret);
1941 }
1942
1943@@ -75,9 +75,9 @@
1944 {
1945 auto ret = copy_event(ev);
1946
1947- for (size_t i = 0; i < ret->motion.pointer_count; i++)
1948+ for (size_t i = 0; i < ev->pointer_count; i++)
1949 {
1950- ret->motion.pointer_coordinates[i].action = mir_touch_action_change;
1951+ ret->to_input()->to_motion()->pointer_coordinates[i].action = mir_touch_action_change;
1952 }
1953 return ret;
1954 }
1955@@ -86,10 +86,10 @@
1956 // TODO: Existence of this probably suggests a problem with TouchEvent API...
1957 int index_for_id(MirTouchEvent const* touch_ev, MirTouchId id)
1958 {
1959- MirEvent const* ev = reinterpret_cast<MirEvent const*>(touch_ev);
1960- for (size_t i = 0; i < ev->motion.pointer_count; i++)
1961+ //MirEvent const* ev = reinterpret_cast<MirEvent const*>(touch_ev);
1962+ for (size_t i = 0; i < touch_ev->pointer_count; i++)
1963 {
1964- if (ev->motion.pointer_coordinates[i].id == id)
1965+ if (touch_ev->pointer_coordinates[i].id == id)
1966 return i;
1967 }
1968 return -1;
1969@@ -98,7 +98,7 @@
1970 // Return an event which is a valid successor of valid_ev but contains a mir_touch_action_down for missing_id
1971 mir::EventUPtr add_missing_down(MirEvent const* valid_ev, MirTouchEvent const* ev, MirTouchId missing_id)
1972 {
1973- auto valid_tev = reinterpret_cast<MirTouchEvent const*>(valid_ev);
1974+ auto valid_tev = valid_ev->to_input()->to_motion()->to_touch();//reinterpret_cast<MirTouchEvent const*>(valid_ev);
1975
1976 // So as not to repeat already occurred actions, we copy the last valid (Delivered) event and replace all the actions
1977 // with change, then we will add a missing down for touch "missing_id"
1978@@ -107,9 +107,9 @@
1979
1980 // In the case where a touch ID goes up and then reappears without a down we don't want to
1981 // add a new touch but merely replace the action in the last event.
1982- if (auto existing_index = index_for_id((MirTouchEvent const*)ret.get(), missing_id) >= 0)
1983+ if (auto existing_index = index_for_id(ret->to_input()->to_motion()->to_touch(), missing_id) >= 0)
1984 {
1985- ret->motion.pointer_coordinates[existing_index].action = mir_touch_action_down;
1986+ ret->to_input()->to_motion()->pointer_coordinates[existing_index].action = mir_touch_action_down;
1987 }
1988 else
1989 {
1990@@ -136,7 +136,7 @@
1991 auto ret = convert_touch_actions_to_change(tev);
1992 auto index = index_for_id(tev, missing_an_up_id);
1993
1994- ret->motion.pointer_coordinates[index].action = mir_touch_action_up;
1995+ ret->to_input()->to_motion()->pointer_coordinates[index].action = mir_touch_action_up;
1996
1997 return ret;
1998 }
1999@@ -145,9 +145,9 @@
2000 // ev
2001 mir::EventUPtr remove_old_releases_from(MirEvent const* ev)
2002 {
2003- auto tev = reinterpret_cast<MirTouchEvent const*>(ev);
2004+ auto tev = ev->to_input()->to_motion()->to_touch();
2005 auto ret = copy_event(tev);
2006- ret->motion.pointer_count = 0;
2007+ ret->to_input()->to_motion()->pointer_count = 0;
2008
2009 for (size_t i = 0; i < mir_touch_event_point_count(tev); i++)
2010 {
2011
2012=== modified file 'tests/unit-tests/client/input/test_android_input_receiver.cpp'
2013--- tests/unit-tests/client/input/test_android_input_receiver.cpp 2016-01-29 08:18:22 +0000
2014+++ tests/unit-tests/client/input/test_android_input_receiver.cpp 2016-03-28 23:13:38 +0000
2015@@ -131,10 +131,6 @@
2016 {
2017 public:
2018 AndroidInputReceiverSetup()
2019- : event_handler{[this](MirEvent* ev)
2020- {
2021- last_event = *ev;
2022- }}
2023 {
2024 auto status = droidinput::InputChannel::openInputFdPair(server_fd, client_fd);
2025 EXPECT_EQ(droidinput::OK, status);
2026@@ -154,8 +150,7 @@
2027 int server_fd, client_fd;
2028
2029 static std::chrono::milliseconds const next_event_timeout;
2030- MirEvent last_event;
2031- std::function<void(MirEvent*)> event_handler;
2032+ std::function<void(MirEvent*)> event_handler{[](MirEvent*){}};
2033 };
2034
2035 std::chrono::milliseconds const AndroidInputReceiverSetup::next_event_timeout(1000);
2036@@ -163,9 +158,16 @@
2037
2038 TEST_F(AndroidInputReceiverSetup, receiver_receives_key_events)
2039 {
2040+ MirKeyboardEvent last_event;
2041 mircva::InputReceiver receiver{client_fd,
2042 std::make_shared<mircv::XKBMapper>(),
2043- event_handler,
2044+ [&last_event](MirEvent* ev)
2045+ {
2046+ if (ev->type == mir_event_type_key)
2047+ {
2048+ last_event = *ev->to_input()->to_keyboard();
2049+ }
2050+ },
2051 std::make_shared<mircv::NullInputReceiverReport>()};
2052 TestingInputProducer producer{server_fd};
2053
2054@@ -177,7 +179,7 @@
2055 receiver.dispatch(md::FdEvent::readable);
2056
2057 EXPECT_EQ(mir_event_type_key, last_event.type);
2058- EXPECT_EQ(producer.testing_key_event_scan_code, last_event.key.scan_code);
2059+ EXPECT_EQ(producer.testing_key_event_scan_code, last_event.scan_code);
2060 }
2061
2062 TEST_F(AndroidInputReceiverSetup, receiver_handles_events)
2063@@ -230,14 +232,14 @@
2064
2065 auto t = 0ns;
2066
2067- MirEvent ev;
2068+ std::unique_ptr<MirEvent> ev;
2069 bool handler_called{false};
2070
2071 mircva::InputReceiver receiver{client_fd,
2072 std::make_shared<mircv::XKBMapper>(),
2073 [&ev, &handler_called](MirEvent* event)
2074 {
2075- ev = *event;
2076+ ev.reset(event->clone());
2077 handler_called = true;
2078 },
2079 std::make_shared<mircv::NullInputReceiverReport>(),
2080@@ -257,7 +259,7 @@
2081 EXPECT_TRUE(mt::fd_becomes_readable(receiver.watch_fd(), next_event_timeout));
2082 receiver.dispatch(md::FdEvent::readable);
2083 EXPECT_TRUE(handler_called);
2084- ASSERT_EQ(mir_event_type_key, ev.type);
2085+ ASSERT_EQ(mir_event_type_key, ev->type);
2086
2087 // The motion is still too new. Won't be reported yet, but is batched.
2088 auto start = high_resolution_clock::now();
2089@@ -284,7 +286,7 @@
2090 receiver.dispatch(md::FdEvent::readable);
2091
2092 EXPECT_TRUE(handler_called);
2093- EXPECT_EQ(mir_event_type_motion, ev.type);
2094+ EXPECT_EQ(mir_event_type_motion, ev->type);
2095 }
2096
2097 TEST_F(AndroidInputReceiverSetup, finish_signalled_after_handler)
2098
2099=== modified file 'tests/unit-tests/client/input/test_xkb_mapper.cpp'
2100--- tests/unit-tests/client/input/test_xkb_mapper.cpp 2016-01-29 08:18:22 +0000
2101+++ tests/unit-tests/client/input/test_xkb_mapper.cpp 2016-03-28 23:13:38 +0000
2102@@ -39,7 +39,7 @@
2103 0, scan_code, mir_input_event_modifier_none);
2104
2105 mapper.update_state_and_map_event(*ev);
2106- return ev->key.key_code;
2107+ return ev->to_input()->to_keyboard()->key_code;
2108 }
2109
2110 }
2111
2112=== modified file 'tests/unit-tests/client/test_event_distributor.cpp'
2113--- tests/unit-tests/client/test_event_distributor.cpp 2015-06-25 03:00:08 +0000
2114+++ tests/unit-tests/client/test_event_distributor.cpp 2016-03-28 23:13:38 +0000
2115@@ -55,7 +55,7 @@
2116 event_distributor.register_event_handler([this](MirEvent const& event) { event_handled1(event); });
2117 event_distributor.register_event_handler([this](MirEvent const& event) { event_handled2(event); });
2118
2119- MirEvent e;
2120+ MirPromptSessionEvent e;
2121 e.type = mir_event_type_prompt_session_state_change;
2122
2123 EXPECT_CALL(*this, event_handled1(MirEventTypeIs(e.type))).Times(1);
2124@@ -71,7 +71,7 @@
2125 int reg_id2 = event_distributor.register_event_handler([this](MirEvent const& event) { event_handled2(event); });
2126 event_distributor.unregister_event_handler(reg_id2);
2127
2128- MirEvent e;
2129+ MirPromptSessionEvent e;
2130 e.type = mir_event_type_prompt_session_state_change;
2131
2132 EXPECT_CALL(*this, event_handled1(MirEventTypeIs(e.type))).Times(1);
2133@@ -92,7 +92,7 @@
2134 });
2135 reg_id2 = event_distributor.register_event_handler([this](MirEvent const& event) { event_handled2(event); });
2136
2137- MirEvent e;
2138+ MirPromptSessionEvent e;
2139 e.type = mir_event_type_prompt_session_state_change;
2140
2141 EXPECT_CALL(*this, event_handled1(MirEventTypeIs(e.type))).Times(1);
2142@@ -134,7 +134,7 @@
2143 std::mutex mutex;
2144 };
2145
2146- MirEvent e;
2147+ MirPromptSessionEvent e;
2148 e.type = mir_event_type_prompt_session_state_change;
2149
2150 std::vector<EventCatcher*> catchers;
2151
2152=== modified file 'tests/unit-tests/input/test_input_event.cpp'
2153--- tests/unit-tests/input/test_input_event.cpp 2016-01-29 08:18:22 +0000
2154+++ tests/unit-tests/input/test_input_event.cpp 2016-03-28 23:13:38 +0000
2155@@ -61,9 +61,9 @@
2156 AINPUT_SOURCE_ANY = 0xffffff00
2157 };
2158
2159-MirEvent a_key_ev()
2160+MirKeyboardEvent a_key_ev()
2161 {
2162- MirEvent key_ev;
2163+ MirKeyboardEvent key_ev;
2164 memset(&key_ev, 0, sizeof(key_ev));
2165
2166 key_ev.type = mir_event_type_key;
2167@@ -71,13 +71,13 @@
2168 return key_ev;
2169 }
2170
2171-MirEvent a_motion_ev(int device_class = AINPUT_SOURCE_UNKNOWN)
2172+MirMotionEvent a_motion_ev(int device_class = AINPUT_SOURCE_UNKNOWN)
2173 {
2174- MirEvent motion_ev;
2175+ MirMotionEvent motion_ev;
2176 memset(&motion_ev, 0, sizeof(motion_ev));
2177
2178 motion_ev.type = mir_event_type_motion;
2179- motion_ev.motion.source_id = device_class;
2180+ motion_ev.source_id = device_class;
2181
2182 return motion_ev;
2183 }
2184@@ -87,6 +87,7 @@
2185 TEST(InputEvent, old_style_key_and_motion_events_are_input_events)
2186 {
2187 auto key_ev = a_key_ev();
2188+ key_ev.type = mir_event_type_key;
2189
2190 EXPECT_EQ(mir_event_type_input, mir_event_get_type(&key_ev));
2191 EXPECT_EQ(mir_input_event_type_key, mir_input_event_get_type(mir_event_get_input_event(&key_ev)));
2192@@ -105,14 +106,14 @@
2193 auto old_ev = a_motion_ev();
2194
2195 old_ev.type = mir_event_type_motion;
2196- old_ev.motion.device_id = dev_id_1;
2197+ old_ev.device_id = dev_id_1;
2198 EXPECT_EQ(dev_id_1, mir_input_event_get_device_id(
2199 mir_event_get_input_event(&old_ev)));
2200
2201- old_ev.type = mir_event_type_key;
2202- old_ev.motion.device_id = dev_id_2;
2203+ auto kev = a_key_ev();
2204+ kev.device_id = dev_id_2;
2205 EXPECT_EQ(dev_id_2, mir_input_event_get_device_id(
2206- mir_event_get_input_event(&old_ev)));
2207+ mir_event_get_input_event(&kev)));
2208 }
2209
2210 TEST(CommonInputEventProperties, event_time_taken_from_old_style_event)
2211@@ -120,14 +121,14 @@
2212 std::chrono::nanoseconds event_time_1{79}, event_time_2{83};
2213 auto old_ev = a_motion_ev();
2214
2215- old_ev.motion.event_time = event_time_1;
2216+ old_ev.event_time = event_time_1;
2217 EXPECT_EQ(event_time_1.count(), mir_input_event_get_event_time(
2218 mir_event_get_input_event(&old_ev)));
2219
2220- old_ev.type = mir_event_type_key;
2221- old_ev.key.event_time = event_time_2;
2222+ auto kev = a_key_ev();
2223+ kev.event_time = event_time_2;
2224 EXPECT_EQ(event_time_2.count(), mir_input_event_get_event_time(
2225- mir_event_get_input_event(&old_ev)));
2226+ mir_event_get_input_event(&kev)));
2227 }
2228
2229 TEST(KeyInputEventProperties, timestamp_taken_from_old_style_event)
2230@@ -138,7 +139,7 @@
2231
2232 for (auto expected : {event_time_1, event_time_2})
2233 {
2234- old_ev.key.event_time = expected;
2235+ old_ev.event_time = expected;
2236
2237 auto const input_event = mir_keyboard_event_input_event(keyboard_event);
2238
2239@@ -151,12 +152,12 @@
2240 {
2241 auto old_ev = a_key_ev();
2242
2243- old_ev.key.action = mir_keyboard_action_down;
2244+ old_ev.action = mir_keyboard_action_down;
2245
2246 auto new_kev = mir_input_event_get_keyboard_event(mir_event_get_input_event(&old_ev));
2247 EXPECT_EQ(mir_keyboard_action_down, mir_keyboard_event_action(new_kev));
2248
2249- old_ev.key.action = mir_keyboard_action_up;
2250+ old_ev.action = mir_keyboard_action_up;
2251 EXPECT_EQ(mir_keyboard_action_up, mir_keyboard_event_action(new_kev));
2252 }
2253
2254@@ -167,9 +168,9 @@
2255 MirInputEventModifiers modifiers = mir_input_event_modifier_shift;
2256
2257 auto old_ev = a_key_ev();
2258- old_ev.key.key_code = key_code;
2259- old_ev.key.scan_code = scan_code;
2260- old_ev.key.modifiers = modifiers;
2261+ old_ev.key_code = key_code;
2262+ old_ev.scan_code = scan_code;
2263+ old_ev.modifiers = modifiers;
2264
2265 auto new_kev = mir_input_event_get_keyboard_event(mir_event_get_input_event(&old_ev));
2266 EXPECT_EQ(key_code, mir_keyboard_event_key_code(new_kev));
2267@@ -185,7 +186,7 @@
2268
2269 for (auto expected : {event_time_1, event_time_2})
2270 {
2271- old_ev.motion.event_time = expected;
2272+ old_ev.event_time = expected;
2273
2274 auto const input_event = mir_touch_event_input_event(touch_event);
2275
2276@@ -198,7 +199,7 @@
2277 unsigned const pointer_count = 3;
2278 auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN);
2279
2280- old_ev.motion.pointer_count = pointer_count;
2281+ old_ev.pointer_count = pointer_count;
2282
2283 auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&old_ev));
2284 EXPECT_EQ(pointer_count, mir_touch_event_point_count(tev));
2285@@ -209,8 +210,8 @@
2286 unsigned const touch_id = 31;
2287 auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN);
2288
2289- old_ev.motion.pointer_count = 1;
2290- old_ev.motion.pointer_coordinates[0].id = touch_id;
2291+ old_ev.pointer_count = 1;
2292+ old_ev.pointer_coordinates[0].id = touch_id;
2293
2294 auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&old_ev));
2295 EXPECT_EQ(touch_id, mir_touch_event_id(tev, 0));
2296@@ -220,8 +221,8 @@
2297 TEST(TouchEventProperties, down_and_up_actions_are_taken_from_old_event)
2298 {
2299 auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN);
2300- old_ev.motion.pointer_count = 1;
2301- old_ev.motion.pointer_coordinates[0].action = mir_touch_action_change;
2302+ old_ev.pointer_count = 1;
2303+ old_ev.pointer_coordinates[0].action = mir_touch_action_change;
2304
2305 auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&old_ev));
2306 EXPECT_EQ(mir_touch_action_change, mir_touch_event_action(tev, 0));
2307@@ -231,11 +232,10 @@
2308 {
2309 auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN);
2310
2311- auto& old_mev = old_ev.motion;
2312- old_mev.pointer_count = 3;
2313- old_mev.pointer_coordinates[0].tool_type = mir_touch_tooltype_unknown;
2314- old_mev.pointer_coordinates[1].tool_type = mir_touch_tooltype_finger;
2315- old_mev.pointer_coordinates[2].tool_type = mir_touch_tooltype_stylus;
2316+ old_ev.pointer_count = 3;
2317+ old_ev.pointer_coordinates[0].tool_type = mir_touch_tooltype_unknown;
2318+ old_ev.pointer_coordinates[1].tool_type = mir_touch_tooltype_finger;
2319+ old_ev.pointer_coordinates[2].tool_type = mir_touch_tooltype_stylus;
2320
2321 auto tev = mir_input_event_get_touch_event(mir_event_get_input_event(&old_ev));
2322 EXPECT_EQ(mir_touch_tooltype_unknown, mir_touch_event_tooltype(tev, 0));
2323@@ -247,8 +247,8 @@
2324 {
2325 float x_value = 19, y_value = 23, touch_major = .3, touch_minor = .2, pressure = .9, size = 1111;
2326 auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN);
2327- old_ev.motion.pointer_count = 1;
2328- auto &old_pc = old_ev.motion.pointer_coordinates[0];
2329+ old_ev.pointer_count = 1;
2330+ auto &old_pc = old_ev.pointer_coordinates[0];
2331 old_pc.x = x_value;
2332 old_pc.y = y_value;
2333 old_pc.touch_major = touch_major;
2334@@ -314,7 +314,7 @@
2335
2336 for (auto expected : {event_time_1, event_time_2})
2337 {
2338- old_ev.motion.event_time = expected;
2339+ old_ev.event_time = expected;
2340
2341 auto const input_event = mir_pointer_event_input_event(pointer_event);
2342
2343@@ -326,7 +326,7 @@
2344 {
2345 MirInputEventModifiers modifiers = mir_input_event_modifier_shift;
2346 auto old_ev = a_motion_ev(AINPUT_SOURCE_MOUSE);
2347- old_ev.motion.modifiers = modifiers;
2348+ old_ev.modifiers = modifiers;
2349
2350 auto pointer_event =
2351 mir_input_event_get_pointer_event(mir_event_get_input_event(&old_ev));
2352@@ -337,13 +337,13 @@
2353 {
2354 auto old_ev = a_motion_ev(AINPUT_SOURCE_MOUSE);
2355
2356- old_ev.motion.buttons = mir_pointer_button_primary;
2357+ old_ev.buttons = mir_pointer_button_primary;
2358 auto pev = mir_input_event_get_pointer_event(mir_event_get_input_event(&old_ev));
2359
2360 EXPECT_TRUE(mir_pointer_event_button_state(pev, mir_pointer_button_primary));
2361 EXPECT_FALSE(mir_pointer_event_button_state(pev, mir_pointer_button_secondary));
2362
2363- old_ev.motion.buttons |= mir_pointer_button_secondary;
2364+ old_ev.buttons |= mir_pointer_button_secondary;
2365
2366 EXPECT_TRUE(mir_pointer_event_button_state(pev, mir_pointer_button_primary));
2367 EXPECT_TRUE(mir_pointer_event_button_state(pev, mir_pointer_button_secondary));
2368@@ -357,11 +357,11 @@
2369 {
2370 float x = 7, y = 9.3, hscroll = 13, vscroll = 17;
2371 auto old_ev = a_motion_ev(AINPUT_SOURCE_MOUSE);
2372- old_ev.motion.pointer_count = 0;
2373- old_ev.motion.pointer_coordinates[0].x = x;
2374- old_ev.motion.pointer_coordinates[0].y = y;
2375- old_ev.motion.pointer_coordinates[0].vscroll = vscroll;
2376- old_ev.motion.pointer_coordinates[0].hscroll = hscroll;
2377+ old_ev.pointer_count = 0;
2378+ old_ev.pointer_coordinates[0].x = x;
2379+ old_ev.pointer_coordinates[0].y = y;
2380+ old_ev.pointer_coordinates[0].vscroll = vscroll;
2381+ old_ev.pointer_coordinates[0].hscroll = hscroll;
2382
2383 auto pev = mir_input_event_get_pointer_event(mir_event_get_input_event(&old_ev));
2384 EXPECT_EQ(x, mir_pointer_event_axis_value(pev, mir_pointer_axis_x));
2385
2386=== modified file 'tests/unit-tests/input/test_surface_input_dispatcher.cpp'
2387--- tests/unit-tests/input/test_surface_input_dispatcher.cpp 2016-01-29 08:18:22 +0000
2388+++ tests/unit-tests/input/test_surface_input_dispatcher.cpp 2016-03-28 23:13:38 +0000
2389@@ -264,7 +264,7 @@
2390 FakeKeyboard keyboard;
2391 auto event = keyboard.press();
2392
2393- EXPECT_CALL(*surface, consume(mt::MirKeyboardEventMatches(*event))).Times(1);
2394+ EXPECT_CALL(*surface, consume(mt::MirKeyboardEventMatches(ByRef(*event)))).Times(1);
2395
2396 dispatcher.start();
2397
2398@@ -307,7 +307,7 @@
2399 auto down_event = keyboard.press();
2400 auto up_event = keyboard.release();
2401
2402- EXPECT_CALL(*surface_1, consume(mt::MirKeyboardEventMatches(*down_event))).Times(1);
2403+ EXPECT_CALL(*surface_1, consume(mt::MirKeyboardEventMatches(ByRef(*down_event)))).Times(1);
2404 EXPECT_CALL(*surface_2, consume(_)).Times(0);
2405
2406 dispatcher.start();
2407@@ -326,7 +326,7 @@
2408 auto event = keyboard.press();
2409
2410 InSequence seq;
2411- EXPECT_CALL(*surface, consume(mt::MirKeyboardEventMatches(*event))).Times(1);
2412+ EXPECT_CALL(*surface, consume(mt::MirKeyboardEventMatches(ByRef(*event)))).Times(1);
2413
2414 dispatcher.start();
2415
2416
2417=== modified file 'tests/unit-tests/input/test_validator.cpp'
2418--- tests/unit-tests/input/test_validator.cpp 2016-01-29 08:18:22 +0000
2419+++ tests/unit-tests/input/test_validator.cpp 2016-03-28 23:13:38 +0000
2420@@ -87,9 +87,9 @@
2421 add_another_touch(inserted_down_id1, 1, mir_touch_action_down);
2422
2423 InSequence seq;
2424- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id0)));
2425- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id1)));
2426- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch)));
2427+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id0))));
2428+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id1))));
2429+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch))));
2430
2431 rewriter.validate_and_dispatch(*touch);
2432 }
2433@@ -108,10 +108,10 @@
2434 add_another_touch(inserted_release, 1, mir_touch_action_up);
2435
2436 InSequence seq;
2437- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1)));
2438- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2)));
2439- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_release)));
2440- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_3)));
2441+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
2442+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
2443+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_release))));
2444+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_3))));
2445
2446 rewriter.validate_and_dispatch(*touch_1);
2447 rewriter.validate_and_dispatch(*touch_2);
2448@@ -138,12 +138,12 @@
2449 add_another_touch(inserted_release_id0, 2, mir_touch_action_change);
2450
2451 InSequence seq;
2452- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1)));
2453- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2)));
2454- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_3)));
2455- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_release_id1)));
2456- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_release_id0)));
2457- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_4)));
2458+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
2459+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
2460+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_3))));
2461+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_release_id1))));
2462+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_release_id0))));
2463+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_4))));
2464
2465 rewriter.validate_and_dispatch(*touch_1);
2466 rewriter.validate_and_dispatch(*touch_2);
2467@@ -169,12 +169,12 @@
2468 auto inserted_down_id2 = make_touch(0, mir_touch_action_change);
2469 add_another_touch(inserted_down_id2, 2, mir_touch_action_down);
2470
2471- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1)));
2472- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2)));
2473- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_3)));
2474- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_release_id1)));
2475- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id2)));
2476- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_4)));
2477+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
2478+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
2479+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_3))));
2480+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_release_id1))));
2481+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id2))));
2482+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_4))));
2483
2484 rewriter.validate_and_dispatch(*touch_1);
2485 rewriter.validate_and_dispatch(*touch_2);
2486@@ -196,11 +196,11 @@
2487 auto inserted_down_id2 = make_touch(1, mir_touch_action_change);
2488 add_another_touch(inserted_down_id2, 2, mir_touch_action_down);
2489
2490- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1)));
2491- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2)));
2492- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_up_id0)));
2493- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id2)));
2494- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_3)));
2495+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
2496+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
2497+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_up_id0))));
2498+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id2))));
2499+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_3))));
2500
2501 rewriter.validate_and_dispatch(*touch_1);
2502 rewriter.validate_and_dispatch(*touch_2);
2503@@ -226,12 +226,12 @@
2504 add_another_touch(inserted_down_id1, 1, mir_touch_action_down);
2505
2506 InSequence seq;
2507- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1)));
2508- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2)));
2509- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_3)));
2510- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_4)));
2511- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id1)));
2512- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_5)));
2513+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
2514+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
2515+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_3))));
2516+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_4))));
2517+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id1))));
2518+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_5))));
2519
2520 rewriter.validate_and_dispatch(*touch_1);
2521 rewriter.validate_and_dispatch(*touch_2);
2522@@ -252,10 +252,10 @@
2523 auto inserted_up_id0 = make_touch(0, mir_touch_action_up);
2524 auto inserted_down_id1 = make_touch(1, mir_touch_action_down);
2525
2526- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_1)));
2527- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_up_id0)));
2528- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*inserted_down_id1)));
2529- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(*touch_2)));
2530+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
2531+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_up_id0))));
2532+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id1))));
2533+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
2534
2535 rewriter.validate_and_dispatch(*touch_1);
2536 rewriter.validate_and_dispatch(*touch_2);
2537
2538=== modified file 'tests/unit-tests/scene/test_application_session.cpp'
2539--- tests/unit-tests/scene/test_application_session.cpp 2016-03-23 06:39:56 +0000
2540+++ tests/unit-tests/scene/test_application_session.cpp 2016-03-28 23:13:38 +0000
2541@@ -95,7 +95,7 @@
2542 }
2543
2544 MATCHER_P(EqPromptSessionEventState, state, "") {
2545- return arg.type == mir_event_type_prompt_session_state_change && arg.prompt_session.new_state == state;
2546+ return arg.type == mir_event_type_prompt_session_state_change && arg.to_prompt_session()->new_state == state;
2547 }
2548
2549 MATCHER_P(HasParent, parent, "")
2550@@ -865,13 +865,14 @@
2551 {
2552 using namespace ::testing;
2553
2554- MirEvent event;
2555+ //MirEvent* event;
2556+ std::unique_ptr<MirEvent> event;
2557 bool event_received{false};
2558
2559 EXPECT_CALL(*sender, handle_event(IsSurfaceOutputEvent()))
2560- .WillOnce(Invoke([&event, &event_received](auto ev)
2561+ .WillOnce(Invoke([&event, &event_received](MirEvent const& ev)
2562 {
2563- event = ev;
2564+ event.reset(ev.clone());
2565 event_received = true;
2566 }));
2567
2568@@ -888,7 +889,7 @@
2569 auto surface = app_session.surface(surf_id);
2570
2571 ASSERT_TRUE(event_received);
2572- EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
2573+ EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
2574 }
2575
2576 TEST_F(ApplicationSessionSurfaceOutput, sends_correct_surface_details_to_surface)
2577@@ -897,13 +898,13 @@
2578
2579 std::array<TestOutput const*, 2> outputs{{ &high_dpi, &projector }};
2580
2581- std::array<MirEvent, 2> event;
2582+ std::array<std::unique_ptr<MirEvent>, 2> event;
2583 int events_received{0};
2584
2585 ON_CALL(*sender, handle_event(IsSurfaceOutputEvent()))
2586- .WillByDefault(Invoke([&event, &events_received](auto ev)
2587+ .WillByDefault(Invoke([&event, &events_received](MirEvent const& ev)
2588 {
2589- event[events_received] = ev;
2590+ event[events_received].reset(ev.clone());
2591 ++events_received;
2592 }));
2593
2594@@ -939,8 +940,8 @@
2595
2596 for (int i = 0; i < 2 ; ++i)
2597 {
2598- EXPECT_THAT(event[i].surface_output.surface_id, Eq(ids[i].as_value()));
2599- EXPECT_THAT(&event[i], SurfaceOutputEventFor(*outputs[i]));
2600+ EXPECT_THAT(event[i]->to_surface_output()->surface_id, Eq(ids[i].as_value()));
2601+ EXPECT_THAT(event[i].get(), SurfaceOutputEventFor(*outputs[i]));
2602 }
2603 }
2604
2605@@ -950,13 +951,13 @@
2606
2607 std::array<TestOutput const*, 2> outputs{{ &projector, &high_dpi }};
2608
2609- MirEvent event;
2610+ std::unique_ptr<MirEvent> event;
2611 bool event_received{false};
2612
2613 ON_CALL(*sender, handle_event(IsSurfaceOutputEvent()))
2614- .WillByDefault(Invoke([&event, &event_received](auto ev)
2615+ .WillByDefault(Invoke([&event, &event_received](MirEvent const& ev)
2616 {
2617- event = ev;
2618+ event.reset(ev.clone());
2619 event_received = true;
2620 }));
2621
2622@@ -984,8 +985,8 @@
2623
2624 ASSERT_TRUE(event_received);
2625
2626- EXPECT_THAT(event.surface_output.surface_id, Eq(id.as_value()));
2627- EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
2628+ EXPECT_THAT(event->to_surface_output()->surface_id, Eq(id.as_value()));
2629+ EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
2630 }
2631
2632 TEST_F(ApplicationSessionSurfaceOutput, surfaces_on_edges_get_correct_values)
2633@@ -994,13 +995,13 @@
2634
2635 std::array<TestOutput const*, 2> outputs{{ &projector, &high_dpi }};
2636
2637- MirEvent event;
2638+ std::unique_ptr<MirEvent> event;
2639 bool event_received{false};
2640
2641 ON_CALL(*sender, handle_event(IsSurfaceOutputEvent()))
2642- .WillByDefault(Invoke([&event, &event_received](auto ev)
2643+ .WillByDefault(Invoke([&event, &event_received](MirEvent const& ev)
2644 {
2645- event = ev;
2646+ event.reset(ev.clone());
2647 event_received = true;
2648 }));
2649
2650@@ -1027,21 +1028,21 @@
2651 surface->move_to({outputs[0]->width - ((surface->size().width.as_uint32_t()) / 2), 100});
2652
2653 ASSERT_TRUE(event_received);
2654- EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
2655+ EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
2656
2657 event_received = false;
2658 // This should be *just* entirely on the projector
2659 surface->move_to({outputs[0]->width - surface->size().width.as_uint32_t(), 100});
2660
2661 ASSERT_TRUE(event_received);
2662- EXPECT_THAT(&event, SurfaceOutputEventFor(projector));
2663+ EXPECT_THAT(event.get(), SurfaceOutputEventFor(projector));
2664
2665 event_received = false;
2666 // This should have a single pixel overlap on the high_dpi
2667 surface->move_to({outputs[0]->width - (surface->size().width.as_uint32_t() - 1), 100});
2668
2669 ASSERT_TRUE(event_received);
2670- EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
2671+ EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
2672 }
2673
2674 TEST_F(ApplicationSessionSurfaceOutput, sends_surface_output_event_on_move)
2675@@ -1050,14 +1051,14 @@
2676
2677 std::array<TestOutput const*, 2> outputs {{ &projector, &high_dpi }};
2678
2679- MirEvent event;
2680+ std::unique_ptr<MirEvent> event;
2681 int events_received{0};
2682
2683
2684 ON_CALL(*sender, handle_event(IsSurfaceOutputEvent()))
2685- .WillByDefault(Invoke([&event, &events_received](auto ev)
2686+ .WillByDefault(Invoke([&event, &events_received](MirEvent const& ev)
2687 {
2688- event = ev;
2689+ event.reset(ev.clone());
2690 events_received++;
2691 }));
2692
2693@@ -1087,8 +1088,8 @@
2694 ASSERT_THAT(events_received, Ge(1));
2695 auto events_expected = events_received + 1;
2696
2697- EXPECT_THAT(event.surface_output.surface_id, Eq(id.as_value()));
2698- EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
2699+ EXPECT_THAT(event->to_surface_output()->surface_id, Eq(id.as_value()));
2700+ EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
2701
2702 // Now solely on the left output
2703 surface->move_to({0, 0});
2704@@ -1096,8 +1097,8 @@
2705 ASSERT_THAT(events_received, Eq(events_expected));
2706 events_expected++;
2707
2708- EXPECT_THAT(event.surface_output.surface_id, Eq(id.as_value()));
2709- EXPECT_THAT(&event, SurfaceOutputEventFor(projector));
2710+ EXPECT_THAT(event->to_surface_output()->surface_id, Eq(id.as_value()));
2711+ EXPECT_THAT(event.get(), SurfaceOutputEventFor(projector));
2712
2713 // Now solely on the right output
2714 surface->move_to({outputs[0]->width + 100, 100});
2715@@ -1105,8 +1106,8 @@
2716 ASSERT_THAT(events_received, Eq(events_expected));
2717 events_expected++;
2718
2719- EXPECT_THAT(event.surface_output.surface_id, Eq(id.as_value()));
2720- EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
2721+ EXPECT_THAT(event->to_surface_output()->surface_id, Eq(id.as_value()));
2722+ EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
2723 }
2724
2725 TEST_F(ApplicationSessionSurfaceOutput, sends_surface_output_event_on_move_only_if_changed)
2726@@ -1115,13 +1116,11 @@
2727
2728 std::array<TestOutput const*, 2> outputs {{ &projector, &high_dpi }};
2729
2730- MirEvent event;
2731 int events_received{0};
2732
2733 ON_CALL(*sender, handle_event(IsSurfaceOutputEvent()))
2734- .WillByDefault(Invoke([&event, &events_received](auto ev)
2735+ .WillByDefault(Invoke([&events_received](MirEvent const&)
2736 {
2737- event = ev;
2738 events_received++;
2739 }));
2740
2741
2742=== modified file 'tests/unit-tests/scene/test_surface.cpp'
2743--- tests/unit-tests/scene/test_surface.cpp 2016-01-29 08:18:22 +0000
2744+++ tests/unit-tests/scene/test_surface.cpp 2016-03-28 23:13:38 +0000
2745@@ -414,8 +414,8 @@
2746 mev::add_touch(*touch_event, 0, mir_touch_action_down, mir_touch_tooltype_finger, 0, 0,
2747 0, 0, 0, 0);
2748
2749- EXPECT_CALL(mock_sender, send_event(mt::MirKeyboardEventMatches(*key_event), _)).Times(1);
2750- EXPECT_CALL(mock_sender, send_event(mt::MirTouchEventMatches(*touch_event), _)).Times(1);
2751+ EXPECT_CALL(mock_sender, send_event(mt::MirKeyboardEventMatches(ByRef(*key_event)), _)).Times(1);
2752+ EXPECT_CALL(mock_sender, send_event(mt::MirTouchEventMatches(ByRef(*touch_event)), _)).Times(1);
2753
2754 surface.consume(key_event.get());
2755 surface.consume(touch_event.get());
2756
2757=== modified file 'tests/unit-tests/scene/test_surface_impl.cpp'
2758--- tests/unit-tests/scene/test_surface_impl.cpp 2016-01-29 08:18:22 +0000
2759+++ tests/unit-tests/scene/test_surface_impl.cpp 2016-03-28 23:13:38 +0000
2760@@ -54,6 +54,19 @@
2761 namespace
2762 {
2763
2764+MATCHER_P(MirResizeEventEq, event, "")
2765+{
2766+ if (arg.type != mir_event_type_resize ||
2767+ event->type != mir_event_type_resize)
2768+ {
2769+ return false;
2770+ }
2771+
2772+ return arg.to_resize()->width == event->to_resize()->width &&
2773+ arg.to_resize()->height == event->to_resize()->height &&
2774+ arg.to_resize()->surface_id == event->to_resize()->surface_id;
2775+}
2776+
2777 typedef testing::NiceMock<mtd::MockBufferStream> StubBufferStream;
2778
2779 struct Surface : testing::Test
2780@@ -180,7 +193,7 @@
2781 surface->add_observer(observer);
2782
2783 auto e = mev::make_event(stub_id, new_size);
2784- EXPECT_CALL(*sink, handle_event(*e))
2785+ EXPECT_CALL(*sink, handle_event(MirResizeEventEq(e.get())))
2786 .Times(1);
2787
2788 surface->resize(new_size);
2789@@ -200,11 +213,11 @@
2790 surface->add_observer(observer);
2791
2792 auto e = mev::make_event(stub_id, new_size);
2793- EXPECT_CALL(*sink, handle_event(*e))
2794+ EXPECT_CALL(*sink, handle_event(MirResizeEventEq(e.get())))
2795 .Times(1);
2796
2797 auto e2 = mev::make_event(stub_id, new_size2);
2798- EXPECT_CALL(*sink, handle_event(*e2))
2799+ EXPECT_CALL(*sink, handle_event(MirResizeEventEq(e2.get())))
2800 .Times(1);
2801
2802 surface->resize(new_size);
2803@@ -251,12 +264,12 @@
2804
2805 surface->add_observer(observer);
2806
2807- MirEvent e;
2808+ MirCloseSurfaceEvent e;
2809 memset(&e, 0, sizeof e);
2810 e.type = mir_event_type_close_surface;
2811- e.close_surface.surface_id = stub_id.as_value();
2812+ e.to_close_surface()->surface_id = stub_id.as_value();
2813
2814- EXPECT_CALL(*sink, handle_event(e)).Times(1);
2815+ EXPECT_CALL(*sink, handle_event(Eq(ByRef(e)))).Times(1);
2816
2817 surface->request_client_surface_close();
2818 }

Subscribers

People subscribed via source and target branches