summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2016-03-01 15:45:42 -0600
committerDan Willemsen2016-03-22 15:01:15 -0500
commit018a96d03f0d452bf078084eedcd5693da42308d (patch)
tree28a998736c3637944985ccacb20539527e19d3e5 /liblog/logger.h
parent80b1b188281b0c89e94cd9c3c3f2b04f007d6b28 (diff)
downloadplatform-system-core-018a96d03f0d452bf078084eedcd5693da42308d.tar.gz
platform-system-core-018a96d03f0d452bf078084eedcd5693da42308d.tar.xz
platform-system-core-018a96d03f0d452bf078084eedcd5693da42308d.zip
liblog: split out transports into separate files
Create config_logger, logger and logger_read to house the log interfaces. Add fake_logger, logd_logger and pmsg_logger to house the write and read transports. Allows for an easier and direct path to add new transports to the library. SideEffects: None, logger benchmark performance unaffected Bug: 27176738 Bug: 27405083 Change-Id: I01b38637334a5242905c8c89f6ab0a92e2540008
Diffstat (limited to 'liblog/logger.h')
-rw-r--r--liblog/logger.h159
1 files changed, 159 insertions, 0 deletions
diff --git a/liblog/logger.h b/liblog/logger.h
new file mode 100644
index 000000000..61bc3968a
--- /dev/null
+++ b/liblog/logger.h
@@ -0,0 +1,159 @@
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 */
33union android_log_context {
34 void *private;
35 int sock;
36 int fd;
37 struct listnode *node;
38};
39
40struct android_log_transport_write {
41 struct listnode node;
42 const char *name;
43 union android_log_context context; /* Initialized by static allocation */
44
45 int (*available)(log_id_t logId);
46 int (*open)();
47 void (*close)();
48 int (*write)(log_id_t logId, struct timespec *ts, struct iovec *vec, size_t nr);
49};
50
51struct android_log_logger_list;
52struct android_log_transport_context;
53struct android_log_logger;
54
55struct android_log_transport_read {
56 struct listnode node;
57 const char *name;
58
59 int (*available)(log_id_t logId);
60 int (*version)(struct android_log_logger *logger,
61 struct android_log_transport_context *transp);
62 void (*close)(struct android_log_logger_list *logger_list,
63 struct android_log_transport_context *transp);
64
65 /*
66 * Expect all to instantiate open on any call, so we do not have
67 * an expicit open call
68 */
69 int (*read)(struct android_log_logger_list *logger_list,
70 struct android_log_transport_context *transp,
71 struct log_msg *log_msg);
72 /* Assumption is only called if not ANDROID_LOG_NONBLOCK */
73 int (*poll)(struct android_log_logger_list *logger_list,
74 struct android_log_transport_context *transp);
75
76 int (*clear)(struct android_log_logger *logger,
77 struct android_log_transport_context *transp);
78 ssize_t (*setSize)(struct android_log_logger *logger,
79 struct android_log_transport_context *transp,
80 size_t size);
81 ssize_t (*getSize)(struct android_log_logger *logger,
82 struct android_log_transport_context *transp);
83 ssize_t (*getReadableSize)(struct android_log_logger *logger,
84 struct android_log_transport_context *transp);
85
86 ssize_t (*getPrune)(struct android_log_logger_list *logger_list,
87 struct android_log_transport_context *transp,
88 char *buf, size_t len);
89 ssize_t (*setPrune)(struct android_log_logger_list *logger_list,
90 struct android_log_transport_context *transp,
91 char *buf, size_t len);
92 ssize_t (*getStats)(struct android_log_logger_list *logger_list,
93 struct android_log_transport_context *transp,
94 char *buf, size_t len);
95};
96
97struct android_log_logger_list {
98 struct listnode logger;
99 struct listnode transport;
100 int mode;
101 unsigned int tail;
102 log_time start;
103 pid_t pid;
104};
105
106struct android_log_logger {
107 struct listnode node;
108 struct android_log_logger_list *parent;
109
110 log_id_t logId;
111};
112
113struct android_log_transport_context {
114 struct listnode node;
115 union android_log_context context; /* zero init per-transport context */
116 struct android_log_logger_list *parent;
117
118 struct android_log_transport_read *transport;
119 unsigned logMask;
120 int ret;
121 struct log_msg logMsg; /* valid is logMsg.len != 0 */
122};
123
124/* assumes caller has structures read-locked, single threaded, or fenced */
125#define transport_context_for_each(transp, logger_list) \
126 for (transp = node_to_item((logger_list)->transport.next, \
127 struct android_log_transport_context, \
128 node); \
129 (transp != node_to_item(&(logger_list)->transport, \
130 struct android_log_transport_context, \
131 node)) && \
132 (transp->parent == (logger_list)); \
133 transp = node_to_item(transp->node.next, \
134 struct android_log_transport_context, node))
135
136#define logger_for_each(logp, logger_list) \
137 for (logp = node_to_item((logger_list)->logger.next, \
138 struct android_log_logger, node); \
139 (logp != node_to_item(&(logger_list)->logger, \
140 struct android_log_logger, node)) && \
141 (logp->parent == (logger_list)); \
142 logp = node_to_item((logp)->node.next, \
143 struct android_log_logger, node))
144
145/* OS specific dribs and drabs */
146
147#if defined(_WIN32)
148typedef uint32_t uid_t;
149#endif
150
151LIBLOG_HIDDEN uid_t __android_log_uid();
152LIBLOG_HIDDEN pid_t __android_log_pid();
153LIBLOG_HIDDEN void __android_log_lock();
154LIBLOG_HIDDEN int __android_log_trylock();
155LIBLOG_HIDDEN void __android_log_unlock();
156
157__END_DECLS
158
159#endif /* _LIBLOG_LOGGER_H__ */