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