| Mark Salyzyn | facf94c | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 1 | /* | 
|  | 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 Salyzyn | 7100288 | 2016-03-08 16:18:26 -0800 | [diff] [blame] | 17 | #include <log/log_frontend.h> | 
|  | 18 |  | 
| Mark Salyzyn | facf94c | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 19 | #include "config_read.h" | 
|  | 20 | #include "logger.h" | 
|  | 21 |  | 
|  | 22 | LIBLOG_HIDDEN struct listnode __android_log_transport_read = | 
|  | 23 | { &__android_log_transport_read, &__android_log_transport_read }; | 
|  | 24 | LIBLOG_HIDDEN struct listnode __android_log_persist_read = | 
|  | 25 | { &__android_log_persist_read, &__android_log_persist_read }; | 
|  | 26 |  | 
|  | 27 | static void __android_log_add_transport( | 
|  | 28 | struct listnode *list, struct android_log_transport_read *transport) { | 
|  | 29 | size_t i; | 
|  | 30 |  | 
|  | 31 | /* 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; | 
|  | 34 |  | 
|  | 35 | if (list_empty(list)) { | 
|  | 36 | if (!transport->available || ((*transport->available)(i) >= 0)) { | 
|  | 37 | list_add_tail(list, &transport->node); | 
|  | 38 | return; | 
|  | 39 | } | 
|  | 40 | } else { | 
|  | 41 | read_transport_for_each(transp, list) { | 
|  | 42 | if (!transp->available) { | 
|  | 43 | return; | 
|  | 44 | } | 
|  | 45 | if (((*transp->available)(i) < 0) && | 
|  | 46 | (!transport->available || | 
|  | 47 | ((*transport->available)(i) >= 0))) { | 
|  | 48 | list_add_tail(list, &transport->node); | 
|  | 49 | return; | 
|  | 50 | } | 
|  | 51 | } | 
|  | 52 | } | 
|  | 53 | } | 
|  | 54 | } | 
|  | 55 |  | 
|  | 56 | LIBLOG_HIDDEN void __android_log_config_read() { | 
| Mark Salyzyn | 7100288 | 2016-03-08 16:18:26 -0800 | [diff] [blame] | 57 | if (__android_log_frontend & LOGGER_LOCAL) { | 
|  | 58 | extern struct android_log_transport_read localLoggerRead; | 
| Mark Salyzyn | facf94c | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 59 |  | 
| Mark Salyzyn | 7100288 | 2016-03-08 16:18:26 -0800 | [diff] [blame] | 60 | __android_log_add_transport(&__android_log_transport_read, | 
|  | 61 | &localLoggerRead); | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | #if (FAKE_LOG_DEVICE == 0) | 
|  | 65 | if ((__android_log_frontend == LOGGER_DEFAULT) || | 
|  | 66 | (__android_log_frontend & LOGGER_LOGD)) { | 
|  | 67 | extern struct android_log_transport_read logdLoggerRead; | 
|  | 68 | extern struct android_log_transport_read pmsgLoggerRead; | 
|  | 69 |  | 
|  | 70 | __android_log_add_transport(&__android_log_transport_read, | 
|  | 71 | &logdLoggerRead); | 
|  | 72 | __android_log_add_transport(&__android_log_persist_read, | 
|  | 73 | &pmsgLoggerRead); | 
|  | 74 | } | 
| Mark Salyzyn | facf94c | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 75 | #endif | 
|  | 76 | } | 
| Mark Salyzyn | 96432fc | 2016-03-08 16:18:26 -0800 | [diff] [blame] | 77 |  | 
|  | 78 | LIBLOG_HIDDEN void __android_log_config_read_close() { | 
|  | 79 | struct android_log_transport_read *transport; | 
|  | 80 | struct listnode *n; | 
|  | 81 |  | 
|  | 82 | read_transport_for_each_safe(transport, n, &__android_log_transport_read) { | 
|  | 83 | list_remove(&transport->node); | 
|  | 84 | } | 
|  | 85 | read_transport_for_each_safe(transport, n, &__android_log_persist_read) { | 
|  | 86 | list_remove(&transport->node); | 
|  | 87 | } | 
|  | 88 | } |