| 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 |  | 
|  | 17 | #include "config_write.h" | 
|  | 18 | #include "logger.h" | 
|  | 19 |  | 
|  | 20 | LIBLOG_HIDDEN struct listnode __android_log_transport_write = | 
|  | 21 | { &__android_log_transport_write, &__android_log_transport_write }; | 
|  | 22 | LIBLOG_HIDDEN struct listnode __android_log_persist_write = | 
|  | 23 | { &__android_log_persist_write, &__android_log_persist_write}; | 
|  | 24 |  | 
|  | 25 | static 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 |  | 
|  | 54 | LIBLOG_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 | } |