xref: /aosp_15_r20/system/logging/logd/LogBufferElement.h (revision 598139dc91b21518d67c408eaea2644226490971)
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 #pragma once
18 
19 #include <stdint.h>
20 #include <stdlib.h>
21 #include <sys/types.h>
22 
23 #include <log/log.h>
24 
25 #include "LogWriter.h"
26 
27 #include "LogStatistics.h"
28 
29 class __attribute__((packed)) LogBufferElement {
30   public:
31     LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid,
32                      uint64_t sequence, const char* msg, uint16_t len);
33     LogBufferElement(const LogBufferElement& elem);
34     LogBufferElement(LogBufferElement&& elem) noexcept;
35     ~LogBufferElement();
36 
37     uint32_t GetTag() const;
38 
39     bool FlushTo(LogWriter* writer);
40 
41     LogStatisticsElement ToLogStatisticsElement() const;
42 
log_id()43     log_id_t log_id() const { return static_cast<log_id_t>(log_id_); }
uid()44     uid_t uid() const { return uid_; }
pid()45     pid_t pid() const { return pid_; }
tid()46     pid_t tid() const { return tid_; }
msg_len()47     uint16_t msg_len() const { return msg_len_; }
msg()48     const char* msg() const { return msg_; }
sequence()49     uint64_t sequence() const { return sequence_; }
realtime()50     log_time realtime() const { return realtime_; }
51 
52   private:
53     // sized to match reality of incoming log packets
54     const uint32_t uid_;
55     const uint32_t pid_;
56     const uint32_t tid_;
57     uint64_t sequence_;
58     log_time realtime_;
59     char* msg_;
60     const uint16_t msg_len_;
61     const uint8_t log_id_;
62 };
63