• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "bundle_active_event_stats.h"
17 
18 namespace OHOS {
19 namespace DeviceUsageStats {
BundleActiveEventStats()20 BundleActiveEventStats::BundleActiveEventStats()
21 {
22     eventId_ = 0;
23     beginTimeStamp_ = 0;
24     endTimeStamp_ = 0;
25     lastEventTime_ = 0;
26     totalTime_ = 0;
27     count_ = 0;
28     name_.clear();
29 }
30 
BundleActiveEventStats(const BundleActiveEventStats & orig)31 BundleActiveEventStats::BundleActiveEventStats(const BundleActiveEventStats& orig)
32 {
33     eventId_ = orig.eventId_;
34     beginTimeStamp_ = orig.beginTimeStamp_;
35     endTimeStamp_ = orig.endTimeStamp_;
36     lastEventTime_ = orig.lastEventTime_;
37     totalTime_ = orig.totalTime_;
38     count_ = orig.count_;
39     name_ = orig.name_;
40 }
41 
GetEventId()42 int32_t BundleActiveEventStats::GetEventId()
43 {
44     return eventId_;
45 }
46 
GetFirstTimeStamp()47 int64_t BundleActiveEventStats::GetFirstTimeStamp()
48 {
49     return beginTimeStamp_;
50 }
51 
GetLastTimeStamp()52 int64_t BundleActiveEventStats::GetLastTimeStamp()
53 {
54     return endTimeStamp_;
55 }
56 
GetLastEventTime()57 int64_t BundleActiveEventStats::GetLastEventTime()
58 {
59     return lastEventTime_;
60 }
61 
GetTotalTime()62 int64_t BundleActiveEventStats::GetTotalTime()
63 {
64     return totalTime_;
65 }
66 
GetCount()67 int32_t BundleActiveEventStats::GetCount()
68 {
69     return count_;
70 }
71 
add(const BundleActiveEventStats & right)72 void BundleActiveEventStats::add(const BundleActiveEventStats& right)
73 {
74     if (eventId_ != right.eventId_) {
75         return;
76     }
77 
78     if (right.beginTimeStamp_ > beginTimeStamp_) {
79         lastEventTime_ = std::max(lastEventTime_, right.lastEventTime_);
80     }
81     beginTimeStamp_ = std::min(beginTimeStamp_, right.beginTimeStamp_);
82     endTimeStamp_ = std::max(endTimeStamp_, right.endTimeStamp_);
83     totalTime_ += right.totalTime_;
84     count_ += right.count_;
85 }
86 
Marshalling(Parcel & parcel) const87 bool BundleActiveEventStats::Marshalling(Parcel &parcel) const
88 {
89     if (parcel.WriteInt32(eventId_) &&
90         parcel.WriteInt64(beginTimeStamp_) &&
91         parcel.WriteInt64(endTimeStamp_) &&
92         parcel.WriteInt64(lastEventTime_) &&
93         parcel.WriteInt64(totalTime_) &&
94         parcel.WriteInt32(count_) &&
95         parcel.WriteString(name_)) {
96         return true;
97     }
98     return false;
99 }
100 
UnMarshalling(Parcel & parcel)101 std::shared_ptr<BundleActiveEventStats> BundleActiveEventStats::UnMarshalling(Parcel &parcel)
102 {
103     std::shared_ptr<BundleActiveEventStats> result = std::make_shared<BundleActiveEventStats>();
104     result->eventId_ = parcel.ReadInt32();
105     result->beginTimeStamp_ = parcel.ReadInt64();
106     result->endTimeStamp_ = parcel.ReadInt64();
107     result->lastEventTime_ = parcel.ReadInt64();
108     result->totalTime_ = parcel.ReadInt64();
109     result->count_ = parcel.ReadInt32();
110     result->name_ = parcel.ReadString();
111     return result;
112 }
113 }  // namespace DeviceUsageStats
114 }  // namespace OHOS
115 
116