• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "badge_number_callback_data.h"
17 
18 #include <string>
19 
20 #include "ans_log_wrapper.h"
21 #include "parcel.h"
22 #include "string_ex.h"
23 
24 namespace OHOS {
25 namespace Notification {
BadgeNumberCallbackData(const std::string & bundle,int32_t uid,int32_t badgeNumber)26 BadgeNumberCallbackData::BadgeNumberCallbackData(const std::string &bundle, int32_t uid, int32_t badgeNumber)
27     : bundle_(bundle), uid_(uid), badgeNumber_(badgeNumber)
28 {}
29 
SetBundle(const std::string & bundle)30 void BadgeNumberCallbackData::SetBundle(const std::string &bundle)
31 {
32     bundle_ = bundle;
33 }
34 
GetBundle() const35 std::string BadgeNumberCallbackData::GetBundle() const
36 {
37     return bundle_;
38 }
39 
SetUid(int32_t uid)40 void BadgeNumberCallbackData::SetUid(int32_t uid)
41 {
42     uid_ = uid;
43 }
44 
GetUid() const45 int32_t BadgeNumberCallbackData::GetUid() const
46 {
47     return uid_;
48 }
49 
SetBadgeNumber(int32_t badgeNumber)50 void BadgeNumberCallbackData::SetBadgeNumber(int32_t badgeNumber)
51 {
52     badgeNumber_ = badgeNumber;
53 }
54 
GetBadgeNumber() const55 int32_t BadgeNumberCallbackData::GetBadgeNumber() const
56 {
57     return badgeNumber_;
58 }
59 
Dump()60 std::string BadgeNumberCallbackData::Dump()
61 {
62     return "BadgeNumberCallbackData{ "
63             "bundle = " + bundle_ +
64             ", uid = " + std::to_string(uid_) +
65             ", badgeNumber = " + std::to_string(badgeNumber_) +
66             " }";
67 }
68 
Marshalling(Parcel & parcel) const69 bool BadgeNumberCallbackData::Marshalling(Parcel &parcel) const
70 {
71     if (!parcel.WriteString16(Str8ToStr16(bundle_))) {
72         ANS_LOGE("Failed to write bundle name");
73         return false;
74     }
75 
76     if (!parcel.WriteInt32(uid_)) {
77         ANS_LOGE("Failed to write uid");
78         return false;
79     }
80 
81     if (!parcel.WriteInt32(badgeNumber_)) {
82         ANS_LOGE("Failed to write badgeNumber");
83         return false;
84     }
85 
86     return true;
87 }
88 
Unmarshalling(Parcel & parcel)89 BadgeNumberCallbackData *BadgeNumberCallbackData::Unmarshalling(Parcel &parcel)
90 {
91     auto objptr = new (std::nothrow) BadgeNumberCallbackData();
92     if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) {
93         delete objptr;
94         objptr = nullptr;
95     }
96 
97     return objptr;
98 }
99 
ReadFromParcel(Parcel & parcel)100 bool BadgeNumberCallbackData::ReadFromParcel(Parcel &parcel)
101 {
102     bundle_ = Str16ToStr8(parcel.ReadString16());
103     uid_ = parcel.ReadInt32();
104     badgeNumber_ = parcel.ReadInt32();
105 
106     return true;
107 }
108 }  // namespace Notification
109 }  // namespace OHOS