Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1 | /* |
| 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 Salyzyn | f7c0f75 | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 20 | #include <stdatomic.h> |
Mark Salyzyn | 97c1c2b | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 23 | #include <sysutils/SocketClient.h> |
| 24 | #include <log/log.h> |
| 25 | #include <log/log_read.h> |
| 26 | |
Mark Salyzyn | 08739ba | 2015-03-16 08:26:05 -0700 | [diff] [blame^] | 27 | namespace android { |
| 28 | |
| 29 | // Furnished in main.cpp. Caller must own and free returned value |
| 30 | // This function is designed for a single caller and is NOT thread-safe |
| 31 | char *uidToName(uid_t uid); |
| 32 | |
| 33 | } |
| 34 | |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 35 | class LogBufferElement { |
| 36 | const log_id_t mLogId; |
| 37 | const uid_t mUid; |
| 38 | const pid_t mPid; |
Mark Salyzyn | b992d0d | 2014-03-20 16:09:38 -0700 | [diff] [blame] | 39 | const pid_t mTid; |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 40 | char *mMsg; |
| 41 | const unsigned short mMsgLen; |
Mark Salyzyn | f7c0f75 | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 42 | const uint64_t mSequence; |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 43 | const log_time mRealTime; |
Mark Salyzyn | f7c0f75 | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 44 | static atomic_int_fast64_t sequence; |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 45 | |
| 46 | public: |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 47 | LogBufferElement(log_id_t log_id, log_time realtime, |
Mark Salyzyn | b992d0d | 2014-03-20 16:09:38 -0700 | [diff] [blame] | 48 | uid_t uid, pid_t pid, pid_t tid, |
| 49 | const char *msg, unsigned short len); |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 50 | virtual ~LogBufferElement(); |
| 51 | |
| 52 | log_id_t getLogId() const { return mLogId; } |
| 53 | uid_t getUid(void) const { return mUid; } |
| 54 | pid_t getPid(void) const { return mPid; } |
Mark Salyzyn | b992d0d | 2014-03-20 16:09:38 -0700 | [diff] [blame] | 55 | pid_t getTid(void) const { return mTid; } |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 56 | unsigned short getMsgLen() const { return mMsgLen; } |
Mark Salyzyn | f7c0f75 | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 57 | uint64_t getSequence(void) const { return mSequence; } |
| 58 | static uint64_t getCurrentSequence(void) { return sequence.load(memory_order_relaxed); } |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 59 | log_time getRealTime(void) const { return mRealTime; } |
| 60 | |
Mark Salyzyn | f7c0f75 | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 61 | static const uint64_t FLUSH_ERROR; |
| 62 | uint64_t flushTo(SocketClient *writer); |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | #endif |