2
* Copyright © 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Alan Griffiths <alan@octopull.co.uk>
19
#include "mir/logging/input_report.h"
20
#include "mir/logging/logger.h"
21
#include "mir/logging/input_timestamp.h"
23
#include "std/MirLog.h"
31
namespace ml = mir::logging;
32
namespace mlil = mir::logging::legacy_input_report;
36
char const* const component = "android-input";
38
class LegacyInputReport;
41
std::shared_ptr<LegacyInputReport> the_legacy_input_report;
43
class LegacyInputReport
46
LegacyInputReport(std::shared_ptr<ml::Logger> const& logger) :
51
void log(int prio, char const* buffer)
55
case ANDROID_LOG_UNKNOWN:
56
case ANDROID_LOG_DEFAULT:
57
case ANDROID_LOG_VERBOSE:
58
case ANDROID_LOG_DEBUG:
59
logger->log(ml::Logger::debug, buffer, component);
62
case ANDROID_LOG_INFO:
63
logger->log(ml::Logger::informational, buffer, component);
66
case ANDROID_LOG_WARN:
67
logger->log(ml::Logger::warning, buffer, component);
70
case ANDROID_LOG_ERROR:
71
logger->log(ml::Logger::error, buffer, component);
76
std::shared_ptr<ml::Logger> const logger;
79
void my_write_to_log(int prio, char const* buffer)
81
std::unique_lock<std::mutex> lock(mutex);
82
the_legacy_input_report->log(prio, buffer);
87
void mlil::initialize(std::shared_ptr<Logger> const& logger)
89
std::unique_lock<std::mutex> lock(mutex);
90
::the_legacy_input_report = std::make_shared<LegacyInputReport>(logger);
92
mir::write_to_log = my_write_to_log;
96
ml::InputReport::InputReport(const std::shared_ptr<Logger>& logger)
101
const char* ml::InputReport::component()
103
static const char* s = "input";
107
void ml::InputReport::received_event_from_kernel(int64_t when, int type, int code, int value)
109
std::stringstream ss;
111
ss << "Received event"
112
<< " time=" << ml::input_timestamp(when)
115
<< " value=" << value;
117
logger->log(Logger::informational, ss.str(), component());
120
void ml::InputReport::published_key_event(int dest_fd, uint32_t seq_id, int64_t event_time)
122
std::stringstream ss;
124
ss << "Published key event"
125
<< " seq_id=" << seq_id
126
<< " time=" << ml::input_timestamp(event_time)
127
<< " dest_fd=" << dest_fd;
129
logger->log(Logger::informational, ss.str(), component());
132
void ml::InputReport::published_motion_event(int dest_fd, uint32_t seq_id, int64_t event_time)
134
std::stringstream ss;
136
ss << "Published motion event"
137
<< " seq_id=" << seq_id
138
<< " time=" << ml::input_timestamp(event_time)
139
<< " dest_fd=" << dest_fd;
141
logger->log(Logger::informational, ss.str(), component());
144
void ml::InputReport::received_event_finished_signal(int src_fd, uint32_t seq_id)
146
std::stringstream ss;
148
ss << "Received event finished"
149
<< " seq_id=" << seq_id
150
<< " src_fd=" << src_fd;
152
logger->log(Logger::informational, ss.str(), component());