~ubuntu-branches/ubuntu/utopic/mir/utopic-proposed

« back to all changes in this revision

Viewing changes to src/server/logging/input_report.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-03-10 19:28:46 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: package-import@ubuntu.com-20140310192846-rq9qm3ec26yrelo2
Tags: upstream-0.1.6+14.04.20140310
Import upstream version 0.1.6+14.04.20140310

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2013 Canonical Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17
 
 */
18
 
 
19
 
#include "mir/logging/input_report.h"
20
 
#include "mir/logging/logger.h"
21
 
#include "mir/logging/input_timestamp.h"
22
 
 
23
 
#include "std/MirLog.h"
24
 
#include <std/Log.h>
25
 
 
26
 
 
27
 
#include <sstream>
28
 
#include <cstring>
29
 
#include <mutex>
30
 
 
31
 
namespace ml = mir::logging;
32
 
namespace mlil = mir::logging::legacy_input_report;
33
 
 
34
 
namespace
35
 
{
36
 
char const* const component = "android-input";
37
 
 
38
 
class LegacyInputReport;
39
 
 
40
 
std::mutex mutex;
41
 
std::shared_ptr<LegacyInputReport> the_legacy_input_report;
42
 
 
43
 
class LegacyInputReport
44
 
{
45
 
public:
46
 
    LegacyInputReport(std::shared_ptr<ml::Logger> const& logger) :
47
 
        logger(logger)
48
 
    {
49
 
    }
50
 
 
51
 
    void log(int prio, char const* buffer)
52
 
    {
53
 
        switch (prio)
54
 
        {
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);
60
 
            break;
61
 
 
62
 
        case ANDROID_LOG_INFO:
63
 
            logger->log(ml::Logger::informational, buffer, component);
64
 
            break;
65
 
 
66
 
        case ANDROID_LOG_WARN:
67
 
            logger->log(ml::Logger::warning, buffer, component);
68
 
            break;
69
 
 
70
 
        case ANDROID_LOG_ERROR:
71
 
            logger->log(ml::Logger::error, buffer, component);
72
 
        };
73
 
    }
74
 
 
75
 
private:
76
 
    std::shared_ptr<ml::Logger> const logger;
77
 
};
78
 
 
79
 
void my_write_to_log(int prio, char const* buffer)
80
 
{
81
 
    std::unique_lock<std::mutex> lock(mutex);
82
 
    the_legacy_input_report->log(prio, buffer);
83
 
}
84
 
}
85
 
 
86
 
 
87
 
void mlil::initialize(std::shared_ptr<Logger> const& logger)
88
 
{
89
 
    std::unique_lock<std::mutex> lock(mutex);
90
 
    ::the_legacy_input_report = std::make_shared<LegacyInputReport>(logger);
91
 
 
92
 
    mir::write_to_log = my_write_to_log;
93
 
}
94
 
 
95
 
 
96
 
ml::InputReport::InputReport(const std::shared_ptr<Logger>& logger)
97
 
    : logger(logger)
98
 
{
99
 
}
100
 
 
101
 
const char* ml::InputReport::component()
102
 
{
103
 
    static const char* s = "input";
104
 
    return s;
105
 
}
106
 
 
107
 
void ml::InputReport::received_event_from_kernel(int64_t when, int type, int code, int value)
108
 
{
109
 
    std::stringstream ss;
110
 
 
111
 
    ss << "Received event"
112
 
       << " time=" << ml::input_timestamp(when)
113
 
       << " type=" << type
114
 
       << " code=" << code
115
 
       << " value=" << value;
116
 
 
117
 
    logger->log(Logger::informational, ss.str(), component());
118
 
}
119
 
 
120
 
void ml::InputReport::published_key_event(int dest_fd, uint32_t seq_id, int64_t event_time)
121
 
{
122
 
    std::stringstream ss;
123
 
 
124
 
    ss << "Published key event"
125
 
       << " seq_id=" << seq_id
126
 
       << " time=" << ml::input_timestamp(event_time)
127
 
       << " dest_fd=" << dest_fd;
128
 
 
129
 
    logger->log(Logger::informational, ss.str(), component());
130
 
}
131
 
 
132
 
void ml::InputReport::published_motion_event(int dest_fd, uint32_t seq_id, int64_t event_time)
133
 
{
134
 
    std::stringstream ss;
135
 
 
136
 
    ss << "Published motion event"
137
 
       << " seq_id=" << seq_id
138
 
       << " time=" << ml::input_timestamp(event_time)
139
 
       << " dest_fd=" << dest_fd;
140
 
 
141
 
    logger->log(Logger::informational, ss.str(), component());
142
 
}
143
 
 
144
 
void ml::InputReport::received_event_finished_signal(int src_fd, uint32_t seq_id)
145
 
{
146
 
    std::stringstream ss;
147
 
 
148
 
    ss << "Received event finished"
149
 
       << " seq_id=" << seq_id
150
 
       << " src_fd=" << src_fd;
151
 
 
152
 
    logger->log(Logger::informational, ss.str(), component());
153
 
}