Mir

Merge lp://qastaging/~robertcarr/mir/more-event-pretty-printing into lp://qastaging/mir

Proposed by Robert Carr
Status: Work in progress
Proposed branch: lp://qastaging/~robertcarr/mir/more-event-pretty-printing
Merge into: lp://qastaging/mir
Diff against target: 195 lines (+132/-16)
1 file modified
src/client/logging/input_receiver_report.cpp (+132/-16)
To merge this branch: bzr merge lp://qastaging/~robertcarr/mir/more-event-pretty-printing
Reviewer Review Type Date Requested Status
Alan Griffiths Needs Fixing
Alexandros Frantzis (community) Needs Fixing
Review via email: mp+194765@code.qastaging.launchpad.net

Commit message

Add enumeration/flag printing to event pretty printer.

Description of the change

Add enumeration/flag printing to event pretty printer.

i.e.
===
MirMotionEvent{
  type: motion
  device_id: 1
  source_id: 8194
  action: mir_motion_action_hover_move
  flags: mir_motion_flag_window_is_obscured
  modifiers:
  edge_flags: 0
  button_state:
  x_offset: 0
  y_offset: 0
  x_precision: 1
  y_precision: 1
  down_time: 0
  event_time: 1384211437272475834
  pointer_count: 1
  pointer[0]{
    id: 0
    raw_x: 2
    raw_y: 2
    x: 2
    y: 2
    touch_minor: 0
    size: 0
    pressure: 0
    orientation: 0
    vscroll: 0
    hscroll: 0
  }
}
===

To post a comment you must log in.
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

8 +static std::string format_key_action(MirKeyAction action)
... and others

No need for static, we are defining these inside an anonymous namespace.
(I know that existing functions there are already static, but I'd rather we fixed them than pollute all the new functions).

23 + static std::tuple<MirKeyFlag, char const*> key_flag_strings[] = {
... and others

Could be const.

36 + for (unsigned int i = 0; i < sizeof(key_flag_strings)/sizeof(*key_flag_strings); i++) {
... and others

for (auto const& key_flag_string : key_flag_strings)
{
}

review: Needs Fixing
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :
Download full text (3.6 KiB)

19 +static std::string format_key_flags(MirKeyFlag flags)
20 +{
21 + std::stringstream ss;
22 +
23 + static std::tuple<MirKeyFlag, char const*> key_flag_strings[] = {
24 + std::make_tuple(mir_key_flag_woke_here, "mir_key_flag_woke_here"),
25 + std::make_tuple(mir_key_flag_soft_keyboard, "mir_key_flag_soft_keyboard"),
26 + std::make_tuple(mir_key_flag_keep_touch_mode, "mir_key_flag_keep_touch_mode"),
27 + std::make_tuple(mir_key_flag_from_system, "mir_key_flag_from_system"),
28 + std::make_tuple(mir_key_flag_editor_action, "mir_key_flag_editor_action"),
29 + std::make_tuple(mir_key_flag_canceled, "mir_key_flag_canceled"),
30 + std::make_tuple(mir_key_flag_virtual_hard_key, "mir_key_flag_virtual_hard_key"),
31 + std::make_tuple(mir_key_flag_long_press, "mir_key_flag_long_press"),
32 + std::make_tuple(mir_key_flag_canceled_long_press, "mir_key_flag_canceled_long_press"),
33 + std::make_tuple(mir_key_flag_tracking, "mir_key_flag_tracking"),
34 + std::make_tuple(mir_key_flag_fallback, "mir_key_flag_fallback")
35 + };
36 + for (unsigned int i = 0; i < sizeof(key_flag_strings)/sizeof(*key_flag_strings); i++) {
37 + auto flag = std::get<0>(key_flag_strings[i]);
38 + auto const& str = std::get<1>(key_flag_strings[i]);
39 + if (flags & flag)
40 + ss << str << " ";
41 + }
42 + return ss.str();
43 +}

This (and similar code) looks unnecessarily hard to parse. C.f.

static std::string format_key_flags(MirKeyFlag flags)
{
    static struct { MirKeyFlag flag; char const* str; } const key_flag_strings[] = {
        { mir_key_flag_woke_here, "mir_key_flag_woke_here" },
        { mir_key_flag_soft_keyboard, "mir_key_flag_soft_keyboard" },
        { mir_key_flag_keep_touch_mode, "mir_key_flag_keep_touch_mode" },
        { mir_key_flag_from_system, "mir_key_flag_from_system" },
        { mir_key_flag_editor_action, "mir_key_flag_editor_action" },
        { mir_key_flag_canceled, "mir_key_flag_canceled" },
        { mir_key_flag_virtual_hard_key, "mir_key_flag_virtual_hard_key" },
        { mir_key_flag_long_press, "mir_key_flag_long_press" },
        { mir_key_flag_canceled_long_press, "mir_key_flag_canceled_long_press" },
        { mir_key_flag_tracking, "mir_key_flag_tracking" },
        { mir_key_flag_fallback, "mir_key_flag_fallback" }
    };

    std::stringstream ss;
    for (auto key_flag_string = std::begin(key_flag_strings); key_flag_string != std::end(key_flag_strings); ++key_flag_string)
    {
        if (flags & key_flag_string->flag)
            ss << key_flag_string->str << " ";
    }
    return ss.str();
}

or

std::string format_key_flags(MirKeyFlag flags)
{
    struct Entry { MirKeyFlag flag; char const* str; };

    static auto const key_flag_strings = {
        Entry{ mir_key_flag_woke_here, "mir_key_flag_woke_here" },
        Entry{ mir_key_flag_soft_keyboard, "mir_key_flag_soft_keyboard" },
        Entry{ mir_key_flag_keep_touch_mode, "mir_key_flag_keep_touch_mode" },
        Entry{ mir_key_flag_from_system, "mir_key_flag_from_system" },
        Entry{ mir_key_flag_editor_action, "mir_key_flag_editor_action" },
        Entry{ mir_key_flag_canceled, "mir_key_flag_canceled" },
        Entry{ mir_key_flag_virtual_hard_key, "mir_key_flag_virtual...

Read more...

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

8 +static std::string format_key_action(MirKeyAction action)
9 +{
10 + std::stringstream ss;
11 +
12 + static std::string key_action_strings[] = { "mir_key_action_down", "mir_key_action_up",
13 + "mir_key_action_multiple" };
14 + ss << key_action_strings[action];
15 +
16 + return ss.str();
17 +}

C.f.

char const* format_key_action(MirKeyAction action)
{
    static char const* const key_action_strings[] =
    {
        "mir_key_action_down",
        "mir_key_action_up",
        "mir_key_action_multiple"
    };

    return key_action_strings[action];
}

review: Needs Fixing
1213. By Robert Carr

Restore closing } to serialized event

Revision history for this message
Robert Carr (robertcarr) wrote :

Sorry to waste time...this was kind of a a careless how fast can I do this with an emacs macro while mir builds on my phone kind of situation ;)

Cleaned things up.

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

Nit:

167 - for (unsigned int i = 0; i < ev.pointer_count; i++)
168 - {
169 + for (unsigned int i = 0; i < ev.pointer_count; i++) {

(and elsewhere) that's not our brace style.

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

I still think there's a lot of unnecessary creation of strings that are later copied to the output stream.

It isn't hard to copy them directly. E.g.

inline std::ostream& operator<<(std::ostream& o, std::function<std::ostream&(std::ostream&)> const& f)
{
    return f(o);
}

std::function<std::ostream&(std::ostream&)> format_key_flags(MirKeyFlag flags)
{
    static struct { MirKeyFlag flag; char const* str; } const key_flag_strings[] = {
        { mir_key_flag_woke_here, "mir_key_flag_woke_here" },
        { mir_key_flag_soft_keyboard, "mir_key_flag_soft_keyboard" },
        { mir_key_flag_keep_touch_mode, "mir_key_flag_keep_touch_mode" },
        { mir_key_flag_from_system, "mir_key_flag_from_system" },
        { mir_key_flag_editor_action, "mir_key_flag_editor_action" },
        { mir_key_flag_canceled, "mir_key_flag_canceled" },
        { mir_key_flag_virtual_hard_key, "mir_key_flag_virtual_hard_key" },
        { mir_key_flag_long_press, "mir_key_flag_long_press" },
        { mir_key_flag_canceled_long_press, "mir_key_flag_canceled_long_press" },
        { mir_key_flag_tracking, "mir_key_flag_tracking" },
        { mir_key_flag_fallback, "mir_key_flag_fallback" }
    };

    return [&](std::ostream& ss) -> std::ostream&
    {
        for (auto const& entry : key_flag_strings)
        {
            if (flags & entry.flag)
                ss << entry.str << " ";
        }
        return ss;
    };
}

And, of course, https://code.launchpad.net/~robertcarr/mir/more-event-pretty-printing/+merge/194765/comments/449812 is still not addressed

Unmerged revisions

1213. By Robert Carr

Restore closing } to serialized event

1212. By Robert Carr

Improve client input report

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches