~mir-team/mir/in-process-egl+input-conglomeration

« back to all changes in this revision

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

Merged trunk and fixed issues

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
 
 
22
#include "std/MirLog.h"
 
23
#include <std/Log.h>
 
24
 
 
25
#include <mutex>
 
26
 
 
27
namespace ml = mir::logging;
 
28
namespace mli = mir::logging::input_report;
 
29
 
 
30
namespace
 
31
{
 
32
char const* const component = "android-input";
 
33
 
 
34
class MyInputReport;
 
35
 
 
36
std::mutex mutex;
 
37
std::shared_ptr<MyInputReport> the_input_report;
 
38
 
 
39
class MyInputReport
 
40
{
 
41
public:
 
42
    MyInputReport(std::shared_ptr<ml::Logger> const& logger) :
 
43
        logger(logger)
 
44
    {
 
45
    }
 
46
 
 
47
    void log(int prio, char const* buffer)
 
48
    {
 
49
        switch (prio)
 
50
        {
 
51
        case ANDROID_LOG_UNKNOWN:
 
52
        case ANDROID_LOG_DEFAULT:
 
53
        case ANDROID_LOG_VERBOSE:
 
54
        case ANDROID_LOG_DEBUG:
 
55
            logger->log<ml::Logger::debug>(buffer, component);
 
56
            break;
 
57
 
 
58
        case ANDROID_LOG_INFO:
 
59
            logger->log<ml::Logger::informational>(buffer, component);
 
60
            break;
 
61
 
 
62
        case ANDROID_LOG_WARN:
 
63
            logger->log<ml::Logger::warning>(buffer, component);
 
64
            break;
 
65
 
 
66
        case ANDROID_LOG_ERROR:
 
67
            logger->log<ml::Logger::error>(buffer, component);
 
68
        };
 
69
    }
 
70
 
 
71
private:
 
72
    std::shared_ptr<ml::Logger> const logger;
 
73
};
 
74
 
 
75
void my_write_to_log(int prio, char const* buffer)
 
76
{
 
77
    std::unique_lock<std::mutex> lock(mutex);
 
78
    the_input_report->log(prio, buffer);
 
79
}
 
80
}
 
81
 
 
82
 
 
83
void mli::initialize(std::shared_ptr<Logger> const& logger)
 
84
{
 
85
    std::unique_lock<std::mutex> lock(mutex);
 
86
    ::the_input_report = std::make_shared<MyInputReport>(logger);
 
87
 
 
88
    mir::write_to_log = my_write_to_log;
 
89
}