• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "os_account_subscribe_info.h"
16 #include "account_log_wrapper.h"
17 
18 namespace OHOS {
19 namespace AccountSA {
OsAccountSubscribeInfo()20 OsAccountSubscribeInfo::OsAccountSubscribeInfo()
21     : osAccountSubscribeType_(ACTIVATING), name_("")
22 {}
23 
OsAccountSubscribeInfo(const OS_ACCOUNT_SUBSCRIBE_TYPE & osAccountSubscribeType,const std::string & name)24 OsAccountSubscribeInfo::OsAccountSubscribeInfo(const OS_ACCOUNT_SUBSCRIBE_TYPE &osAccountSubscribeType,
25     const std::string &name) : osAccountSubscribeType_(osAccountSubscribeType), name_(name)
26 {}
27 
~OsAccountSubscribeInfo()28 OsAccountSubscribeInfo::~OsAccountSubscribeInfo()
29 {}
30 
GetOsAccountSubscribeType(OS_ACCOUNT_SUBSCRIBE_TYPE & osAccountSubscribeType) const31 void OsAccountSubscribeInfo::GetOsAccountSubscribeType(OS_ACCOUNT_SUBSCRIBE_TYPE &osAccountSubscribeType) const
32 {
33     osAccountSubscribeType = osAccountSubscribeType_;
34 }
35 
SetOsAccountSubscribeType(const OS_ACCOUNT_SUBSCRIBE_TYPE & osAccountSubscribeType)36 void OsAccountSubscribeInfo::SetOsAccountSubscribeType(const OS_ACCOUNT_SUBSCRIBE_TYPE &osAccountSubscribeType)
37 {
38     osAccountSubscribeType_ = osAccountSubscribeType;
39 }
40 
GetName(std::string & name) const41 void OsAccountSubscribeInfo::GetName(std::string &name) const
42 {
43     name = name_;
44 }
45 
SetName(const std::string & name)46 void OsAccountSubscribeInfo::SetName(const std::string &name)
47 {
48     name_ = name;
49 }
50 
Marshalling(Parcel & parcel) const51 bool OsAccountSubscribeInfo::Marshalling(Parcel &parcel) const
52 {
53     if (!parcel.WriteInt32(osAccountSubscribeType_)) {
54         ACCOUNT_LOGE("failed to write osAccountSubscribeType_");
55         return false;
56     }
57     if (!parcel.WriteString(name_)) {
58         ACCOUNT_LOGE("failed to write name_");
59         return false;
60     }
61 
62     return true;
63 }
64 
Unmarshalling(Parcel & parcel)65 OsAccountSubscribeInfo *OsAccountSubscribeInfo::Unmarshalling(Parcel &parcel)
66 {
67     OsAccountSubscribeInfo *subscribeInfo = new (std::nothrow) OsAccountSubscribeInfo();
68 
69     if (subscribeInfo && !subscribeInfo->ReadFromParcel(parcel)) {
70         ACCOUNT_LOGE("failed to read from parcel");
71         delete subscribeInfo;
72         subscribeInfo = nullptr;
73     }
74 
75     return subscribeInfo;
76 }
77 
ReadFromParcel(Parcel & parcel)78 bool OsAccountSubscribeInfo::ReadFromParcel(Parcel &parcel)
79 {
80     int type = -1;
81     if (!parcel.ReadInt32(type)) {
82         ACCOUNT_LOGE("failed to read OS_ACCOUNT_SUBSCRIBE_TYPE osAccountSubscribeType_");
83         return false;
84     }
85     osAccountSubscribeType_ = static_cast<OS_ACCOUNT_SUBSCRIBE_TYPE>(type);
86     if (!parcel.ReadString(name_)) {
87         ACCOUNT_LOGE("failed to read string  name_");
88         return false;
89     }
90 
91     return true;
92 }
93 }  // namespace AccountSA
94 }  // namespace OHOS