| Mark Salyzyn | 018a96d | 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 | #ifndef _LIBLOG_LOGGER_H__ | 
 | 18 | #define _LIBLOG_LOGGER_H__ | 
 | 19 |  | 
 | 20 | #include <stdbool.h> | 
 | 21 | #include <log/uio.h> | 
 | 22 |  | 
 | 23 | #include <cutils/list.h> | 
 | 24 | #include <log/log.h> | 
 | 25 | #include <log/log_read.h> | 
 | 26 | #include <log/logger.h> | 
 | 27 |  | 
 | 28 | #include "log_portability.h" | 
 | 29 |  | 
 | 30 | __BEGIN_DECLS | 
 | 31 |  | 
 | 32 | /* Union, sock or fd of zero is not allowed unless static initialized */ | 
 | 33 | union android_log_context { | 
 | 34 |   void *private; | 
 | 35 |   int sock; | 
 | 36 |   int fd; | 
 | 37 |   struct listnode *node; | 
 | 38 | }; | 
 | 39 |  | 
 | 40 | struct android_log_transport_write { | 
 | 41 |   struct listnode node; | 
 | 42 |   const char *name; | 
| Mark Salyzyn | c33103c | 2016-03-28 16:20:29 -0700 | [diff] [blame] | 43 |   unsigned logMask; /* cache of available success */ | 
| Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 44 |   union android_log_context context; /* Initialized by static allocation */ | 
 | 45 |  | 
 | 46 |   int (*available)(log_id_t logId); | 
 | 47 |   int (*open)(); | 
 | 48 |   void (*close)(); | 
 | 49 |   int (*write)(log_id_t logId, struct timespec *ts, struct iovec *vec, size_t nr); | 
 | 50 | }; | 
 | 51 |  | 
 | 52 | struct android_log_logger_list; | 
 | 53 | struct android_log_transport_context; | 
 | 54 | struct android_log_logger; | 
 | 55 |  | 
 | 56 | struct android_log_transport_read { | 
 | 57 |   struct listnode node; | 
 | 58 |   const char *name; | 
 | 59 |  | 
 | 60 |   int (*available)(log_id_t logId); | 
 | 61 |   int (*version)(struct android_log_logger *logger, | 
 | 62 |                  struct android_log_transport_context *transp); | 
 | 63 |   void (*close)(struct android_log_logger_list *logger_list, | 
 | 64 |                 struct android_log_transport_context *transp); | 
 | 65 |  | 
 | 66 |   /* | 
 | 67 |    * Expect all to instantiate open on any call, so we do not have | 
 | 68 |    * an expicit open call | 
 | 69 |    */ | 
 | 70 |   int (*read)(struct android_log_logger_list *logger_list, | 
 | 71 |               struct android_log_transport_context *transp, | 
 | 72 |               struct log_msg *log_msg); | 
 | 73 |   /* Assumption is only called if not ANDROID_LOG_NONBLOCK */ | 
 | 74 |   int (*poll)(struct android_log_logger_list *logger_list, | 
 | 75 |               struct android_log_transport_context *transp); | 
 | 76 |  | 
 | 77 |   int (*clear)(struct android_log_logger *logger, | 
 | 78 |                struct android_log_transport_context *transp); | 
 | 79 |   ssize_t (*setSize)(struct android_log_logger *logger, | 
 | 80 |                      struct android_log_transport_context *transp, | 
 | 81 |                      size_t size); | 
 | 82 |   ssize_t (*getSize)(struct android_log_logger *logger, | 
 | 83 |                      struct android_log_transport_context *transp); | 
 | 84 |   ssize_t (*getReadableSize)(struct android_log_logger *logger, | 
 | 85 |                              struct android_log_transport_context *transp); | 
 | 86 |  | 
 | 87 |   ssize_t (*getPrune)(struct android_log_logger_list *logger_list, | 
 | 88 |                       struct android_log_transport_context *transp, | 
 | 89 |                       char *buf, size_t len); | 
 | 90 |   ssize_t (*setPrune)(struct android_log_logger_list *logger_list, | 
 | 91 |                       struct android_log_transport_context *transp, | 
 | 92 |                       char *buf, size_t len); | 
 | 93 |   ssize_t (*getStats)(struct android_log_logger_list *logger_list, | 
 | 94 |                       struct android_log_transport_context *transp, | 
 | 95 |                       char *buf, size_t len); | 
 | 96 | }; | 
 | 97 |  | 
 | 98 | struct android_log_logger_list { | 
 | 99 |   struct listnode logger; | 
 | 100 |   struct listnode transport; | 
 | 101 |   int mode; | 
 | 102 |   unsigned int tail; | 
 | 103 |   log_time start; | 
 | 104 |   pid_t pid; | 
 | 105 | }; | 
 | 106 |  | 
 | 107 | struct android_log_logger { | 
 | 108 |   struct listnode node; | 
 | 109 |   struct android_log_logger_list *parent; | 
 | 110 |  | 
 | 111 |   log_id_t logId; | 
 | 112 | }; | 
 | 113 |  | 
 | 114 | struct android_log_transport_context { | 
 | 115 |   struct listnode node; | 
 | 116 |   union android_log_context context; /* zero init per-transport context */ | 
 | 117 |   struct android_log_logger_list *parent; | 
 | 118 |  | 
 | 119 |   struct android_log_transport_read *transport; | 
 | 120 |   unsigned logMask; | 
 | 121 |   int ret; | 
 | 122 |   struct log_msg logMsg; /* valid is logMsg.len != 0 */ | 
 | 123 | }; | 
 | 124 |  | 
 | 125 | /* assumes caller has structures read-locked, single threaded, or fenced */ | 
 | 126 | #define transport_context_for_each(transp, logger_list)              \ | 
| Chih-Hung Hsieh | f0f94fe | 2016-05-18 15:47:19 -0700 | [diff] [blame] | 127 |   for ((transp) = node_to_item((logger_list)->transport.next,        \ | 
| Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 128 |                              struct android_log_transport_context,   \ | 
 | 129 |                              node);                                  \ | 
| Chih-Hung Hsieh | f0f94fe | 2016-05-18 15:47:19 -0700 | [diff] [blame] | 130 |        ((transp) != node_to_item(&(logger_list)->transport,          \ | 
| Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 131 |                                struct android_log_transport_context, \ | 
 | 132 |                                node)) &&                             \ | 
| Chih-Hung Hsieh | f0f94fe | 2016-05-18 15:47:19 -0700 | [diff] [blame] | 133 |            ((transp)->parent == (logger_list));                      \ | 
 | 134 |        (transp) = node_to_item((transp)->node.next,                  \ | 
| Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 135 |                              struct android_log_transport_context, node)) | 
 | 136 |  | 
 | 137 | #define logger_for_each(logp, logger_list)                          \ | 
| Chih-Hung Hsieh | f0f94fe | 2016-05-18 15:47:19 -0700 | [diff] [blame] | 138 |     for ((logp) = node_to_item((logger_list)->logger.next,          \ | 
| Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 139 |                              struct android_log_logger, node);      \ | 
| Chih-Hung Hsieh | f0f94fe | 2016-05-18 15:47:19 -0700 | [diff] [blame] | 140 |          ((logp) != node_to_item(&(logger_list)->logger,            \ | 
| Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 141 |                                struct android_log_logger, node)) && \ | 
| Chih-Hung Hsieh | f0f94fe | 2016-05-18 15:47:19 -0700 | [diff] [blame] | 142 |              ((logp)->parent == (logger_list));                     \ | 
 | 143 |          (logp) = node_to_item((logp)->node.next,                   \ | 
| Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 144 |                              struct android_log_logger, node)) | 
 | 145 |  | 
 | 146 | /* OS specific dribs and drabs */ | 
 | 147 |  | 
 | 148 | #if defined(_WIN32) | 
 | 149 | typedef uint32_t uid_t; | 
 | 150 | #endif | 
 | 151 |  | 
 | 152 | LIBLOG_HIDDEN uid_t __android_log_uid(); | 
 | 153 | LIBLOG_HIDDEN pid_t __android_log_pid(); | 
 | 154 | LIBLOG_HIDDEN void __android_log_lock(); | 
 | 155 | LIBLOG_HIDDEN int __android_log_trylock(); | 
 | 156 | LIBLOG_HIDDEN void __android_log_unlock(); | 
| Mark Salyzyn | 7ef5249 | 2016-03-25 15:50:46 -0700 | [diff] [blame] | 157 | LIBLOG_HIDDEN int __android_log_is_debuggable(); | 
| Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 158 |  | 
 | 159 | __END_DECLS | 
 | 160 |  | 
 | 161 | #endif /* _LIBLOG_LOGGER_H__ */ |