Home | History | Annotate | Download | only in liblog
      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_read.h"
     18 #include "logger.h"
     19 
     20 LIBLOG_HIDDEN struct listnode __android_log_transport_read =
     21     { &__android_log_transport_read, &__android_log_transport_read };
     22 LIBLOG_HIDDEN struct listnode __android_log_persist_read =
     23     { &__android_log_persist_read, &__android_log_persist_read };
     24 
     25 static void __android_log_add_transport(
     26         struct listnode *list, struct android_log_transport_read *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_read *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             read_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_read() {
     55 #if (FAKE_LOG_DEVICE == 0)
     56     extern struct android_log_transport_read logdLoggerRead;
     57     extern struct android_log_transport_read pmsgLoggerRead;
     58 
     59     __android_log_add_transport(&__android_log_transport_read, &logdLoggerRead);
     60     __android_log_add_transport(&__android_log_persist_read, &pmsgLoggerRead);
     61 #endif
     62 }
     63