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 "stationary_params.h"
17
18 namespace OHOS {
19 namespace Msdp {
20 namespace DeviceStatus {
21
SubscribeStationaryParam(Type type,ActivityEvent event,ReportLatencyNs latency,sptr<IRemoteDevStaCallback> callback)22 SubscribeStationaryParam::SubscribeStationaryParam(Type type, ActivityEvent event,
23 ReportLatencyNs latency, sptr<IRemoteDevStaCallback> callback)
24 : type_(type), event_(event), latency_(latency), callback_(callback)
25 {}
26
Marshalling(MessageParcel & parcel) const27 bool SubscribeStationaryParam::Marshalling(MessageParcel &parcel) const
28 {
29 return (
30 parcel.WriteInt32(type_) &&
31 parcel.WriteInt32(event_) &&
32 parcel.WriteInt32(latency_) &&
33 (callback_ != nullptr) &&
34 parcel.WriteRemoteObject(callback_->AsObject())
35 );
36 }
37
Unmarshalling(MessageParcel & parcel)38 bool SubscribeStationaryParam::Unmarshalling(MessageParcel &parcel)
39 {
40 int32_t type {};
41 int32_t event {};
42 int32_t latency {};
43
44 bool result = parcel.ReadInt32(type) &&
45 parcel.ReadInt32(event) &&
46 parcel.ReadInt32(latency);
47 if (!result) {
48 return false;
49 }
50 type_ = static_cast<Type>(type);
51 event_ = static_cast<ActivityEvent>(event);
52 latency_ = static_cast<ReportLatencyNs>(latency);
53 sptr<IRemoteObject> obj = parcel.ReadRemoteObject();
54 if (obj == nullptr) {
55 return false;
56 }
57 callback_ = iface_cast<IRemoteDevStaCallback>(obj);
58 return (callback_ != nullptr);
59 }
60
GetStaionaryDataParam(Type type)61 GetStaionaryDataParam::GetStaionaryDataParam(Type type)
62 : type_(type) {}
63
Marshalling(MessageParcel & parcel) const64 bool GetStaionaryDataParam::Marshalling(MessageParcel &parcel) const
65 {
66 return parcel.WriteInt32(type_);
67 }
68
Unmarshalling(MessageParcel & parcel)69 bool GetStaionaryDataParam::Unmarshalling(MessageParcel &parcel)
70 {
71 int32_t type {};
72
73 if (!parcel.ReadInt32(type)) {
74 return false;
75 }
76 type_ = static_cast<Type>(type);
77 return true;
78 }
79
GetStaionaryDataReply(Data data)80 GetStaionaryDataReply::GetStaionaryDataReply(Data data)
81 : data_(data) {}
82
Marshalling(MessageParcel & parcel) const83 bool GetStaionaryDataReply::Marshalling(MessageParcel &parcel) const
84 {
85 return (
86 parcel.WriteInt32(data_.type) &&
87 parcel.WriteInt32(data_.value) &&
88 parcel.WriteInt32(data_.status) &&
89 parcel.WriteInt32(data_.action) &&
90 parcel.WriteDouble(data_.movement)
91 );
92 }
93
Unmarshalling(MessageParcel & parcel)94 bool GetStaionaryDataReply::Unmarshalling(MessageParcel &parcel)
95 {
96 int32_t type {};
97 int32_t value {};
98 int32_t status {};
99 int32_t action {};
100
101 bool result = parcel.ReadInt32(type) &&
102 parcel.ReadInt32(value) &&
103 parcel.ReadInt32(status) &&
104 parcel.ReadInt32(action) &&
105 parcel.ReadDouble(data_.movement);
106 if (!result) {
107 return false;
108 }
109 data_.type = static_cast<Type>(type);
110 data_.value = static_cast<OnChangedValue>(value);
111 data_.status = static_cast<Status>(status);
112 data_.action = static_cast<Action>(action);
113 return true;
114 }
115 } // namespace DeviceStatus
116 } // namespace Msdp
117 } // namespace OHOS