summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2016-11-22 09:56:32 -0600
committerandroid-build-merger2016-11-22 09:56:32 -0600
commitd96b925d9c829717bd5e07772738448d50aa7b39 (patch)
treec27b3b648ec43a810460766a547550bf6776713c /include
parent715e33452e728855251578d918467d94666fe10a (diff)
parent418558f8af3297736acc2e90213491d4db367cb0 (diff)
downloadplatform-system-core-d96b925d9c829717bd5e07772738448d50aa7b39.tar.gz
platform-system-core-d96b925d9c829717bd5e07772738448d50aa7b39.tar.xz
platform-system-core-d96b925d9c829717bd5e07772738448d50aa7b39.zip
Merge "liblog: move android_log_event_context class to log/log_event_list.h"
am: 418558f8af Change-Id: I4f537d4010e60b86ad4f565135804cf92fa7bd37
Diffstat (limited to 'include')
-rw-r--r--include/log/log.h210
-rw-r--r--include/log/log_event_list.h296
2 files changed, 297 insertions, 209 deletions
diff --git a/include/log/log.h b/include/log/log.h
index a44aba898..d6f0eb524 100644
--- a/include/log/log.h
+++ b/include/log/log.h
@@ -27,15 +27,8 @@
27#include <time.h> /* clock_gettime */ 27#include <time.h> /* clock_gettime */
28#include <unistd.h> 28#include <unistd.h>
29 29
30#include <log/uio.h> /* helper to define iovec for portability */
31
32#if (defined(__cplusplus) && defined(_USING_LIBCXX))
33extern "C++" {
34#include <string>
35}
36#endif
37
38#include <android/log.h> 30#include <android/log.h>
31#include <log/uio.h> /* helper to define iovec for portability */
39 32
40#ifdef __cplusplus 33#ifdef __cplusplus
41extern "C" { 34extern "C" {
@@ -774,207 +767,6 @@ const char* android_log_id_to_name(log_id_t log_id);
774 767
775/* --------------------------------------------------------------------- */ 768/* --------------------------------------------------------------------- */
776 769
777#ifndef __ANDROID_USE_LIBLOG_EVENT_INTERFACE
778#ifndef __ANDROID_API__
779#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 1
780#elif __ANDROID_API__ > 23 /* > Marshmallow */
781#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 1
782#else
783#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 0
784#endif
785#endif
786
787#if __ANDROID_USE_LIBLOG_EVENT_INTERFACE
788
789/* For manipulating lists of events. */
790
791#define ANDROID_MAX_LIST_NEST_DEPTH 8
792
793/*
794 * The opaque context used to manipulate lists of events.
795 */
796#ifndef __android_log_context_defined
797#define __android_log_context_defined
798typedef struct android_log_context_internal* android_log_context;
799#endif
800
801/*
802 * Elements returned when reading a list of events.
803 */
804#ifndef __android_log_list_element_defined
805#define __android_log_list_element_defined
806typedef struct {
807 AndroidEventLogType type;
808 uint16_t complete;
809 uint16_t len;
810 union {
811 int32_t int32;
812 int64_t int64;
813 char* string;
814 float float32;
815 } data;
816} android_log_list_element;
817#endif
818
819/*
820 * Creates a context associated with an event tag to write elements to
821 * the list of events.
822 */
823android_log_context create_android_logger(uint32_t tag);
824
825/* All lists must be braced by a begin and end call */
826/*
827 * NB: If the first level braces are missing when specifying multiple
828 * elements, we will manufacturer a list to embrace it for your API
829 * convenience. For a single element, it will remain solitary.
830 */
831int android_log_write_list_begin(android_log_context ctx);
832int android_log_write_list_end(android_log_context ctx);
833
834int android_log_write_int32(android_log_context ctx, int32_t value);
835int android_log_write_int64(android_log_context ctx, int64_t value);
836int android_log_write_string8(android_log_context ctx, const char* value);
837int android_log_write_string8_len(android_log_context ctx,
838 const char* value, size_t maxlen);
839int android_log_write_float32(android_log_context ctx, float value);
840
841/* Submit the composed list context to the specified logger id */
842/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
843int android_log_write_list(android_log_context ctx, log_id_t id);
844
845/*
846 * Creates a context from a raw buffer representing a list of events to be read.
847 */
848android_log_context create_android_log_parser(const char* msg, size_t len);
849
850android_log_list_element android_log_read_next(android_log_context ctx);
851android_log_list_element android_log_peek_next(android_log_context ctx);
852
853/* Finished with reader or writer context */
854int android_log_destroy(android_log_context* ctx);
855
856#ifdef __cplusplus
857#ifndef __class_android_log_event_context
858#define __class_android_log_event_context
859/* android_log_context C++ helpers */
860extern "C++" {
861class android_log_event_context {
862 android_log_context ctx;
863 int ret;
864
865 android_log_event_context(const android_log_event_context&) = delete;
866 void operator =(const android_log_event_context&) = delete;
867
868public:
869 explicit android_log_event_context(int tag) : ret(0) {
870 ctx = create_android_logger(static_cast<uint32_t>(tag));
871 }
872 explicit android_log_event_context(log_msg& log_msg) : ret(0) {
873 ctx = create_android_log_parser(log_msg.msg() + sizeof(uint32_t),
874 log_msg.entry.len - sizeof(uint32_t));
875 }
876 ~android_log_event_context() { android_log_destroy(&ctx); }
877
878 int close() {
879 int retval = android_log_destroy(&ctx);
880 if (retval < 0) ret = retval;
881 return retval;
882 }
883
884 /* To allow above C calls to use this class as parameter */
885 operator android_log_context() const { return ctx; }
886
887 int status() const { return ret; }
888
889 int begin() {
890 int retval = android_log_write_list_begin(ctx);
891 if (retval < 0) ret = retval;
892 return ret;
893 }
894 int end() {
895 int retval = android_log_write_list_end(ctx);
896 if (retval < 0) ret = retval;
897 return ret;
898 }
899
900 android_log_event_context& operator <<(int32_t value) {
901 int retval = android_log_write_int32(ctx, value);
902 if (retval < 0) ret = retval;
903 return *this;
904 }
905 android_log_event_context& operator <<(uint32_t value) {
906 int retval = android_log_write_int32(ctx, static_cast<int32_t>(value));
907 if (retval < 0) ret = retval;
908 return *this;
909 }
910 android_log_event_context& operator <<(int64_t value) {
911 int retval = android_log_write_int64(ctx, value);
912 if (retval < 0) ret = retval;
913 return *this;
914 }
915 android_log_event_context& operator <<(uint64_t value) {
916 int retval = android_log_write_int64(ctx, static_cast<int64_t>(value));
917 if (retval < 0) ret = retval;
918 return *this;
919 }
920 android_log_event_context& operator <<(const char* value) {
921 int retval = android_log_write_string8(ctx, value);
922 if (retval < 0) ret = retval;
923 return *this;
924 }
925#if defined(_USING_LIBCXX)
926 android_log_event_context& operator <<(const std::string& value) {
927 int retval = android_log_write_string8_len(ctx,
928 value.data(),
929 value.length());
930 if (retval < 0) ret = retval;
931 return *this;
932 }
933#endif
934 android_log_event_context& operator <<(float value) {
935 int retval = android_log_write_float32(ctx, value);
936 if (retval < 0) ret = retval;
937 return *this;
938 }
939
940 int write(log_id_t id = LOG_ID_EVENTS) {
941 int retval = android_log_write_list(ctx, id);
942 if (retval < 0) ret = retval;
943 return ret;
944 }
945
946 int operator <<(log_id_t id) {
947 int retval = android_log_write_list(ctx, id);
948 if (retval < 0) ret = retval;
949 android_log_destroy(&ctx);
950 return ret;
951 }
952
953 /*
954 * Append should be a lesser-used interface, but adds
955 * access to string with length. So we offer all types.
956 */
957 template <typename Tvalue>
958 bool Append(Tvalue value) { *this << value; return ret >= 0; }
959
960 bool Append(const char* value, size_t len) {
961 int retval = android_log_write_string8_len(ctx, value, len);
962 if (retval < 0) ret = retval;
963 return ret >= 0;
964 }
965
966 android_log_list_element read() { return android_log_read_next(ctx); }
967 android_log_list_element peek() { return android_log_peek_next(ctx); }
968
969};
970}
971#endif
972#endif
973
974#endif /* __ANDROID_USE_LIBLOG_EVENT_INTERFACE */
975
976/* --------------------------------------------------------------------- */
977
978#ifndef _ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 770#ifndef _ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE
979#ifndef __ANDROID_API__ 771#ifndef __ANDROID_API__
980#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 1 772#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 1
diff --git a/include/log/log_event_list.h b/include/log/log_event_list.h
new file mode 100644
index 000000000..04c1cd6fb
--- /dev/null
+++ b/include/log/log_event_list.h
@@ -0,0 +1,296 @@
1/*
2 * Copyright (C) 2005-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 _LIBS_LOG_EVENT_LIST_H
18#define _LIBS_LOG_EVENT_LIST_H
19
20#include <stdint.h>
21
22#if (defined(__cplusplus) && defined(_USING_LIBCXX))
23extern "C++" {
24#include <string>
25}
26#endif
27
28#include <log/log.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#ifndef __ANDROID_USE_LIBLOG_EVENT_INTERFACE
35#ifndef __ANDROID_API__
36#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 1
37#elif __ANDROID_API__ > 23 /* > Marshmallow */
38#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 1
39#else
40#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 0
41#endif
42#endif
43
44#if __ANDROID_USE_LIBLOG_EVENT_INTERFACE
45
46/* For manipulating lists of events. */
47
48#define ANDROID_MAX_LIST_NEST_DEPTH 8
49
50/*
51 * The opaque context used to manipulate lists of events.
52 */
53#ifndef __android_log_context_defined
54#define __android_log_context_defined
55typedef struct android_log_context_internal* android_log_context;
56#endif
57
58/*
59 * Elements returned when reading a list of events.
60 */
61#ifndef __android_log_list_element_defined
62#define __android_log_list_element_defined
63typedef struct {
64 AndroidEventLogType type;
65 uint16_t complete;
66 uint16_t len;
67 union {
68 int32_t int32;
69 int64_t int64;
70 char* string;
71 float float32;
72 } data;
73} android_log_list_element;
74#endif
75
76/*
77 * Creates a context associated with an event tag to write elements to
78 * the list of events.
79 */
80android_log_context create_android_logger(uint32_t tag);
81
82/* All lists must be braced by a begin and end call */
83/*
84 * NB: If the first level braces are missing when specifying multiple
85 * elements, we will manufacturer a list to embrace it for your API
86 * convenience. For a single element, it will remain solitary.
87 */
88int android_log_write_list_begin(android_log_context ctx);
89int android_log_write_list_end(android_log_context ctx);
90
91int android_log_write_int32(android_log_context ctx, int32_t value);
92int android_log_write_int64(android_log_context ctx, int64_t value);
93int android_log_write_string8(android_log_context ctx, const char* value);
94int android_log_write_string8_len(android_log_context ctx,
95 const char* value, size_t maxlen);
96int android_log_write_float32(android_log_context ctx, float value);
97
98/* Submit the composed list context to the specified logger id */
99/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
100int android_log_write_list(android_log_context ctx, log_id_t id);
101
102/*
103 * Creates a context from a raw buffer representing a list of events to be read.
104 */
105android_log_context create_android_log_parser(const char* msg, size_t len);
106
107android_log_list_element android_log_read_next(android_log_context ctx);
108android_log_list_element android_log_peek_next(android_log_context ctx);
109
110/* Finished with reader or writer context */
111int android_log_destroy(android_log_context* ctx);
112
113#ifdef __cplusplus
114#ifndef __class_android_log_event_list_defined
115#define __class_android_log_event_list_defined
116/* android_log_list C++ helpers */
117extern "C++" {
118class android_log_event_list {
119
120private:
121 android_log_context ctx;
122 int ret;
123
124 android_log_event_list(const android_log_event_list&) = delete;
125 void operator =(const android_log_event_list&) = delete;
126
127public:
128 explicit android_log_event_list(int tag) : ret(0) {
129 ctx = create_android_logger(static_cast<uint32_t>(tag));
130 }
131 explicit android_log_event_list(log_msg& log_msg) : ret(0) {
132 ctx = create_android_log_parser(log_msg.msg() + sizeof(uint32_t),
133 log_msg.entry.len - sizeof(uint32_t));
134 }
135 ~android_log_event_list() { android_log_destroy(&ctx); }
136
137 int close() {
138 int retval = android_log_destroy(&ctx);
139 if (retval < 0) ret = retval;
140 return retval;
141 }
142
143 /* To allow above C calls to use this class as parameter */
144 operator android_log_context() const { return ctx; }
145
146 int status() const { return ret; }
147
148 int begin() {
149 int retval = android_log_write_list_begin(ctx);
150 if (retval < 0) ret = retval;
151 return ret;
152 }
153 int end() {
154 int retval = android_log_write_list_end(ctx);
155 if (retval < 0) ret = retval;
156 return ret;
157 }
158
159 android_log_event_list& operator <<(int32_t value) {
160 int retval = android_log_write_int32(ctx, value);
161 if (retval < 0) ret = retval;
162 return *this;
163 }
164
165 android_log_event_list& operator <<(uint32_t value) {
166 int retval = android_log_write_int32(ctx, static_cast<int32_t>(value));
167 if (retval < 0) ret = retval;
168 return *this;
169 }
170
171 android_log_event_list& operator <<(int64_t value) {
172 int retval = android_log_write_int64(ctx, value);
173 if (retval < 0) ret = retval;
174 return *this;
175 }
176
177 android_log_event_list& operator <<(uint64_t value) {
178 int retval = android_log_write_int64(ctx, static_cast<int64_t>(value));
179 if (retval < 0) ret = retval;
180 return *this;
181 }
182
183 android_log_event_list& operator <<(const char* value) {
184 int retval = android_log_write_string8(ctx, value);
185 if (retval < 0) ret = retval;
186 return *this;
187 }
188
189#if defined(_USING_LIBCXX)
190 android_log_event_list& operator <<(const std::string& value) {
191 int retval = android_log_write_string8_len(ctx,
192 value.data(),
193 value.length());
194 if (retval < 0) ret = retval;
195 return *this;
196 }
197#endif
198
199 android_log_event_list& operator <<(float value) {
200 int retval = android_log_write_float32(ctx, value);
201 if (retval < 0) ret = retval;
202 return *this;
203 }
204
205 int write(log_id_t id = LOG_ID_EVENTS) {
206 int retval = android_log_write_list(ctx, id);
207 if (retval < 0) ret = retval;
208 return ret;
209 }
210
211 int operator <<(log_id_t id) {
212 int retval = android_log_write_list(ctx, id);
213 if (retval < 0) ret = retval;
214 android_log_destroy(&ctx);
215 return ret;
216 }
217
218 /*
219 * Append<Type> methods removes any integer promotion
220 * confusion, and adds access to string with length.
221 * Append methods are also added for all types for
222 * convenience.
223 */
224
225 bool AppendInt(int32_t value) {
226 int retval = android_log_write_int32(ctx, value);
227 if (retval < 0) ret = retval;
228 return ret >= 0;
229 }
230
231 bool AppendLong(int64_t value) {
232 int retval = android_log_write_int64(ctx, value);
233 if (retval < 0) ret = retval;
234 return ret >= 0;
235 }
236
237 bool AppendString(const char* value) {
238 int retval = android_log_write_string8(ctx, value);
239 if (retval < 0) ret = retval;
240 return ret >= 0;
241 }
242
243 bool AppendString(const char* value, size_t len) {
244 int retval = android_log_write_string8_len(ctx, value, len);
245 if (retval < 0) ret = retval;
246 return ret >= 0;
247 }
248
249#if defined(_USING_LIBCXX)
250 bool AppendString(const std::string& value) {
251 int retval = android_log_write_string8_len(ctx,
252 value.data(),
253 value.length());
254 if (retval < 0) ret = retval;
255 return ret;
256 }
257
258 bool Append(const std::string& value) {
259 int retval = android_log_write_string8_len(ctx,
260 value.data(),
261 value.length());
262 if (retval < 0) ret = retval;
263 return ret;
264 }
265#endif
266
267 bool AppendFloat(float value) {
268 int retval = android_log_write_float32(ctx, value);
269 if (retval < 0) ret = retval;
270 return ret >= 0;
271 }
272
273 template <typename Tvalue>
274 bool Append(Tvalue value) { *this << value; return ret >= 0; }
275
276 bool Append(const char* value, size_t len) {
277 int retval = android_log_write_string8_len(ctx, value, len);
278 if (retval < 0) ret = retval;
279 return ret >= 0;
280 }
281
282 android_log_list_element read() { return android_log_read_next(ctx); }
283 android_log_list_element peek() { return android_log_peek_next(ctx); }
284
285};
286}
287#endif
288#endif
289
290#endif /* __ANDROID_USE_LIBLOG_EVENT_INTERFACE */
291
292#ifdef __cplusplus
293}
294#endif
295
296#endif /* _LIBS_LOG_EVENT_LIST_H */