blob: 3139f7828a6adbdb619caf56f90c0ff9bcc8f09f [file] [log] [blame]
Mark Salyzynfacf94c2016-03-01 13:45:42 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mark Salyzyn81321a72017-03-09 07:28:29 -080017#include <log/log_transport.h>
Mark Salyzyn71002882016-03-08 16:18:26 -080018
Mark Salyzynfacf94c2016-03-01 13:45:42 -080019#include "config_read.h"
20#include "logger.h"
21
Tom Cherry2d9779e2019-02-08 11:46:19 -080022struct listnode __android_log_transport_read = {&__android_log_transport_read,
23 &__android_log_transport_read};
24struct listnode __android_log_persist_read = {&__android_log_persist_read,
25 &__android_log_persist_read};
Mark Salyzynfacf94c2016-03-01 13:45:42 -080026
Tom Cherry71ba1642019-01-10 10:37:36 -080027static void __android_log_add_transport(struct listnode* list,
28 struct android_log_transport_read* transport) {
29 uint32_t i;
Mark Salyzynfacf94c2016-03-01 13:45:42 -080030
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080031 /* Try to keep one functioning transport for each log buffer id */
32 for (i = LOG_ID_MIN; i < LOG_ID_MAX; i++) {
33 struct android_log_transport_read* transp;
Mark Salyzynfacf94c2016-03-01 13:45:42 -080034
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080035 if (list_empty(list)) {
Tom Cherry71ba1642019-01-10 10:37:36 -080036 if (!transport->available || ((*transport->available)(static_cast<log_id_t>(i)) >= 0)) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080037 list_add_tail(list, &transport->node);
38 return;
39 }
40 } else {
41 read_transport_for_each(transp, list) {
42 if (!transp->available) {
43 return;
Mark Salyzynfacf94c2016-03-01 13:45:42 -080044 }
Tom Cherry71ba1642019-01-10 10:37:36 -080045 if (((*transp->available)(static_cast<log_id_t>(i)) < 0) &&
46 (!transport->available || ((*transport->available)(static_cast<log_id_t>(i)) >= 0))) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080047 list_add_tail(list, &transport->node);
48 return;
49 }
50 }
Mark Salyzynfacf94c2016-03-01 13:45:42 -080051 }
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080052 }
Mark Salyzynfacf94c2016-03-01 13:45:42 -080053}
54
Tom Cherry2d9779e2019-02-08 11:46:19 -080055void __android_log_config_read() {
Mark Salyzyn71002882016-03-08 16:18:26 -080056#if (FAKE_LOG_DEVICE == 0)
Tom Cherry71ba1642019-01-10 10:37:36 -080057 if ((__android_log_transport == LOGGER_DEFAULT) || (__android_log_transport & LOGGER_LOGD)) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080058 extern struct android_log_transport_read logdLoggerRead;
59 extern struct android_log_transport_read pmsgLoggerRead;
Mark Salyzyn71002882016-03-08 16:18:26 -080060
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080061 __android_log_add_transport(&__android_log_transport_read, &logdLoggerRead);
62 __android_log_add_transport(&__android_log_persist_read, &pmsgLoggerRead);
63 }
Mark Salyzynfacf94c2016-03-01 13:45:42 -080064#endif
65}
Mark Salyzyn96432fc2016-03-08 16:18:26 -080066
Tom Cherry2d9779e2019-02-08 11:46:19 -080067void __android_log_config_read_close() {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080068 struct android_log_transport_read* transport;
69 struct listnode* n;
Mark Salyzyn96432fc2016-03-08 16:18:26 -080070
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080071 read_transport_for_each_safe(transport, n, &__android_log_transport_read) {
72 list_remove(&transport->node);
73 }
74 read_transport_for_each_safe(transport, n, &__android_log_persist_read) {
75 list_remove(&transport->node);
76 }
Mark Salyzyn96432fc2016-03-08 16:18:26 -080077}