• 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 "ability_connection_info.h"
17 
18 #include "dtbschedmgr_log.h"
19 #include "parcel_helper.h"
20 #include "parcel_macro.h"
21 #include "string_ex.h"
22 
23 namespace OHOS {
24 namespace DistributedCollab {
25 namespace {
26 const std::string TAG = "collabSessionInfo";
27 }
28 
ReadFromParcel(Parcel & parcel)29 bool PeerInfo::ReadFromParcel(Parcel &parcel)
30 {
31     deviceId = Str16ToStr8(parcel.ReadString16());
32     bundleName = Str16ToStr8(parcel.ReadString16());
33     moduleName = Str16ToStr8(parcel.ReadString16());
34     abilityName = Str16ToStr8(parcel.ReadString16());
35     serverId = Str16ToStr8(parcel.ReadString16());
36     serviceName = serverId;
37     return true;
38 }
39 
Marshalling(Parcel & parcel) const40 bool PeerInfo::Marshalling(Parcel &parcel) const
41 {
42     parcel.WriteString16(Str8ToStr16(deviceId));
43     parcel.WriteString16(Str8ToStr16(bundleName));
44     parcel.WriteString16(Str8ToStr16(moduleName));
45     parcel.WriteString16(Str8ToStr16(abilityName));
46     parcel.WriteString16(Str8ToStr16(serverId));
47     return true;
48 }
49 
Unmarshalling(Parcel & parcel)50 PeerInfo *PeerInfo::Unmarshalling(Parcel &parcel)
51 {
52     PeerInfo *info = new (std::nothrow) PeerInfo();
53     if (info != nullptr && !info->ReadFromParcel(parcel)) {
54         HILOGE("read from parcel failed");
55         delete info;
56         info = nullptr;
57     }
58     return info;
59 }
60 
ReadFromParcel(Parcel & parcel)61 bool ConnectOption::ReadFromParcel(Parcel &parcel)
62 {
63     needSendData = parcel.ReadBool();
64     needSendStream = parcel.ReadBool();
65     needReceiveStream = parcel.ReadBool();
66     std::shared_ptr<AAFwk::WantParams> optionsPtr(parcel.ReadParcelable<AAFwk::WantParams>());
67     if (optionsPtr) {
68         options = *optionsPtr;
69     }
70     std::shared_ptr<AAFwk::WantParams> parametersPtr(parcel.ReadParcelable<AAFwk::WantParams>());
71     if (parametersPtr) {
72         parameters = *parametersPtr;
73     }
74     return true;
75 }
76 
Marshalling(Parcel & parcel) const77 bool ConnectOption::Marshalling(Parcel &parcel) const
78 {
79     parcel.WriteBool(needSendData);
80     parcel.WriteBool(needSendStream);
81     parcel.WriteBool(needReceiveStream);
82     parcel.WriteParcelable(&options);
83     parcel.WriteParcelable(&parameters);
84     return true;
85 }
86 
Unmarshalling(Parcel & parcel)87 ConnectOption *ConnectOption::Unmarshalling(Parcel &parcel)
88 {
89     ConnectOption *opt = new (std::nothrow) ConnectOption();
90     if (opt != nullptr && !opt->ReadFromParcel(parcel)) {
91         HILOGE("read from parcel failed");
92         delete opt;
93         opt = nullptr;
94     }
95     return opt;
96 }
97 }  // namespace DistributedCollab
98 }  // namespace OHOS