• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 DATASHARE_PROXY_COMMON_H
17 #define DATASHARE_PROXY_COMMON_H
18 
19 #include "datashare_observer.h"
20 
21 namespace OHOS {
22 namespace DataShare {
23 static constexpr int32_t URI_MAX_SIZE = 256;
24 static constexpr int32_t VALUE_MAX_SIZE = 4096;
25 static constexpr int32_t APPIDENTIFIER_MAX_SIZE = 128;
26 static constexpr int32_t URI_MAX_COUNT = 32;
27 static constexpr int32_t PROXY_DATA_MAX_COUNT = 32;
28 static constexpr int32_t ALLOW_LIST_MAX_COUNT = 256;
29 constexpr const char* ALLOW_ALL = "all";
30 constexpr const char* DATA_PROXY_SCHEMA = "datashareproxy://";
31 
32 enum DataProxyErrorCode {
33     SUCCESS = 0,
34     URI_NOT_EXIST,
35     NO_PERMISSION,
36     OVER_LIMIT,
37     INNER_ERROR,
38 };
39 
40 /**
41  * @brief DataProxy Value Type .
42  */
43 enum DataProxyValueType : int32_t {
44     /** DataProxy Value Types is int.*/
45     VALUE_INT = 0,
46     /** DataProxy Value Types is double.*/
47     VALUE_DOUBLE,
48     /** DataProxy Value Types is string.*/
49     VALUE_STRING,
50     /** DataProxy Value Types is bool.*/
51     VALUE_BOOL,
52 };
53 
54 using DataProxyValue = std::variant<int64_t, double, std::string, bool>;
55 
56 enum DataProxyType {
57     SHARED_CONFIG = 0,
58 };
59 
60 struct DataProxyConfig {
61     DataProxyType type_;
62 };
63 
64 struct DataShareProxyData {
65     /**
66      * @brief Constructor.
67      */
68     DataShareProxyData() = default;
69 
70     /**
71      * @brief Destructor.
72      */
73     ~DataShareProxyData() = default;
74 
75     DataShareProxyData(const std::string &uri, const DataProxyValue &value,
uri_DataShareProxyData76         const std::vector<std::string> &allowList = {}) : uri_(uri), value_(value), allowList_(allowList) {}
77 
78     std::string uri_;
79     DataProxyValue value_ = "";
80     std::vector<std::string> allowList_;
81     bool isValueUndefined = false;
82     bool isAllowListUndefined = false;
83 };
84 
85 struct DataProxyResult {
86     DataProxyResult() = default;
DataProxyResultDataProxyResult87     DataProxyResult(const std::string &uri, const DataProxyErrorCode &result) : uri_(uri), result_(result) {}
88     std::string uri_;
89     DataProxyErrorCode result_;
90 };
91 
92 struct DataProxyGetResult {
93     DataProxyGetResult() = default;
94     DataProxyGetResult(const std::string &uri, const DataProxyErrorCode &result,
95         const DataProxyValue &value = {}, const std::vector<std::string> allowList = {})
uri_DataProxyGetResult96         : uri_(uri), result_(result), value_(value), allowList_(allowList) {}
97     std::string uri_;
98     DataProxyErrorCode result_;
99     DataProxyValue value_;
100     std::vector<std::string> allowList_;
101 };
102 
103 struct DataProxyChangeInfo {
104     DataProxyChangeInfo() = default;
DataProxyChangeInfoDataProxyChangeInfo105     DataProxyChangeInfo(const DataShareObserver::ChangeType &changeType,
106         const std::string &uri, const DataProxyValue &value)
107         : changeType_(changeType), uri_(uri), value_(value) {}
108     DataShareObserver::ChangeType changeType_ = DataShareObserver::INVAILD;
109     std::string uri_;
110     DataProxyValue value_;
111 };
112 } // namespace DataShare
113 } // namespace OHOS
114 #endif // DATASHARE_PROXY_COMMON_H