2014-02-26 18:50:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012-2014 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LOGD_LOG_BUFFER_ELEMENT_H__
|
|
|
|
#define _LOGD_LOG_BUFFER_ELEMENT_H__
|
|
|
|
|
2015-03-03 22:39:37 +01:00
|
|
|
#include <stdatomic.h>
|
2015-03-16 20:04:09 +01:00
|
|
|
#include <stdlib.h>
|
2015-03-10 21:51:35 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2014-02-26 18:50:16 +01:00
|
|
|
#include <sysutils/SocketClient.h>
|
|
|
|
#include <log/log.h>
|
|
|
|
#include <log/log_read.h>
|
|
|
|
|
2015-03-16 16:26:05 +01:00
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// Furnished in main.cpp. Caller must own and free returned value
|
|
|
|
// This function is designed for a single caller and is NOT thread-safe
|
|
|
|
char *uidToName(uid_t uid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-26 18:50:16 +01:00
|
|
|
class LogBufferElement {
|
|
|
|
const log_id_t mLogId;
|
|
|
|
const uid_t mUid;
|
|
|
|
const pid_t mPid;
|
2014-03-21 00:09:38 +01:00
|
|
|
const pid_t mTid;
|
2014-02-26 18:50:16 +01:00
|
|
|
char *mMsg;
|
2015-03-16 20:04:09 +01:00
|
|
|
union {
|
|
|
|
const unsigned short mMsgLen; // mMSg != NULL
|
|
|
|
unsigned short mDropped; // mMsg == NULL
|
|
|
|
};
|
2015-03-03 22:39:37 +01:00
|
|
|
const uint64_t mSequence;
|
2014-02-26 18:50:16 +01:00
|
|
|
const log_time mRealTime;
|
2015-03-03 22:39:37 +01:00
|
|
|
static atomic_int_fast64_t sequence;
|
2014-02-26 18:50:16 +01:00
|
|
|
|
2015-03-16 20:04:09 +01:00
|
|
|
// assumption: mMsg == NULL
|
|
|
|
size_t populateDroppedMessage(char *&buffer, bool privileged);
|
|
|
|
|
2014-02-26 18:50:16 +01:00
|
|
|
public:
|
2014-03-05 16:41:49 +01:00
|
|
|
LogBufferElement(log_id_t log_id, log_time realtime,
|
2014-03-21 00:09:38 +01:00
|
|
|
uid_t uid, pid_t pid, pid_t tid,
|
|
|
|
const char *msg, unsigned short len);
|
2014-02-26 18:50:16 +01:00
|
|
|
virtual ~LogBufferElement();
|
|
|
|
|
|
|
|
log_id_t getLogId() const { return mLogId; }
|
|
|
|
uid_t getUid(void) const { return mUid; }
|
|
|
|
pid_t getPid(void) const { return mPid; }
|
2014-03-21 00:09:38 +01:00
|
|
|
pid_t getTid(void) const { return mTid; }
|
2015-03-16 20:04:09 +01:00
|
|
|
unsigned short getDropped(void) const { return mMsg ? 0 : mDropped; }
|
|
|
|
unsigned short setDropped(unsigned short value) {
|
|
|
|
if (mMsg) {
|
|
|
|
free(mMsg);
|
|
|
|
mMsg = NULL;
|
|
|
|
}
|
|
|
|
return mDropped = value;
|
|
|
|
}
|
|
|
|
unsigned short getMsgLen() const { return mMsg ? mMsgLen : 0; }
|
2015-03-03 22:39:37 +01:00
|
|
|
uint64_t getSequence(void) const { return mSequence; }
|
|
|
|
static uint64_t getCurrentSequence(void) { return sequence.load(memory_order_relaxed); }
|
2014-02-26 18:50:16 +01:00
|
|
|
log_time getRealTime(void) const { return mRealTime; }
|
|
|
|
|
2015-03-03 22:39:37 +01:00
|
|
|
static const uint64_t FLUSH_ERROR;
|
|
|
|
uint64_t flushTo(SocketClient *writer);
|
2014-02-26 18:50:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|