]> sigrok.org Git - pulseview.git/blame - android/loghandler.cpp
Installer: Update icon cache also after uninstallation
[pulseview.git] / android / loghandler.cpp
CommitLineData
9137928c
MC
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2014 Marcus Comstedt <marcus@mc.pp.se>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifdef ENABLE_DECODE
21#include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
22#endif
23
24#include <android/log.h>
25
26#include <stdint.h>
27#include <libsigrok/libsigrok.h>
28
2acdb232 29#include "android/loghandler.hpp"
9137928c
MC
30
31namespace pv {
32
33int AndroidLogHandler::sr_callback(void *cb_data, int loglevel, const char *format, va_list args)
34{
35 static const int prio[] = {
36 [SR_LOG_NONE] = ANDROID_LOG_SILENT,
37 [SR_LOG_ERR] = ANDROID_LOG_ERROR,
38 [SR_LOG_WARN] = ANDROID_LOG_WARN,
39 [SR_LOG_INFO] = ANDROID_LOG_INFO,
40 [SR_LOG_DBG] = ANDROID_LOG_DEBUG,
41 [SR_LOG_SPEW] = ANDROID_LOG_VERBOSE,
42 };
43 int ret;
44
45 /* This specific log callback doesn't need the void pointer data. */
46 (void)cb_data;
47
48 /* Only output messages of at least the selected loglevel(s). */
49 if (loglevel > sr_log_loglevel_get())
1c90d94f 50 return SR_OK;
9137928c
MC
51
52 if (loglevel < SR_LOG_NONE)
1c90d94f 53 loglevel = SR_LOG_NONE;
9137928c 54 else if (loglevel > SR_LOG_SPEW)
1c90d94f 55 loglevel = SR_LOG_SPEW;
9137928c
MC
56
57 ret = __android_log_vprint(prio[loglevel], "sr", format, args);
58
59 return ret;
60}
61
62int AndroidLogHandler::srd_callback(void *cb_data, int loglevel, const char *format, va_list args)
63{
64#ifdef ENABLE_DECODE
65 static const int prio[] = {
66 [SRD_LOG_NONE] = ANDROID_LOG_SILENT,
67 [SRD_LOG_ERR] = ANDROID_LOG_ERROR,
68 [SRD_LOG_WARN] = ANDROID_LOG_WARN,
69 [SRD_LOG_INFO] = ANDROID_LOG_INFO,
70 [SRD_LOG_DBG] = ANDROID_LOG_DEBUG,
71 [SRD_LOG_SPEW] = ANDROID_LOG_VERBOSE,
72 };
73 int ret;
74
75 /* This specific log callback doesn't need the void pointer data. */
76 (void)cb_data;
77
78 /* Only output messages of at least the selected loglevel(s). */
79 if (loglevel > srd_log_loglevel_get())
1c90d94f 80 return SRD_OK;
9137928c
MC
81
82 if (loglevel < SRD_LOG_NONE)
1c90d94f 83 loglevel = SRD_LOG_NONE;
9137928c 84 else if (loglevel > SRD_LOG_SPEW)
1c90d94f 85 loglevel = SRD_LOG_SPEW;
9137928c
MC
86
87 ret = __android_log_vprint(prio[loglevel], "srd", format, args);
88
89 return ret;
90#else
91 return 0;
92#endif
93}
94
95void AndroidLogHandler::install_callbacks()
96{
4c60462b 97 sr_log_callback_set(sr_callback, nullptr);
9137928c 98#ifdef ENABLE_DECODE
4c60462b 99 srd_log_callback_set(srd_callback, nullptr);
9137928c
MC
100#endif
101}
102
103} // namespace pv