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 static sr_log_callback prev_sr_log_cb
;
34 static void *prev_sr_log_cb_data
;
37 static srd_log_callback prev_srd_log_cb
;
38 static void *prev_srd_log_cb_data
;
41 int AndroidLogHandler::sr_callback(void *cb_data
, int loglevel
, const char *format
, va_list args
)
43 static const int prio
[] = {
44 [SR_LOG_NONE
] = ANDROID_LOG_SILENT
,
45 [SR_LOG_ERR
] = ANDROID_LOG_ERROR
,
46 [SR_LOG_WARN
] = ANDROID_LOG_WARN
,
47 [SR_LOG_INFO
] = ANDROID_LOG_INFO
,
48 [SR_LOG_DBG
] = ANDROID_LOG_DEBUG
,
49 [SR_LOG_SPEW
] = ANDROID_LOG_VERBOSE
,
54 /* This specific log callback doesn't need the void pointer data. */
57 /* Call the previously registered log callback (library's default). */
60 prev_sr_log_cb(prev_sr_log_cb_data
, loglevel
, format
, args2
);
63 /* Only output messages of at least the selected loglevel(s). */
64 if (loglevel
> sr_log_loglevel_get())
67 if (loglevel
< SR_LOG_NONE
)
68 loglevel
= SR_LOG_NONE
;
69 else if (loglevel
> SR_LOG_SPEW
)
70 loglevel
= SR_LOG_SPEW
;
72 ret
= __android_log_vprint(prio
[loglevel
], "sr", format
, args
);
77 int AndroidLogHandler::srd_callback(void *cb_data
, int loglevel
, const char *format
, va_list args
)
80 static const int prio
[] = {
81 [SRD_LOG_NONE
] = ANDROID_LOG_SILENT
,
82 [SRD_LOG_ERR
] = ANDROID_LOG_ERROR
,
83 [SRD_LOG_WARN
] = ANDROID_LOG_WARN
,
84 [SRD_LOG_INFO
] = ANDROID_LOG_INFO
,
85 [SRD_LOG_DBG
] = ANDROID_LOG_DEBUG
,
86 [SRD_LOG_SPEW
] = ANDROID_LOG_VERBOSE
,
91 /* This specific log callback doesn't need the void pointer data. */
94 /* Call the previously registered log callback (library's default). */
97 prev_srd_log_cb(prev_srd_log_cb_data
, loglevel
, format
, args2
);
100 /* Only output messages of at least the selected loglevel(s). */
101 if (loglevel
> srd_log_loglevel_get())
104 if (loglevel
< SRD_LOG_NONE
)
105 loglevel
= SRD_LOG_NONE
;
106 else if (loglevel
> SRD_LOG_SPEW
)
107 loglevel
= SRD_LOG_SPEW
;
109 ret
= __android_log_vprint(prio
[loglevel
], "srd", format
, args
);
117 void AndroidLogHandler::install_callbacks()
119 sr_log_callback_get(&prev_sr_log_cb
, &prev_sr_log_cb_data
);
120 sr_log_callback_set(sr_callback
, nullptr);
122 srd_log_callback_get(&prev_srd_log_cb
, &prev_srd_log_cb_data
);
123 srd_log_callback_set(srd_callback
, nullptr);