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 "cooperate_params.h"
17
18namespace OHOS {
19namespace Msdp {
20namespace DeviceStatus {
21
22StartCooperateParam::StartCooperateParam(int32_t userData, const std::string &remoteNetworkId,
23                                         int32_t startDeviceId, bool checkPermission)
24    : remoteNetworkId(remoteNetworkId), userData(userData),
25      startDeviceId(startDeviceId), checkPermission(checkPermission)
26{}
27
28bool StartCooperateParam::Marshalling(MessageParcel &parcel) const
29{
30    return (
31        parcel.WriteString(remoteNetworkId) &&
32        parcel.WriteInt32(startDeviceId) &&
33        parcel.WriteInt32(userData) &&
34        parcel.WriteBool(checkPermission)
35    );
36}
37
38bool StartCooperateParam::Unmarshalling(MessageParcel &parcel)
39{
40    return (
41        parcel.ReadString(remoteNetworkId) &&
42        parcel.ReadInt32(startDeviceId) &&
43        parcel.ReadInt32(userData) &&
44        parcel.ReadBool(checkPermission)
45    );
46}
47
48StopCooperateParam::StopCooperateParam(int32_t userData, bool isUnchained, bool checkPermission)
49    : userData(userData), isUnchained(isUnchained), checkPermission(checkPermission)
50{}
51
52bool StopCooperateParam::Marshalling(MessageParcel &parcel) const
53{
54    return (
55        parcel.WriteBool(isUnchained) &&
56        parcel.WriteBool(checkPermission) &&
57        parcel.WriteInt32(userData)
58    );
59}
60
61bool StopCooperateParam::Unmarshalling(MessageParcel &parcel)
62{
63    return (
64        parcel.ReadBool(isUnchained) &&
65        parcel.ReadBool(checkPermission) &&
66        parcel.ReadInt32(userData)
67    );
68}
69
70GetCooperateStateParam::GetCooperateStateParam(int32_t userData, const std::string &networkId, bool checkPermission)
71    : networkId(networkId), userData(userData), checkPermission(checkPermission)
72{}
73
74bool GetCooperateStateParam::Marshalling(MessageParcel &parcel) const
75{
76    return (
77        parcel.WriteInt32(userData) &&
78        parcel.WriteString(networkId) &&
79        parcel.WriteBool(checkPermission)
80    );
81}
82
83bool GetCooperateStateParam::Unmarshalling(MessageParcel &parcel)
84{
85    return (
86        parcel.ReadInt32(userData) &&
87        parcel.ReadString(networkId) &&
88        parcel.ReadBool(checkPermission)
89    );
90}
91
92RegisterEventListenerParam::RegisterEventListenerParam(const std::string &networkId) : networkId(networkId)
93{}
94
95bool RegisterEventListenerParam::Marshalling(MessageParcel &parcel) const
96{
97    return parcel.WriteString(networkId);
98}
99
100bool RegisterEventListenerParam::Unmarshalling(MessageParcel &parcel)
101{
102    return parcel.ReadString(networkId);
103}
104
105SetDamplingCoefficientParam::SetDamplingCoefficientParam(uint32_t direction, double coefficient)
106    : direction(direction), coefficient(coefficient) {}
107
108bool SetDamplingCoefficientParam::Marshalling(MessageParcel &parcel) const
109{
110    return (
111        parcel.WriteUint32(direction) &&
112        parcel.WriteDouble(coefficient)
113    );
114}
115
116bool SetDamplingCoefficientParam::Unmarshalling(MessageParcel &parcel)
117{
118    return (
119        parcel.ReadUint32(direction) &&
120        parcel.ReadDouble(coefficient)
121    );
122}
123
124GetCooperateStateSyncParam::GetCooperateStateSyncParam(const std::string &udId) : udId(udId)
125{}
126
127bool GetCooperateStateSyncParam::Marshalling(MessageParcel &parcel) const
128{
129    return parcel.WriteString(udId);
130}
131
132bool GetCooperateStateSyncParam::Unmarshalling(MessageParcel &parcel)
133{
134    return parcel.ReadString(udId);
135}
136
137RegisterHotAreaListenerParam::RegisterHotAreaListenerParam(int32_t userData, bool checkPermission) : userData(userData),
138    checkPermission(checkPermission)
139{}
140
141bool RegisterHotAreaListenerParam::Marshalling(MessageParcel &parcel) const
142{
143    return parcel.WriteInt32(userData) &&
144        parcel.WriteBool(checkPermission);
145}
146
147bool RegisterHotAreaListenerParam::Unmarshalling(MessageParcel &parcel)
148{
149    return parcel.ReadInt32(userData) &&
150        parcel.ReadBool(checkPermission);
151}
152
153} // namespace DeviceStatus
154} // namespace Msdp
155} // namespace OHOS
156