blob: 0aaaea6e48537a1cc2c065f92baae6ae5f903cac [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
20LIBLOG_HIDDEN struct listnode __android_log_transport_write =
21 { &__android_log_transport_write, &__android_log_transport_write };
22LIBLOG_HIDDEN struct listnode __android_log_persist_write =
23 { &__android_log_persist_write, &__android_log_persist_write};
24
25static void __android_log_add_transport(
26 struct listnode *list, struct android_log_transport_write *transport) {
27 size_t i;
28
29 /* 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;
32
33 if (list_empty(list)) {
34 if (!transport->available || ((*transport->available)(i) >= 0)) {
35 list_add_tail(list, &transport->node);
36 return;
37 }
38 } else {
39 write_transport_for_each(transp, list) {
40 if (!transp->available) {
41 return;
42 }
43 if (((*transp->available)(i) < 0) &&
44 (!transport->available ||
45 ((*transport->available)(i) >= 0))) {
46 list_add_tail(list, &transport->node);
47 return;
48 }
49 }
50 }
51 }
52}
53
54LIBLOG_HIDDEN void __android_log_config_write() {
55#if (FAKE_LOG_DEVICE == 0)
56 extern struct android_log_transport_write logdLoggerWrite;
57 extern struct android_log_transport_write pmsgLoggerWrite;
58
59 __android_log_add_transport(&__android_log_transport_write, &logdLoggerWrite);
60 __android_log_add_transport(&__android_log_persist_write, &pmsgLoggerWrite);
61#else
62 extern struct android_log_transport_write fakeLoggerWrite;
63
64 __android_log_add_transport(&__android_log_transport_write, &fakeLoggerWrite);
65#endif
66}
Mark Salyzyn96432fc2016-03-08 16:18:26 -080067
68LIBLOG_HIDDEN void __android_log_config_write_close() {
69 struct android_log_transport_write *transport;
70 struct listnode *n;
71
72 write_transport_for_each_safe(transport, n, &__android_log_transport_write) {
73 transport->logMask = 0;
74 list_remove(&transport->node);
75 }
76 write_transport_for_each_safe(transport, n, &__android_log_persist_write) {
77 transport->logMask = 0;
78 list_remove(&transport->node);
79 }
80}