blob: 0628d3e4ce181a77481dd777dcf2d24d6e91ca5c [file] [log] [blame]
Mark Salyzyn0175b072014-02-26 09:50:16 -08001/*
2 * Copyright (C) 2012-2014 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 _LOGD_LOG_BUFFER_ELEMENT_H__
18#define _LOGD_LOG_BUFFER_ELEMENT_H__
19
Mark Salyzynf7c0f752015-03-03 13:39:37 -080020#include <stdatomic.h>
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -070021#include <sys/types.h>
22
Mark Salyzyn0175b072014-02-26 09:50:16 -080023#include <sysutils/SocketClient.h>
24#include <log/log.h>
25#include <log/log_read.h>
26
27class LogBufferElement {
28 const log_id_t mLogId;
29 const uid_t mUid;
30 const pid_t mPid;
Mark Salyzynb992d0d2014-03-20 16:09:38 -070031 const pid_t mTid;
Mark Salyzyn0175b072014-02-26 09:50:16 -080032 char *mMsg;
33 const unsigned short mMsgLen;
Mark Salyzynf7c0f752015-03-03 13:39:37 -080034 const uint64_t mSequence;
Mark Salyzyn0175b072014-02-26 09:50:16 -080035 const log_time mRealTime;
Mark Salyzynf7c0f752015-03-03 13:39:37 -080036 static atomic_int_fast64_t sequence;
Mark Salyzyn0175b072014-02-26 09:50:16 -080037
38public:
Mark Salyzyn7e2f83c2014-03-05 07:41:49 -080039 LogBufferElement(log_id_t log_id, log_time realtime,
Mark Salyzynb992d0d2014-03-20 16:09:38 -070040 uid_t uid, pid_t pid, pid_t tid,
41 const char *msg, unsigned short len);
Mark Salyzyn0175b072014-02-26 09:50:16 -080042 virtual ~LogBufferElement();
43
44 log_id_t getLogId() const { return mLogId; }
45 uid_t getUid(void) const { return mUid; }
46 pid_t getPid(void) const { return mPid; }
Mark Salyzynb992d0d2014-03-20 16:09:38 -070047 pid_t getTid(void) const { return mTid; }
Mark Salyzyn0175b072014-02-26 09:50:16 -080048 unsigned short getMsgLen() const { return mMsgLen; }
Mark Salyzynf7c0f752015-03-03 13:39:37 -080049 uint64_t getSequence(void) const { return mSequence; }
50 static uint64_t getCurrentSequence(void) { return sequence.load(memory_order_relaxed); }
Mark Salyzyn0175b072014-02-26 09:50:16 -080051 log_time getRealTime(void) const { return mRealTime; }
52
Mark Salyzynf7c0f752015-03-03 13:39:37 -080053 static const uint64_t FLUSH_ERROR;
54 uint64_t flushTo(SocketClient *writer);
Mark Salyzyn0175b072014-02-26 09:50:16 -080055};
56
57#endif