• 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 UDMF_UNIFIED_TYPES_H
17 #define UDMF_UNIFIED_TYPES_H
18 
19 #include <map>
20 #include <string>
21 
22 #include "error_code.h"
23 #include "unified_key.h"
24 #include "unified_meta.h"
25 
26 namespace OHOS {
27 namespace UDMF {
28 enum DataStatus : int32_t {
29     WORKING = 0,
30     HISTORY,
31     DELETED,
32     FADE
33 };
34 
35 struct Summary {
36     std::map<std::string, int64_t> summary {};
37     std::map<std::string, int64_t> specificSummary {};
38     std::map<std::string, std::vector<int32_t>> summaryFormat {};
39     // If version value is 1, it means it contains the format variable;
40     // otherwise(not set or 0), it means it does not contain.
41     int32_t version {1};
42     int64_t totalSize {0};
43 };
44 
45 struct Privilege {
46     uint32_t tokenId {0};
47     std::string readPermission;
48     std::string writePermission;
49 };
50 
51 struct Runtime {
52     UnifiedKey key;
53     bool isPrivate {false};
54     std::vector<Privilege> privileges{};
55     // time when the data is created
56     time_t createTime {};
57     // name of the package for creating data
58     std::string sourcePackage;
59     // current data status
60     DataStatus dataStatus { WORKING };
61     // current data version
62     std::int32_t dataVersion {0};
63     // time when the data is last modified
64     time_t lastModifiedTime {};
65     // time when data is written to the udmf
66     std::string createPackage;
67     // device ID of the data source
68     std::string deviceId;
69     std::uint32_t recordTotalNum {0};
70     uint32_t tokenId {0};
71     std::string sdkVersion;
72     Visibility visibility {};
73     std::string appId;
74 };
75 
76 /*
77  * Options for sharing data through UDMF.
78  */
79 struct CustomOption {
80     Intention intention {};
81     uint32_t tokenId {};
82     Visibility visibility {};
83 };
84 
85 /*
86  * Options for querying data from UDMF.
87  */
88 struct QueryOption {
89     std::string key;
90     Intention intention {};
91     uint32_t tokenId {0};
92 };
93 
94 enum AsyncTaskStatus : uint32_t {
95     ASYNC_IDLE = 0,
96     ASYNC_RUNNING,
97     ASYNC_SUCCESS,
98     ASYNC_FAILURE,
99 };
100 
101 struct AsyncProcessInfo {
102     AsyncTaskStatus syncStatus { ASYNC_IDLE };
103     AsyncTaskStatus permStatus { ASYNC_IDLE };
104     std::string srcDevName;
105     uint32_t syncFinished = 0;
106     uint32_t syncTotal = 0;
107     uint32_t syncId = 0;
108     uint32_t permFnished = 0;
109     uint32_t permTotal = 0;
110     std::string businessUdKey;
111 };
112 
113 struct ProgressInfo {
114     int32_t progress {0};
115     int32_t progressStatus {0};
116     Status errorCode;
117     std::string srcDevName;
118 };
119 
120 struct UriInfo {
121     std::string oriUri;
122     std::string authUri;
123     std::string dfsUri;
124     uint32_t position;
125 };
126 
127 struct DataLoadInfo {
128     std::string sequenceKey;
129     std::set<std::string> types {};
130     uint32_t recordCount {0};
131 };
132 
133 using LoadHandler = std::function<void(const std::string &udKey, const DataLoadInfo &dataLoadInfo)>;
134 
135 struct DataLoadParams {
136     LoadHandler loadHandler;
137     DataLoadInfo dataLoadInfo;
138 };
139 
140 struct DelayGetDataInfo {
141     uint32_t tokenId {0};
142 #ifndef CROSS_PLATFORM
143     sptr<IRemoteObject> dataCallback;
144 #endif
145 };
146 } // namespace UDMF
147 } // namespace OHOS
148 #endif // UDMF_UNIFIED_TYPES_H