Mir

Merge lp:~brandontschaefer/mir/mir-event-capnproto into lp:mir

Proposed by Brandon Schaefer
Status: Superseded
Proposed branch: lp:~brandontschaefer/mir/mir-event-capnproto
Merge into: lp:mir
Prerequisite: lp:~brandontschaefer/mir/class-ify-mir-events
Diff against target: 4172 lines (+1169/-995)
59 files modified
CMakeLists.txt (+2/-1)
debian/control (+2/-0)
include/client/mir/events/event_builders.h (+1/-7)
include/client/mir_toolkit/events/input_device_state_event.h (+14/-0)
include/test/mir/test/event_matchers.h (+7/-2)
src/CMakeLists.txt (+1/-0)
src/capnproto/CMakeLists.txt (+29/-0)
src/capnproto/mir_event.capnp (+237/-0)
src/client/event.cpp (+216/-52)
src/client/event_printer.cpp (+4/-4)
src/client/events/event_builders.cpp (+8/-33)
src/client/input/input_event.cpp (+118/-30)
src/client/mir_cookie.cpp (+10/-9)
src/client/mir_cookie.h (+6/-4)
src/client/mir_surface.cpp (+1/-1)
src/client/symbols.map (+1/-0)
src/common/CMakeLists.txt (+3/-1)
src/common/events/CMakeLists.txt (+3/-0)
src/common/events/close_surface_event.cpp (+4/-4)
src/common/events/event.cpp (+75/-111)
src/common/events/input_configuration_event.cpp (+8/-8)
src/common/events/input_device_state_event.cpp (+46/-131)
src/common/events/input_event.cpp (+0/-5)
src/common/events/keyboard_event.cpp (+31/-26)
src/common/events/keymap_event.cpp (+11/-113)
src/common/events/motion_event.cpp (+93/-108)
src/common/events/orientation_event.cpp (+6/-6)
src/common/events/prompt_session_event.cpp (+4/-4)
src/common/events/resize_event.cpp (+8/-8)
src/common/events/surface_event.cpp (+8/-8)
src/common/events/surface_output_event.cpp (+12/-12)
src/common/events/surface_placement_event.cpp (+11/-6)
src/common/symbols.map (+6/-4)
src/include/common/mir/events/close_surface_event.h (+0/-3)
src/include/common/mir/events/event.h (+21/-62)
src/include/common/mir/events/input_configuration_event.h (+0/-6)
src/include/common/mir/events/input_device_state_event.h (+8/-25)
src/include/common/mir/events/input_event.h (+0/-1)
src/include/common/mir/events/keyboard_event.h (+3/-15)
src/include/common/mir/events/keymap_event.h (+0/-18)
src/include/common/mir/events/motion_event.h (+4/-40)
src/include/common/mir/events/orientation_event.h (+0/-4)
src/include/common/mir/events/prompt_session_event.h (+0/-3)
src/include/common/mir/events/resize_event.h (+0/-5)
src/include/common/mir/events/surface_event.h (+0/-5)
src/include/common/mir/events/surface_output_event.h (+0/-8)
src/server/graphics/nested/input_platform.cpp (+7/-3)
src/server/input/android/input_sender.cpp (+24/-5)
src/server/input/default_event_builder.cpp (+1/-3)
src/server/input/key_repeat_dispatcher.cpp (+1/-3)
src/server/input/validator.cpp (+3/-4)
tests/unit-tests/client/input/test_android_input_receiver.cpp (+1/-1)
tests/unit-tests/input/android/test_android_input_sender.cpp (+9/-5)
tests/unit-tests/input/test_event_builders.cpp (+20/-9)
tests/unit-tests/input/test_surface_input_dispatcher.cpp (+1/-1)
tests/unit-tests/input/test_validator.cpp (+34/-34)
tests/unit-tests/scene/test_application_session.cpp (+39/-25)
tests/unit-tests/scene/test_surface.cpp (+2/-2)
tests/unit-tests/scene/test_surface_impl.cpp (+5/-7)
To merge this branch: bzr merge lp:~brandontschaefer/mir/mir-event-capnproto
Reviewer Review Type Date Requested Status
Mir CI Bot continuous-integration Needs Fixing
Andreas Pokorny (community) Approve
Chris Halse Rogers Approve
Alan Griffiths Approve
Daniel van Vugt Abstain
Cemil Azizoglu (community) Needs Fixing
Review via email: mp+290760@code.launchpad.net

This proposal has been superseded by a proposal from 2016-09-19.

Commit message

Switch to using capnproto for the MirEvents. Long term will be making a capnptoro input sender/recevier using the capnproto serialization.

Description of the change

Moves to support capnproto as how MirEvents are handled under the hood.

The main idea of capnproto is a union for a pool of memory. You can only ever deep copy the arena pool of memory. Otherwise you've to re-init and change the values.

The asReader() (ie. Reader) class is the ReadOnly class for the structure. Its the only way to get const functions. Otherwise they will be non-const functions.

ie.

event.asReader().getXXX() == CONST
event.getXXX() == Returns modifiable structures

There is a current hack in place to keep a pointers lifetime for as long as the event. This should be removed once we can remove this from the public API: mir_input_device_state_event_device_pressed_keys()

Anpok mentions its not actually used yet? It would just be an API break but if no one uses it *shouldnt* be an issue to remove but I have a workaround atm.

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

Need to do more thorough review... For now :

s/MotionEventSet/MotionSetEvent
279 + motionSet @1 :MotionEventSet;

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

+ BOOST_THROW_EXCEPTION(std::runtime_error("Unknown type, major error"));

The message won't be helpful - what was the "Unknown type"? And who is "major error"?

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

@Cemil

Yeah sounds better

@Alan

It was one of those errors... that shouldnt ever happen. I suppose it should just say Unknown event type, and thats about all

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

Also, please feel free to suggest any names anywhere. This would be a good time to change names of things!

I've changed:

MotionEvent --> MotionSetEvet
MotionPointer --> Motion
pointer_coord --> motions
pointer_count --> count

Soo any more are welcome!

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

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

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

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

I'm still looking at the same line of code!

+ BOOST_THROW_EXCEPTION(std::runtime_error("Unknown event type"));

Now this is in MirEvent::type() - and that is called from mir_event_get_input_event() which is part of the C API.

We all know that we must not propagate exceptions though C code.

So, something is wrong here. Actually, probably multiple things:

1. mir_event_get_input_event() is missing a function try block.
2. The error should be fatal, not reported by an exception

I've not checked the other exceptions, but suspect this isn't an isolated case.

review: Needs Fixing
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

It makes no sense to change the names of structures that mismatch our needs.

I mean Motion is abused for pointer and touch screen events.. So actually Motion is a bunch of TouchContacts with contact id, x, y, action, major minor orientation and pressure and a contact type (and as far as I can tell you wont need a size here .. ) . There should be no source id - just device id. The source id information is exposed via the input device api. Also you then need a Pointer event with x, y, dx, dy, hscroll_ticks and vscroll_ticks.. (and later double scroll values for better touchpad scrolling)

How hard would it be to fix the code generator of capnproto to accept and emit mir style code?

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

@Alan

Yeah I missed all those this branch... I had them for the last branch.

Ill print a message then abort there, vs throwing.

@Andreas

Sadly: https://github.com/sandstorm-io/capnproto/issues/164

I just couldnt think of a better name really :(. So you're proposing we split this *Motion* structure into two structures 1 for touch the other for pointer? Or just keep what we have now rename, and include only contact id, x, y, action, major, minor, orientation, pressure, contact type, dx, dy, hscroll/vscroll?

Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

I assumed you intend to fix the MirEvent structures in a later mp - and this is just another one on one mapping MP of what we had, with no intention to consolidate it. So I expected another MP changing the types to match what we actually try to represent with the event API. To finally get rid of all the mapping code for input events.

But If this is meant to reflect the intended end state then this is a needs fixing..

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

This is indeed how i saw the end state of the event API mainly because its how its currently reflected.

If we want to change how it looks... then lets, Im just not 100% sure how your view of the end state is :).

Sooo we can try to do a hangout and talk about what is here vs what we should look like!

Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

I think we do not need the InputConfigurationEvent, but it is in our client API now. We might as well keep it. We will send updated input configuration structures as soon as the configuration changes, which might be enough to indicate configuration events.

Things I changed:
 - dumped all pointer related elements from Contact
 - moved Action into Contact (yay finally no more need to duplicate touch events)
 - dumped size which is directly derived from major/minor
 - added input event that holds the input event properties
 - added a real pointer event with all the axis we expose and the ones we should be able expose soon..

If one cannot have regular properties and an unnamed union inside the same structure, one could use an intermediate structure inside InputEvent that then containd the union of input events.

+struct NanoSeconds
+{
+ count @0 :Int64;
+}
+
+struct InputDeviceId
+{
+ id @0 :UInt64;
+}
+
+struct KeyboardEvent
+{
+ action @0 :Action;
+ keyCode @1 :Int32;
+ scanCode @2 :Int32;
+
+ enum Action
+ {
+ up @0;
+ down @1;
+ repeat @2;
+ }
+}
+
+struct TouchEvent
+{
+ struct Contact
+ {
+ id @0 :Int32;
+ action @1: Action;
+ x @2 :Float32;
+ y @3 :Float32;
+ majorAxis @4 :Float32;
+ minorAxis @5 :Float32;
+ pressure @6 :Float32;
+ orientation @7 :Float32; // not yet exposed
+ toolType @8 :ToolType;
+
+ enum ToolType
+ {
+ unknown @0;
+ finger @1;
+ stylus @2;
+ }
+ enum Action
+ {
+ up @0;
+ down @1;
+ change @2;
+ }
+ }
+
+ deviceId @0 :InputDeviceId;
+ modifiers @1 :UInt32;
+ eventTime @2 :NanoSeconds;
+ cookie @3 :Data;
+
+ count @4 :UInt32;
+ contacts @5 :List(Contact);
+ const maxCount :UInt32 = 16; // do we need that?
+}
+
+struct PointerEvent
+{
+ action @0 :Action;
+ x @1 :Float32;
+ y @2 :Float32;
+ dx @3 :Float32;
+ dy @4 :Float32;
+ hscrollTicks @5 :Float32;
+ vscrollTicks @6 :Float32;
+ hscrollMotion @7 :Float32; // not yet exposed
+ vscrollMotion @8 :Float32; // not yet exposed
+ enum Action
+ {
+ up @0;
+ down @1;
+ enter @2;
+ leave @3;
+ motion @4;
+ };
+}
+
+struct InputEvent
+{
+ deviceId @0 :InputDeviceId;
+ modifiers @1 :UInt32;
+ eventTime @2 :NanoSeconds;
+ cookie @3 :Data;
+ union
+ {
+ keyboard @0 :KeyboardEvent;
+ touch @1 :TouchEvent;
+ pointer @2 :PointerEvent;
+ }
}
+
+ ... snip ...
+
+struct Event
+{
+ union
+ {
+ input @0 :InputEvent;
+ surface @1 :SurfaceEvent;
+ resize @2 :ResizeEvent;
.... snip ...
+ }
+}

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

@Andreas

I like those changes, and I can make a new branch after this one to add that in. Main reason not to in this branch, is i can see that adding +/- 1k lines.

Soo yes now this branch is not the final form :)

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

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

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

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

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

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

The numbers are erratic, but it looks like this new code is slower than Protobuf under stress. Is that expected?...

$ mirping -f

(this branch)
Round-trip time: 0.044031 milliseconds
Round-trip time: 0.044160 milliseconds
Round-trip time: 0.044155 milliseconds
Round-trip time: 0.044229 milliseconds
Round-trip time: 0.044130 milliseconds
Round-trip time: 0.044168 milliseconds

(lp:mir)
Round-trip time: 0.038198 milliseconds
Round-trip time: 0.038178 milliseconds
Round-trip time: 0.037950 milliseconds
Round-trip time: 0.038150 milliseconds
Round-trip time: 0.037935 milliseconds
Round-trip time: 0.038156 milliseconds
Round-trip time: 0.038351 milliseconds

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

+} catch (...)
+{
+ abort();
}

Is this the intended end state? It might assist users encountering this if we at least output the string from the exception before aborting.

Also, the figures Daniel provides are concerning. I thought one motivation for Capnproto was performance.

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

@Duflu

Hmm this ... doesnt replace any protobuf stuff? The only bits that touch protobuf are:

 std::string MirEvent::serialize(MirEvent const* event)
and
 mir::EventUPtr MirEvent::deserialize(std::string const& bytes)

Which are only used for Surface events. Thats all we touch with protobuf, from there its just replacing android directly blitting over an FD (hard to be as fast as that). Though we copy them back into android events for now.

The solution for the serialize/deserialize is to simply move those into actual protobuf structres for now. That'll make it so capnproto does not touch anything that protobuf uses

@Alan
Yeah i can print out the error message to the log!

The number one reason (as far as I know) for capnproto was to get a actual serialization into events to handle keymap/cookies better. Also its a first implementation, I could have caused some slow downs in those two functions. From my testing at lease we are faster with capnproto (when we replace the actual sender/receiver)

The other issue is we have to copy from capnproto --> android event --> fd (client) --> capnproto again. So yes, this is going to be slower on that front until we merge the sender/receiver code for capnproto. Which is done but needs to be tested a bit more. Mainly in the re-sampling areas.

You can test this branch out which has the capnproto input platform:
https://code.launchpad.net/~brandontschaefer/mir/canproto-input-platform

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

Also you'll notice that that branch will still be the same for RPC. The overall issue is having to use capnproto to produce *serialized* bytes to send of protobuf, when protobuf should really be handling that for us... So yes the side effect for right now is a slower RPC when it comes to surface events, but the reason capnproto is slower here is because we are slightly abusing it to get it to work

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

OK. It isn't really a blocking issue yet. Just keep 'mirping -f' in mind because in the long run if performance is still worse then we need to reassess this approach.

Even a few years ago it was apparent that the Mir protocol created a performance handicap compared to Wayland. So making it even slower again would be a red flag.

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

I'd be happier if we addressed two concerns before releasing this:

1. the performance issue
2. eating potentially useful error information

But I'm willing to let this land provided solutions to the above to follow shortly.

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

Opps forgot to push #2!

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

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

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

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

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

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

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

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

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Chris Halse Rogers (raof) wrote :

1384 + for (auto const& c : flat_event.asBytes())
1385 + {
1386 + output += c;
1387 + }

Is it really necessary to do this a character at a time? You'll almost certainly be incurring a couple of unnecessary memory allocations here.

1415 + case mir::capnp::Event::Which::SURFACE_OUTPUT:
1416 + return mir_event_type_surface_output;
1417 + }
1418 +
1419 + mir::log_critical("unknown event type.");
1420 + abort();

Wouldn't the idiomatic thing here be to have a default: stanza in the switch()?

Otherwise, seems pretty sensible (modulo already requested follow-up work)

review: Approve
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

yeah those could be simple std::string(begin(flat_event), end(flat_event)) constructor calls.

I am looking forward to the upcoming MPs

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

Fixed.

I look forward to that branch as well :).

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

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

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

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

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

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

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

Yay cant reproduce that test issue ... seems to happen on xenial and vivid overlay....

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

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

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

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

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

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

review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2016-09-08 16:52:49 +0000
3+++ CMakeLists.txt 2016-09-18 20:00:37 +0000
4@@ -196,6 +196,7 @@
5 find_package(GLESv2 REQUIRED)
6 find_package(GLM REQUIRED)
7 find_package(Protobuf REQUIRED )
8+find_package(CapnProto REQUIRED)
9 find_package(GLog REQUIRED)
10 find_package(GFlags REQUIRED)
11 find_package(LTTngUST REQUIRED)
12@@ -293,7 +294,7 @@
13
14 # There's no nice way to format this. Thanks CMake.
15 mir_add_test(NAME LGPL-required
16- COMMAND /bin/sh -c "! grep -rl 'GNU General' ${PROJECT_SOURCE_DIR}/src/client ${PROJECT_SOURCE_DIR}/include/client ${PROJECT_SOURCE_DIR}/src/common ${PROJECT_SOURCE_DIR}/include/common ${PROJECT_SOURCE_DIR}/src/include/common ${PROJECT_SOURCE_DIR}/src/platform ${PROJECT_SOURCE_DIR}/include/platform ${PROJECT_SOURCE_DIR}/src/include/platform"
17+ COMMAND /bin/sh -c "! grep -rl 'GNU General' ${PROJECT_SOURCE_DIR}/src/client ${PROJECT_SOURCE_DIR}/include/client ${PROJECT_SOURCE_DIR}/src/common ${PROJECT_SOURCE_DIR}/include/common ${PROJECT_SOURCE_DIR}/src/include/common ${PROJECT_SOURCE_DIR}/src/platform ${PROJECT_SOURCE_DIR}/include/platform ${PROJECT_SOURCE_DIR}/src/include/platform ${PROJECT_SOURCE_DIR}/src/capnproto"
18 )
19 mir_add_test(NAME GPL-required
20 COMMAND /bin/sh -c "! grep -rl 'GNU Lesser' ${PROJECT_SOURCE_DIR}/src/server ${PROJECT_SOURCE_DIR}/include/server ${PROJECT_SOURCE_DIR}/src/include/server ${PROJECT_SOURCE_DIR}/tests ${PROJECT_SOURCE_DIR}/examples"
21
22=== modified file 'debian/control'
23--- debian/control 2016-09-12 11:49:12 +0000
24+++ debian/control 2016-09-18 20:00:37 +0000
25@@ -46,6 +46,8 @@
26 python3:any,
27 dh-python,
28 nettle-dev,
29+ libcapnp-dev,
30+ capnproto
31 libepoxy-dev,
32 Standards-Version: 3.9.4
33 Homepage: https://launchpad.net/mir
34
35=== modified file 'include/client/mir/events/event_builders.h'
36--- include/client/mir/events/event_builders.h 2016-09-16 15:18:36 +0000
37+++ include/client/mir/events/event_builders.h 2016-09-18 20:00:37 +0000
38@@ -25,6 +25,7 @@
39 #include "mir/geometry/point.h"
40 #include "mir/geometry/rectangle.h"
41 #include "mir/frontend/surface_id.h"
42+#include "mir/events/input_device_state.h"
43
44 #include <memory>
45 #include <functional>
46@@ -138,13 +139,6 @@
47 EventUPtr make_event(MirInputConfigurationAction action,
48 MirInputDeviceId id, std::chrono::nanoseconds time);
49
50-struct InputDeviceState
51-{
52- MirInputDeviceId id;
53- std::vector<uint32_t> pressed_keys;
54- MirPointerButtons buttons;
55-};
56-
57 EventUPtr make_event(std::chrono::nanoseconds timestamp,
58 MirPointerButtons pointer_buttons,
59 MirInputEventModifiers modifiers,
60
61=== modified file 'include/client/mir_toolkit/events/input_device_state_event.h'
62--- include/client/mir_toolkit/events/input_device_state_event.h 2016-06-02 15:07:12 +0000
63+++ include/client/mir_toolkit/events/input_device_state_event.h 2016-09-18 20:00:37 +0000
64@@ -100,14 +100,28 @@
65 * Retrieve an array of pressed keys on the device identified by the \a index.
66 * The keys are encoded as scan codes.
67 *
68+ * \deprecated Use mir_input_device_state_event_device_pressed_keys_for_index() instead
69 * \param[in] ev The input device state event
70 * \param[in] index The index of the input device
71 * \return An array of pressed keys
72 */
73+__attribute__ ((deprecated))
74 uint32_t const* mir_input_device_state_event_device_pressed_keys(
75 MirInputDeviceStateEvent const* ev, uint32_t index);
76
77 /**
78+ * Retrieve a pressed key on the device identified by the \a index.
79+ * The key is encoded as a scan code.
80+ *
81+ * \param[in] ev The input device state event
82+ * \param[in] index The index of the input device
83+ * \param[in] pressed_index The index of the pressed key
84+ * \return The pressed key at index pressed_index
85+ */
86+uint32_t mir_input_device_state_event_device_pressed_keys_for_index(
87+ MirInputDeviceStateEvent const* ev, uint32_t index, uint32_t pressed_index);
88+
89+/**
90 * Retrieve the size of scan code array of the device identified by the \a index.
91 *
92 * \param[in] ev The input device state event
93
94=== modified file 'include/test/mir/test/event_matchers.h'
95--- include/test/mir/test/event_matchers.h 2016-07-04 12:17:44 +0000
96+++ include/test/mir/test/event_matchers.h 2016-09-18 20:00:37 +0000
97@@ -527,8 +527,13 @@
98 if (num_required_keys != key_count)
99 continue;
100
101- auto pressed_keys = mir_input_device_state_event_device_pressed_keys(device_state, index);
102- if (!std::equal(it_keys, end_keys, pressed_keys))
103+ std::vector<uint32_t> pressed_keys;
104+ for (uint32_t i = 0; i < key_count; i++)
105+ {
106+ pressed_keys.push_back(mir_input_device_state_event_device_pressed_keys_for_index(device_state, index, i));
107+ }
108+
109+ if (!std::equal(it_keys, end_keys, std::begin(pressed_keys)))
110 continue;
111 return true;
112 }
113
114=== modified file 'src/CMakeLists.txt'
115--- src/CMakeLists.txt 2016-08-01 14:43:19 +0000
116+++ src/CMakeLists.txt 2016-09-18 20:00:37 +0000
117@@ -16,6 +16,7 @@
118 # the src/include/... directories should be private to the implementation
119 include_directories(${PROJECT_SOURCE_DIR}/src/include/common)
120 set(MIR_GENERATED_INCLUDE_DIRECTORIES)
121+add_subdirectory(capnproto/)
122 add_subdirectory(common/)
123 add_subdirectory(protobuf/)
124 include_directories(${MIR_GENERATED_INCLUDE_DIRECTORIES})
125
126=== added directory 'src/capnproto'
127=== added file 'src/capnproto/CMakeLists.txt'
128--- src/capnproto/CMakeLists.txt 1970-01-01 00:00:00 +0000
129+++ src/capnproto/CMakeLists.txt 2016-09-18 20:00:37 +0000
130@@ -0,0 +1,29 @@
131+# Copyright © 2016 Canonical Ltd.
132+#
133+# This program is free software: you can redistribute it and/or modify it
134+# under the terms of the GNU Lesser General Public License version 3,
135+# as published by the Free Software Foundation.
136+#
137+# This program is distributed in the hope that it will be useful,
138+# but WITHOUT ANY WARRANTY; without even the implied warranty of
139+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
140+# GNU Lesser General Public License for more details.
141+#
142+# You should have received a copy of the GNU Lesser General Public License
143+# along with this program. If not, see <http://www.gnu.org/licenses/>.
144+#
145+# Author: Brandon Schaefer <brandon.schaefer@canonical.com>
146+
147+set(CAPNPC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
148+
149+capnp_generate_cpp(CAPNPROTO_SRC CAPNPROTO_HDRS mir_event.capnp)
150+
151+add_library(mircapnproto STATIC ${CAPNPROTO_SRC})
152+target_link_libraries(mircapnproto ${CAPNP_LIBRARIES_LITE})
153+
154+list(APPEND MIR_GENERATED_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR})
155+
156+set(
157+ MIR_GENERATED_INCLUDE_DIRECTORIES ${MIR_GENERATED_INCLUDE_DIRECTORIES}
158+ PARENT_SCOPE
159+)
160
161=== added file 'src/capnproto/mir_event.capnp'
162--- src/capnproto/mir_event.capnp 1970-01-01 00:00:00 +0000
163+++ src/capnproto/mir_event.capnp 2016-09-18 20:00:37 +0000
164@@ -0,0 +1,237 @@
165+# Copyright © 2016 Canonical Ltd.
166+#
167+# This program is free software: you can redistribute it and/or modify it
168+# under the terms of the GNU Lesser General Public License version 3,
169+# as published by the Free Software Foundation.
170+#
171+# This program is distributed in the hope that it will be useful,
172+# but WITHOUT ANY WARRANTY; without even the implied warranty of
173+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
174+# GNU Lesser General Public License for more details.
175+#
176+# You should have received a copy of the GNU Lesser General Public License
177+# along with this program. If not, see <http://www.gnu.org/licenses/>.
178+#
179+# Author: Brandon Schaefer <brandon.schaefer@canonical.com>
180+
181+@0x9ff9e89b8e11dc56;
182+
183+# Need to namespace the InputEvent/Event since the generated (Mir)Event has all its ctors deleted.
184+# Which we need a C compliant struct to be generated. So namespace these, and wrap a
185+# builder in a struct MirEvent {..};
186+using Cxx = import "/capnp/c++.capnp";
187+$Cxx.namespace("mir::capnp");
188+
189+struct NanoSeconds
190+{
191+ count @0 :Int64;
192+}
193+
194+struct InputDeviceId
195+{
196+ id @0 :UInt64;
197+}
198+
199+struct Rectangle
200+{
201+ left @0 :Int32;
202+ top @1 :Int32;
203+ width @2 :UInt32;
204+ height @3 :UInt32;
205+}
206+
207+struct KeyboardEvent
208+{
209+ id @0 :Int32;
210+ deviceId @1 :InputDeviceId;
211+ sourceId @2 :Int32;
212+ action @3 :Action;
213+ modifiers @4 :UInt32;
214+ keyCode @5 :Int32;
215+ scanCode @6 :Int32;
216+ eventTime @7 :NanoSeconds;
217+ cookie @8 :Data;
218+
219+ enum Action
220+ {
221+ up @0;
222+ down @1;
223+ repeat @2;
224+ }
225+}
226+
227+struct MotionSetEvent
228+{
229+ struct Motion
230+ {
231+ id @0 :Int32;
232+ x @1 :Float32;
233+ y @2 :Float32;
234+ dx @3 :Float32;
235+ dy @4 :Float32;
236+ touchMajor @5 :Float32;
237+ touchMinor @6 :Float32;
238+ size @7 :Float32;
239+ pressure @8 :Float32;
240+ orientation @9 :Float32;
241+ vscroll @10 :Float32;
242+ hscroll @11 :Float32;
243+
244+ toolType @12 :ToolType;
245+
246+ # TODO: We would like to store this as a TouchAction but we still encode pointer actions
247+ # here as well.
248+ action @13 :Int32;
249+
250+ enum ToolType
251+ {
252+ unknown @0;
253+ finger @1;
254+ stylus @2;
255+ }
256+ }
257+
258+ deviceId @0 :InputDeviceId;
259+ sourceId @1 :Int32;
260+ modifiers @2 :UInt32;
261+ buttons @3 :UInt32;
262+ eventTime @4 :NanoSeconds;
263+ cookie @5 :Data;
264+
265+ count @6 :UInt32;
266+ motions @7 :List(Motion);
267+ const maxCount :UInt32 = 16;
268+}
269+
270+struct InputConfigurationEvent
271+{
272+ action @0 :Action;
273+ when @1 :NanoSeconds;
274+ id @2 :InputDeviceId;
275+
276+ enum Action
277+ {
278+ configurationChanged @0;
279+ deviceReset @1;
280+ }
281+}
282+
283+struct SurfaceEvent
284+{
285+ id @0 :Int32;
286+ attrib @1 :Attrib;
287+ value @2 :Int32;
288+
289+ enum Attrib
290+ {
291+ # Do not specify values...code relies on 0...N ordering.
292+ type @0;
293+ state @1;
294+ swapInterval @2;
295+ focus @3;
296+ dpi @4;
297+ visibility @5;
298+ preferredOrientation @6;
299+ # Must be last
300+ surfaceAttrib @7;
301+ }
302+}
303+
304+struct ResizeEvent
305+{
306+ surfaceId @0 :Int32;
307+ width @1 :Int32;
308+ height @2 :Int32;
309+}
310+
311+struct PromptSessionEvent
312+{
313+ newState @0 :State;
314+
315+ enum State
316+ {
317+ stopped @0;
318+ started @1;
319+ suspended @2;
320+ }
321+}
322+
323+struct OrientationEvent
324+{
325+ surfaceId @0 :Int32;
326+ direction @1 :Int32;
327+}
328+
329+struct CloseSurfaceEvent
330+{
331+ surfaceId @0 :Int32;
332+}
333+
334+struct KeymapEvent
335+{
336+ surfaceId @0 :Int32;
337+
338+ deviceId @1 :InputDeviceId;
339+ buffer @2 :Text;
340+}
341+
342+struct SurfaceOutputEvent
343+{
344+ surfaceId @0 :Int32;
345+ dpi @1 :Int32;
346+ scale @2 :Float32;
347+ formFactor @3 :FormFactor;
348+ outputId @4 :UInt32;
349+
350+ enum FormFactor
351+ {
352+ unknown @0;
353+ phone @1;
354+ tablet @2;
355+ monitor @3;
356+ tv @4;
357+ projector @5;
358+ }
359+}
360+
361+struct InputDeviceStateEvent
362+{
363+ when @0 :NanoSeconds;
364+ buttons @1 :UInt32;
365+ modifiers @2 :UInt32;
366+ pointerX @3 :Float32;
367+ pointerY @4 :Float32;
368+ devices @5 :List(DeviceState);
369+
370+ struct DeviceState
371+ {
372+ deviceId @0 :InputDeviceId;
373+ pressedKeys @1 :List(UInt32);
374+ buttons @2 :UInt32;
375+ }
376+}
377+
378+struct SurfacePlacementEvent
379+{
380+ id @0 :Int32;
381+ rectangle @1 :Rectangle;
382+}
383+
384+struct Event
385+{
386+ union
387+ {
388+ key @0 :KeyboardEvent;
389+ motionSet @1 :MotionSetEvent;
390+ surface @2 :SurfaceEvent;
391+ resize @3 :ResizeEvent;
392+ promptSession @4 :PromptSessionEvent;
393+ orientation @5 :OrientationEvent;
394+ closeSurface @6 :CloseSurfaceEvent;
395+ keymap @7 :KeymapEvent;
396+ inputConfiguration @8 :InputConfigurationEvent;
397+ surfaceOutput @9 :SurfaceOutputEvent;
398+ inputDevice @10 :InputDeviceStateEvent;
399+ surfacePlacement @11 :SurfacePlacementEvent;
400+ }
401+}
402
403=== modified file 'src/client/event.cpp'
404--- src/client/event.cpp 2016-09-16 15:18:36 +0000
405+++ src/client/event.cpp 2016-09-18 20:00:37 +0000
406@@ -40,7 +40,7 @@
407 namespace
408 {
409 template <typename EventType>
410-void expect_event_type(EventType const* ev, MirEventType t)
411+void expect_event_type(EventType const* ev, MirEventType t) try
412 {
413 if (ev->type() != t)
414 {
415@@ -48,6 +48,10 @@
416 mir::event_type_to_string(ev->type()));
417 abort();
418 }
419+} catch (std::exception const& e)
420+{
421+ mir::log_critical(e.what());
422+ abort();
423 }
424
425 void expect_index_in_range(size_t size, size_t index)
426@@ -88,7 +92,7 @@
427 }
428
429
430-MirEventType mir_event_get_type(MirEvent const* ev)
431+MirEventType mir_event_get_type(MirEvent const* ev) try
432 {
433 switch (ev->type())
434 {
435@@ -98,9 +102,13 @@
436 default:
437 return ev->type();
438 }
439+} catch (std::exception const& e)
440+{
441+ mir::log_critical(e.what());
442+ abort();
443 }
444
445-MirInputEvent const* mir_event_get_input_event(MirEvent const* ev)
446+MirInputEvent const* mir_event_get_input_event(MirEvent const* ev) try
447 {
448 if (ev->type() != mir_event_type_key && ev->type() != mir_event_type_motion)
449 {
450@@ -110,236 +118,393 @@
451 }
452
453 return ev->to_input();
454+} catch (std::exception const& e)
455+{
456+ mir::log_critical(e.what());
457+ abort();
458 }
459
460-MirSurfaceEvent const* mir_event_get_surface_event(MirEvent const* ev)
461+MirSurfaceEvent const* mir_event_get_surface_event(MirEvent const* ev) try
462 {
463 expect_event_type(ev, mir_event_type_surface);
464
465 return ev->to_surface();
466+} catch (std::exception const& e)
467+{
468+ mir::log_critical(e.what());
469+ abort();
470 }
471
472-MirResizeEvent const* mir_event_get_resize_event(MirEvent const* ev)
473+MirResizeEvent const* mir_event_get_resize_event(MirEvent const* ev) try
474 {
475 expect_event_type(ev, mir_event_type_resize);
476
477 return ev->to_resize();
478+} catch (std::exception const& e)
479+{
480+ mir::log_critical(e.what());
481+ abort();
482 }
483
484-MirPromptSessionEvent const* mir_event_get_prompt_session_event(MirEvent const* ev)
485+MirPromptSessionEvent const* mir_event_get_prompt_session_event(MirEvent const* ev) try
486 {
487 expect_event_type(ev, mir_event_type_prompt_session_state_change);
488
489 return ev->to_prompt_session();
490+} catch (std::exception const& e)
491+{
492+ mir::log_critical(e.what());
493+ abort();
494 }
495
496-MirOrientationEvent const* mir_event_get_orientation_event(MirEvent const* ev)
497+MirOrientationEvent const* mir_event_get_orientation_event(MirEvent const* ev) try
498 {
499 expect_event_type(ev, mir_event_type_orientation);
500
501 return ev->to_orientation();
502+} catch (std::exception const& e)
503+{
504+ mir::log_critical(e.what());
505+ abort();
506 }
507
508-MirCloseSurfaceEvent const* mir_event_get_close_surface_event(MirEvent const* ev)
509+MirCloseSurfaceEvent const* mir_event_get_close_surface_event(MirEvent const* ev) try
510 {
511 expect_event_type(ev, mir_event_type_close_surface);
512
513 return ev->to_close_surface();
514+} catch (std::exception const& e)
515+{
516+ mir::log_critical(e.what());
517+ abort();
518 }
519
520-MirKeymapEvent const* mir_event_get_keymap_event(MirEvent const* ev)
521+MirKeymapEvent const* mir_event_get_keymap_event(MirEvent const* ev) try
522 {
523 expect_event_type(ev, mir_event_type_keymap);
524
525 return ev->to_keymap();
526+} catch (std::exception const& e)
527+{
528+ mir::log_critical(e.what());
529+ abort();
530 }
531
532-MirInputConfigurationEvent const* mir_event_get_input_configuration_event(MirEvent const* ev)
533+MirInputConfigurationEvent const* mir_event_get_input_configuration_event(MirEvent const* ev) try
534 {
535 expect_event_type(ev, mir_event_type_input_configuration);
536
537 return ev->to_input_configuration();
538+} catch (std::exception const& e)
539+{
540+ mir::log_critical(e.what());
541+ abort();
542 }
543
544-MirSurfaceOutputEvent const* mir_event_get_surface_output_event(MirEvent const* ev)
545+MirSurfaceOutputEvent const* mir_event_get_surface_output_event(MirEvent const* ev) try
546 {
547 expect_event_type(ev, mir_event_type_surface_output);
548
549 return ev->to_surface_output();
550+} catch (std::exception const& e)
551+{
552+ mir::log_critical(e.what());
553+ abort();
554 }
555
556-MirInputDeviceStateEvent const* mir_event_get_input_device_state_event(MirEvent const* ev)
557+MirInputDeviceStateEvent const* mir_event_get_input_device_state_event(MirEvent const* ev) try
558 {
559 expect_event_type(ev, mir_event_type_input_device_state);
560
561 return ev->to_input_device_state();
562+} catch (std::exception const& e)
563+{
564+ mir::log_critical(e.what());
565+ abort();
566 }
567
568 /* Surface event accessors */
569
570-MirSurfaceAttrib mir_surface_event_get_attribute(MirSurfaceEvent const* ev)
571+MirSurfaceAttrib mir_surface_event_get_attribute(MirSurfaceEvent const* ev) try
572 {
573 expect_event_type(ev, mir_event_type_surface);
574
575 return ev->attrib();
576+} catch (std::exception const& e)
577+{
578+ mir::log_critical(e.what());
579+ abort();
580 }
581
582-int mir_surface_event_get_attribute_value(MirSurfaceEvent const* ev)
583+int mir_surface_event_get_attribute_value(MirSurfaceEvent const* ev) try
584 {
585 expect_event_type(ev, mir_event_type_surface);
586
587 return ev->value();
588+} catch (std::exception const& e)
589+{
590+ mir::log_critical(e.what());
591+ abort();
592 }
593
594 /* Resize event accessors */
595
596-int mir_resize_event_get_width(MirResizeEvent const* ev)
597+int mir_resize_event_get_width(MirResizeEvent const* ev) try
598 {
599 expect_event_type(ev, mir_event_type_resize);
600 return ev->width();
601+} catch (std::exception const& e)
602+{
603+ mir::log_critical(e.what());
604+ abort();
605 }
606
607-int mir_resize_event_get_height(MirResizeEvent const* ev)
608+int mir_resize_event_get_height(MirResizeEvent const* ev) try
609 {
610 expect_event_type(ev, mir_event_type_resize);
611 return ev->height();
612+} catch (std::exception const& e)
613+{
614+ mir::log_critical(e.what());
615+ abort();
616 }
617
618 /* Prompt session event accessors */
619
620-MirPromptSessionState mir_prompt_session_event_get_state(MirPromptSessionEvent const* ev)
621+MirPromptSessionState mir_prompt_session_event_get_state(MirPromptSessionEvent const* ev) try
622 {
623 expect_event_type(ev, mir_event_type_prompt_session_state_change);
624 return ev->new_state();
625+} catch (std::exception const& e)
626+{
627+ mir::log_critical(e.what());
628+ abort();
629 }
630
631 /* Orientation event accessors */
632
633-MirOrientation mir_orientation_event_get_direction(MirOrientationEvent const* ev)
634+MirOrientation mir_orientation_event_get_direction(MirOrientationEvent const* ev) try
635 {
636 expect_event_type(ev, mir_event_type_orientation);
637 return ev->direction();
638+} catch (std::exception const& e)
639+{
640+ mir::log_critical(e.what());
641+ abort();
642 }
643
644 /* Keymap event accessors */
645
646-void mir_keymap_event_get_keymap_buffer(MirKeymapEvent const* ev, char const** buffer, size_t* length)
647+void mir_keymap_event_get_keymap_buffer(MirKeymapEvent const* ev, char const** buffer, size_t* length) try
648 {
649 expect_event_type(ev, mir_event_type_keymap);
650
651 *buffer = ev->buffer();
652 *length = ev->size();
653+} catch (std::exception const& e)
654+{
655+ mir::log_critical(e.what());
656+ abort();
657 }
658
659-MirInputDeviceId mir_keymap_event_get_device_id(MirKeymapEvent const* ev)
660+MirInputDeviceId mir_keymap_event_get_device_id(MirKeymapEvent const* ev) try
661 {
662 expect_event_type(ev, mir_event_type_keymap);
663
664 return ev->device_id();
665+} catch (std::exception const& e)
666+{
667+ mir::log_critical(e.what());
668+ abort();
669 }
670
671 /* Input configuration event accessors */
672
673-MirInputConfigurationAction mir_input_configuration_event_get_action(MirInputConfigurationEvent const* ev)
674+MirInputConfigurationAction mir_input_configuration_event_get_action(MirInputConfigurationEvent const* ev) try
675 {
676 expect_event_type(ev, mir_event_type_input_configuration);
677 return ev->action();
678+} catch (std::exception const& e)
679+{
680+ mir::log_critical(e.what());
681+ abort();
682 }
683
684-int64_t mir_input_configuration_event_get_time(MirInputConfigurationEvent const* ev)
685+int64_t mir_input_configuration_event_get_time(MirInputConfigurationEvent const* ev) try
686 {
687 expect_event_type(ev, mir_event_type_input_configuration);
688 return ev->when().count();
689+} catch (std::exception const& e)
690+{
691+ mir::log_critical(e.what());
692+ abort();
693 }
694
695-MirInputDeviceId mir_input_configuration_event_get_device_id(MirInputConfigurationEvent const* ev)
696+MirInputDeviceId mir_input_configuration_event_get_device_id(MirInputConfigurationEvent const* ev) try
697 {
698 expect_event_type(ev, mir_event_type_input_configuration);
699 return ev->id();
700+} catch (std::exception const& e)
701+{
702+ mir::log_critical(e.what());
703+ abort();
704 }
705
706 /* Surface output event accessors */
707
708-int mir_surface_output_event_get_dpi(MirSurfaceOutputEvent const* ev)
709+int mir_surface_output_event_get_dpi(MirSurfaceOutputEvent const* ev) try
710 {
711 expect_event_type(ev, mir_event_type_surface_output);
712 return ev->dpi();
713+} catch (std::exception const& e)
714+{
715+ mir::log_critical(e.what());
716+ abort();
717 }
718
719-MirFormFactor mir_surface_output_event_get_form_factor(MirSurfaceOutputEvent const* ev)
720+MirFormFactor mir_surface_output_event_get_form_factor(MirSurfaceOutputEvent const* ev) try
721 {
722 expect_event_type(ev, mir_event_type_surface_output);
723 return ev->form_factor();
724+} catch (std::exception const& e)
725+{
726+ mir::log_critical(e.what());
727+ abort();
728 }
729
730-float mir_surface_output_event_get_scale(MirSurfaceOutputEvent const* ev)
731+float mir_surface_output_event_get_scale(MirSurfaceOutputEvent const* ev) try
732 {
733 expect_event_type(ev, mir_event_type_surface_output);
734 return ev->scale();
735+} catch (std::exception const& e)
736+{
737+ mir::log_critical(e.what());
738+ abort();
739 }
740
741-uint32_t mir_surface_output_event_get_output_id(MirSurfaceOutputEvent const *ev)
742+uint32_t mir_surface_output_event_get_output_id(MirSurfaceOutputEvent const *ev) try
743 {
744 expect_event_type(ev, mir_event_type_surface_output);
745 return ev->output_id();
746+} catch (std::exception const& e)
747+{
748+ mir::log_critical(e.what());
749+ abort();
750 }
751
752-MirPointerButtons mir_input_device_state_event_pointer_buttons(MirInputDeviceStateEvent const* ev)
753+MirPointerButtons mir_input_device_state_event_pointer_buttons(MirInputDeviceStateEvent const* ev) try
754 {
755 expect_event_type(ev, mir_event_type_input_device_state);
756 return ev->pointer_buttons();
757+} catch (std::exception const& e)
758+{
759+ mir::log_critical(e.what());
760+ abort();
761 }
762
763-float mir_input_device_state_event_pointer_axis(MirInputDeviceStateEvent const* ev, MirPointerAxis axis)
764+float mir_input_device_state_event_pointer_axis(MirInputDeviceStateEvent const* ev, MirPointerAxis axis) try
765 {
766 expect_event_type(ev, mir_event_type_input_device_state);
767 return ev->pointer_axis(axis);
768+} catch (std::exception const& e)
769+{
770+ mir::log_critical(e.what());
771+ abort();
772 }
773
774-int64_t mir_input_device_state_event_time(MirInputDeviceStateEvent const* ev)
775+int64_t mir_input_device_state_event_time(MirInputDeviceStateEvent const* ev) try
776 {
777 expect_event_type(ev, mir_event_type_input_device_state);
778 return ev->when().count();
779+} catch (std::exception const& e)
780+{
781+ mir::log_critical(e.what());
782+ abort();
783 }
784
785-MirInputEventModifiers mir_input_device_state_event_modifiers(MirInputDeviceStateEvent const* ev)
786+MirInputEventModifiers mir_input_device_state_event_modifiers(MirInputDeviceStateEvent const* ev) try
787 {
788 expect_event_type(ev, mir_event_type_input_device_state);
789 return ev->modifiers();
790+} catch (std::exception const& e)
791+{
792+ mir::log_critical(e.what());
793+ abort();
794 }
795
796-uint32_t mir_input_device_state_event_device_count(MirInputDeviceStateEvent const* ev)
797+uint32_t mir_input_device_state_event_device_count(MirInputDeviceStateEvent const* ev) try
798 {
799 expect_event_type(ev, mir_event_type_input_device_state);
800 return ev->device_count();
801+} catch (std::exception const& e)
802+{
803+ mir::log_critical(e.what());
804+ abort();
805 }
806
807-MirInputDeviceId mir_input_device_state_event_device_id(MirInputDeviceStateEvent const* ev, uint32_t index)
808+MirInputDeviceId mir_input_device_state_event_device_id(MirInputDeviceStateEvent const* ev, uint32_t index) try
809 {
810 expect_event_type(ev, mir_event_type_input_device_state);
811 expect_index_in_range(ev->device_count(), index);
812 return ev->device_id(index);
813-}
814-
815-uint32_t const* mir_input_device_state_event_device_pressed_keys(MirInputDeviceStateEvent const* ev, uint32_t index)
816-{
817- expect_event_type(ev, mir_event_type_input_device_state);
818- expect_index_in_range(ev->device_count(), index);
819- return ev->device_pressed_keys(index);
820-}
821-
822-uint32_t mir_input_device_state_event_device_pressed_keys_count(MirInputDeviceStateEvent const* ev, uint32_t index)
823+} catch (std::exception const& e)
824+{
825+ mir::log_critical(e.what());
826+ abort();
827+}
828+
829+uint32_t const* mir_input_device_state_event_device_pressed_keys(MirInputDeviceStateEvent const* ev, uint32_t index) try
830+{
831+ expect_event_type(ev, mir_event_type_input_device_state);
832+ expect_index_in_range(ev->device_count(), index);
833+
834+ auto pressed_keys_vec = const_cast<MirInputDeviceStateEvent*>(ev)->device_pressed_keys(index);
835+ auto stored_pointer = std::shared_ptr<uint32_t>(
836+ new uint32_t[pressed_keys_vec.size()],
837+ [](uint32_t const* p)
838+ { delete[] p; });
839+
840+ std::copy(std::begin(pressed_keys_vec), std::end(pressed_keys_vec), stored_pointer.get());
841+
842+ return static_cast<uint32_t*>(mir::event::store_data_for_lifetime_of_event(ev, stored_pointer));
843+} catch (std::exception const& e)
844+{
845+ mir::log_critical(e.what());
846+ abort();
847+}
848+
849+uint32_t mir_input_device_state_event_device_pressed_keys_for_index(
850+ MirInputDeviceStateEvent const* ev, uint32_t index, uint32_t pressed_index) try
851+{
852+ expect_event_type(ev, mir_event_type_input_device_state);
853+ expect_index_in_range(ev->device_count(), index);
854+ return ev->device_pressed_keys_for_index(index, pressed_index);
855+} catch (std::exception const& e)
856+{
857+ mir::log_critical(e.what());
858+ abort();
859+}
860+
861+uint32_t mir_input_device_state_event_device_pressed_keys_count(MirInputDeviceStateEvent const* ev, uint32_t index) try
862 {
863 expect_event_type(ev, mir_event_type_input_device_state);
864 expect_index_in_range(ev->device_count(), index);
865 return ev->device_pressed_keys_count(index);
866+} catch (std::exception const& e)
867+{
868+ mir::log_critical(e.what());
869+ abort();
870 }
871
872-MirPointerButtons mir_input_device_state_event_device_pointer_buttons(MirInputDeviceStateEvent const* ev, uint32_t index)
873+MirPointerButtons mir_input_device_state_event_device_pointer_buttons(MirInputDeviceStateEvent const* ev, uint32_t index) try
874 {
875 expect_event_type(ev, mir_event_type_input_device_state);
876 expect_index_in_range(ev->device_count(), index);
877 return ev->device_pointer_buttons(index);
878+} catch (std::exception const& e)
879+{
880+ mir::log_critical(e.what());
881+ abort();
882 }
883
884 MirSurfacePlacementEvent const* mir_event_get_surface_placement_event(MirEvent const* event)
885@@ -354,17 +519,16 @@
886
887 // TODO: Until we opaquify the MirEvent structure and add
888 // a ref count ref is implemented as copy.
889-MirEvent const* mir_event_ref(MirEvent const* ev)
890-{
891- return ev->clone();
892+MirEvent const* mir_event_ref(MirEvent const* ev) try
893+{
894+ return new MirEvent(*ev);
895+} catch (std::exception const& e)
896+{
897+ mir::log_critical(e.what());
898+ abort();
899 }
900
901 void mir_event_unref(MirEvent const* ev)
902 {
903- if (mir_event_get_type(ev) == mir_event_type_keymap)
904- {
905- const_cast<MirEvent*>(ev)->to_keymap()->free_buffer();
906- }
907-
908 delete const_cast<MirEvent*>(ev);
909 }
910
911=== modified file 'src/client/event_printer.cpp'
912--- src/client/event_printer.cpp 2016-09-16 15:18:36 +0000
913+++ src/client/event_printer.cpp 2016-09-18 20:00:37 +0000
914@@ -348,11 +348,11 @@
915 out << mir_input_device_state_event_device_id(&event, index)
916 << " btns=" << mir_input_device_state_event_device_pointer_buttons(&event, index)
917 << " pressed=(";
918- auto keys = mir_input_device_state_event_device_pressed_keys(&event, index);
919- for (size_t count_keys = mir_input_device_state_event_device_pressed_keys_count(&event, index), i = 0; i != count_keys; ++i)
920+ auto key_count = mir_input_device_state_event_device_pressed_keys_count(&event, index);
921+ for (uint32_t i = 0; i < key_count; i++)
922 {
923- out << static_cast<uint32_t>(keys[i]);
924- if (i + 1 < count_keys)
925+ out << mir_input_device_state_event_device_pressed_keys_for_index(&event, index, i);
926+ if (i + 1 < key_count)
927 out << ", ";
928 }
929 out << ")";
930
931=== modified file 'src/client/events/event_builders.cpp'
932--- src/client/events/event_builders.cpp 2016-09-16 15:18:36 +0000
933+++ src/client/events/event_builders.cpp 2016-09-18 20:00:37 +0000
934@@ -41,22 +41,6 @@
935
936 namespace
937 {
938- mir::cookie::Blob vector_to_cookie_as_blob(std::vector<uint8_t> const& vector)
939- {
940- mir::cookie::Blob blob{{}};
941-
942- if (vector.size() > blob.size())
943- {
944- throw std::runtime_error("Vector size " + std::to_string(vector.size()) +
945- " is larger then array size: " +
946- std::to_string(blob.size()));
947- }
948-
949- std::copy_n(vector.begin(), vector.size(), blob.begin());
950-
951- return blob;
952- }
953-
954 template <class T>
955 T* new_event()
956 {
957@@ -70,7 +54,6 @@
958 {
959 return mir::EventUPtr(e, ([](MirEvent* e) { delete reinterpret_cast<T*>(e); }));
960 }
961-
962 }
963
964 mir::EventUPtr mev::make_event(mf::SurfaceId const& surface_id, MirOrientation orientation)
965@@ -195,7 +178,7 @@
966 e->set_device_id(device_id);
967 e->set_source_id(AINPUT_SOURCE_KEYBOARD);
968 e->set_event_time(timestamp);
969- e->set_cookie(vector_to_cookie_as_blob(cookie));
970+ e->set_cookie(cookie);
971 e->set_action(action);
972 e->set_key_code(key_code);
973 e->set_scan_code(scan_code);
974@@ -269,7 +252,7 @@
975
976 e->set_device_id(device_id);
977 e->set_event_time(timestamp);
978- e->set_cookie(vector_to_cookie_as_blob(cookie));
979+ e->set_cookie(cookie);
980 e->set_modifiers(modifiers);
981 e->set_source_id(AINPUT_SOURCE_TOUCHSCREEN);
982
983@@ -321,7 +304,7 @@
984 auto& mev = *e->to_input()->to_motion();
985 mev.set_device_id(device_id);
986 mev.set_event_time(timestamp);
987- mev.set_cookie(vector_to_cookie_as_blob(cookie));
988+ mev.set_cookie(cookie);
989 mev.set_modifiers(modifiers);
990 mev.set_source_id(AINPUT_SOURCE_MOUSE);
991 mev.set_buttons(buttons_pressed);
992@@ -390,15 +373,7 @@
993 std::string const& layout, std::string const& variant, std::string const& options)
994 {
995 auto e = new_event<MirKeymapEvent>();
996- auto ep = mir::EventUPtr(e, [](MirEvent* e) {
997- // xkbcommon creates the keymap through malloc
998- if (e && e->type() == mir_event_type_keymap)
999- {
1000- e->to_keymap()->free_buffer();
1001- }
1002-
1003- delete e;
1004- });
1005+ auto ep = make_uptr_event(e);
1006
1007 auto ctx = mi::make_unique_context();
1008 auto map = mi::make_unique_keymap(ctx.get(), mi::Keymap{model, layout, variant, options});
1009@@ -409,8 +384,9 @@
1010 e->set_surface_id(surface_id.as_value());
1011 e->set_device_id(id);
1012 // TODO consider caching compiled keymaps
1013- e->set_buffer(xkb_keymap_get_as_string(map.get(), XKB_KEYMAP_FORMAT_TEXT_V1));
1014- e->set_size(strlen(e->to_keymap()->buffer()));
1015+ auto buffer = xkb_keymap_get_as_string(map.get(), XKB_KEYMAP_FORMAT_TEXT_V1);
1016+ e->set_buffer(buffer);
1017+ std::free(buffer);
1018
1019 return ep;
1020 }
1021@@ -439,8 +415,7 @@
1022 e->set_pointer_buttons(pointer_buttons);
1023 e->set_pointer_axis(mir_pointer_axis_x, x_axis_value);
1024 e->set_pointer_axis(mir_pointer_axis_y, y_axis_value);
1025- for (auto& dev : device_states)
1026- e->add_device(dev.id, std::move(dev.pressed_keys), dev.buttons);
1027+ e->set_device_states(device_states);
1028
1029 return make_uptr_event(e);
1030 }
1031
1032=== modified file 'src/client/input/input_event.cpp'
1033--- src/client/input/input_event.cpp 2016-08-01 07:44:10 +0000
1034+++ src/client/input/input_event.cpp 2016-09-18 20:00:37 +0000
1035@@ -18,6 +18,9 @@
1036
1037 #define MIR_LOG_COMPONENT "input-event-access"
1038
1039+// TODO Remove me once we use capnproto for input platform serialization
1040+#include "mir/cookie/blob.h"
1041+
1042 #include "mir/cookie/cookie.h"
1043 #include "mir/event_type_to_string.h"
1044 #include "mir/events/event_private.h"
1045@@ -91,7 +94,7 @@
1046 }
1047 }
1048
1049-MirInputEventType mir_input_event_get_type(MirInputEvent const* ev)
1050+MirInputEventType mir_input_event_get_type(MirInputEvent const* ev) try
1051 {
1052 if (ev->type() != mir_event_type_key && ev->type() != mir_event_type_motion)
1053 {
1054@@ -108,9 +111,13 @@
1055 default:
1056 abort();
1057 }
1058+} catch (std::exception const& e)
1059+{
1060+ mir::log_critical(e.what());
1061+ abort();
1062 }
1063
1064-MirInputDeviceId mir_input_event_get_device_id(MirInputEvent const* ev)
1065+MirInputDeviceId mir_input_event_get_device_id(MirInputEvent const* ev) try
1066 {
1067 if(mir_event_get_type(ev) != mir_event_type_input)
1068 {
1069@@ -127,9 +134,13 @@
1070 default:
1071 abort();
1072 }
1073+} catch (std::exception const& e)
1074+{
1075+ mir::log_critical(e.what());
1076+ abort();
1077 }
1078
1079-int64_t mir_input_event_get_event_time(MirInputEvent const* ev)
1080+int64_t mir_input_event_get_event_time(MirInputEvent const* ev) try
1081 {
1082 if(mir_event_get_type(ev) != mir_event_type_input)
1083 {
1084@@ -146,6 +157,10 @@
1085 default:
1086 abort();
1087 }
1088+} catch (std::exception const& e)
1089+{
1090+ mir::log_critical(e.what());
1091+ abort();
1092 }
1093
1094 MirInputEvent const* mir_pointer_event_input_event(MirPointerEvent const* event)
1095@@ -177,33 +192,53 @@
1096 return reinterpret_cast<MirKeyboardEvent const*>(ev);
1097 }
1098
1099-MirKeyboardAction mir_keyboard_event_action(MirKeyboardEvent const* kev)
1100+MirKeyboardAction mir_keyboard_event_action(MirKeyboardEvent const* kev) try
1101 {
1102 return kev->action();
1103+} catch (std::exception const& e)
1104+{
1105+ mir::log_critical(e.what());
1106+ abort();
1107 }
1108
1109-xkb_keysym_t mir_keyboard_event_key_code(MirKeyboardEvent const* kev)
1110+xkb_keysym_t mir_keyboard_event_key_code(MirKeyboardEvent const* kev) try
1111 {
1112 return kev->key_code();
1113+} catch (std::exception const& e)
1114+{
1115+ mir::log_critical(e.what());
1116+ abort();
1117 }
1118
1119-int mir_keyboard_event_scan_code(MirKeyboardEvent const* kev)
1120+int mir_keyboard_event_scan_code(MirKeyboardEvent const* kev) try
1121 {
1122 return kev->scan_code();
1123+} catch (std::exception const& e)
1124+{
1125+ mir::log_critical(e.what());
1126+ abort();
1127 }
1128
1129-MirInputEventModifiers mir_keyboard_event_modifiers(MirKeyboardEvent const* kev)
1130+MirInputEventModifiers mir_keyboard_event_modifiers(MirKeyboardEvent const* kev) try
1131 {
1132 return kev->modifiers();
1133+} catch (std::exception const& e)
1134+{
1135+ mir::log_critical(e.what());
1136+ abort();
1137 }
1138 /* Touch event accessors */
1139
1140-MirInputEventModifiers mir_touch_event_modifiers(MirTouchEvent const* tev)
1141+MirInputEventModifiers mir_touch_event_modifiers(MirTouchEvent const* tev) try
1142 {
1143 return tev->to_motion()->modifiers();
1144+} catch (std::exception const& e)
1145+{
1146+ mir::log_critical(e.what());
1147+ abort();
1148 }
1149
1150-MirTouchEvent const* mir_input_event_get_touch_event(MirInputEvent const* ev)
1151+MirTouchEvent const* mir_input_event_get_touch_event(MirInputEvent const* ev) try
1152 {
1153 if(mir_input_event_get_type(ev) != mir_input_event_type_touch)
1154 {
1155@@ -213,14 +248,22 @@
1156 }
1157
1158 return reinterpret_cast<MirTouchEvent const*>(ev);
1159+} catch (std::exception const& e)
1160+{
1161+ mir::log_critical(e.what());
1162+ abort();
1163 }
1164
1165-unsigned int mir_touch_event_point_count(MirTouchEvent const* event)
1166+unsigned int mir_touch_event_point_count(MirTouchEvent const* event) try
1167 {
1168 return event->to_motion()->pointer_count();
1169+} catch (std::exception const& e)
1170+{
1171+ mir::log_critical(e.what());
1172+ abort();
1173 }
1174
1175-MirTouchId mir_touch_event_id(MirTouchEvent const* event, size_t touch_index)
1176+MirTouchId mir_touch_event_id(MirTouchEvent const* event, size_t touch_index) try
1177 {
1178 if (touch_index >= event->to_motion()->pointer_count())
1179 {
1180@@ -229,9 +272,13 @@
1181 }
1182
1183 return event->to_motion()->id(touch_index);
1184+} catch (std::exception const& e)
1185+{
1186+ mir::log_critical(e.what());
1187+ abort();
1188 }
1189
1190-MirTouchAction mir_touch_event_action(MirTouchEvent const* event, size_t touch_index)
1191+MirTouchAction mir_touch_event_action(MirTouchEvent const* event, size_t touch_index) try
1192 {
1193 if(touch_index > event->to_motion()->pointer_count())
1194 {
1195@@ -240,10 +287,14 @@
1196 }
1197
1198 return static_cast<MirTouchAction>(event->to_motion()->action(touch_index));
1199+} catch (std::exception const& e)
1200+{
1201+ mir::log_critical(e.what());
1202+ abort();
1203 }
1204
1205 MirTouchTooltype mir_touch_event_tooltype(MirTouchEvent const* event,
1206- size_t touch_index)
1207+ size_t touch_index) try
1208 {
1209 if(touch_index > event->to_motion()->pointer_count())
1210 {
1211@@ -252,10 +303,14 @@
1212 }
1213
1214 return event->to_motion()->tool_type(touch_index);
1215+} catch (std::exception const& e)
1216+{
1217+ mir::log_critical(e.what());
1218+ abort();
1219 }
1220
1221 float mir_touch_event_axis_value(MirTouchEvent const* event,
1222- size_t touch_index, MirTouchAxis axis)
1223+ size_t touch_index, MirTouchAxis axis) try
1224 {
1225 if(touch_index > event->to_motion()->pointer_count())
1226 {
1227@@ -281,11 +336,15 @@
1228 default:
1229 return -1;
1230 }
1231-}
1232+} catch (std::exception const& e)
1233+{
1234+ mir::log_critical(e.what());
1235+ abort();
1236+}
1237
1238 /* Pointer event accessors */
1239
1240-MirPointerEvent const* mir_input_event_get_pointer_event(MirInputEvent const* ev)
1241+MirPointerEvent const* mir_input_event_get_pointer_event(MirInputEvent const* ev) try
1242 {
1243 if(mir_input_event_get_type(ev) != mir_input_event_type_pointer)
1244 {
1245@@ -295,30 +354,50 @@
1246 }
1247
1248 return reinterpret_cast<MirPointerEvent const*>(ev);
1249+} catch (std::exception const& e)
1250+{
1251+ mir::log_critical(e.what());
1252+ abort();
1253 }
1254
1255-MirInputEventModifiers mir_pointer_event_modifiers(MirPointerEvent const* pev)
1256+MirInputEventModifiers mir_pointer_event_modifiers(MirPointerEvent const* pev) try
1257 {
1258 return pev->to_motion()->modifiers();
1259+} catch (std::exception const& e)
1260+{
1261+ mir::log_critical(e.what());
1262+ abort();
1263 }
1264
1265-MirPointerAction mir_pointer_event_action(MirPointerEvent const* pev)
1266+MirPointerAction mir_pointer_event_action(MirPointerEvent const* pev) try
1267 {
1268 return static_cast<MirPointerAction>(pev->to_motion()->action(0));
1269+} catch (std::exception const& e)
1270+{
1271+ mir::log_critical(e.what());
1272+ abort();
1273 }
1274
1275 bool mir_pointer_event_button_state(MirPointerEvent const* pev,
1276- MirPointerButton button)
1277+ MirPointerButton button) try
1278 {
1279 return pev->to_motion()->buttons() & button;
1280+} catch (std::exception const& e)
1281+{
1282+ mir::log_critical(e.what());
1283+ abort();
1284 }
1285
1286-MirPointerButtons mir_pointer_event_buttons(MirPointerEvent const* pev)
1287+MirPointerButtons mir_pointer_event_buttons(MirPointerEvent const* pev) try
1288 {
1289 return pev->to_motion()->buttons();
1290+} catch (std::exception const& e)
1291+{
1292+ mir::log_critical(e.what());
1293+ abort();
1294 }
1295
1296-float mir_pointer_event_axis_value(MirPointerEvent const* pev, MirPointerAxis axis)
1297+float mir_pointer_event_axis_value(MirPointerEvent const* pev, MirPointerAxis axis) try
1298 {
1299 auto mev = pev->to_motion();
1300 switch (axis)
1301@@ -339,9 +418,13 @@
1302 mir::log_critical("Invalid axis enumeration " + std::to_string(axis));
1303 abort();
1304 }
1305+} catch (std::exception const& e)
1306+{
1307+ mir::log_critical(e.what());
1308+ abort();
1309 }
1310
1311-bool mir_input_event_has_cookie(MirInputEvent const* ev)
1312+bool mir_input_event_has_cookie(MirInputEvent const* ev) try
1313 {
1314 switch (mir_input_event_get_type(ev))
1315 {
1316@@ -375,13 +458,18 @@
1317 }
1318
1319 return false;
1320+} catch (std::exception const& e)
1321+{
1322+ mir::log_critical(e.what());
1323+ abort();
1324 }
1325
1326 size_t mir_cookie_buffer_size(MirCookie const* cookie) try
1327 {
1328 return cookie->size();
1329-} catch (...)
1330+} catch (std::exception const& e)
1331 {
1332+ mir::log_critical(e.what());
1333 abort();
1334 }
1335
1336@@ -399,16 +487,18 @@
1337 abort();
1338 }
1339 }
1340-} catch (...)
1341+} catch (std::exception const& e)
1342 {
1343+ mir::log_critical(e.what());
1344 abort();
1345 }
1346
1347 void mir_cookie_to_buffer(MirCookie const* cookie, void* buffer, size_t size) try
1348 {
1349 return cookie->copy_to(buffer, size);
1350-} catch (...)
1351+} catch (std::exception const& e)
1352 {
1353+ mir::log_critical(e.what());
1354 abort();
1355 }
1356
1357@@ -418,15 +508,13 @@
1358 return NULL;
1359
1360 return new MirCookie(buffer, size);
1361-} catch (...)
1362+} catch (std::exception const& e)
1363 {
1364+ mir::log_critical(e.what());
1365 abort();
1366 }
1367
1368-void mir_cookie_release(MirCookie const* cookie) try
1369+void mir_cookie_release(MirCookie const* cookie)
1370 {
1371 delete cookie;
1372-} catch (...)
1373-{
1374- abort();
1375 }
1376
1377=== modified file 'src/client/mir_cookie.cpp'
1378--- src/client/mir_cookie.cpp 2016-01-22 20:16:50 +0000
1379+++ src/client/mir_cookie.cpp 2016-09-18 20:00:37 +0000
1380@@ -22,28 +22,29 @@
1381
1382 #include <string.h>
1383
1384-MirCookie::MirCookie(void const* buffer, size_t size)
1385+MirCookie::MirCookie(void const* buffer, size_t size) :
1386+ cookie_(size)
1387 {
1388- memcpy(blob_.data(), buffer, size);
1389+ memcpy(cookie_.data(), buffer, size);
1390 }
1391
1392-MirCookie::MirCookie(mir::cookie::Blob const& blob) :
1393- blob_(blob)
1394+MirCookie::MirCookie(std::vector<uint8_t> const& cookie) :
1395+ cookie_(cookie)
1396 {
1397 }
1398
1399 void MirCookie::copy_to(void* buffer, size_t size) const
1400 {
1401- mir::require(size == blob_.size());
1402- memcpy(buffer, blob_.data(), size);
1403+ mir::require(size == cookie_.size());
1404+ memcpy(buffer, cookie_.data(), size);
1405 }
1406
1407 size_t MirCookie::size() const
1408 {
1409- return blob_.size();
1410+ return cookie_.size();
1411 }
1412
1413-mir::cookie::Blob MirCookie::blob() const
1414+std::vector<uint8_t> MirCookie::cookie() const
1415 {
1416- return blob_;
1417+ return cookie_;
1418 }
1419
1420=== modified file 'src/client/mir_cookie.h'
1421--- src/client/mir_cookie.h 2016-01-22 20:16:50 +0000
1422+++ src/client/mir_cookie.h 2016-09-18 20:00:37 +0000
1423@@ -20,21 +20,23 @@
1424 #ifndef MIR_CLIENT_MIR_COOKIE_H_
1425 #define MIR_CLIENT_MIR_COOKIE_H_
1426
1427-#include "mir/cookie/blob.h"
1428+#include <cstdint>
1429+#include <cstdlib>
1430+#include <vector>
1431
1432 class MirCookie
1433 {
1434 public:
1435 explicit MirCookie(void const* buffer, size_t size);
1436- explicit MirCookie(mir::cookie::Blob const& blob);
1437+ explicit MirCookie(std::vector<uint8_t> const& cookie);
1438
1439 void copy_to(void* buffer, size_t size) const;
1440 size_t size() const;
1441
1442- mir::cookie::Blob blob() const;
1443+ std::vector<uint8_t> cookie() const;
1444
1445 private:
1446- mir::cookie::Blob blob_;
1447+ std::vector<uint8_t> cookie_;
1448 };
1449
1450 #endif // MIR_CLIENT_MIR_COOKIE_H_
1451
1452=== modified file 'src/client/mir_surface.cpp'
1453--- src/client/mir_surface.cpp 2016-08-31 10:46:40 +0000
1454+++ src/client/mir_surface.cpp 2016-09-18 20:00:37 +0000
1455@@ -496,7 +496,7 @@
1456
1457 auto const event_cookie = raise_request.mutable_cookie();
1458
1459- event_cookie->set_cookie(cookie->blob().data(), cookie->size());
1460+ event_cookie->set_cookie(cookie->cookie().data(), cookie->size());
1461
1462 server->raise_surface(
1463 &raise_request,
1464
1465=== modified file 'src/client/symbols.map'
1466--- src/client/symbols.map 2016-09-16 15:18:36 +0000
1467+++ src/client/symbols.map 2016-09-18 20:00:37 +0000
1468@@ -429,6 +429,7 @@
1469 mir_output_get_gamma;
1470 mir_output_set_gamma;
1471 mir_connection_cancel_base_display_configuration_preview;
1472+ mir_input_device_state_event_device_pressed_keys_for_index;
1473 mir_surface_placement_get_relative_position;
1474 mir_display_output_type_name;
1475 mir_output_type_name;
1476
1477=== modified file 'src/common/CMakeLists.txt'
1478--- src/common/CMakeLists.txt 2016-09-16 15:18:36 +0000
1479+++ src/common/CMakeLists.txt 2016-09-18 20:00:37 +0000
1480@@ -1,6 +1,5 @@
1481 add_definitions(-DMIR_LOG_COMPONENT_FALLBACK="mircommon")
1482
1483-set(MIR_GENERATED_INCLUDE_DIRECTORIES)
1484 set(MIR_COMMON_SOURCES)
1485 set(MIR_COMMON_REFERENCES)
1486
1487@@ -45,9 +44,12 @@
1488 )
1489
1490 target_link_libraries(mircommon
1491+ mircapnproto
1492 ${MIR_COMMON_REFERENCES}
1493 )
1494
1495+add_dependencies(mircommon mircapnproto)
1496+
1497 set_target_properties(mircommon
1498
1499 PROPERTIES
1500
1501=== modified file 'src/common/events/CMakeLists.txt'
1502--- src/common/events/CMakeLists.txt 2016-09-16 15:18:36 +0000
1503+++ src/common/events/CMakeLists.txt 2016-09-18 20:00:37 +0000
1504@@ -36,7 +36,10 @@
1505 ${EVENT_SOURCES}
1506 )
1507
1508+add_dependencies(mirevents mircapnproto)
1509+
1510 include_directories(
1511 ${PROJECT_SOURCE_DIR}/include/client
1512 ${PROJECT_SOURCE_DIR}/src/include/cookie
1513+ ${MIR_GENERATED_INCLUDE_DIRECTORIES}
1514 )
1515
1516=== modified file 'src/common/events/close_surface_event.cpp'
1517--- src/common/events/close_surface_event.cpp 2016-03-29 03:41:45 +0000
1518+++ src/common/events/close_surface_event.cpp 2016-09-18 20:00:37 +0000
1519@@ -18,17 +18,17 @@
1520
1521 #include "mir/events/close_surface_event.h"
1522
1523-MirCloseSurfaceEvent::MirCloseSurfaceEvent() :
1524- MirEvent(mir_event_type_close_surface)
1525+MirCloseSurfaceEvent::MirCloseSurfaceEvent()
1526 {
1527+ event.initCloseSurface();
1528 }
1529
1530 int MirCloseSurfaceEvent::surface_id() const
1531 {
1532- return surface_id_;
1533+ return event.asReader().getCloseSurface().getSurfaceId();
1534 }
1535
1536 void MirCloseSurfaceEvent::set_surface_id(int id)
1537 {
1538- surface_id_ = id;
1539+ event.getCloseSurface().setSurfaceId(id);
1540 }
1541
1542=== modified file 'src/common/events/event.cpp'
1543--- src/common/events/event.cpp 2016-09-16 15:18:36 +0000
1544+++ src/common/events/event.cpp 2016-09-18 20:00:37 +0000
1545@@ -18,8 +18,8 @@
1546
1547 #include <boost/throw_exception.hpp>
1548
1549+#include "mir/log.h"
1550 #include "mir/events/event.h"
1551-
1552 #include "mir/events/close_surface_event.h"
1553 #include "mir/events/input_configuration_event.h"
1554 #include "mir/events/input_event.h"
1555@@ -34,127 +34,91 @@
1556 #include "mir/events/input_device_state_event.h"
1557 #include "mir/events/surface_placement_event.h"
1558
1559-MirEvent::MirEvent(MirEventType type) :
1560- type_(type)
1561-{
1562-}
1563-
1564-MirEvent* MirEvent::clone() const
1565-{
1566- switch (type_)
1567- {
1568- case mir_event_type_key:
1569- return mir::event::deep_copy<MirKeyboardEvent>(this);
1570- case mir_event_type_motion:
1571- return mir::event::deep_copy<MirMotionEvent>(this);
1572- case mir_event_type_surface:
1573- return mir::event::deep_copy<MirSurfaceEvent>(this);
1574- case mir_event_type_resize:
1575- return mir::event::deep_copy<MirResizeEvent>(this);
1576- case mir_event_type_prompt_session_state_change:
1577- return mir::event::deep_copy<MirPromptSessionEvent>(this);
1578- case mir_event_type_orientation:
1579- return mir::event::deep_copy<MirOrientationEvent>(this);
1580- case mir_event_type_close_surface:
1581- return mir::event::deep_copy<MirCloseSurfaceEvent>(this);
1582- case mir_event_type_input_configuration:
1583- return mir::event::deep_copy<MirInputConfigurationEvent>(this);
1584- case mir_event_type_surface_output:
1585- return mir::event::deep_copy<MirSurfaceOutputEvent>(this);
1586- case mir_event_type_keymap:
1587- return to_keymap()->clone();
1588- case mir_event_type_input_device_state:
1589- return to_input_device_state()->clone();
1590- case mir_event_type_surface_placement:
1591- return mir::event::deep_copy<MirSurfacePlacementEvent>(this);
1592- case mir_event_type_input:
1593- break;
1594- }
1595-
1596- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to clone event"));
1597-}
1598-
1599+#include <capnp/serialize.h>
1600+
1601+#include <unordered_map>
1602+
1603+namespace ml = mir::logging;
1604+
1605+namespace
1606+{
1607+std::unordered_map<MirEvent const*, std::shared_ptr<void>> event_lifetime_storage;
1608+}
1609+
1610+void* mir::event::store_data_for_lifetime_of_event(MirEvent const* ev, std::shared_ptr<void> const& data)
1611+{
1612+ event_lifetime_storage[ev] = data;
1613+ return data.get();
1614+}
1615+
1616+MirEvent::MirEvent(MirEvent const& e)
1617+{
1618+ auto reader = e.event.asReader();
1619+ message.setRoot(reader);
1620+ event = message.getRoot<mir::capnp::Event>();
1621+}
1622+
1623+MirEvent& MirEvent::operator=(MirEvent const& e)
1624+{
1625+ auto reader = e.event.asReader();
1626+ message.setRoot(reader);
1627+ event = message.getRoot<mir::capnp::Event>();
1628+ return *this;
1629+}
1630+
1631+// TODO Look at replacing the surface event serializer with a capnproto layer
1632 mir::EventUPtr MirEvent::deserialize(std::string const& bytes)
1633 {
1634- auto minimal_event_size = sizeof(MirEventType);
1635- auto const stream_size = bytes.size();
1636- if (stream_size < minimal_event_size)
1637- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
1638-
1639- MirEventType type;
1640- mir::event::consume(bytes.data(), type);
1641-
1642- switch (type)
1643- {
1644- case mir_event_type_key:
1645- return mir::event::deserialize_from<MirKeyboardEvent>(bytes);
1646- case mir_event_type_motion:
1647- return mir::event::deserialize_from<MirMotionEvent>(bytes);
1648- case mir_event_type_surface:
1649- return mir::event::deserialize_from<MirSurfaceEvent>(bytes);
1650- case mir_event_type_resize:
1651- return mir::event::deserialize_from<MirResizeEvent>(bytes);
1652- case mir_event_type_prompt_session_state_change:
1653- return mir::event::deserialize_from<MirPromptSessionEvent>(bytes);
1654- case mir_event_type_orientation:
1655- return mir::event::deserialize_from<MirOrientationEvent>(bytes);
1656- case mir_event_type_close_surface:
1657- return mir::event::deserialize_from<MirCloseSurfaceEvent>(bytes);
1658- case mir_event_type_input_configuration:
1659- return mir::event::deserialize_from<MirInputConfigurationEvent>(bytes);
1660- case mir_event_type_surface_output:
1661- return mir::event::deserialize_from<MirSurfaceOutputEvent>(bytes);
1662- case mir_event_type_keymap:
1663- return MirKeymapEvent::deserialize(bytes);
1664- case mir_event_type_input_device_state:
1665- return MirInputDeviceStateEvent::deserialize(bytes);
1666- case mir_event_type_surface_placement:
1667- return mir::event::deserialize_from<MirSurfacePlacementEvent>(bytes);
1668- case mir_event_type_input:
1669- break;
1670- }
1671-
1672- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
1673+ auto e = mir::EventUPtr(new MirEvent, [](MirEvent* ev) { event_lifetime_storage.erase(ev); delete ev; });
1674+ kj::ArrayPtr<::capnp::word const> words(reinterpret_cast<::capnp::word const*>(
1675+ bytes.data()), bytes.size() / sizeof(::capnp::word));
1676+
1677+ initMessageBuilderFromFlatArrayCopy(words, e->message);
1678+ e->event = e->message.getRoot<mir::capnp::Event>();
1679+
1680+ return e;
1681 }
1682
1683 std::string MirEvent::serialize(MirEvent const* event)
1684 {
1685- switch (event->type())
1686- {
1687- case mir_event_type_key:
1688- return mir::event::serialize_from<MirKeyboardEvent>(event);
1689- case mir_event_type_motion:
1690- return mir::event::serialize_from<MirMotionEvent>(event);
1691- case mir_event_type_surface:
1692- return mir::event::serialize_from<MirSurfaceEvent>(event);
1693- case mir_event_type_resize:
1694- return mir::event::serialize_from<MirResizeEvent>(event);
1695- case mir_event_type_prompt_session_state_change:
1696- return mir::event::serialize_from<MirPromptSessionEvent>(event);
1697- case mir_event_type_orientation:
1698- return mir::event::serialize_from<MirOrientationEvent>(event);
1699- case mir_event_type_close_surface:
1700- return mir::event::serialize_from<MirCloseSurfaceEvent>(event);
1701- case mir_event_type_input_configuration:
1702- return mir::event::serialize_from<MirInputConfigurationEvent>(event);
1703- case mir_event_type_surface_output:
1704- return mir::event::serialize_from<MirSurfaceOutputEvent>(event);
1705- case mir_event_type_keymap:
1706- return MirKeymapEvent::serialize(event);
1707- case mir_event_type_input_device_state:
1708- return MirInputDeviceStateEvent::serialize(event);
1709- case mir_event_type_surface_placement:
1710- return mir::event::serialize_from<MirSurfacePlacementEvent>(event);
1711- case mir_event_type_input:
1712- break;
1713- }
1714+ std::string output;
1715+ auto flat_event = ::capnp::messageToFlatArray(const_cast<MirEvent*>(event)->message);
1716
1717- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to serialize event"));
1718+ return {reinterpret_cast<char*>(flat_event.asBytes().begin()), flat_event.asBytes().size()};
1719 }
1720
1721 MirEventType MirEvent::type() const
1722 {
1723- return type_;
1724+ switch (event.asReader().which())
1725+ {
1726+ case mir::capnp::Event::Which::KEY:
1727+ return mir_event_type_key;
1728+ case mir::capnp::Event::Which::MOTION_SET:
1729+ return mir_event_type_motion;
1730+ case mir::capnp::Event::Which::SURFACE:
1731+ return mir_event_type_surface;
1732+ case mir::capnp::Event::Which::RESIZE:
1733+ return mir_event_type_resize;
1734+ case mir::capnp::Event::Which::PROMPT_SESSION:
1735+ return mir_event_type_prompt_session_state_change;
1736+ case mir::capnp::Event::Which::ORIENTATION:
1737+ return mir_event_type_orientation;
1738+ case mir::capnp::Event::Which::CLOSE_SURFACE:
1739+ return mir_event_type_close_surface;
1740+ case mir::capnp::Event::Which::KEYMAP:
1741+ return mir_event_type_keymap;
1742+ case mir::capnp::Event::Which::INPUT_CONFIGURATION:
1743+ return mir_event_type_input_configuration;
1744+ case mir::capnp::Event::Which::SURFACE_OUTPUT:
1745+ return mir_event_type_surface_output;
1746+ case mir::capnp::Event::Which::INPUT_DEVICE:
1747+ return mir_event_type_input_device_state;
1748+ case mir::capnp::Event::Which::SURFACE_PLACEMENT:
1749+ return mir_event_type_surface_placement;
1750+ default:
1751+ mir::log_critical("unknown event type.");
1752+ abort();
1753+ }
1754 }
1755
1756 MirInputEvent* MirEvent::to_input()
1757
1758=== modified file 'src/common/events/input_configuration_event.cpp'
1759--- src/common/events/input_configuration_event.cpp 2016-03-29 03:41:45 +0000
1760+++ src/common/events/input_configuration_event.cpp 2016-09-18 20:00:37 +0000
1761@@ -18,37 +18,37 @@
1762
1763 #include "mir/events/input_configuration_event.h"
1764
1765-MirInputConfigurationEvent::MirInputConfigurationEvent() :
1766- MirEvent(mir_event_type_input_configuration)
1767+MirInputConfigurationEvent::MirInputConfigurationEvent()
1768 {
1769+ event.initInputConfiguration();
1770 }
1771
1772 MirInputConfigurationAction MirInputConfigurationEvent::action() const
1773 {
1774- return action_;
1775+ return static_cast<MirInputConfigurationAction>(event.asReader().getInputConfiguration().getAction());
1776 }
1777
1778 void MirInputConfigurationEvent::set_action(MirInputConfigurationAction action)
1779 {
1780- action_ = action;
1781+ event.getInputConfiguration().setAction(static_cast<mir::capnp::InputConfigurationEvent::Action>(action));
1782 }
1783
1784 std::chrono::nanoseconds MirInputConfigurationEvent::when() const
1785 {
1786- return when_;
1787+ return std::chrono::nanoseconds{event.asReader().getInputConfiguration().getWhen().getCount()};
1788 }
1789
1790 void MirInputConfigurationEvent::set_when(std::chrono::nanoseconds const& when)
1791 {
1792- when_ = when;
1793+ event.getInputConfiguration().getWhen().setCount(when.count());
1794 }
1795
1796 MirInputDeviceId MirInputConfigurationEvent::id() const
1797 {
1798- return id_;
1799+ return event.asReader().getInputConfiguration().getId().getId();
1800 }
1801
1802 void MirInputConfigurationEvent::set_id(MirInputDeviceId id)
1803 {
1804- id_ = id;
1805+ event.getInputConfiguration().getId().setId(id);
1806 }
1807
1808=== modified file 'src/common/events/input_device_state_event.cpp'
1809--- src/common/events/input_device_state_event.cpp 2016-05-26 20:59:38 +0000
1810+++ src/common/events/input_device_state_event.cpp 2016-09-18 20:00:37 +0000
1811@@ -21,18 +21,18 @@
1812 #include <boost/throw_exception.hpp>
1813
1814 MirInputDeviceStateEvent::MirInputDeviceStateEvent()
1815- : MirEvent(mir_event_type_input_device_state)
1816 {
1817+ event.initInputDevice();
1818 }
1819
1820 MirPointerButtons MirInputDeviceStateEvent::pointer_buttons() const
1821 {
1822- return pointer_buttons_;
1823+ return static_cast<MirPointerButtons>(event.asReader().getInputDevice().getButtons());
1824 }
1825
1826 void MirInputDeviceStateEvent::set_pointer_buttons(MirPointerButtons new_pointer_buttons)
1827 {
1828- pointer_buttons_ = new_pointer_buttons;
1829+ event.getInputDevice().setButtons(new_pointer_buttons);
1830 }
1831
1832 float MirInputDeviceStateEvent::pointer_axis(MirPointerAxis axis) const
1833@@ -40,9 +40,9 @@
1834 switch(axis)
1835 {
1836 case mir_pointer_axis_x:
1837- return pointer_x;
1838+ return event.asReader().getInputDevice().getPointerX();
1839 case mir_pointer_axis_y:
1840- return pointer_y;
1841+ return event.asReader().getInputDevice().getPointerY();
1842 default:
1843 return 0.0f;
1844 }
1845@@ -53,10 +53,10 @@
1846 switch(axis)
1847 {
1848 case mir_pointer_axis_x:
1849- pointer_x = value;
1850+ event.getInputDevice().setPointerX(value);
1851 break;
1852 case mir_pointer_axis_y:
1853- pointer_y = value;
1854+ event.getInputDevice().setPointerY(value);
1855 break;
1856 default:
1857 break;
1858@@ -65,159 +65,74 @@
1859
1860 std::chrono::nanoseconds MirInputDeviceStateEvent::when() const
1861 {
1862- return when_;
1863+ return std::chrono::nanoseconds{event.asReader().getInputDevice().getWhen().getCount()};
1864 }
1865
1866 void MirInputDeviceStateEvent::set_when(std::chrono::nanoseconds const& when)
1867 {
1868- when_ = when;
1869+ event.getInputDevice().getWhen().setCount(when.count());
1870 }
1871
1872 MirInputEventModifiers MirInputDeviceStateEvent::modifiers() const
1873 {
1874- return modifiers_;
1875+ return static_cast<MirInputEventModifiers>(event.asReader().getInputDevice().getModifiers());
1876 }
1877
1878 void MirInputDeviceStateEvent::set_modifiers(MirInputEventModifiers modifiers)
1879 {
1880- modifiers_ = modifiers;
1881+ event.getInputDevice().setModifiers(modifiers);
1882 }
1883
1884-void MirInputDeviceStateEvent::add_device(MirInputDeviceId id, std::vector<uint32_t> && pressed_keys, MirPointerButtons pointer_buttons)
1885+void MirInputDeviceStateEvent::set_device_states(std::vector<mir::events::InputDeviceState> const& device_states)
1886 {
1887- devices.emplace_back(id, std::move(pressed_keys), pointer_buttons);
1888+ event.getInputDevice().initDevices(device_states.size());
1889+
1890+ for (size_t i = 0; i < device_states.size(); i++)
1891+ {
1892+ auto const& state = device_states[i];
1893+ event.getInputDevice().getDevices()[i].getDeviceId().setId(state.id);
1894+ event.getInputDevice().getDevices()[i].setButtons(state.buttons);
1895+ event.getInputDevice().getDevices()[i].initPressedKeys(state.pressed_keys.size());
1896+ for (size_t j = 0; j < state.pressed_keys.size(); j++)
1897+ {
1898+ event.getInputDevice().getDevices()[i].getPressedKeys().set(j, state.pressed_keys[j]);
1899+ }
1900+ }
1901 }
1902
1903 uint32_t MirInputDeviceStateEvent::device_count() const
1904 {
1905- return devices.size();
1906+ return event.asReader().getInputDevice().getDevices().size();
1907 }
1908
1909 MirInputDeviceId MirInputDeviceStateEvent::device_id(size_t index) const
1910 {
1911- return devices[index].id;
1912-}
1913-
1914-uint32_t const* MirInputDeviceStateEvent::device_pressed_keys(size_t index) const
1915-{
1916- return devices[index].pressed_keys.data();
1917+ return event.asReader().getInputDevice().getDevices()[index].getDeviceId().getId();
1918+}
1919+
1920+std::vector<uint32_t> MirInputDeviceStateEvent::device_pressed_keys(size_t index)
1921+{
1922+ auto pressed_keys = event.asReader().getInputDevice().getDevices()[index].getPressedKeys();
1923+ std::vector<uint32_t> pressed_keys_vector;
1924+ for (auto const& pk : pressed_keys)
1925+ {
1926+ pressed_keys_vector.push_back(pk);
1927+ }
1928+
1929+ return pressed_keys_vector;
1930+}
1931+
1932+uint32_t MirInputDeviceStateEvent::device_pressed_keys_for_index(size_t index, size_t pressed_index) const
1933+{
1934+ return event.asReader().getInputDevice().getDevices()[index].getPressedKeys()[pressed_index];
1935 }
1936
1937 uint32_t MirInputDeviceStateEvent::device_pressed_keys_count(size_t index) const
1938 {
1939- return devices[index].pressed_keys.size();
1940+ return event.asReader().getInputDevice().getDevices()[index].getPressedKeys().size();
1941 }
1942
1943 MirPointerButtons MirInputDeviceStateEvent::device_pointer_buttons(size_t index) const
1944 {
1945- return devices[index].pointer_buttons;
1946-}
1947-
1948-namespace
1949-{
1950-void delete_input_device_state_event(MirEvent* to)
1951-{
1952- delete to->to_input_device_state();
1953-}
1954-template<typename Data>
1955-void encode(std::string& encoded, Data const& data)
1956-{
1957- encoded.append(reinterpret_cast<char const*>(&data), sizeof data);
1958-}
1959-}
1960-
1961-mir::EventUPtr MirInputDeviceStateEvent::deserialize(std::string const& bytes)
1962-{
1963- auto const stream_size = bytes.size();
1964-
1965- MirEventType type;
1966- std::chrono::nanoseconds when;
1967- MirInputEventModifiers modifiers;
1968- MirPointerButtons pointer_buttons;
1969- float pointer_x;
1970- float pointer_y;
1971- uint32_t count;
1972-
1973- auto minimal_event_size = sizeof type + sizeof when + sizeof modifiers + sizeof pointer_buttons + sizeof pointer_x +
1974- sizeof pointer_y + sizeof count;
1975-
1976- if (stream_size < minimal_event_size)
1977- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
1978-
1979- char const* pos = mir::event::consume(bytes.data(), type);
1980- pos = mir::event::consume(pos, when);
1981- pos = mir::event::consume(pos, modifiers);
1982- pos = mir::event::consume(pos, pointer_buttons);
1983- pos = mir::event::consume(pos, pointer_x);
1984- pos = mir::event::consume(pos, pointer_y);
1985- pos = mir::event::consume(pos, count);
1986-
1987- auto new_event = new MirInputDeviceStateEvent;
1988- new_event->set_when(when);
1989- new_event->set_modifiers(modifiers);
1990- new_event->set_pointer_buttons(pointer_buttons);
1991- new_event->set_pointer_axis(mir_pointer_axis_x, pointer_x);
1992- new_event->set_pointer_axis(mir_pointer_axis_y, pointer_y);
1993-
1994- for (size_t i = 0; i != count; ++i)
1995- {
1996- uint32_t pressed_count = 0;
1997- MirInputDeviceId id;
1998- pos = mir::event::consume(pos, id);
1999- pos = mir::event::consume(pos, pointer_buttons);
2000- pos = mir::event::consume(pos, pressed_count);
2001-
2002- std::vector<uint32_t> pressed_keys(pressed_count);
2003-
2004- for (size_t j = 0;j != pressed_count; ++j)
2005- pos = mir::event::consume(pos, pressed_keys[j]);
2006-
2007- new_event->add_device(id, std::move(pressed_keys), pointer_buttons);
2008- }
2009-
2010- return mir::EventUPtr(new_event, delete_input_device_state_event);
2011-}
2012-
2013-std::string MirInputDeviceStateEvent::serialize(MirEvent const* event)
2014-{
2015- std::string encoded;
2016- auto input_state = event->to_input_device_state();
2017- encoded.reserve(sizeof event->type() +
2018- sizeof input_state->when() +
2019- sizeof input_state->modifiers() +
2020- sizeof input_state->pointer_buttons() +
2021- sizeof input_state->pointer_axis(mir_pointer_axis_x) +
2022- sizeof input_state->pointer_axis(mir_pointer_axis_y) +
2023- sizeof input_state->device_count() +
2024- input_state->device_count() *
2025- (
2026- sizeof input_state->device_id(0) +
2027- sizeof input_state->device_pointer_buttons(0) +
2028- sizeof input_state->device_pressed_keys_count(0)
2029- )
2030- );
2031- encode(encoded, event->type());
2032- encode(encoded, input_state->when());
2033- encode(encoded, input_state->modifiers());
2034- encode(encoded, input_state->pointer_buttons());
2035- encode(encoded, input_state->pointer_axis(mir_pointer_axis_x));
2036- encode(encoded, input_state->pointer_axis(mir_pointer_axis_y));
2037- encode(encoded, input_state->device_count());
2038- for (auto const& dev : input_state->devices)
2039- {
2040- encode(encoded, dev.id);
2041- encode(encoded, dev.pointer_buttons);
2042- encode(encoded, uint32_t(dev.pressed_keys.size()));
2043- for (auto const& key : dev.pressed_keys)
2044- encode(encoded, key);
2045- }
2046-
2047- return encoded;
2048-
2049-}
2050-
2051-MirEvent* MirInputDeviceStateEvent::clone() const
2052-{
2053- auto new_ev = new MirInputDeviceStateEvent(*this);
2054- return new_ev;
2055+ return event.asReader().getInputDevice().getDevices()[index].getButtons();
2056 }
2057
2058=== modified file 'src/common/events/input_event.cpp'
2059--- src/common/events/input_event.cpp 2016-03-29 03:41:45 +0000
2060+++ src/common/events/input_event.cpp 2016-09-18 20:00:37 +0000
2061@@ -21,11 +21,6 @@
2062 #include "mir/events/keyboard_event.h"
2063 #include "mir/events/motion_event.h"
2064
2065-MirInputEvent::MirInputEvent(MirEventType type) :
2066- MirEvent(type)
2067-{
2068-}
2069-
2070 MirKeyboardEvent* MirInputEvent::to_keyboard()
2071 {
2072 return static_cast<MirKeyboardEvent*>(this);
2073
2074=== modified file 'src/common/events/keyboard_event.cpp'
2075--- src/common/events/keyboard_event.cpp 2016-03-29 03:41:45 +0000
2076+++ src/common/events/keyboard_event.cpp 2016-09-18 20:00:37 +0000
2077@@ -19,87 +19,92 @@
2078 #include "mir/events/input_event.h"
2079 #include "mir/events/keyboard_event.h"
2080
2081-MirKeyboardEvent::MirKeyboardEvent() :
2082- MirInputEvent(mir_event_type_key)
2083+MirKeyboardEvent::MirKeyboardEvent()
2084 {
2085+ event.initKey();
2086 }
2087
2088 int32_t MirKeyboardEvent::device_id() const
2089 {
2090- return device_id_;
2091+ return event.asReader().getKey().getDeviceId().getId();
2092 }
2093
2094 void MirKeyboardEvent::set_device_id(int32_t id)
2095 {
2096- device_id_ = id;
2097+ event.getKey().getDeviceId().setId(id);
2098 }
2099
2100 int32_t MirKeyboardEvent::source_id() const
2101 {
2102- return source_id_;
2103+ return event.asReader().getKey().getSourceId();
2104 }
2105
2106 void MirKeyboardEvent::set_source_id(int32_t id)
2107 {
2108- source_id_ = id;
2109+ event.getKey().setSourceId(id);
2110 }
2111
2112 MirKeyboardAction MirKeyboardEvent::action() const
2113 {
2114- return action_;
2115+ return static_cast<MirKeyboardAction>(event.asReader().getKey().getAction());
2116 }
2117
2118 void MirKeyboardEvent::set_action(MirKeyboardAction action)
2119 {
2120- action_ = action;
2121+ event.getKey().setAction(static_cast<mir::capnp::KeyboardEvent::Action>(action));
2122 }
2123
2124 MirInputEventModifiers MirKeyboardEvent::modifiers() const
2125 {
2126- return modifiers_;
2127+ return event.asReader().getKey().getModifiers();
2128 }
2129
2130 void MirKeyboardEvent::set_modifiers(MirInputEventModifiers modifiers)
2131 {
2132- modifiers_ = modifiers;
2133+ event.getKey().setModifiers(modifiers);
2134 }
2135
2136 int32_t MirKeyboardEvent::key_code() const
2137 {
2138- return key_code_;
2139+ return event.asReader().getKey().getKeyCode();
2140 }
2141
2142 void MirKeyboardEvent::set_key_code(int32_t key_code)
2143 {
2144- key_code_ = key_code;
2145+ event.getKey().setKeyCode(key_code);
2146 }
2147
2148 int32_t MirKeyboardEvent::scan_code() const
2149 {
2150- return scan_code_;
2151+ return event.asReader().getKey().getScanCode();
2152 }
2153
2154 void MirKeyboardEvent::set_scan_code(int32_t scan_code)
2155 {
2156- scan_code_ = scan_code;
2157+ event.getKey().setScanCode(scan_code);
2158 }
2159
2160 std::chrono::nanoseconds MirKeyboardEvent::event_time() const
2161 {
2162- return event_time_;
2163+ return std::chrono::nanoseconds{event.asReader().getKey().getEventTime().getCount()};
2164 }
2165
2166 void MirKeyboardEvent::set_event_time(std::chrono::nanoseconds const& event_time)
2167 {
2168- event_time_ = event_time;
2169-}
2170-
2171-mir::cookie::Blob MirKeyboardEvent::cookie() const
2172-{
2173- return cookie_;
2174-}
2175-
2176-void MirKeyboardEvent::set_cookie(mir::cookie::Blob const& cookie)
2177-{
2178- cookie_ = cookie;
2179+ event.getKey().getEventTime().setCount(event_time.count());
2180+}
2181+
2182+std::vector<uint8_t> MirKeyboardEvent::cookie() const
2183+{
2184+ auto cookie = event.asReader().getKey().getCookie();
2185+ std::vector<uint8_t> vec_cookie(cookie.size());
2186+ std::copy(std::begin(cookie), std::end(cookie), std::begin(vec_cookie));
2187+
2188+ return vec_cookie;
2189+}
2190+
2191+void MirKeyboardEvent::set_cookie(std::vector<uint8_t> const& cookie)
2192+{
2193+ ::capnp::Data::Reader cookie_data(cookie.data(), cookie.size());
2194+ event.getKey().setCookie(cookie_data);
2195 }
2196
2197=== modified file 'src/common/events/keymap_event.cpp'
2198--- src/common/events/keymap_event.cpp 2016-03-29 03:41:45 +0000
2199+++ src/common/events/keymap_event.cpp 2016-09-18 20:00:37 +0000
2200@@ -20,145 +20,43 @@
2201
2202 #include "mir/events/keymap_event.h"
2203
2204-namespace
2205-{
2206-void delete_keymap_event(MirEvent* e)
2207-{
2208- if (e && e->to_keymap()->buffer())
2209- {
2210- e->to_keymap()->free_buffer();
2211- }
2212-
2213- delete e;
2214-}
2215-
2216-template<typename Data>
2217-void encode(std::string& encoded, Data const& data)
2218-{
2219- encoded.append(reinterpret_cast<char const*>(&data), sizeof data);
2220-}
2221-}
2222-
2223-MirKeymapEvent::MirKeymapEvent() :
2224- MirEvent(mir_event_type_keymap)
2225-{
2226-}
2227-
2228-MirEvent* MirKeymapEvent::clone() const
2229-{
2230- auto new_ev = mir::event::deep_copy<MirKeymapEvent>(this);
2231- auto keymap = new_ev->to_keymap();
2232-
2233- // malloc to match xkbcommons allocation behavior
2234- auto buffer = static_cast<char*>(malloc(keymap->size()));
2235- std::memcpy(buffer, keymap->buffer(), keymap->size());
2236- keymap->set_buffer(buffer);
2237-
2238- return new_ev;
2239-}
2240-
2241-// Edge case where we have handle the char* buffer manually!
2242-mir::EventUPtr MirKeymapEvent::deserialize(std::string const& bytes)
2243-{
2244- MirInputDeviceId device_id;
2245- int surface_id;
2246- size_t size;
2247-
2248- auto minimal_event_size = sizeof(MirEventType);
2249- auto const stream_size = bytes.size();
2250- if (stream_size < minimal_event_size)
2251- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
2252-
2253- MirEventType type;
2254- char const* pos = mir::event::consume(bytes.data(), type);
2255-
2256- minimal_event_size += sizeof(surface_id) + sizeof(device_id) + sizeof(size);
2257-
2258- if (stream_size < minimal_event_size)
2259- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
2260-
2261- pos = mir::event::consume(pos, surface_id);
2262- pos = mir::event::consume(pos, device_id);
2263- pos = mir::event::consume(pos, size);
2264-
2265- minimal_event_size += size;
2266-
2267- if (stream_size < minimal_event_size)
2268- BOOST_THROW_EXCEPTION(std::runtime_error("Failed to deserialize event"));
2269-
2270- auto buffer = static_cast<char*>(std::malloc(size));
2271- std::memcpy(buffer, pos, size);
2272-
2273- auto new_event = new MirKeymapEvent;
2274- new_event->set_surface_id(surface_id);
2275- new_event->set_device_id(device_id);
2276- new_event->set_size(size);
2277- new_event->set_buffer(buffer);
2278-
2279- return mir::EventUPtr(new_event, delete_keymap_event);
2280-}
2281-
2282-
2283-// Edge case where we have handle the char* buffer manually!
2284-std::string MirKeymapEvent::serialize(MirEvent const* event)
2285-{
2286- std::string encoded;
2287- auto keymap = event->to_keymap();
2288- encoded.reserve(sizeof event->type() +
2289- sizeof keymap->surface_id() +
2290- sizeof keymap->device_id() +
2291- sizeof keymap->size() +
2292- keymap->size());
2293- encode(encoded, event->type());
2294- encode(encoded, keymap->surface_id());
2295- encode(encoded, keymap->device_id());
2296- encode(encoded, keymap->size());
2297- encoded.append(keymap->buffer(), keymap->size());
2298-
2299- return encoded;
2300+MirKeymapEvent::MirKeymapEvent()
2301+{
2302+ event.initKeymap();
2303 }
2304
2305 int MirKeymapEvent::surface_id() const
2306 {
2307- return surface_id_;
2308+ return event.asReader().getKeymap().getSurfaceId();
2309 }
2310
2311 void MirKeymapEvent::set_surface_id(int id)
2312 {
2313- surface_id_ = id;
2314+ event.getKeymap().setSurfaceId(id);
2315 }
2316
2317 MirInputDeviceId MirKeymapEvent::device_id() const
2318 {
2319- return device_id_;
2320+ return event.asReader().getKeymap().getDeviceId().getId();
2321 }
2322
2323 void MirKeymapEvent::set_device_id(MirInputDeviceId id)
2324 {
2325- device_id_ = id;
2326+ event.getKeymap().getDeviceId().setId(id);
2327 }
2328
2329 char const* MirKeymapEvent::buffer() const
2330 {
2331- return buffer_;
2332+ return event.asReader().getKeymap().getBuffer().cStr();
2333 }
2334
2335 void MirKeymapEvent::set_buffer(char const* buffer)
2336 {
2337- buffer_ = buffer;
2338-}
2339-
2340-void MirKeymapEvent::free_buffer()
2341-{
2342- std::free(const_cast<char*>(buffer_));
2343+ ::capnp::Text::Reader capnp_text(buffer, strlen(buffer));
2344+ event.getKeymap().setBuffer(capnp_text);
2345 }
2346
2347 size_t MirKeymapEvent::size() const
2348 {
2349- return size_;
2350-}
2351-
2352-void MirKeymapEvent::set_size(size_t size)
2353-{
2354- size_ = size;
2355+ return event.asReader().getKeymap().getBuffer().size();
2356 }
2357
2358=== modified file 'src/common/events/motion_event.cpp'
2359--- src/common/events/motion_event.cpp 2016-03-30 05:27:27 +0000
2360+++ src/common/events/motion_event.cpp 2016-09-18 20:00:37 +0000
2361@@ -20,303 +20,288 @@
2362
2363 #include "mir/events/motion_event.h"
2364
2365-MirMotionEvent::MirMotionEvent() :
2366- MirInputEvent(mir_event_type_motion)
2367+MirMotionEvent::MirMotionEvent()
2368 {
2369+ event.initMotionSet();
2370+ event.getMotionSet().initMotions(mir::capnp::MotionSetEvent::MAX_COUNT);
2371 }
2372
2373 int32_t MirMotionEvent::device_id() const
2374 {
2375- return device_id_;
2376+ return event.asReader().getMotionSet().getDeviceId().getId();
2377 }
2378
2379 void MirMotionEvent::set_device_id(int32_t id)
2380 {
2381- device_id_ = id;
2382+ event.getMotionSet().getDeviceId().setId(id);
2383 }
2384
2385 int32_t MirMotionEvent::source_id() const
2386 {
2387- return source_id_;
2388+ return event.asReader().getMotionSet().getSourceId();
2389 }
2390
2391 void MirMotionEvent::set_source_id(int32_t id)
2392 {
2393- source_id_ = id;
2394+ event.getMotionSet().setSourceId(id);
2395 }
2396
2397 MirInputEventModifiers MirMotionEvent::modifiers() const
2398 {
2399- return modifiers_;
2400+ return event.asReader().getMotionSet().getModifiers();
2401 }
2402
2403 void MirMotionEvent::set_modifiers(MirInputEventModifiers modifiers)
2404 {
2405- modifiers_ = modifiers;
2406+ event.getMotionSet().setModifiers(modifiers);
2407 }
2408
2409 MirPointerButtons MirMotionEvent::buttons() const
2410 {
2411- return buttons_;
2412+ return event.asReader().getMotionSet().getButtons();
2413 }
2414
2415 void MirMotionEvent::set_buttons(MirPointerButtons buttons)
2416 {
2417- buttons_ = buttons;
2418+ event.getMotionSet().setButtons(buttons);
2419 }
2420
2421 std::chrono::nanoseconds MirMotionEvent::event_time() const
2422 {
2423- return event_time_;
2424+ return std::chrono::nanoseconds{event.asReader().getMotionSet().getEventTime().getCount()};
2425 }
2426
2427 void MirMotionEvent::set_event_time(std::chrono::nanoseconds const& event_time)
2428 {
2429- event_time_ = event_time;
2430-}
2431-
2432-mir::cookie::Blob MirMotionEvent::cookie() const
2433-{
2434- return cookie_;
2435-}
2436-
2437-void MirMotionEvent::set_cookie(mir::cookie::Blob const& blob)
2438-{
2439- cookie_ = blob;
2440+ event.getMotionSet().getEventTime().setCount(event_time.count());
2441+}
2442+
2443+std::vector<uint8_t> MirMotionEvent::cookie() const
2444+{
2445+ auto cookie = event.asReader().getMotionSet().getCookie();
2446+ std::vector<uint8_t> vec_cookie(cookie.size());
2447+ std::copy(std::begin(cookie), std::end(cookie), std::begin(vec_cookie));
2448+
2449+ return vec_cookie;
2450+}
2451+
2452+void MirMotionEvent::set_cookie(std::vector<uint8_t> const& cookie)
2453+{
2454+ ::capnp::Data::Reader cookie_data(cookie.data(), cookie.size());
2455+ event.getMotionSet().setCookie(cookie_data);
2456 }
2457
2458 size_t MirMotionEvent::pointer_count() const
2459 {
2460- return pointer_count_;
2461+ return event.asReader().getMotionSet().getCount();
2462 }
2463
2464 void MirMotionEvent::set_pointer_count(size_t count)
2465 {
2466- pointer_count_ = count;
2467+ return event.getMotionSet().setCount(count);
2468+}
2469+
2470+void MirMotionEvent::throw_if_out_of_bounds(size_t index) const
2471+{
2472+ if (index > event.asReader().getMotionSet().getCount())
2473+ BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2474 }
2475
2476 int MirMotionEvent::id(size_t index) const
2477 {
2478- if (index > pointer_count_)
2479- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2480+ throw_if_out_of_bounds(index);
2481
2482- return pointer_coordinates_[index].id;
2483+ return event.asReader().getMotionSet().getMotions()[index].getId();
2484 }
2485
2486 void MirMotionEvent::set_id(size_t index, int id)
2487 {
2488- if (index > pointer_count_)
2489- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2490+ throw_if_out_of_bounds(index);
2491
2492- pointer_coordinates_[index].id = id;
2493+ event.getMotionSet().getMotions()[index].setId(id);
2494 }
2495
2496 float MirMotionEvent::x(size_t index) const
2497 {
2498- if (index > pointer_count_)
2499- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2500+ throw_if_out_of_bounds(index);
2501
2502- return pointer_coordinates_[index].x;
2503+ return event.asReader().getMotionSet().getMotions()[index].getX();
2504 }
2505
2506 void MirMotionEvent::set_x(size_t index, float x)
2507 {
2508- if (index > pointer_count_)
2509- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2510+ throw_if_out_of_bounds(index);
2511
2512- pointer_coordinates_[index].x = x;
2513+ event.getMotionSet().getMotions()[index].setX(x);
2514 }
2515
2516 float MirMotionEvent::y(size_t index) const
2517 {
2518- if (index > pointer_count_)
2519- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2520+ throw_if_out_of_bounds(index);
2521
2522- return pointer_coordinates_[index].y;
2523+ return event.asReader().getMotionSet().getMotions()[index].getY();
2524 }
2525
2526 void MirMotionEvent::set_y(size_t index, float y)
2527 {
2528- if (index > pointer_count_)
2529- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2530+ throw_if_out_of_bounds(index);
2531
2532- pointer_coordinates_[index].y = y;
2533+ event.getMotionSet().getMotions()[index].setY(y);
2534 }
2535
2536 float MirMotionEvent::dx(size_t index) const
2537 {
2538- if (index > pointer_count_)
2539- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2540+ throw_if_out_of_bounds(index);
2541
2542- return pointer_coordinates_[index].dx;
2543+ return event.asReader().getMotionSet().getMotions()[index].getDx();
2544 }
2545
2546 void MirMotionEvent::set_dx(size_t index, float dx)
2547 {
2548- if (index > pointer_count_)
2549- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2550+ throw_if_out_of_bounds(index);
2551
2552- pointer_coordinates_[index].dx = dx;
2553+ event.getMotionSet().getMotions()[index].setDx(dx);
2554 }
2555
2556 float MirMotionEvent::dy(size_t index) const
2557 {
2558- if (index > pointer_count_)
2559- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2560+ throw_if_out_of_bounds(index);
2561
2562- return pointer_coordinates_[index].dy;
2563+ return event.asReader().getMotionSet().getMotions()[index].getDy();
2564 }
2565
2566 void MirMotionEvent::set_dy(size_t index, float dy)
2567 {
2568- if (index > pointer_count_)
2569- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2570+ throw_if_out_of_bounds(index);
2571
2572- pointer_coordinates_[index].dy = dy;
2573+ event.getMotionSet().getMotions()[index].setDy(dy);
2574 }
2575
2576 float MirMotionEvent::touch_major(size_t index) const
2577 {
2578- if (index > pointer_count_)
2579- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2580+ throw_if_out_of_bounds(index);
2581
2582- return pointer_coordinates_[index].touch_major;
2583+ return event.asReader().getMotionSet().getMotions()[index].getTouchMajor();
2584 }
2585
2586 void MirMotionEvent::set_touch_major(size_t index, float major)
2587 {
2588- if (index > pointer_count_)
2589- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2590+ throw_if_out_of_bounds(index);
2591
2592- pointer_coordinates_[index].touch_major = major;
2593+ event.getMotionSet().getMotions()[index].setTouchMajor(major);
2594 }
2595
2596 float MirMotionEvent::touch_minor(size_t index) const
2597 {
2598- if (index > pointer_count_)
2599- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2600+ throw_if_out_of_bounds(index);
2601
2602- return pointer_coordinates_[index].touch_minor;
2603+ return event.asReader().getMotionSet().getMotions()[index].getTouchMinor();
2604 }
2605
2606 void MirMotionEvent::set_touch_minor(size_t index, float minor)
2607 {
2608- if (index > pointer_count_)
2609- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2610+ throw_if_out_of_bounds(index);
2611
2612- pointer_coordinates_[index].touch_minor = minor;
2613+ event.getMotionSet().getMotions()[index].setTouchMinor(minor);
2614 }
2615
2616 float MirMotionEvent::size(size_t index) const
2617 {
2618- if (index > pointer_count_)
2619- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2620+ throw_if_out_of_bounds(index);
2621
2622- return pointer_coordinates_[index].size;
2623+ return event.asReader().getMotionSet().getMotions()[index].getSize();
2624 }
2625
2626 void MirMotionEvent::set_size(size_t index, float size)
2627 {
2628- if (index > pointer_count_)
2629- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2630+ throw_if_out_of_bounds(index);
2631
2632- pointer_coordinates_[index].size = size;
2633+ event.getMotionSet().getMotions()[index].setSize(size);
2634 }
2635
2636 float MirMotionEvent::pressure(size_t index) const
2637 {
2638- if (index > pointer_count_)
2639- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2640+ throw_if_out_of_bounds(index);
2641
2642- return pointer_coordinates_[index].pressure;
2643+ return event.asReader().getMotionSet().getMotions()[index].getPressure();
2644 }
2645
2646 void MirMotionEvent::set_pressure(size_t index, float pressure)
2647 {
2648- if (index > pointer_count_)
2649- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2650+ throw_if_out_of_bounds(index);
2651
2652- pointer_coordinates_[index].pressure = pressure;
2653+ event.getMotionSet().getMotions()[index].setPressure(pressure);
2654 }
2655
2656 float MirMotionEvent::orientation(size_t index) const
2657 {
2658- if (index > pointer_count_)
2659- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2660+ throw_if_out_of_bounds(index);
2661
2662- return pointer_coordinates_[index].orientation;
2663+ return event.asReader().getMotionSet().getMotions()[index].getOrientation();
2664 }
2665
2666 void MirMotionEvent::set_orientation(size_t index, float orientation)
2667 {
2668- if (index > pointer_count_)
2669- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2670+ throw_if_out_of_bounds(index);
2671
2672- pointer_coordinates_[index].orientation = orientation;
2673+ event.getMotionSet().getMotions()[index].setOrientation(orientation);
2674 }
2675
2676 float MirMotionEvent::vscroll(size_t index) const
2677 {
2678- if (index > pointer_count_)
2679- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2680+ throw_if_out_of_bounds(index);
2681
2682- return pointer_coordinates_[index].vscroll;
2683+ return event.asReader().getMotionSet().getMotions()[index].getVscroll();
2684 }
2685
2686 void MirMotionEvent::set_vscroll(size_t index, float vscroll)
2687 {
2688- if (index > pointer_count_)
2689- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2690+ throw_if_out_of_bounds(index);
2691
2692- pointer_coordinates_[index].vscroll = vscroll;
2693+ event.getMotionSet().getMotions()[index].setVscroll(vscroll);
2694 }
2695
2696 float MirMotionEvent::hscroll(size_t index) const
2697 {
2698- if (index > pointer_count_)
2699- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2700+ throw_if_out_of_bounds(index);
2701
2702- return pointer_coordinates_[index].hscroll;
2703+ return event.asReader().getMotionSet().getMotions()[index].getHscroll();
2704 }
2705
2706 void MirMotionEvent::set_hscroll(size_t index, float hscroll)
2707 {
2708- if (index > pointer_count_)
2709- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2710+ throw_if_out_of_bounds(index);
2711
2712- pointer_coordinates_[index].hscroll = hscroll;
2713+ event.getMotionSet().getMotions()[index].setHscroll(hscroll);
2714 }
2715
2716 MirTouchTooltype MirMotionEvent::tool_type(size_t index) const
2717 {
2718- if (index > pointer_count_)
2719- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2720+ throw_if_out_of_bounds(index);
2721
2722- return pointer_coordinates_[index].tool_type;
2723+ return static_cast<MirTouchTooltype>(event.asReader().getMotionSet().getMotions()[index].getToolType());
2724 }
2725
2726 void MirMotionEvent::set_tool_type(size_t index, MirTouchTooltype tool_type)
2727 {
2728- if (index > pointer_count_)
2729- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2730+ throw_if_out_of_bounds(index);
2731
2732- pointer_coordinates_[index].tool_type = tool_type;
2733+ auto capnp_tool_type = static_cast<mir::capnp::MotionSetEvent::Motion::ToolType>(tool_type);
2734+ event.getMotionSet().getMotions()[index].setToolType(capnp_tool_type);
2735 }
2736
2737 int MirMotionEvent::action(size_t index) const
2738 {
2739- if (index > pointer_count_)
2740- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2741+ throw_if_out_of_bounds(index);
2742
2743- return pointer_coordinates_[index].action;
2744+ return event.asReader().getMotionSet().getMotions()[index].getAction();
2745 }
2746
2747 void MirMotionEvent::set_action(size_t index, int action)
2748 {
2749- if (index > pointer_count_)
2750- BOOST_THROW_EXCEPTION(std::out_of_range("Out of bounds index in pointer coordinates"));
2751+ throw_if_out_of_bounds(index);
2752
2753- pointer_coordinates_[index].action = action;
2754+ event.getMotionSet().getMotions()[index].setAction(action);
2755 }
2756
2757 MirTouchEvent* MirMotionEvent::to_touch()
2758
2759=== modified file 'src/common/events/orientation_event.cpp'
2760--- src/common/events/orientation_event.cpp 2016-03-29 03:41:45 +0000
2761+++ src/common/events/orientation_event.cpp 2016-09-18 20:00:37 +0000
2762@@ -18,27 +18,27 @@
2763
2764 #include "mir/events/orientation_event.h"
2765
2766-MirOrientationEvent::MirOrientationEvent() :
2767- MirEvent(mir_event_type_orientation)
2768+MirOrientationEvent::MirOrientationEvent()
2769 {
2770+ event.initOrientation();
2771 }
2772
2773 int MirOrientationEvent::surface_id() const
2774 {
2775- return surface_id_;
2776+ return event.asReader().getOrientation().getSurfaceId();
2777 }
2778
2779 void MirOrientationEvent::set_surface_id(int id)
2780 {
2781- surface_id_ = id;
2782+ event.getOrientation().setSurfaceId(id);
2783 }
2784
2785 MirOrientation MirOrientationEvent::direction() const
2786 {
2787- return direction_;
2788+ return static_cast<MirOrientation>(event.asReader().getOrientation().getDirection());
2789 }
2790
2791 void MirOrientationEvent::set_direction(MirOrientation orientation)
2792 {
2793- direction_ = orientation;
2794+ event.getOrientation().setDirection(orientation);
2795 }
2796
2797=== modified file 'src/common/events/prompt_session_event.cpp'
2798--- src/common/events/prompt_session_event.cpp 2016-03-29 03:41:45 +0000
2799+++ src/common/events/prompt_session_event.cpp 2016-09-18 20:00:37 +0000
2800@@ -18,17 +18,17 @@
2801
2802 #include "mir/events/prompt_session_event.h"
2803
2804-MirPromptSessionEvent::MirPromptSessionEvent() :
2805- MirEvent(mir_event_type_prompt_session_state_change)
2806+MirPromptSessionEvent::MirPromptSessionEvent()
2807 {
2808+ event.initPromptSession();
2809 }
2810
2811 MirPromptSessionState MirPromptSessionEvent::new_state() const
2812 {
2813- return new_state_;
2814+ return static_cast<MirPromptSessionState>(event.asReader().getPromptSession().getNewState());
2815 }
2816
2817 void MirPromptSessionEvent::set_new_state(MirPromptSessionState state)
2818 {
2819- new_state_ = state;
2820+ event.getPromptSession().setNewState(static_cast<mir::capnp::PromptSessionEvent::State>(state));
2821 }
2822
2823=== modified file 'src/common/events/resize_event.cpp'
2824--- src/common/events/resize_event.cpp 2016-03-29 03:41:45 +0000
2825+++ src/common/events/resize_event.cpp 2016-09-18 20:00:37 +0000
2826@@ -18,37 +18,37 @@
2827
2828 #include "mir/events/resize_event.h"
2829
2830-MirResizeEvent::MirResizeEvent() :
2831- MirEvent(mir_event_type_resize)
2832+MirResizeEvent::MirResizeEvent()
2833 {
2834+ event.initResize();
2835 }
2836
2837 int MirResizeEvent::surface_id() const
2838 {
2839- return surface_id_;
2840+ return event.asReader().getResize().getSurfaceId();
2841 }
2842
2843 void MirResizeEvent::set_surface_id(int id)
2844 {
2845- surface_id_ = id;
2846+ event.getResize().setSurfaceId(id);
2847 }
2848
2849 int MirResizeEvent::width() const
2850 {
2851- return width_;
2852+ return event.asReader().getResize().getWidth();
2853 }
2854
2855 void MirResizeEvent::set_width(int width)
2856 {
2857- width_ = width;
2858+ event.getResize().setWidth(width);
2859 }
2860
2861 int MirResizeEvent::height() const
2862 {
2863- return height_;
2864+ return event.asReader().getResize().getHeight();
2865 }
2866
2867 void MirResizeEvent::set_height(int height)
2868 {
2869- height_ = height;
2870+ event.getResize().setHeight(height);
2871 }
2872
2873=== modified file 'src/common/events/surface_event.cpp'
2874--- src/common/events/surface_event.cpp 2016-03-29 03:41:45 +0000
2875+++ src/common/events/surface_event.cpp 2016-09-18 20:00:37 +0000
2876@@ -18,37 +18,37 @@
2877
2878 #include "mir/events/surface_event.h"
2879
2880-MirSurfaceEvent::MirSurfaceEvent() :
2881- MirEvent(mir_event_type_surface)
2882+MirSurfaceEvent::MirSurfaceEvent()
2883 {
2884+ event.initSurface();
2885 }
2886
2887 int MirSurfaceEvent::id() const
2888 {
2889- return id_;
2890+ return event.asReader().getSurface().getId();
2891 }
2892
2893 void MirSurfaceEvent::set_id(int id)
2894 {
2895- id_ = id;
2896+ event.getSurface().setId(id);
2897 }
2898
2899 MirSurfaceAttrib MirSurfaceEvent::attrib() const
2900 {
2901- return attrib_;
2902+ return static_cast<MirSurfaceAttrib>(event.asReader().getSurface().getAttrib());
2903 }
2904
2905 void MirSurfaceEvent::set_attrib(MirSurfaceAttrib attrib)
2906 {
2907- attrib_ = attrib;
2908+ event.getSurface().setAttrib(static_cast<mir::capnp::SurfaceEvent::Attrib>(attrib));
2909 }
2910
2911 int MirSurfaceEvent::value() const
2912 {
2913- return value_;
2914+ return event.asReader().getSurface().getValue();
2915 }
2916
2917 void MirSurfaceEvent::set_value(int value)
2918 {
2919- value_ = value;
2920+ event.getSurface().setValue(value);
2921 }
2922
2923=== modified file 'src/common/events/surface_output_event.cpp'
2924--- src/common/events/surface_output_event.cpp 2016-03-29 03:41:45 +0000
2925+++ src/common/events/surface_output_event.cpp 2016-09-18 20:00:37 +0000
2926@@ -18,57 +18,57 @@
2927
2928 #include "mir/events/surface_output_event.h"
2929
2930-MirSurfaceOutputEvent::MirSurfaceOutputEvent() :
2931- MirEvent(mir_event_type_surface_output)
2932+MirSurfaceOutputEvent::MirSurfaceOutputEvent()
2933 {
2934+ event.initSurfaceOutput();
2935 }
2936
2937 int MirSurfaceOutputEvent::surface_id() const
2938 {
2939- return surface_id_;
2940+ return event.asReader().getSurfaceOutput().getSurfaceId();
2941 }
2942
2943 void MirSurfaceOutputEvent::set_surface_id(int id)
2944 {
2945- surface_id_ = id;
2946+ event.getSurfaceOutput().setSurfaceId(id);
2947 }
2948
2949 int MirSurfaceOutputEvent::dpi() const
2950 {
2951- return dpi_;
2952+ return event.asReader().getSurfaceOutput().getDpi();
2953 }
2954
2955 void MirSurfaceOutputEvent::set_dpi(int dpi)
2956 {
2957- dpi_ = dpi;
2958+ event.getSurfaceOutput().setDpi(dpi);
2959 }
2960
2961 float MirSurfaceOutputEvent::scale() const
2962 {
2963- return scale_;
2964+ return event.asReader().getSurfaceOutput().getScale();
2965 }
2966
2967 void MirSurfaceOutputEvent::set_scale(float scale)
2968 {
2969- scale_ = scale;
2970+ event.getSurfaceOutput().setScale(scale);
2971 }
2972
2973 MirFormFactor MirSurfaceOutputEvent::form_factor() const
2974 {
2975- return form_factor_;
2976+ return static_cast<MirFormFactor>(event.asReader().getSurfaceOutput().getFormFactor());
2977 }
2978
2979 void MirSurfaceOutputEvent::set_form_factor(MirFormFactor factor)
2980 {
2981- form_factor_ = factor;
2982+ event.getSurfaceOutput().setFormFactor(static_cast<mir::capnp::SurfaceOutputEvent::FormFactor>(factor));
2983 }
2984
2985 uint32_t MirSurfaceOutputEvent::output_id() const
2986 {
2987- return output_id_;
2988+ return event.asReader().getSurfaceOutput().getOutputId();
2989 }
2990
2991 void MirSurfaceOutputEvent::set_output_id(uint32_t id)
2992 {
2993- output_id_ = id;
2994+ event.getSurfaceOutput().setOutputId(id);
2995 }
2996
2997=== modified file 'src/common/events/surface_placement_event.cpp'
2998--- src/common/events/surface_placement_event.cpp 2016-09-12 14:18:39 +0000
2999+++ src/common/events/surface_placement_event.cpp 2016-09-18 20:00:37 +0000
3000@@ -18,29 +18,34 @@
3001
3002 #include "mir/events/surface_placement_event.h"
3003
3004-MirSurfacePlacementEvent::MirSurfacePlacementEvent() :
3005- MirEvent(mir_event_type_surface_placement)
3006+MirSurfacePlacementEvent::MirSurfacePlacementEvent()
3007 {
3008+ event.initSurfacePlacement();
3009 }
3010
3011 int MirSurfacePlacementEvent::id() const
3012 {
3013- return id_;
3014+ return event.asReader().getSurfacePlacement().getId();
3015 }
3016
3017 void MirSurfacePlacementEvent::set_id(int const id)
3018 {
3019- id_ = id;
3020+ event.getSurfacePlacement().setId(id);
3021 }
3022
3023 MirRectangle MirSurfacePlacementEvent::placement() const
3024 {
3025- return placement_;
3026+ auto rect = event.asReader().getSurfacePlacement().getRectangle();
3027+ return {rect.getLeft(), rect.getTop(), rect.getWidth(), rect.getHeight()};
3028 }
3029
3030 void MirSurfacePlacementEvent::set_placement(MirRectangle const& placement)
3031 {
3032- placement_ = placement;
3033+ auto rect = event.getSurfacePlacement().getRectangle();
3034+ rect.setLeft(placement.left);
3035+ rect.setTop(placement.top);
3036+ rect.setWidth(placement.width);
3037+ rect.setHeight(placement.height);
3038 }
3039
3040 MirSurfacePlacementEvent const* MirEvent::to_surface_placement() const
3041
3042=== modified file 'src/common/symbols.map'
3043--- src/common/symbols.map 2016-09-16 15:18:36 +0000
3044+++ src/common/symbols.map 2016-09-18 20:00:37 +0000
3045@@ -360,9 +360,6 @@
3046 android::InputPublisher::publishEventBuffer*;
3047 MirEvent::to_input_device_state*;
3048 MirInputDeviceStateEvent::MirInputDeviceStateEvent*;
3049- MirInputDeviceStateEvent::add_device*;
3050- MirInputDeviceStateEvent::clone*;
3051- MirInputDeviceStateEvent::deserialize*;
3052 MirInputDeviceStateEvent::device_count*;
3053 MirInputDeviceStateEvent::device_id*;
3054 MirInputDeviceStateEvent::device_pointer_buttons*;
3055@@ -371,7 +368,6 @@
3056 MirInputDeviceStateEvent::modifiers*;
3057 MirInputDeviceStateEvent::pointer_axis*;
3058 MirInputDeviceStateEvent::pointer_buttons*;
3059- MirInputDeviceStateEvent::serialize*;
3060 MirInputDeviceStateEvent::set_modifiers*;
3061 MirInputDeviceStateEvent::set_pointer_axis*;
3062 MirInputDeviceStateEvent::set_pointer_buttons*;
3063@@ -390,6 +386,12 @@
3064 MIR_COMMON_0.25 {
3065 global:
3066 extern "C++" {
3067+ MirEvent::MirEvent*;
3068+ MirEvent::operator*;
3069+ MirInputEvent::operator*;
3070+ MirInputDeviceStateEvent::set_device_states*;
3071+ MirInputDeviceStateEvent::device_pressed_keys_for_index*;
3072+ mir::event::store_data_for_lifetime_of_event*;
3073 MirSurfacePlacementEvent::MirSurfacePlacementEvent*;
3074 MirSurfacePlacementEvent::id*;
3075 MirSurfacePlacementEvent::set_id*;
3076
3077=== modified file 'src/include/common/mir/events/close_surface_event.h'
3078--- src/include/common/mir/events/close_surface_event.h 2016-03-30 18:47:45 +0000
3079+++ src/include/common/mir/events/close_surface_event.h 2016-09-18 20:00:37 +0000
3080@@ -27,9 +27,6 @@
3081
3082 int surface_id() const;
3083 void set_surface_id(int id);
3084-
3085-private:
3086- int surface_id_{-1};
3087 };
3088
3089 #endif /* MIR_COMMON_CLOSE_SURFACE_EVENT_H_ */
3090
3091=== modified file 'src/include/common/mir/events/event.h'
3092--- src/include/common/mir/events/event.h 2016-09-16 15:18:36 +0000
3093+++ src/include/common/mir/events/event.h 2016-09-18 20:00:37 +0000
3094@@ -21,14 +21,33 @@
3095
3096 #include "mir_toolkit/event.h"
3097 #include "mir/events/event_builders.h"
3098+#include "mir_event.capnp.h"
3099+
3100+#include <capnp/message.h>
3101
3102 #include <cstring>
3103
3104 // Only MirPointerEvent and MirTouchEvent are typedefed in the public API
3105 typedef struct MirMotionEvent MirMotionEvent;
3106
3107+namespace mir
3108+{
3109+namespace event
3110+{
3111+/* Evil hack to keep data around for the lifetime of an event.
3112+ * The reference will go down when the event it self goes out of scope.
3113+ * TODO: Remove this once we can remove this public function:
3114+ * uint32_t const* mir_input_device_state_event_device_pressed_keys
3115+ */
3116+void* store_data_for_lifetime_of_event(MirEvent const* ev, std::shared_ptr<void> const& data);
3117+}
3118+}
3119+
3120 struct MirEvent
3121 {
3122+ MirEvent(MirEvent const& event);
3123+ MirEvent& operator=(MirEvent const& event);
3124+
3125 MirEventType type() const;
3126
3127 MirInputEvent* to_input();
3128@@ -70,69 +89,9 @@
3129
3130 protected:
3131 MirEvent() = default;
3132- explicit MirEvent(MirEventType type);
3133- MirEvent(MirEvent const& event) = default;
3134- MirEvent& operator=(MirEvent const& event) = default;
3135
3136- MirEventType type_;
3137+ ::capnp::MallocMessageBuilder message;
3138+ mir::capnp::Event::Builder event{message.initRoot<mir::capnp::Event>()};
3139 };
3140
3141-namespace mir
3142-{
3143-namespace event
3144-{
3145-template<typename Data>
3146-char const* consume(char const* pos, Data& data)
3147-{
3148- std::memcpy(&data, pos, sizeof data);
3149- return pos + sizeof data;
3150-}
3151-
3152-template<typename T>
3153-void assert_type_is_trivially_copyable()
3154-{
3155-#if __GNUC__ >= 5
3156- static_assert(std::is_trivially_copyable<T>::value, "");
3157-#else
3158- static_assert(__has_trivial_copy(T), "");
3159-#endif
3160-}
3161-
3162-// T needs to be trivially copyable
3163-// vivid wont allow a std::is_trivially_copyable
3164-template<typename T>
3165-mir::EventUPtr deserialize_from(std::string const& bytes)
3166-{
3167- assert_type_is_trivially_copyable<T>();
3168-
3169- T* t = new T;
3170- memcpy(t, bytes.data(), bytes.size());
3171-
3172- return mir::EventUPtr(t, [](MirEvent* e) { delete e; });
3173-}
3174-
3175-template<typename T>
3176-std::string serialize_from(MirEvent const* ev)
3177-{
3178- assert_type_is_trivially_copyable<T>();
3179-
3180- std::string encoded_bytes;
3181- encoded_bytes.append(reinterpret_cast<char const*>(ev), sizeof(T));
3182-
3183- return encoded_bytes;
3184-}
3185-
3186-template<typename T>
3187-MirEvent* deep_copy(MirEvent const* ev)
3188-{
3189- assert_type_is_trivially_copyable<T>();
3190-
3191- T* t = new T;
3192- memcpy(t, ev, sizeof(T));
3193-
3194- return t;
3195-}
3196-}
3197-}
3198-
3199 #endif /* MIR_COMMON_EVENT_H_ */
3200
3201=== modified file 'src/include/common/mir/events/input_configuration_event.h'
3202--- src/include/common/mir/events/input_configuration_event.h 2016-03-30 19:01:10 +0000
3203+++ src/include/common/mir/events/input_configuration_event.h 2016-09-18 20:00:37 +0000
3204@@ -20,7 +20,6 @@
3205 #define MIR_COMMON_INPUT_CONFIGURATION_EVENT_H_
3206
3207 #include <chrono>
3208-#include <limits>
3209
3210 #include "mir/events/event.h"
3211
3212@@ -36,11 +35,6 @@
3213
3214 MirInputDeviceId id() const;
3215 void set_id(MirInputDeviceId id);
3216-
3217-private:
3218- MirInputConfigurationAction action_;
3219- std::chrono::nanoseconds when_{0};
3220- MirInputDeviceId id_{std::numeric_limits<MirInputDeviceId>::max()};
3221 };
3222
3223 #endif /* MIR_COMMON_INPUT_CONFIGURATION_EVENT_H_ */
3224
3225=== modified file 'src/include/common/mir/events/input_device_state_event.h'
3226--- src/include/common/mir/events/input_device_state_event.h 2016-05-26 20:59:38 +0000
3227+++ src/include/common/mir/events/input_device_state_event.h 2016-09-18 20:00:37 +0000
3228@@ -21,8 +21,10 @@
3229
3230 #include <chrono>
3231 #include <limits>
3232+#include <unordered_map>
3233
3234 #include "mir/events/event.h"
3235+#include "mir/events/input_device_state.h"
3236
3237 struct MirInputDeviceStateEvent : MirEvent
3238 {
3239@@ -43,33 +45,14 @@
3240 uint32_t device_count() const;
3241 MirInputDeviceId device_id(size_t index) const;
3242 MirPointerButtons device_pointer_buttons(size_t index) const;
3243- uint32_t const* device_pressed_keys(size_t index) const;
3244+
3245+ // Public API deprecated remove this once it has been removed
3246+ std::vector<uint32_t> device_pressed_keys(size_t index);
3247+
3248+ uint32_t device_pressed_keys_for_index(size_t index, size_t pressed_index) const;
3249 uint32_t device_pressed_keys_count(size_t index) const;
3250
3251- static mir::EventUPtr deserialize(std::string const& bytes);
3252- static std::string serialize(MirEvent const* event);
3253- MirEvent* clone() const;
3254-
3255- void add_device(MirInputDeviceId id, std::vector<uint32_t> && pressed_keys, MirPointerButtons pointer_buttons);
3256-
3257-private:
3258- std::chrono::nanoseconds when_{0};
3259- MirPointerButtons pointer_buttons_{0};
3260- MirInputEventModifiers modifiers_{0};
3261-
3262- float pointer_x{0.0f};
3263- float pointer_y{0.0f};
3264-
3265- struct DeviceState
3266- {
3267- DeviceState(MirInputDeviceId id, std::vector<uint32_t> && pressed_keys, MirPointerButtons buttons)
3268- : id{id}, pressed_keys{std::move(pressed_keys)}, pointer_buttons{buttons}
3269- {}
3270- MirInputDeviceId id;
3271- std::vector<uint32_t> pressed_keys;
3272- MirPointerButtons pointer_buttons;
3273- };
3274- std::vector<DeviceState> devices;
3275+ void set_device_states(std::vector<mir::events::InputDeviceState> const& device_states);
3276 };
3277
3278 #endif /* MIR_COMMON_INPUT_DEVICE_STATE_EVENT_H_*/
3279
3280=== modified file 'src/include/common/mir/events/input_event.h'
3281--- src/include/common/mir/events/input_event.h 2016-03-29 03:41:45 +0000
3282+++ src/include/common/mir/events/input_event.h 2016-09-18 20:00:37 +0000
3283@@ -31,7 +31,6 @@
3284
3285 protected:
3286 MirInputEvent() = default;
3287- explicit MirInputEvent(MirEventType type);
3288 MirInputEvent(MirInputEvent const& event) = default;
3289 MirInputEvent& operator=(MirInputEvent const& event) = default;
3290 };
3291
3292=== modified file 'src/include/common/mir/events/keyboard_event.h'
3293--- src/include/common/mir/events/keyboard_event.h 2016-03-30 18:47:45 +0000
3294+++ src/include/common/mir/events/keyboard_event.h 2016-09-18 20:00:37 +0000
3295@@ -21,9 +21,9 @@
3296
3297 #include <chrono>
3298 #include <cstdint>
3299+#include <vector>
3300
3301 #include "mir/events/input_event.h"
3302-#include "mir/cookie/blob.h"
3303
3304 struct MirKeyboardEvent : MirInputEvent
3305 {
3306@@ -50,20 +50,8 @@
3307 std::chrono::nanoseconds event_time() const;
3308 void set_event_time(std::chrono::nanoseconds const& event_time);
3309
3310- mir::cookie::Blob cookie() const;
3311- void set_cookie(mir::cookie::Blob const& cookie);
3312-
3313-private:
3314- int32_t device_id_{-1};
3315- int32_t source_id_{-1};
3316- MirKeyboardAction action_;
3317- MirInputEventModifiers modifiers_{0};
3318-
3319- int32_t key_code_{0};
3320- int32_t scan_code_{0};
3321-
3322- std::chrono::nanoseconds event_time_{0};
3323- mir::cookie::Blob cookie_;
3324+ std::vector<uint8_t> cookie() const;
3325+ void set_cookie(std::vector<uint8_t> const& cookie);
3326 };
3327
3328 #endif /* MIR_COMMON_KEYBOARD_EVENT_H_ */
3329
3330=== modified file 'src/include/common/mir/events/keymap_event.h'
3331--- src/include/common/mir/events/keymap_event.h 2016-03-30 19:01:10 +0000
3332+++ src/include/common/mir/events/keymap_event.h 2016-09-18 20:00:37 +0000
3333@@ -20,7 +20,6 @@
3334 #define MIR_COMMON_KEYMAP_EVENT_H_
3335
3336 #include <xkbcommon/xkbcommon.h>
3337-#include <limits>
3338
3339 #include "mir/events/event.h"
3340
3341@@ -35,26 +34,9 @@
3342 void set_device_id(MirInputDeviceId id);
3343
3344 char const* buffer() const;
3345- /* FIXME We takes over ownership of the buffer pointer, but we should not be.
3346- Either user a unique_ptr here later (when we dont depend on is_trivially_copyable)
3347- or copy it into a vector or do a deep copy.
3348- */
3349 void set_buffer(char const* buffer);
3350- void free_buffer();
3351
3352 size_t size() const;
3353- void set_size(size_t size);
3354-
3355- /* FIXME Need to handle the special case of Keymap events due to char const* buffer */
3356- static mir::EventUPtr deserialize(std::string const& bytes);
3357- static std::string serialize(MirEvent const* event);
3358- MirEvent* clone() const;
3359-
3360-private:
3361- int surface_id_{-1};
3362- MirInputDeviceId device_id_{std::numeric_limits<MirInputDeviceId>::max()};
3363- char const* buffer_{nullptr};
3364- size_t size_{0};
3365 };
3366
3367 #endif /* MIR_COMMON_KEYMAP_EVENT_H_ */
3368
3369=== modified file 'src/include/common/mir/events/motion_event.h'
3370--- src/include/common/mir/events/motion_event.h 2016-03-30 18:47:45 +0000
3371+++ src/include/common/mir/events/motion_event.h 2016-09-18 20:00:37 +0000
3372@@ -19,35 +19,10 @@
3373 #ifndef MIR_COMMON_MOTION_EVENT_H_
3374 #define MIR_COMMON_MOTION_EVENT_H_
3375
3376-/* TODO: To the moon. */
3377-#define MIR_INPUT_EVENT_MAX_POINTER_COUNT 16
3378-
3379 #include <chrono>
3380 #include <cstdint>
3381
3382 #include "mir/events/input_event.h"
3383-#include "mir/cookie/blob.h"
3384-
3385-struct MirMotionPointer
3386-{
3387- int id;
3388- float x;
3389- float y;
3390- float dx;
3391- float dy;
3392- float touch_major;
3393- float touch_minor;
3394- float size;
3395- float pressure;
3396- float orientation;
3397- float vscroll;
3398- float hscroll;
3399- MirTouchTooltype tool_type;
3400-
3401- // TODO: We would like to store this as a MirTouchAction but we still encode pointer actions
3402- // here as well.
3403- int action;
3404-};
3405
3406 struct MirMotionEvent : MirInputEvent
3407 {
3408@@ -68,8 +43,8 @@
3409 std::chrono::nanoseconds event_time() const;
3410 void set_event_time(std::chrono::nanoseconds const& event_time);
3411
3412- mir::cookie::Blob cookie() const;
3413- void set_cookie(mir::cookie::Blob const& blob);
3414+ std::vector<uint8_t> cookie() const;
3415+ void set_cookie(std::vector<uint8_t> const& cookie);
3416
3417 size_t pointer_count() const;
3418 void set_pointer_count(size_t count);
3419@@ -123,19 +98,8 @@
3420 MirPointerEvent const* to_pointer() const;
3421
3422 private:
3423- int32_t device_id_{-1};
3424- int32_t source_id_{-1};
3425-
3426- MirInputEventModifiers modifiers_{0};
3427-
3428- MirPointerButtons buttons_{0};
3429- std::chrono::nanoseconds event_time_{0};
3430- mir::cookie::Blob cookie_;
3431-
3432- size_t pointer_count_{0};
3433- MirMotionPointer pointer_coordinates_[MIR_INPUT_EVENT_MAX_POINTER_COUNT];
3434- /* "_coordinates" is a misnomer here because there's plenty more info than
3435- just coordinates, but renaming it accurately would be an API break */
3436+ void throw_if_out_of_bounds(size_t index) const;
3437+
3438 };
3439
3440 // These are left empty as they are just aliases for a MirMotionEvent,
3441
3442=== modified file 'src/include/common/mir/events/orientation_event.h'
3443--- src/include/common/mir/events/orientation_event.h 2016-03-30 18:47:45 +0000
3444+++ src/include/common/mir/events/orientation_event.h 2016-09-18 20:00:37 +0000
3445@@ -30,10 +30,6 @@
3446
3447 MirOrientation direction() const;
3448 void set_direction(MirOrientation orientation);
3449-
3450-private:
3451- int surface_id_{-1};
3452- MirOrientation direction_;
3453 };
3454
3455 #endif /* MIR_COMMON_ORIENTATION_EVENT_H_ */
3456
3457=== modified file 'src/include/common/mir/events/prompt_session_event.h'
3458--- src/include/common/mir/events/prompt_session_event.h 2016-03-29 03:41:45 +0000
3459+++ src/include/common/mir/events/prompt_session_event.h 2016-09-18 20:00:37 +0000
3460@@ -27,9 +27,6 @@
3461
3462 MirPromptSessionState new_state() const;
3463 void set_new_state(MirPromptSessionState state);
3464-
3465-private:
3466- MirPromptSessionState new_state_;
3467 };
3468
3469 #endif /* MIR_COMMON_PROMPT_SESSION_EVENT_H_ */
3470
3471=== modified file 'src/include/common/mir/events/resize_event.h'
3472--- src/include/common/mir/events/resize_event.h 2016-03-30 18:47:45 +0000
3473+++ src/include/common/mir/events/resize_event.h 2016-09-18 20:00:37 +0000
3474@@ -33,11 +33,6 @@
3475
3476 int height() const;
3477 void set_height(int height);
3478-
3479-private:
3480- int surface_id_{-1};
3481- int width_{0};
3482- int height_{0};
3483 };
3484
3485 #endif /* MIR_COMMON_RESIZE_EVENT_H_ */
3486
3487=== modified file 'src/include/common/mir/events/surface_event.h'
3488--- src/include/common/mir/events/surface_event.h 2016-03-29 03:41:45 +0000
3489+++ src/include/common/mir/events/surface_event.h 2016-09-18 20:00:37 +0000
3490@@ -33,11 +33,6 @@
3491
3492 int value() const;
3493 void set_value(int value);
3494-
3495-private:
3496- int id_{0};
3497- MirSurfaceAttrib attrib_;
3498- int value_{0};
3499 };
3500
3501 #endif /* MIR_COMMON_SURFACE_EVENT_H_ */
3502
3503=== modified file 'src/include/common/mir/events/surface_output_event.h'
3504--- src/include/common/mir/events/surface_output_event.h 2016-03-30 19:01:10 +0000
3505+++ src/include/common/mir/events/surface_output_event.h 2016-09-18 20:00:37 +0000
3506@@ -20,7 +20,6 @@
3507 #define MIR_COMMON_SURFACE_OUTPUT_EVENT_H_
3508
3509 #include <cstdint>
3510-#include <limits>
3511
3512 #include "mir/events/event.h"
3513
3514@@ -42,13 +41,6 @@
3515
3516 uint32_t output_id() const;
3517 void set_output_id(uint32_t id);
3518-
3519-private:
3520- int surface_id_{-1};
3521- int dpi_{0};
3522- float scale_{0.0f};
3523- MirFormFactor form_factor_;
3524- uint32_t output_id_{std::numeric_limits<uint32_t>::max()};
3525 };
3526
3527 #endif /* MIR_COMMON_SURFACE_OUTPUT_EVENT_H_ */
3528
3529=== modified file 'src/server/graphics/nested/input_platform.cpp'
3530--- src/server/graphics/nested/input_platform.cpp 2016-09-01 12:28:46 +0000
3531+++ src/server/graphics/nested/input_platform.cpp 2016-09-18 20:00:37 +0000
3532@@ -229,7 +229,7 @@
3533 {
3534 unknown_device_events[id].emplace_back(
3535 std::piecewise_construct,
3536- std::forward_as_tuple(event.clone(), [](MirEvent* e){delete e;}),
3537+ std::forward_as_tuple(new MirEvent(event), [](MirEvent* e){delete e;}),
3538 std::forward_as_tuple(area));
3539 }
3540 }
3541@@ -247,9 +247,13 @@
3542 {
3543 auto dest = it->second->destination;
3544 auto key_count = mir_input_device_state_event_device_pressed_keys_count(device_state, index);
3545- auto const* scan_codes = mir_input_device_state_event_device_pressed_keys(device_state, index);
3546+ std::vector<uint32_t> scan_codes;
3547+ for (uint32_t i = 0; i < key_count; i++)
3548+ {
3549+ scan_codes.push_back(mir_input_device_state_event_device_pressed_keys_for_index(device_state, index, i));
3550+ }
3551
3552- dest->key_state({scan_codes, scan_codes + key_count});
3553+ dest->key_state(scan_codes);
3554 dest->pointer_state(
3555 mir_input_device_state_event_device_pointer_buttons(device_state, index));
3556 }
3557
3558=== modified file 'src/server/input/android/input_sender.cpp'
3559--- src/server/input/android/input_sender.cpp 2016-06-03 08:39:59 +0000
3560+++ src/server/input/android/input_sender.cpp 2016-09-18 20:00:37 +0000
3561@@ -38,6 +38,23 @@
3562
3563 namespace droidinput = android;
3564
3565+namespace
3566+{
3567+// FIXME Temp, only needed to use the android input_sender/receiver
3568+mir::cookie::Blob convert_cookie_to_blob(std::vector<uint8_t> const& cookie)
3569+{
3570+ if (cookie.size() > mir::cookie::default_blob_size)
3571+ {
3572+ BOOST_THROW_EXCEPTION(std::runtime_error("The cookie size must be less the mir::cookie::default_blob_size"));
3573+ }
3574+
3575+ mir::cookie::Blob cookie_blob{{0}};
3576+ std::copy(std::begin(cookie), std::end(cookie), std::begin(cookie_blob));
3577+
3578+ return cookie_blob;
3579+}
3580+}
3581+
3582 mia::InputSender::InputSender(std::shared_ptr<mir::compositor::Scene> const& scene,
3583 std::shared_ptr<mir::MainLoop> const& main_loop,
3584 std::shared_ptr<InputReport> const& report)
3585@@ -256,7 +273,7 @@
3586 mir_keyboard_event_scan_code(key_event),
3587 mia::android_modifiers_from_mir(mir_keyboard_event_modifiers(key_event)),
3588 repeat_count,
3589- event.to_input()->to_keyboard()->cookie(),
3590+ convert_cookie_to_blob(event.to_input()->to_keyboard()->cookie()),
3591 event_time,
3592 event_time);
3593 }
3594@@ -264,8 +281,8 @@
3595 droidinput::status_t mia::InputSender::ActiveTransfer::send_touch_event(uint32_t seq, MirEvent const& event)
3596 {
3597 droidinput::status_t ret = droidinput::OK;
3598- droidinput::PointerCoords coords[MIR_INPUT_EVENT_MAX_POINTER_COUNT];
3599- droidinput::PointerProperties properties[MIR_INPUT_EVENT_MAX_POINTER_COUNT];
3600+ droidinput::PointerCoords coords[mir::capnp::MotionSetEvent::MAX_COUNT];
3601+ droidinput::PointerProperties properties[mir::capnp::MotionSetEvent::MAX_COUNT];
3602 auto input_event = mir_event_get_input_event(&event);
3603 auto touch = mir_input_event_get_touch_event(input_event);
3604 std::chrono::nanoseconds const event_time{mir_input_event_get_event_time(input_event)};
3605@@ -333,7 +350,8 @@
3606 ret = publisher.publishMotionEvent(seq, mir_input_event_get_device_id(input_event), AINPUT_SOURCE_TOUCHSCREEN,
3607 state_change.android_action, flags, edge_flags,
3608 mia::android_modifiers_from_mir(mir_touch_event_modifiers(touch)),
3609- button_state, x_offset, y_offset, x_precision, y_precision, event.to_input()->to_motion()->cookie(),
3610+ button_state, x_offset, y_offset, x_precision, y_precision,
3611+ convert_cookie_to_blob(event.to_input()->to_motion()->cookie()),
3612 event_time, event_time, contacts_in_event, properties, coords);
3613 }
3614
3615@@ -370,7 +388,8 @@
3616 mia::android_pointer_action_from_mir(mir_pointer_event_action(pointer), mir_pointer_event_buttons(pointer)),
3617 flags, edge_flags, mia::android_modifiers_from_mir(mir_pointer_event_modifiers(pointer)),
3618 mia::android_pointer_buttons_from_mir(mir_pointer_event_buttons(pointer)), x_offset, y_offset, x_precision,
3619- y_precision, event.to_input()->to_motion()->cookie(), event_time, event_time, 1, &pointer_properties, &pointer_coord);
3620+ y_precision, convert_cookie_to_blob(event.to_input()->to_motion()->cookie()),
3621+ event_time, event_time, 1, &pointer_properties, &pointer_coord);
3622 }
3623
3624
3625
3626=== modified file 'src/server/input/default_event_builder.cpp'
3627--- src/server/input/default_event_builder.cpp 2016-06-03 08:39:59 +0000
3628+++ src/server/input/default_event_builder.cpp 2016-09-18 20:00:37 +0000
3629@@ -59,10 +59,8 @@
3630 auto mev = event.to_input()->to_motion();
3631 auto const cookie = cookie_authority->make_cookie(mev->event_time().count());
3632 auto const serialized_cookie = cookie->serialize();
3633- mir::cookie::Blob event_cookie;
3634- std::copy_n(std::begin(serialized_cookie), event_cookie.size(), std::begin(event_cookie));
3635
3636- mev->set_cookie(event_cookie);
3637+ mev->set_cookie(serialized_cookie);
3638 }
3639
3640 me::add_touch(event, touch_id, action, tooltype, x_axis_value, y_axis_value, pressure_value, touch_major_value,
3641
3642=== modified file 'src/server/input/key_repeat_dispatcher.cpp'
3643--- src/server/input/key_repeat_dispatcher.cpp 2016-05-03 06:55:25 +0000
3644+++ src/server/input/key_repeat_dispatcher.cpp 2016-09-18 20:00:37 +0000
3645@@ -173,9 +173,7 @@
3646 new_kev.set_event_time(std::chrono::steady_clock::now().time_since_epoch());
3647 auto const cookie = cookie_authority->make_cookie(new_kev.event_time().count());
3648 auto const serialized_cookie = cookie->serialize();
3649- mir::cookie::Blob event_cookie;
3650- std::copy_n(std::begin(serialized_cookie), event_cookie.size(), std::begin(event_cookie));
3651- new_kev.set_cookie(event_cookie);
3652+ new_kev.set_cookie(serialized_cookie);
3653 next_dispatcher->dispatch(new_kev);
3654
3655 capture_alarm->reschedule_in(repeat_delay);
3656
3657=== modified file 'src/server/input/validator.cpp'
3658--- src/server/input/validator.cpp 2016-05-03 06:55:25 +0000
3659+++ src/server/input/validator.cpp 2016-09-18 20:00:37 +0000
3660@@ -56,7 +56,8 @@
3661
3662 namespace
3663 {
3664-void delete_event(MirEvent *e) { mir_event_unref(e); }
3665+void delete_event(MirEvent *e) { delete e; }
3666+
3667 mir::EventUPtr make_event_uptr(MirEvent *e)
3668 {
3669 return mir::EventUPtr(e, delete_event);
3670@@ -64,9 +65,7 @@
3671
3672 mir::EventUPtr copy_event(MirTouchEvent const* ev)
3673 {
3674- MirTouchEvent* ret = new MirTouchEvent;
3675- memcpy(ret, ev, sizeof(MirTouchEvent));
3676- return make_event_uptr(ret);
3677+ return make_event_uptr(new MirTouchEvent(*ev));
3678 }
3679
3680 // Return a copy of ev with existing touch actions converted to change.
3681
3682=== modified file 'tests/unit-tests/client/input/test_android_input_receiver.cpp'
3683--- tests/unit-tests/client/input/test_android_input_receiver.cpp 2016-05-03 06:55:25 +0000
3684+++ tests/unit-tests/client/input/test_android_input_receiver.cpp 2016-09-18 20:00:37 +0000
3685@@ -230,7 +230,7 @@
3686 std::make_shared<mircv::XKBMapper>(),
3687 [&ev, &handler_called](MirEvent* event)
3688 {
3689- ev.reset(event->clone());
3690+ ev.reset(new MirEvent(*event));
3691 handler_called = true;
3692 },
3693 std::make_shared<mircv::NullInputReceiverReport>(),
3694
3695=== modified file 'tests/unit-tests/input/android/test_android_input_sender.cpp'
3696--- tests/unit-tests/input/android/test_android_input_sender.cpp 2016-06-07 21:10:34 +0000
3697+++ tests/unit-tests/input/android/test_android_input_sender.cpp 2016-09-18 20:00:37 +0000
3698@@ -503,7 +503,8 @@
3699 const auto timestamp = std::chrono::nanoseconds(10);
3700 register_surface();
3701 std::vector<mir::events::InputDeviceState> states;
3702- states.push_back({MirInputDeviceId{23}, {50, 60, 80}, 0});
3703+ std::vector<uint32_t> const pressed_keys = {50, 60, 80};
3704+ states.push_back({MirInputDeviceId{23}, pressed_keys, 0});
3705 states.push_back({MirInputDeviceId{21}, {}, mir_pointer_button_primary});
3706
3707 auto device_state = mir::events::make_event(timestamp, mir_pointer_button_primary, mir_input_event_modifier_caps_lock,
3708@@ -522,10 +523,13 @@
3709 EXPECT_THAT(mir_input_device_state_event_device_count(input_device_state), Eq(2));
3710
3711 EXPECT_THAT(mir_input_device_state_event_device_id(input_device_state, 0), Eq(MirInputDeviceId{23}));
3712- EXPECT_THAT(mir_input_device_state_event_device_pressed_keys_count(input_device_state, 0), Eq(3));
3713- EXPECT_THAT(mir_input_device_state_event_device_pressed_keys(input_device_state, 0)[0], Eq(50));
3714- EXPECT_THAT(mir_input_device_state_event_device_pressed_keys(input_device_state, 0)[1], Eq(60));
3715- EXPECT_THAT(mir_input_device_state_event_device_pressed_keys(input_device_state, 0)[2], Eq(80));
3716+ auto keys_count = mir_input_device_state_event_device_pressed_keys_count(input_device_state, 0);
3717+ EXPECT_THAT(keys_count, Eq(3));
3718+
3719+ for (uint32_t i = 0; i < keys_count; i++)
3720+ {
3721+ EXPECT_THAT(mir_input_device_state_event_device_pressed_keys_for_index(input_device_state, 0, i), Eq(pressed_keys[i]));
3722+ }
3723 EXPECT_THAT(mir_input_device_state_event_device_pointer_buttons(input_device_state, 0), 0);
3724
3725 EXPECT_THAT(mir_input_device_state_event_device_id(input_device_state, 1), Eq(MirInputDeviceId{21}));
3726
3727=== modified file 'tests/unit-tests/input/test_event_builders.cpp'
3728--- tests/unit-tests/input/test_event_builders.cpp 2016-05-26 20:59:38 +0000
3729+++ tests/unit-tests/input/test_event_builders.cpp 2016-09-18 20:00:37 +0000
3730@@ -189,12 +189,14 @@
3731 auto const pos_y = 53.2f;
3732 auto const button_state = mir_pointer_button_primary|mir_pointer_button_secondary;
3733 auto const modifiers = mir_input_event_modifier_ctrl_right | mir_input_event_modifier_ctrl;
3734+ std::vector<uint32_t> const pressed_keys = {KEY_LEFTALT, KEY_M};
3735+
3736 auto ev = mev::make_event(timestamp,
3737 button_state,
3738 modifiers,
3739 pos_x,
3740 pos_y,
3741- {mev::InputDeviceState{MirInputDeviceId{3}, {KEY_LEFTALT, KEY_M}, 0},
3742+ {mev::InputDeviceState{MirInputDeviceId{3}, pressed_keys, 0},
3743 mev::InputDeviceState{MirInputDeviceId{2}, {}, button_state}});
3744
3745 EXPECT_THAT(mir_event_get_type(ev.get()), Eq(mir_event_type_input_device_state));
3746@@ -208,9 +210,14 @@
3747 EXPECT_THAT(mir_input_device_state_event_device_count(ids_event), Eq(2));
3748
3749 EXPECT_THAT(mir_input_device_state_event_device_id(ids_event, 0), Eq(MirInputDeviceId{3}));
3750- EXPECT_THAT(mir_input_device_state_event_device_pressed_keys_count(ids_event, 0), Eq(2));
3751- EXPECT_THAT(mir_input_device_state_event_device_pressed_keys(ids_event, 0)[0], Eq(KEY_LEFTALT));
3752- EXPECT_THAT(mir_input_device_state_event_device_pressed_keys(ids_event, 0)[1], Eq(KEY_M));
3753+
3754+ auto const pressed_keys_count = mir_input_device_state_event_device_pressed_keys_count(ids_event, 0);
3755+ EXPECT_THAT(pressed_keys_count, Eq(2));
3756+ for (uint32_t i = 0; i < pressed_keys_count; i++)
3757+ {
3758+ EXPECT_THAT(mir_input_device_state_event_device_pressed_keys_for_index(ids_event, 0, i), Eq(pressed_keys[i]));
3759+ }
3760+
3761 EXPECT_THAT(mir_input_device_state_event_device_pointer_buttons(ids_event, 0), Eq(0));
3762
3763 EXPECT_THAT(mir_input_device_state_event_device_id(ids_event, 1), Eq(MirInputDeviceId{2}));
3764@@ -252,6 +259,7 @@
3765 auto const pos_y = 0.0f;
3766 auto const button_state = mir_pointer_button_primary | mir_pointer_button_secondary;
3767 auto const modifiers = mir_input_event_modifier_none;
3768+ std::vector<uint32_t> const pressed_keys = {KEY_RIGHTALT, KEY_LEFTSHIFT, KEY_Q};
3769 auto ev = mev::make_event(timestamp,
3770 button_state,
3771 modifiers,
3772@@ -259,7 +267,7 @@
3773 pos_y,
3774 {mev::InputDeviceState{MirInputDeviceId{0}, {}, mir_pointer_button_primary},
3775 mev::InputDeviceState{MirInputDeviceId{2}, {}, mir_pointer_button_secondary},
3776- mev::InputDeviceState{MirInputDeviceId{3}, {KEY_RIGHTALT, KEY_LEFTSHIFT, KEY_Q}, 0}});
3777+ mev::InputDeviceState{MirInputDeviceId{3}, pressed_keys, 0}});
3778
3779 auto encoded = MirEvent::serialize(ev.get());
3780
3781@@ -269,8 +277,11 @@
3782 auto ids_event = mir_event_get_input_device_state_event(deserialzed_event.get());
3783
3784 EXPECT_THAT(mir_input_device_state_event_device_count(ids_event), Eq(3));
3785- EXPECT_THAT(mir_input_device_state_event_device_pressed_keys_count(ids_event, 2), Eq(3));
3786- EXPECT_THAT(mir_input_device_state_event_device_pressed_keys(ids_event, 2)[0], Eq(KEY_RIGHTALT));
3787- EXPECT_THAT(mir_input_device_state_event_device_pressed_keys(ids_event, 2)[1], Eq(KEY_LEFTSHIFT));
3788- EXPECT_THAT(mir_input_device_state_event_device_pressed_keys(ids_event, 2)[2], Eq(KEY_Q));
3789+ auto pressed_keys_count = mir_input_device_state_event_device_pressed_keys_count(ids_event, 2);
3790+ EXPECT_THAT(pressed_keys_count, Eq(3));
3791+
3792+ for (uint32_t i = 0; i < pressed_keys_count; i++)
3793+ {
3794+ EXPECT_THAT(mir_input_device_state_event_device_pressed_keys_for_index(ids_event, 2, i), Eq(pressed_keys[i]));
3795+ }
3796 }
3797
3798=== modified file 'tests/unit-tests/input/test_surface_input_dispatcher.cpp'
3799--- tests/unit-tests/input/test_surface_input_dispatcher.cpp 2016-06-10 12:55:53 +0000
3800+++ tests/unit-tests/input/test_surface_input_dispatcher.cpp 2016-09-18 20:00:37 +0000
3801@@ -264,7 +264,7 @@
3802 FakeKeyboard keyboard;
3803 auto event = keyboard.press();
3804
3805- EXPECT_CALL(*surface, consume(mt::MirKeyboardEventMatches(ByRef(*event)))).Times(1);
3806+ EXPECT_CALL(*surface, consume(mt::MirKeyboardEventMatches(event.get()))).Times(1);
3807
3808 dispatcher.start();
3809
3810
3811=== modified file 'tests/unit-tests/input/test_validator.cpp'
3812--- tests/unit-tests/input/test_validator.cpp 2016-05-03 06:55:25 +0000
3813+++ tests/unit-tests/input/test_validator.cpp 2016-09-18 20:00:37 +0000
3814@@ -87,9 +87,9 @@
3815 add_another_touch(inserted_down_id1, 1, mir_touch_action_down);
3816
3817 InSequence seq;
3818- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id0))));
3819- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id1))));
3820- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch))));
3821+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id0.get())));
3822+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id1.get())));
3823+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch.get())));
3824
3825 rewriter.validate_and_dispatch(*touch);
3826 }
3827@@ -108,10 +108,10 @@
3828 add_another_touch(inserted_release, 1, mir_touch_action_up);
3829
3830 InSequence seq;
3831- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
3832- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
3833- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_release))));
3834- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_3))));
3835+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get())));
3836+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get())));
3837+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_release.get())));
3838+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get())));
3839
3840 rewriter.validate_and_dispatch(*touch_1);
3841 rewriter.validate_and_dispatch(*touch_2);
3842@@ -138,12 +138,12 @@
3843 add_another_touch(inserted_release_id0, 2, mir_touch_action_change);
3844
3845 InSequence seq;
3846- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
3847- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
3848- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_3))));
3849- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_release_id1))));
3850- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_release_id0))));
3851- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_4))));
3852+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get())));
3853+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get())));
3854+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get())));
3855+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_release_id1.get())));
3856+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_release_id0.get())));
3857+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_4.get())));
3858
3859 rewriter.validate_and_dispatch(*touch_1);
3860 rewriter.validate_and_dispatch(*touch_2);
3861@@ -169,12 +169,12 @@
3862 auto inserted_down_id2 = make_touch(0, mir_touch_action_change);
3863 add_another_touch(inserted_down_id2, 2, mir_touch_action_down);
3864
3865- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
3866- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
3867- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_3))));
3868- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_release_id1))));
3869- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id2))));
3870- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_4))));
3871+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get())));
3872+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get())));
3873+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get())));
3874+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_release_id1.get())));
3875+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id2.get())));
3876+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_4.get())));
3877
3878 rewriter.validate_and_dispatch(*touch_1);
3879 rewriter.validate_and_dispatch(*touch_2);
3880@@ -196,11 +196,11 @@
3881 auto inserted_down_id2 = make_touch(1, mir_touch_action_change);
3882 add_another_touch(inserted_down_id2, 2, mir_touch_action_down);
3883
3884- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
3885- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
3886- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_up_id0))));
3887- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id2))));
3888- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_3))));
3889+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get())));
3890+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get())));
3891+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_up_id0.get())));
3892+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id2.get())));
3893+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get())));
3894
3895 rewriter.validate_and_dispatch(*touch_1);
3896 rewriter.validate_and_dispatch(*touch_2);
3897@@ -226,12 +226,12 @@
3898 add_another_touch(inserted_down_id1, 1, mir_touch_action_down);
3899
3900 InSequence seq;
3901- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
3902- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
3903- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_3))));
3904- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_4))));
3905- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id1))));
3906- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_5))));
3907+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get())));
3908+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get())));
3909+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get())));
3910+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_4.get())));
3911+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id1.get())));
3912+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_5.get())));
3913
3914 rewriter.validate_and_dispatch(*touch_1);
3915 rewriter.validate_and_dispatch(*touch_2);
3916@@ -252,10 +252,10 @@
3917 auto inserted_up_id0 = make_touch(0, mir_touch_action_up);
3918 auto inserted_down_id1 = make_touch(1, mir_touch_action_down);
3919
3920- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
3921- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_up_id0))));
3922- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_down_id1))));
3923- EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
3924+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get())));
3925+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_up_id0.get())));
3926+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id1.get())));
3927+ EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get())));
3928
3929 rewriter.validate_and_dispatch(*touch_1);
3930 rewriter.validate_and_dispatch(*touch_2);
3931
3932=== modified file 'tests/unit-tests/scene/test_application_session.cpp'
3933--- tests/unit-tests/scene/test_application_session.cpp 2016-08-10 10:43:39 +0000
3934+++ tests/unit-tests/scene/test_application_session.cpp 2016-09-18 20:00:37 +0000
3935@@ -897,14 +897,16 @@
3936 {
3937 using namespace ::testing;
3938
3939- //MirEvent* event;
3940- std::unique_ptr<MirEvent> event;
3941+ MirSurfaceOutputEvent event;
3942 bool event_received{false};
3943
3944 EXPECT_CALL(*sender, handle_event(IsSurfaceOutputEvent()))
3945 .WillOnce(Invoke([&event, &event_received](MirEvent const& ev)
3946 {
3947- event.reset(ev.clone());
3948+ if (event.type() == mir_event_type_surface_output)
3949+ {
3950+ event = *ev.to_surface_output();
3951+ }
3952 event_received = true;
3953 }));
3954
3955@@ -922,7 +924,7 @@
3956 auto surface = app_session.surface(surf_id);
3957
3958 ASSERT_TRUE(event_received);
3959- EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
3960+ EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
3961 }
3962
3963 TEST_F(ApplicationSessionSurfaceOutput, sends_correct_surface_details_to_surface)
3964@@ -931,13 +933,16 @@
3965
3966 std::array<TestOutput const*, 2> outputs{{ &high_dpi, &projector }};
3967
3968- std::array<std::unique_ptr<MirEvent>, 2> event;
3969+ std::array<MirSurfaceOutputEvent, 2> event;
3970 int events_received{0};
3971
3972 ON_CALL(*sender, handle_event(IsSurfaceOutputEvent()))
3973 .WillByDefault(Invoke([&event, &events_received](MirEvent const& ev)
3974 {
3975- event[events_received].reset(ev.clone());
3976+ if (ev.type() == mir_event_type_surface_output)
3977+ {
3978+ event[events_received] = *ev.to_surface_output();
3979+ }
3980 ++events_received;
3981 }));
3982
3983@@ -974,8 +979,8 @@
3984
3985 for (int i = 0; i < 2 ; ++i)
3986 {
3987- EXPECT_THAT(event[i]->to_surface_output()->surface_id(), Eq(ids[i].as_value()));
3988- EXPECT_THAT(event[i].get(), SurfaceOutputEventFor(*outputs[i]));
3989+ EXPECT_THAT(event[i].to_surface_output()->surface_id(), Eq(ids[i].as_value()));
3990+ EXPECT_THAT(&event[i], SurfaceOutputEventFor(*outputs[i]));
3991 }
3992 }
3993
3994@@ -985,13 +990,16 @@
3995
3996 std::array<TestOutput const*, 2> outputs{{ &projector, &high_dpi }};
3997
3998- std::unique_ptr<MirEvent> event;
3999+ MirSurfaceOutputEvent event;
4000 bool event_received{false};
4001
4002 ON_CALL(*sender, handle_event(IsSurfaceOutputEvent()))
4003 .WillByDefault(Invoke([&event, &event_received](MirEvent const& ev)
4004 {
4005- event.reset(ev.clone());
4006+ if (ev.type() == mir_event_type_surface_output)
4007+ {
4008+ event = *ev.to_surface_output();
4009+ }
4010 event_received = true;
4011 }));
4012
4013@@ -1020,8 +1028,8 @@
4014
4015 ASSERT_TRUE(event_received);
4016
4017- EXPECT_THAT(event->to_surface_output()->surface_id(), Eq(id.as_value()));
4018- EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
4019+ EXPECT_THAT(event.to_surface_output()->surface_id(), Eq(id.as_value()));
4020+ EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
4021 }
4022
4023 TEST_F(ApplicationSessionSurfaceOutput, surfaces_on_edges_get_correct_values)
4024@@ -1030,13 +1038,16 @@
4025
4026 std::array<TestOutput const*, 2> outputs{{ &projector, &high_dpi }};
4027
4028- std::unique_ptr<MirEvent> event;
4029+ MirSurfaceOutputEvent event;
4030 bool event_received{false};
4031
4032 ON_CALL(*sender, handle_event(IsSurfaceOutputEvent()))
4033 .WillByDefault(Invoke([&event, &event_received](MirEvent const& ev)
4034 {
4035- event.reset(ev.clone());
4036+ if (ev.type() == mir_event_type_surface_output)
4037+ {
4038+ event = *ev.to_surface_output();
4039+ }
4040 event_received = true;
4041 }));
4042
4043@@ -1064,21 +1075,21 @@
4044 surface->move_to({outputs[0]->width - ((surface->size().width.as_uint32_t()) / 2), 100});
4045
4046 ASSERT_TRUE(event_received);
4047- EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
4048+ EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
4049
4050 event_received = false;
4051 // This should be *just* entirely on the projector
4052 surface->move_to({outputs[0]->width - surface->size().width.as_uint32_t(), 100});
4053
4054 ASSERT_TRUE(event_received);
4055- EXPECT_THAT(event.get(), SurfaceOutputEventFor(projector));
4056+ EXPECT_THAT(&event, SurfaceOutputEventFor(projector));
4057
4058 event_received = false;
4059 // This should have a single pixel overlap on the high_dpi
4060 surface->move_to({outputs[0]->width - (surface->size().width.as_uint32_t() - 1), 100});
4061
4062 ASSERT_TRUE(event_received);
4063- EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
4064+ EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
4065 }
4066
4067 TEST_F(ApplicationSessionSurfaceOutput, sends_surface_output_event_on_move)
4068@@ -1087,14 +1098,17 @@
4069
4070 std::array<TestOutput const*, 2> outputs {{ &projector, &high_dpi }};
4071
4072- std::unique_ptr<MirEvent> event;
4073+ MirSurfaceOutputEvent event;
4074 int events_received{0};
4075
4076
4077 ON_CALL(*sender, handle_event(IsSurfaceOutputEvent()))
4078 .WillByDefault(Invoke([&event, &events_received](MirEvent const& ev)
4079 {
4080- event.reset(ev.clone());
4081+ if (ev.type() == mir_event_type_surface_output)
4082+ {
4083+ event = *ev.to_surface_output();
4084+ }
4085 events_received++;
4086 }));
4087
4088@@ -1125,8 +1139,8 @@
4089 ASSERT_THAT(events_received, Ge(1));
4090 auto events_expected = events_received + 1;
4091
4092- EXPECT_THAT(event->to_surface_output()->surface_id(), Eq(id.as_value()));
4093- EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
4094+ EXPECT_THAT(event.to_surface_output()->surface_id(), Eq(id.as_value()));
4095+ EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
4096
4097 // Now solely on the left output
4098 surface->move_to({0, 0});
4099@@ -1134,8 +1148,8 @@
4100 ASSERT_THAT(events_received, Eq(events_expected));
4101 events_expected++;
4102
4103- EXPECT_THAT(event->to_surface_output()->surface_id(), Eq(id.as_value()));
4104- EXPECT_THAT(event.get(), SurfaceOutputEventFor(projector));
4105+ EXPECT_THAT(event.to_surface_output()->surface_id(), Eq(id.as_value()));
4106+ EXPECT_THAT(&event, SurfaceOutputEventFor(projector));
4107
4108 // Now solely on the right output
4109 surface->move_to({outputs[0]->width + 100, 100});
4110@@ -1143,8 +1157,8 @@
4111 ASSERT_THAT(events_received, Eq(events_expected));
4112 events_expected++;
4113
4114- EXPECT_THAT(event->to_surface_output()->surface_id(), Eq(id.as_value()));
4115- EXPECT_THAT(event.get(), SurfaceOutputEventFor(high_dpi));
4116+ EXPECT_THAT(event.to_surface_output()->surface_id(), Eq(id.as_value()));
4117+ EXPECT_THAT(&event, SurfaceOutputEventFor(high_dpi));
4118 }
4119
4120 TEST_F(ApplicationSessionSurfaceOutput, sends_surface_output_event_on_move_only_if_changed)
4121
4122=== modified file 'tests/unit-tests/scene/test_surface.cpp'
4123--- tests/unit-tests/scene/test_surface.cpp 2016-08-24 02:09:08 +0000
4124+++ tests/unit-tests/scene/test_surface.cpp 2016-09-18 20:00:37 +0000
4125@@ -410,8 +410,8 @@
4126 mev::add_touch(*touch_event, 0, mir_touch_action_down, mir_touch_tooltype_finger, 0, 0,
4127 0, 0, 0, 0);
4128
4129- EXPECT_CALL(mock_sender, send_event(mt::MirKeyboardEventMatches(ByRef(*key_event)), _)).Times(1);
4130- EXPECT_CALL(mock_sender, send_event(mt::MirTouchEventMatches(ByRef(*touch_event)), _)).Times(1);
4131+ EXPECT_CALL(mock_sender, send_event(mt::MirKeyboardEventMatches(key_event.get()), _)).Times(1);
4132+ EXPECT_CALL(mock_sender, send_event(mt::MirTouchEventMatches(touch_event.get()), _)).Times(1);
4133
4134 surface.consume(key_event.get());
4135 surface.consume(touch_event.get());
4136
4137=== modified file 'tests/unit-tests/scene/test_surface_impl.cpp'
4138--- tests/unit-tests/scene/test_surface_impl.cpp 2016-08-24 02:09:08 +0000
4139+++ tests/unit-tests/scene/test_surface_impl.cpp 2016-09-18 20:00:37 +0000
4140@@ -166,12 +166,6 @@
4141 EXPECT_EQ(mir_surface_state_fullscreen, surface->state());
4142 }
4143
4144-bool operator==(MirEvent const& a, MirEvent const& b)
4145-{
4146- // We will always fill unused bytes with zero, so memcmp is accurate...
4147- return !memcmp(&a, &b, sizeof(MirEvent));
4148-}
4149-
4150 TEST_F(Surface, clamps_undersized_resize)
4151 {
4152 using namespace testing;
4153@@ -255,6 +249,10 @@
4154 surface->configure(mir_surface_attrib_focus, mir_surface_focused);
4155 surface->configure(mir_surface_attrib_focus, mir_surface_unfocused);
4156 }
4157+MATCHER_P(MirCloseSurfaceEventMatches, event, "")
4158+{
4159+ return arg.type() == event->type();
4160+}
4161
4162 TEST_F(Surface, emits_client_close_events)
4163 {
4164@@ -269,7 +267,7 @@
4165 MirCloseSurfaceEvent e;
4166 e.to_close_surface()->set_surface_id(stub_id.as_value());
4167
4168- EXPECT_CALL(*sink, handle_event(Eq(ByRef(e)))).Times(1);
4169+ EXPECT_CALL(*sink, handle_event(MirCloseSurfaceEventMatches(&e))).Times(1);
4170
4171 surface->request_client_surface_close();
4172 }

Subscribers

People subscribed via source and target branches