1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "watch_point.h"
17 
18 #include <iostream>
19 
20 namespace OHOS {
21 namespace HiviewDFX {
WatchPoint()22 WatchPoint::WatchPoint()
23     : seq_(0), timestamp_(0), pid_(0), uid_(0), tid_(0), domain_(""), stringId_(""), msg_("")
24 {
25 }
26 
WatchPoint(const WatchPoint::Builder & builder)27 WatchPoint::WatchPoint(const WatchPoint::Builder& builder)
28     : seq_(builder.seq_),
29     timestamp_(builder.timestamp_),
30     pid_(builder.pid_),
31     uid_(builder.uid_),
32     tid_(builder.tid_),
33     domain_(builder.domain_),
34     stringId_(builder.stringId_),
35     msg_(builder.msg_),
36     packageName_(builder.packageName_),
37     processName_(builder.processName_),
38     foreGround_(builder.foreGround_),
39     logPath_(builder.logPath_),
40     hitraceTime_(builder.hitraceTime_),
41     sysrqTime_(builder.sysrqTime_)
42 {
43 }
44 
Builder()45 WatchPoint::Builder::Builder()
46     : seq_(0), timestamp_(0), pid_(0), uid_(0), tid_(0), domain_(""), stringId_(""), msg_("")
47 {
48 }
49 
~Builder()50 WatchPoint::Builder::~Builder() {}
51 
InitSeq(long seq)52 WatchPoint::Builder& WatchPoint::Builder::InitSeq(long seq)
53 {
54     seq_ = seq;
55     return *this;
56 }
57 
InitTimestamp(unsigned long long timestamp)58 WatchPoint::Builder& WatchPoint::Builder::InitTimestamp(unsigned long long timestamp)
59 {
60     timestamp_ = timestamp;
61     return *this;
62 }
63 
InitPid(long pid)64 WatchPoint::Builder& WatchPoint::Builder::InitPid(long pid)
65 {
66     pid_ = pid;
67     return *this;
68 }
69 
InitUid(long uid)70 WatchPoint::Builder& WatchPoint::Builder::InitUid(long uid)
71 {
72     uid_ = uid;
73     return *this;
74 }
75 
InitTid(long tid)76 WatchPoint::Builder& WatchPoint::Builder::InitTid(long tid)
77 {
78     tid_ = tid;
79     return *this;
80 }
81 
InitDomain(const std::string & domain)82 WatchPoint::Builder& WatchPoint::Builder::InitDomain(const std::string& domain)
83 {
84     domain_ = domain;
85     return *this;
86 }
87 
InitStringId(const std::string & stringId)88 WatchPoint::Builder& WatchPoint::Builder::InitStringId(const std::string& stringId)
89 {
90     stringId_ = stringId;
91     return *this;
92 }
93 
InitMsg(const std::string & msg)94 WatchPoint::Builder& WatchPoint::Builder::InitMsg(const std::string& msg)
95 {
96     msg_ = msg;
97     return *this;
98 }
99 
InitProcessName(const std::string & processName)100 WatchPoint::Builder& WatchPoint::Builder::InitProcessName(const std::string& processName)
101 {
102     processName_ = processName;
103     return *this;
104 }
105 
InitPackageName(const std::string & packageName)106 WatchPoint::Builder& WatchPoint::Builder::InitPackageName(const std::string& packageName)
107 {
108     packageName_ = packageName;
109     return *this;
110 }
111 
InitForeGround(const std::string & foreGround)112 WatchPoint::Builder& WatchPoint::Builder::InitForeGround(const std::string& foreGround)
113 {
114     foreGround_ = foreGround;
115     return *this;
116 }
117 
InitLogPath(const std::string & logPath)118 WatchPoint::Builder& WatchPoint::Builder::InitLogPath(const std::string& logPath)
119 {
120     logPath_ = logPath;
121     return *this;
122 }
123 
InitHitraceTime(const std::string & hitraceTime)124 WatchPoint::Builder& WatchPoint::Builder::InitHitraceTime(const std::string& hitraceTime)
125 {
126     hitraceTime_ = hitraceTime;
127     return *this;
128 }
129 
InitSysrqTime(const std::string & sysrqTime)130 WatchPoint::Builder& WatchPoint::Builder::InitSysrqTime(const std::string& sysrqTime)
131 {
132     sysrqTime_ = sysrqTime;
133     return *this;
134 }
135 
Build() const136 WatchPoint WatchPoint::Builder::Build() const
137 {
138     WatchPoint watchPoint = WatchPoint(*this);
139     return watchPoint;
140 }
141 
GetSeq() const142 long WatchPoint::GetSeq() const
143 {
144     return seq_;
145 }
146 
GetTimestamp() const147 unsigned long long WatchPoint::GetTimestamp() const
148 {
149     return timestamp_;
150 }
151 
GetPid() const152 long WatchPoint::GetPid() const
153 {
154     return pid_;
155 }
156 
GetUid() const157 long WatchPoint::GetUid() const
158 {
159     return uid_;
160 }
161 
GetTid() const162 long WatchPoint::GetTid() const
163 {
164     return tid_;
165 }
166 
GetDomain() const167 std::string WatchPoint::GetDomain() const
168 {
169     return domain_;
170 }
171 
GetStringId() const172 std::string WatchPoint::GetStringId() const
173 {
174     return stringId_;
175 }
176 
GetMsg() const177 std::string WatchPoint::GetMsg() const
178 {
179     return msg_;
180 }
181 
GetPackageName() const182 std::string WatchPoint::GetPackageName() const
183 {
184     return packageName_;
185 }
186 
GetProcessName() const187 std::string WatchPoint::GetProcessName() const
188 {
189     return processName_;
190 }
191 
GetForeGround() const192 std::string WatchPoint::GetForeGround() const
193 {
194     return foreGround_;
195 }
196 
GetLogPath() const197 std::string WatchPoint::GetLogPath() const
198 {
199     return logPath_;
200 }
201 
GetHitraceTime() const202 std::string WatchPoint::GetHitraceTime() const
203 {
204     return hitraceTime_;
205 }
206 
GetSysrqTime() const207 std::string WatchPoint::GetSysrqTime() const
208 {
209     return sysrqTime_;
210 }
211 
SetLogPath(const std::string & logPath)212 void WatchPoint::SetLogPath(const std::string& logPath)
213 {
214     logPath_ = logPath;
215 }
216 
SetSeq(long seq)217 void WatchPoint::SetSeq(long seq)
218 {
219     seq_ = seq;
220 }
221 
operator <(const WatchPoint & node) const222 bool WatchPoint::operator<(const WatchPoint& node) const
223 {
224     if (timestamp_ == node.timestamp_) {
225         return stringId_.compare(node.GetStringId());
226     }
227     return timestamp_ < node.timestamp_;
228 }
229 
operator ==(const WatchPoint & node) const230 bool WatchPoint::operator==(const WatchPoint& node) const
231 {
232     return timestamp_ == node.GetTimestamp() && stringId_.compare(node.GetStringId());
233 }
234 } // namespace HiviewDFX
235 } // namespace OHOS
236