• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "cloud_value_util.h"
17 
18 namespace OHOS::CloudData {
19 namespace SharingUtil {
Convert(const Privilege & privilege)20 SharingPlege Convert(const Privilege &privilege)
21 {
22     SharingPlege result;
23     result.writable = privilege.writable;
24     result.readable = privilege.readable ;
25     result.creatable = privilege.creatable;
26     result.deletable = privilege.deletable;
27     result.shareable = privilege.shareable;
28     return result;
29 }
30 
Convert(const Participant & participant)31 SharingPtpant Convert(const Participant &participant)
32 {
33     SharingPtpant result;
34     result.identity = participant.identity;
35     result.role = participant.role;
36     result.state = participant.state;
37     result.privilege = Convert(participant.privilege);
38     result.attachInfo = participant.attachInfo;
39     return result;
40 }
41 
Convert(const Confirmation & cfm)42 SharingCfm Convert(const Confirmation &cfm)
43 {
44     switch (cfm) {
45         case Confirmation::CFM_UNKNOWN:
46             return SharingCfm::CFM_UNKNOWN;
47         case Confirmation::CFM_ACCEPTED:
48             return SharingCfm::CFM_ACCEPTED;
49         case Confirmation::CFM_REJECTED:
50             return SharingCfm::CFM_REJECTED;
51         case Confirmation::CFM_SUSPENDED:
52             return SharingCfm::CFM_SUSPENDED;
53         default:
54             break;
55     }
56     return SharingCfm::CFM_UNKNOWN;
57 }
58 
Convert(const SharingPtpant & participant)59 Participant Convert(const SharingPtpant &participant)
60 {
61     Participant result;
62     result.identity = participant.identity;
63     result.role = participant.role;
64     result.state = participant.state;
65     result.privilege = Convert(participant.privilege);
66     result.attachInfo = participant.attachInfo;
67     return result;
68 }
69 
Convert(const SharingCfm & cfm)70 Confirmation Convert(const SharingCfm &cfm)
71 {
72     switch (cfm) {
73         case SharingCfm::CFM_UNKNOWN:
74             return Confirmation::CFM_UNKNOWN;
75         case SharingCfm::CFM_ACCEPTED:
76             return Confirmation::CFM_ACCEPTED;
77         case SharingCfm::CFM_REJECTED:
78             return Confirmation::CFM_REJECTED;
79         case SharingCfm::CFM_SUSPENDED:
80             return Confirmation::CFM_SUSPENDED;
81         default:
82             break;
83     }
84     return Confirmation::CFM_UNKNOWN;
85 }
86 
Convert(const SharingPlege & privilege)87 Privilege Convert(const SharingPlege &privilege)
88 {
89     Privilege result;
90     result.writable = privilege.writable;
91     result.readable = privilege.readable ;
92     result.creatable = privilege.creatable;
93     result.deletable = privilege.deletable;
94     result.shareable = privilege.shareable;
95     return result;
96 }
97 
Convert(const SharingResults & results)98 QueryResults Convert(const SharingResults &results)
99 {
100     return { std::get<0>(results), std::get<1>(results),
101         Convert<SharingPtpant, Participant>(std::get<2>(results)) };
102 }
103 
Convert(const std::vector<Participant> & participants)104 std::vector<SharingPtpant> Convert(const std::vector<Participant> &participants)
105 {
106     return Convert<Participant, SharingPtpant>(participants);
107 }
108 
Convert(const std::vector<SharingPtpant> & input)109 std::vector<Participant> Convert(const std::vector<SharingPtpant> &input)
110 {
111     return Convert<SharingPtpant, Participant>(input);
112 }
113 
114 template<typename T, typename O>
Convert(const std::vector<T> & data)115 std::vector<O> Convert(const std::vector<T> &data)
116 {
117     std::vector<O> out;
118     out.reserve(data.size());
119     for (const auto &v : data) {
120         out.emplace_back(Convert(v));
121     }
122     return out;
123 }
124 
Convert(CenterCode code)125 Status Convert(CenterCode code)
126 {
127     switch (code) {
128         case CenterCode::IPC_ERROR:
129             return Status::IPC_ERROR;
130         default:
131             break;
132     }
133     return Status::SUCCESS;
134 }
135 } // namespace::SharingUtil
136 } // namespace OHOS::CloudData
137