• 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 #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SHARING_CENTER_H
17 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SHARING_CENTER_H
18 
19 #include <errors.h>
20 #include <string>
21 #include <tuple>
22 #include <vector>
23 
24 #include "visibility.h"
25 namespace OHOS::DistributedData {
26 class API_EXPORT SharingCenter {
27 public:
28     enum Role { ROLE_NIL = -1, ROLE_INVITER, ROLE_INVITEE, ROLE_BUTT };
29 
30     enum Confirmation {
31         CFM_NIL = -1,
32         CFM_UNKNOWN,
33         CFM_ACCEPTED,
34         CFM_REJECTED,
35         CFM_SUSPENDED,
36         CFM_UNAVAILABLE,
37         CFM_BUTT
38     };
39 
40     struct Privilege {
41         bool writable = false;
42         bool readable = false;
43         bool creatable = false;
44         bool deletable = false;
45         bool shareable = false;
46     };
47 
48     struct Participant {
49         std::string identity;
50         int32_t role = Role::ROLE_NIL;
51         int32_t state = Confirmation::CFM_NIL;
52         Privilege privilege;
53         std::string attachInfo;
54     };
55 
56     using Participants = std::vector<Participant>;
57     using Results = std::tuple<int32_t, std::string, std::vector<std::pair<int32_t, std::string>>>;
58     using QueryResults = std::tuple<int32_t, std::string, Participants>;
59     enum CloudShareModule {
60         CLOUD_SHARE_MODULE_ID = 12,
61     };
62     static const ErrCode SHARING_ERR_OFFSET = ErrCodeOffset(SUBSYS_DISTRIBUTEDDATAMNG, CLOUD_SHARE_MODULE_ID);
63     enum SharingCode : int32_t {
64         SUCCESS = 0,
65         REPEATED_REQUEST,
66         NOT_INVITER,
67         NOT_INVITER_OR_INVITEE,
68         OVER_QUOTA,
69         TOO_MANY_PARTICIPANTS,
70         INVALID_ARGS,
71         NETWORK_ERROR,
72         CLOUD_DISABLED,
73         SERVER_ERROR,
74         INNER_ERROR,
75         INVALID_INVITATION,
76         RATE_LIMIT,
77         IPC_ERROR,
78         NOT_SUPPORT,
79         CUSTOM_ERROR = 1000,
80     };
81 
82     virtual Results Share(int32_t userId, const std::string &bundleName, const std::string &sharingRes,
83         const Participants &participants);
84     virtual Results Unshare(int32_t userId, const std::string &bundleName, const std::string &sharingRes,
85         const Participants &participants);
86     virtual std::pair<int32_t, std::string> Exit(
87         int32_t userId, const std::string &bundleName, const std::string &sharingRes);
88     virtual Results ChangePrivilege(int32_t userId, const std::string &bundleName, const std::string &sharingRes,
89         const Participants &participants);
90     virtual QueryResults Query(int32_t userId, const std::string &bundleName, const std::string &sharingRes);
91     virtual QueryResults QueryByInvitation(
92         int32_t userId, const std::string &bundleName, const std::string &invitation);
93     virtual std::tuple<int32_t, std::string, std::string> ConfirmInvitation(
94         int32_t userId, const std::string &bundleName, const std::string &invitation, int32_t confirmation);
95     virtual std::pair<int32_t, std::string> ChangeConfirmation(
96         int32_t userId, const std::string &bundleName, const std::string &sharingRes, int32_t confirmation);
97 };
98 } // namespace OHOS::DistributedData
99 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SHARING_CENTER_H
100