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 "socket_params.h"
17
18namespace OHOS {
19namespace Msdp {
20namespace DeviceStatus {
21AllocSocketPairParam::AllocSocketPairParam(const std::string &programName, int32_t moduleType)
22    : programName(programName), moduleType(moduleType)
23{}
24
25bool AllocSocketPairParam::Marshalling(MessageParcel &parcel) const
26{
27    return (
28        parcel.WriteString(programName) &&
29        parcel.WriteInt32(moduleType)
30    );
31}
32
33bool AllocSocketPairParam::Unmarshalling(MessageParcel &parcel)
34{
35    return (
36        parcel.ReadString(programName) &&
37        parcel.ReadInt32(moduleType)
38    );
39}
40
41AllocSocketPairReply::AllocSocketPairReply(int32_t tokenType, int32_t socketFd)
42    : tokenType(tokenType), socketFd(socketFd)
43{}
44
45bool AllocSocketPairReply::Marshalling(MessageParcel &parcel) const
46{
47    return (
48        parcel.WriteInt32(tokenType) &&
49        parcel.WriteFileDescriptor(socketFd)
50    );
51}
52
53bool AllocSocketPairReply::Unmarshalling(MessageParcel &parcel)
54{
55    bool ret = parcel.ReadInt32(tokenType);
56    socketFd = parcel.ReadFileDescriptor();
57    return (ret && (socketFd >= 0));
58}
59} // namespace DeviceStatus
60} // namespace Msdp
61} // namespace OHOS
62