Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / events / ozone / evdev / touch_evdev_debug_buffer.cc
blob363c3183e05049fe2c1f5f1f5640edad8cb9aabe
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/events/ozone/evdev/touch_evdev_debug_buffer.h"
7 #include <stdio.h>
9 #include "base/files/file.h"
10 #include "base/files/file_util.h"
11 #include "base/logging.h"
12 #include "base/strings/stringprintf.h"
13 #include "ui/events/ozone/evdev/event_device_info.h"
15 using base::File;
17 namespace ui {
19 TouchEventLogEvdev::TouchEventLogEvdev()
20 : logged_events_(new TouchEvent[kDebugBufferSize]) {
23 TouchEventLogEvdev::~TouchEventLogEvdev() {
26 void TouchEventLogEvdev::Initialize(const EventDeviceInfo& devinfo) {
27 device_name_ = devinfo.name();
28 for (int code = ABS_X; code <= ABS_MAX; code++) {
29 if (devinfo.HasAbsEvent(code)) {
30 axes_.push_back(AbsAxisData(code, devinfo.GetAbsInfoByCode(code)));
35 void TouchEventLogEvdev::ProcessEvent(size_t cur_slot, const input_event* ev) {
36 if (ev->type == EV_ABS || ev->type == EV_SYN ||
37 (ev->type == EV_KEY && ev->code == BTN_TOUCH)) {
38 logged_events_[debug_buffer_tail_].ev = *ev;
39 logged_events_[debug_buffer_tail_].slot = cur_slot;
40 debug_buffer_tail_++;
41 debug_buffer_tail_ %= kDebugBufferSize;
45 void TouchEventLogEvdev::DumpLog(const char* filename) {
46 base::FilePath fp = base::FilePath(filename);
47 File file(fp, File::FLAG_CREATE | File::FLAG_WRITE);
48 std::string report_content("");
49 std::string device_name_str =
50 base::StringPrintf("# device: %s\n", device_name_.c_str());
51 report_content += device_name_str;
52 for (size_t i = 0; i < axes_.size(); ++i) {
53 std::string absinfo = base::StringPrintf(
54 "# absinfo: %d %d %d %d %d %d\n", axes_[i].code, axes_[i].info.maximum,
55 axes_[i].info.maximum, axes_[i].info.fuzz, axes_[i].info.flat,
56 axes_[i].info.resolution);
57 report_content += absinfo;
59 for (int i = 0; i < kDebugBufferSize; ++i) {
60 struct TouchEvent* te =
61 &logged_events_[(debug_buffer_tail_ + i) % kDebugBufferSize];
62 if (te->ev.time.tv_sec == 0 && te->ev.time.tv_usec == 0)
63 continue;
64 std::string event_string = base::StringPrintf(
65 "E: %ld.%06ld %04x %04x %d %d\n", te->ev.time.tv_sec,
66 te->ev.time.tv_usec, te->ev.type, te->ev.code, te->ev.value, te->slot);
67 report_content += event_string;
69 file.Write(0, report_content.c_str(), report_content.length());
72 TouchEventLogEvdev::AbsAxisData::AbsAxisData(int code,
73 const input_absinfo& info)
74 : code(code), info(info) {
77 TouchEventLogEvdev::AbsAxisData::AbsAxisData(const AbsAxisData& other) =
78 default;
80 TouchEventLogEvdev::AbsAxisData::~AbsAxisData() {
83 } // namespace ui