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