• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "notification_do_not_disturb_date.h"
17 #include "ans_log_wrapper.h"
18 
19 namespace OHOS {
20 namespace Notification {
NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType doNotDisturbType,int64_t beginDate,int64_t endDate)21 NotificationDoNotDisturbDate::NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType doNotDisturbType,
22     int64_t beginDate, int64_t endDate)
23     : doNotDisturbType_(doNotDisturbType), beginDate_(beginDate), endDate_(endDate)
24 {}
25 
SetDoNotDisturbType(NotificationConstant::DoNotDisturbType doNotDisturbType)26 void NotificationDoNotDisturbDate::SetDoNotDisturbType(NotificationConstant::DoNotDisturbType doNotDisturbType)
27 {
28     doNotDisturbType_ = doNotDisturbType;
29 }
30 
GetDoNotDisturbType() const31 NotificationConstant::DoNotDisturbType NotificationDoNotDisturbDate::GetDoNotDisturbType() const
32 {
33     return doNotDisturbType_;
34 }
35 
SetBeginDate(const int64_t beginDate)36 void NotificationDoNotDisturbDate::SetBeginDate(const int64_t beginDate)
37 {
38     beginDate_ = beginDate;
39 }
40 
GetBeginDate() const41 int64_t NotificationDoNotDisturbDate::GetBeginDate() const
42 {
43     return beginDate_;
44 }
45 
SetEndDate(const int64_t endDate)46 void NotificationDoNotDisturbDate::SetEndDate(const int64_t endDate)
47 {
48     endDate_ = endDate;
49 }
50 
GetEndDate() const51 int64_t NotificationDoNotDisturbDate::GetEndDate() const
52 {
53     return endDate_;
54 }
55 
Dump()56 std::string NotificationDoNotDisturbDate::Dump()
57 {
58     return "NotificationDoNotDisturbDate{ "
59             "doNotDisturbType = " + std::to_string(static_cast<int32_t>(doNotDisturbType_)) +
60             ", beginDate = " + std::to_string(beginDate_) +
61             ", endDate = " + std::to_string(endDate_) +
62             " }";
63 }
64 
Marshalling(Parcel & parcel) const65 bool NotificationDoNotDisturbDate::Marshalling(Parcel &parcel) const
66 {
67     if (!parcel.WriteInt32(static_cast<int32_t>(doNotDisturbType_))) {
68         ANS_LOGE("Failed to write doNotDisturbType");
69         return false;
70     }
71 
72     if (!parcel.WriteInt64(beginDate_)) {
73         ANS_LOGE("Failed to write begin time");
74         return false;
75     }
76 
77     if (!parcel.WriteInt64(endDate_)) {
78         ANS_LOGE("Failed to write end time");
79         return false;
80     }
81 
82     return true;
83 }
84 
Unmarshalling(Parcel & parcel)85 NotificationDoNotDisturbDate *NotificationDoNotDisturbDate::Unmarshalling(Parcel &parcel)
86 {
87     auto objptr = new (std::nothrow) NotificationDoNotDisturbDate();
88     if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) {
89         delete objptr;
90         objptr = nullptr;
91     }
92 
93     return objptr;
94 }
95 
ReadFromParcel(Parcel & parcel)96 bool NotificationDoNotDisturbDate::ReadFromParcel(Parcel &parcel)
97 {
98     doNotDisturbType_ = static_cast<NotificationConstant::DoNotDisturbType>(parcel.ReadInt32());
99     beginDate_        = parcel.ReadInt64();
100     endDate_          = parcel.ReadInt64();
101 
102     return true;
103 }
104 }  // namespace Notification
105 }  // namespace OHOS