2 * This file is part of the PulseView project.
4 * Copyright (C) 2014 Marcus Comstedt <marcus@mc.pp.se>
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.
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.
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/>.
21 #include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
24 #include <android/log.h>
27 #include <libsigrok/libsigrok.h>
29 #include "android/loghandler.hpp"
33 int AndroidLogHandler::sr_callback(void *cb_data, int loglevel, const char *format, va_list args)
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,
45 /* This specific log callback doesn't need the void pointer data. */
48 /* Only output messages of at least the selected loglevel(s). */
49 if (loglevel > sr_log_loglevel_get())
52 if (loglevel < SR_LOG_NONE)
53 loglevel = SR_LOG_NONE;
54 else if (loglevel > SR_LOG_SPEW)
55 loglevel = SR_LOG_SPEW;
57 ret = __android_log_vprint(prio[loglevel], "sr", format, args);
62 int AndroidLogHandler::srd_callback(void *cb_data, int loglevel, const char *format, va_list args)
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,
75 /* This specific log callback doesn't need the void pointer data. */
78 /* Only output messages of at least the selected loglevel(s). */
79 if (loglevel > srd_log_loglevel_get())
82 if (loglevel < SRD_LOG_NONE)
83 loglevel = SRD_LOG_NONE;
84 else if (loglevel > SRD_LOG_SPEW)
85 loglevel = SRD_LOG_SPEW;
87 ret = __android_log_vprint(prio[loglevel], "srd", format, args);
95 void AndroidLogHandler::install_callbacks()
97 sr_log_callback_set(sr_callback, NULL);
99 srd_log_callback_set(srd_callback, NULL);