• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "os_account_state_parcel.h"
17 
18 #include "account_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace AccountSA {
Marshalling(Parcel & parcel) const22 bool OsAccountStateParcel::Marshalling(Parcel &parcel) const
23 {
24     if (!parcel.WriteInt32(state)) {
25         ACCOUNT_LOGE("Failed to write state");
26         return false;
27     }
28     if (!parcel.WriteInt32(fromId)) {
29         ACCOUNT_LOGE("Failed to write fromId");
30         return false;
31     }
32     if (!parcel.WriteInt32(toId)) {
33         ACCOUNT_LOGE("Failed to write toId");
34         return false;
35     }
36     bool withHandshake = (callback != nullptr);
37     if (!parcel.WriteBool(withHandshake)) {
38         ACCOUNT_LOGE("Failed to write handshake");
39         return false;
40     }
41     if (withHandshake && !parcel.WriteRemoteObject(callback)) {
42         ACCOUNT_LOGE("Failed to write callback");
43         return false;
44     }
45     return true;
46 }
47 
Unmarshalling(Parcel & parcel)48 OsAccountStateParcel *OsAccountStateParcel::Unmarshalling(Parcel &parcel)
49 {
50     OsAccountStateParcel *stateParcel = new (std::nothrow) OsAccountStateParcel();
51     if ((stateParcel != nullptr) && (!stateParcel->ReadFromParcel(parcel))) {
52         ACCOUNT_LOGE("Failed to read state parcel");
53         delete stateParcel;
54         stateParcel = nullptr;
55     }
56     return stateParcel;
57 }
58 
ReadFromParcel(Parcel & parcel)59 bool OsAccountStateParcel::ReadFromParcel(Parcel &parcel)
60 {
61     int32_t stateInt;
62     if (!parcel.ReadInt32(stateInt)) {
63         ACCOUNT_LOGE("Failed to read state");
64         return false;
65     }
66     state = static_cast<OsAccountState>(stateInt);
67     if (!parcel.ReadInt32(fromId)) {
68         ACCOUNT_LOGE("Failed to read fromId");
69         return false;
70     }
71     if (!parcel.ReadInt32(toId)) {
72         ACCOUNT_LOGE("Failed to read toId");
73         return false;
74     }
75     bool withHandshake = false;
76     if (!parcel.ReadBool(withHandshake)) {
77         ACCOUNT_LOGE("Failed to read handshake");
78         return false;
79     }
80     if (!withHandshake) {
81         return true;
82     }
83     callback = static_cast<MessageParcel *>(&parcel)->ReadRemoteObject();
84     if (callback == nullptr) {
85         ACCOUNT_LOGE("Failed to read callback");
86         return false;
87     }
88     return true;
89 }
90 } // AccountSA
91 } // OHOS
92