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 logPath_(builder.logPath_)
39 {
40 }
41
Builder()42 WatchPoint::Builder::Builder()
43 : seq_(0), timestamp_(0), pid_(0), uid_(0), tid_(0), domain_(""), stringId_(""), msg_("")
44 {
45 }
46
~Builder()47 WatchPoint::Builder::~Builder() {}
48
InitSeq(long seq)49 WatchPoint::Builder& WatchPoint::Builder::InitSeq(long seq)
50 {
51 seq_ = seq;
52 return *this;
53 }
54
InitTimestamp(unsigned long long timestamp)55 WatchPoint::Builder& WatchPoint::Builder::InitTimestamp(unsigned long long timestamp)
56 {
57 timestamp_ = timestamp;
58 return *this;
59 }
60
InitPid(long pid)61 WatchPoint::Builder& WatchPoint::Builder::InitPid(long pid)
62 {
63 pid_ = pid;
64 return *this;
65 }
66
InitUid(long uid)67 WatchPoint::Builder& WatchPoint::Builder::InitUid(long uid)
68 {
69 uid_ = uid;
70 return *this;
71 }
72
InitTid(long tid)73 WatchPoint::Builder& WatchPoint::Builder::InitTid(long tid)
74 {
75 tid_ = tid;
76 return *this;
77 }
78
InitDomain(const std::string & domain)79 WatchPoint::Builder& WatchPoint::Builder::InitDomain(const std::string& domain)
80 {
81 domain_ = domain;
82 return *this;
83 }
84
InitStringId(const std::string & stringId)85 WatchPoint::Builder& WatchPoint::Builder::InitStringId(const std::string& stringId)
86 {
87 stringId_ = stringId;
88 return *this;
89 }
90
InitMsg(const std::string & msg)91 WatchPoint::Builder& WatchPoint::Builder::InitMsg(const std::string& msg)
92 {
93 msg_ = msg;
94 return *this;
95 }
96
InitProcessName(const std::string & processName)97 WatchPoint::Builder& WatchPoint::Builder::InitProcessName(const std::string& processName)
98 {
99 processName_ = processName;
100 return *this;
101 }
102
InitPackageName(const std::string & packageName)103 WatchPoint::Builder& WatchPoint::Builder::InitPackageName(const std::string& packageName)
104 {
105 packageName_ = packageName;
106 return *this;
107 }
108
InitLogPath(const std::string & logPath)109 WatchPoint::Builder& WatchPoint::Builder::InitLogPath(const std::string& logPath)
110 {
111 logPath_ = logPath;
112 return *this;
113 }
114
Build() const115 WatchPoint WatchPoint::Builder::Build() const
116 {
117 WatchPoint watchPoint = WatchPoint(*this);
118 return watchPoint;
119 }
120
GetSeq() const121 long WatchPoint::GetSeq() const
122 {
123 return seq_;
124 }
125
GetTimestamp() const126 unsigned long long WatchPoint::GetTimestamp() const
127 {
128 return timestamp_;
129 }
130
GetPid() const131 long WatchPoint::GetPid() const
132 {
133 return pid_;
134 }
135
GetUid() const136 long WatchPoint::GetUid() const
137 {
138 return uid_;
139 }
140
GetTid() const141 long WatchPoint::GetTid() const
142 {
143 return tid_;
144 }
145
GetDomain() const146 std::string WatchPoint::GetDomain() const
147 {
148 return domain_;
149 }
150
GetStringId() const151 std::string WatchPoint::GetStringId() const
152 {
153 return stringId_;
154 }
155
GetMsg() const156 std::string WatchPoint::GetMsg() const
157 {
158 return msg_;
159 }
160
GetPackageName() const161 std::string WatchPoint::GetPackageName() const
162 {
163 return packageName_;
164 }
165
GetProcessName() const166 std::string WatchPoint::GetProcessName() const
167 {
168 return processName_;
169 }
170
GetLogPath() const171 std::string WatchPoint::GetLogPath() const
172 {
173 return logPath_;
174 }
175
SetLogPath(const std::string & logPath)176 void WatchPoint::SetLogPath(const std::string& logPath)
177 {
178 logPath_ = logPath;
179 }
180
SetSeq(long seq)181 void WatchPoint::SetSeq(long seq)
182 {
183 seq_ = seq;
184 }
185
operator <(const WatchPoint & node) const186 bool WatchPoint::operator<(const WatchPoint& node) const
187 {
188 if (timestamp_ == node.timestamp_) {
189 return stringId_.compare(node.GetStringId());
190 }
191 return timestamp_ < node.timestamp_;
192 }
193
operator ==(const WatchPoint & node) const194 bool WatchPoint::operator==(const WatchPoint& node) const
195 {
196 return timestamp_ == node.GetTimestamp() && stringId_.compare(node.GetStringId());
197 }
198 } // namespace HiviewDFX
199 } // namespace OHOS
200