Merge "liblog: add private android_log_write_list_buffer()" am: 636c851f8d am: a95e19abd2 am: c3bbcb885c

am: a1817f68b0

Change-Id: If662d2b8195801d681935677d938b2197820eb0b
This commit is contained in:
Mark Salyzyn 2016-11-22 16:21:27 +00:00 committed by android-build-merger
commit 7374bca9c5
4 changed files with 88 additions and 1 deletions

View file

@ -116,6 +116,7 @@ int android_log_destroy(android_log_context* ctx);
/* android_log_list C++ helpers */
extern "C++" {
class android_log_event_list {
friend class __android_log_event_list;
private:
android_log_context ctx;

View file

@ -25,6 +25,13 @@
#include <stdint.h>
#include <sys/types.h>
#if (defined(__cplusplus) && defined(_USING_LIBCXX))
extern "C++" {
#include <string>
}
#endif
#include <log/log_event_list.h>
#include <log/log.h>
#define LOGGER_MAGIC 'l'
@ -146,6 +153,40 @@ bool __android_logger_property_get_bool(const char* key, int flag);
unsigned long __android_logger_get_buffer_size(log_id_t logId);
bool __android_logger_valid_buffer_size(unsigned long value);
/* Retrieve the composed event buffer */
int android_log_write_list_buffer(android_log_context ctx, const char** msg);
#ifdef __cplusplus
#ifdef __class_android_log_event_list_defined
#ifndef __class_android_log_event_list_private_defined
#define __class_android_log_event_list_private_defined
/* android_log_context C++ helpers */
extern "C++" {
class __android_log_event_list : public android_log_event_list {
__android_log_event_list(const android_log_event_list&) = delete;
void operator =(const __android_log_event_list&) = delete;
public:
explicit __android_log_event_list(int tag) : android_log_event_list(tag) { }
explicit __android_log_event_list(log_msg& log_msg) : android_log_event_list(log_msg) { }
#if defined(_USING_LIBCXX)
operator std::string() {
if (ret) return std::string("");
const char* cp = NULL;
ssize_t len = android_log_write_list_buffer(ctx, &cp);
if (len < 0) ret = len;
if (!cp || (len <= 0)) return std::string("");
return std::string(cp, len);
}
#endif
};
}
#endif
#endif
#endif
#if defined(__cplusplus)
}
#endif

View file

@ -320,7 +320,7 @@ LIBLOG_ABI_PUBLIC int android_log_write_list(android_log_context ctx,
context->storage[1] = context->count[0];
len = context->len = context->pos;
msg = (const char *)context->storage;
/* it'snot a list */
/* it's not a list */
if (context->count[0] <= 1) {
len -= sizeof(uint8_t) + sizeof(uint8_t);
if (len < 0) {
@ -333,6 +333,38 @@ LIBLOG_ABI_PUBLIC int android_log_write_list(android_log_context ctx,
__android_log_security_bwrite(context->tag, msg, len);
}
LIBLOG_ABI_PRIVATE int android_log_write_list_buffer(android_log_context ctx,
const char **buffer) {
android_log_context_internal *context;
const char *msg;
ssize_t len;
context = (android_log_context_internal *)ctx;
if (!context || (kAndroidLoggerWrite != context->read_write_flag)) {
return -EBADF;
}
if (context->list_nest_depth) {
return -EIO;
}
if (buffer == NULL) {
return -EFAULT;
}
/* NB: if there was overflow, then log is truncated. Nothing reported */
context->storage[1] = context->count[0];
len = context->len = context->pos;
msg = (const char *)context->storage;
/* it's not a list */
if (context->count[0] <= 1) {
len -= sizeof(uint8_t) + sizeof(uint8_t);
if (len < 0) {
len = 0;
}
msg += sizeof(uint8_t) + sizeof(uint8_t);
}
*buffer = msg;
return len;
}
/*
* Extract a 4-byte value from a byte stream.
*/

View file

@ -2651,6 +2651,19 @@ TEST(liblog, create_android_logger_overflow) {
ASSERT_TRUE(NULL == ctx);
}
TEST(liblog, android_log_write_list_buffer) {
__android_log_event_list ctx(1005);
ctx << 1005 << "tag_def" << "(tag|1),(name|3),(format|3)";
std::string buffer(ctx);
ctx.close();
char msgBuf[1024];
memset(msgBuf, 0, sizeof(msgBuf));
EXPECT_EQ(android_log_buffer_to_string(buffer.data(), buffer.length(),
msgBuf, sizeof(msgBuf)), 0);
EXPECT_STREQ(msgBuf, "[1005,tag_def,(tag|1),(name|3),(format|3)]");
}
static const char __pmsg_file[] =
"/data/william-shakespeare/MuchAdoAboutNothing.txt";