blob: 4dfc84dc5dd8cade0a6f1d3bffba13cc2b043ebc [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
17#include "config_write.h"
18#include "logger.h"
19
Tom Cherry2d9779e2019-02-08 11:46:19 -080020struct listnode __android_log_transport_write = {&__android_log_transport_write,
21 &__android_log_transport_write};
22struct listnode __android_log_persist_write = {&__android_log_persist_write,
23 &__android_log_persist_write};
Mark Salyzynfacf94c2016-03-01 13:45:42 -080024
Tom Cherry71ba1642019-01-10 10:37:36 -080025static void __android_log_add_transport(struct listnode* list,
26 struct android_log_transport_write* transport) {
27 uint32_t i;
Mark Salyzynfacf94c2016-03-01 13:45:42 -080028
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080029 /* Try to keep one functioning transport for each log buffer id */
30 for (i = LOG_ID_MIN; i < LOG_ID_MAX; i++) {
31 struct android_log_transport_write* transp;
Mark Salyzynfacf94c2016-03-01 13:45:42 -080032
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080033 if (list_empty(list)) {
Tom Cherry71ba1642019-01-10 10:37:36 -080034 if (!transport->available || ((*transport->available)(static_cast<log_id_t>(i)) >= 0)) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080035 list_add_tail(list, &transport->node);
36 return;
37 }
38 } else {
39 write_transport_for_each(transp, list) {
40 if (!transp->available) {
41 return;
Mark Salyzynfacf94c2016-03-01 13:45:42 -080042 }
Tom Cherry71ba1642019-01-10 10:37:36 -080043 if (((*transp->available)(static_cast<log_id_t>(i)) < 0) &&
44 (!transport->available || ((*transport->available)(static_cast<log_id_t>(i)) >= 0))) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080045 list_add_tail(list, &transport->node);
46 return;
47 }
48 }
Mark Salyzynfacf94c2016-03-01 13:45:42 -080049 }
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080050 }
Mark Salyzynfacf94c2016-03-01 13:45:42 -080051}
52
Tom Cherry2d9779e2019-02-08 11:46:19 -080053void __android_log_config_write() {
Mark Salyzynfacf94c2016-03-01 13:45:42 -080054#if (FAKE_LOG_DEVICE == 0)
Tom Cherry9d350342019-09-30 15:17:21 -070055 extern struct android_log_transport_write logdLoggerWrite;
56 extern struct android_log_transport_write pmsgLoggerWrite;
Mark Salyzynfacf94c2016-03-01 13:45:42 -080057
Tom Cherry9d350342019-09-30 15:17:21 -070058 __android_log_add_transport(&__android_log_transport_write, &logdLoggerWrite);
59 __android_log_add_transport(&__android_log_persist_write, &pmsgLoggerWrite);
Mark Salyzynfacf94c2016-03-01 13:45:42 -080060#else
Tom Cherry9d350342019-09-30 15:17:21 -070061 extern struct android_log_transport_write fakeLoggerWrite;
Mark Salyzynfacf94c2016-03-01 13:45:42 -080062
Tom Cherry9d350342019-09-30 15:17:21 -070063 __android_log_add_transport(&__android_log_transport_write, &fakeLoggerWrite);
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_write_close() {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080068 struct android_log_transport_write* transport;
69 struct listnode* n;
Mark Salyzyn96432fc2016-03-08 16:18:26 -080070
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080071 write_transport_for_each_safe(transport, n, &__android_log_transport_write) {
72 transport->logMask = 0;
73 list_remove(&transport->node);
74 }
75 write_transport_for_each_safe(transport, n, &__android_log_persist_write) {
76 transport->logMask = 0;
77 list_remove(&transport->node);
78 }
Mark Salyzyn96432fc2016-03-08 16:18:26 -080079}