• 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 #ifndef UDMF_CAPI_COMMON_H
17 #define UDMF_CAPI_COMMON_H
18 
19 #include "unified_record.h"
20 #include "unified_data.h"
21 #include "udmf.h"
22 #include <mutex>
23 #include <cstdint>
24 
25 # define MAX_GENERAL_ENTRY_SIZE (100 * 1024 * 1024)
26 
27 struct UdsObject {
28     const int64_t cid;
29     std::shared_ptr<OHOS::UDMF::Object> obj;
30     std::mutex mutex;
31     explicit UdsObject(int cid);
32     template<typename T> T* GetUdsValue(const char* paramName);
33     template<typename T> int SetUdsValue(const char* paramName, const T &pramValue);
34 private:
35     template<typename T> bool HasObjectKey(const char* paramName);
36 };
37 
38 enum NdkStructId : std::int64_t {
39     UTD_STRUCT_ID = 1002930,
40     UDS_PLAIN_TEXT_STRUCT_ID,
41     UDS_HYPERLINK_STRUCT_ID,
42     UDS_HTML_STRUCT_ID,
43     UDS_APP_ITEM_STRUCT_ID,
44     UDMF_UNIFIED_DATA_STRUCT_ID,
45     UDMF_UNIFIED_RECORD_STRUCT_ID,
46     UDMF_UNIFIED_DATA_PROPERTIES_ID,
47     UDS_FILE_URI_STRUCT_ID,
48     UDS_PIXEL_MAP_STRUCT_ID,
49     UDS_ARRAY_BUFFER_STRUCT_ID,
50     UDS_CONTENT_FORM_STRUCT_ID
51 };
52 
53 struct OH_Utd {
54     const int64_t cid = UTD_STRUCT_ID;
55     std::mutex mutex;
56     std::string typeId;
57     const char **belongingToTypes {nullptr};
58     unsigned int belongingToTypesCount {0};
59     const char **filenameExtensions {nullptr};
60     unsigned int filenameExtensionsCount {0};
61     const char **mimeTypes {nullptr};
62     unsigned int mimeTypeCount {0};
63     std::string description;
64     std::string referenceURL;
65     std::string iconFile;
66 };
67 
68 struct OH_UdsPlainText : public UdsObject {
69     OH_UdsPlainText();
70 };
71 struct OH_UdsHyperlink : public UdsObject {
72     OH_UdsHyperlink();
73 };
74 struct OH_UdsHtml : public UdsObject {
75     OH_UdsHtml();
76 };
77 struct OH_UdsAppItem : public UdsObject {
78     OH_UdsAppItem();
79 };
80 struct OH_UdsFileUri : public UdsObject {
81     OH_UdsFileUri();
82 };
83 struct OH_UdsPixelMap : public UdsObject {
84     OH_UdsPixelMap();
85 };
86 struct OH_UdsArrayBuffer : public UdsObject {
87     OH_UdsArrayBuffer();
88 };
89 struct OH_UdsContentForm : public UdsObject {
90     OH_UdsContentForm();
91 };
92 
93 struct OH_UdmfRecord {
94     const int64_t cid = UDMF_UNIFIED_RECORD_STRUCT_ID;
95     std::shared_ptr<OHOS::UDMF::UnifiedRecord> record_;
96     unsigned char *recordData {nullptr};
97     unsigned int recordDataLen {0};
98     char **typesArray {nullptr};
99     unsigned int typesCount {0};
100     char *lastType {nullptr};
101     std::mutex mutex;
102 };
103 
104 struct OH_UdmfData {
105     const int64_t cid = UDMF_UNIFIED_DATA_STRUCT_ID;
106     std::shared_ptr<OHOS::UDMF::UnifiedData> unifiedData_;
107     char **typesArray {nullptr};
108     unsigned int typesCount {0};
109     OH_UdmfRecord **records {nullptr};
110     unsigned int recordsCount {0};
111     std::mutex mutex;
112 };
113 
114 struct OH_UdmfProperty {
115     const int64_t cid = UDMF_UNIFIED_DATA_PROPERTIES_ID;
116     std::shared_ptr<OHOS::UDMF::UnifiedDataProperties> properties_;
117     std::mutex mutex;
118     std::string extraStr;
119 };
120 
121 struct OH_Udmf_ProgressInfo {
122     int progress;
123     int status;
124 };
125 
126 struct OH_UdmfDataLoadInfo {
127     char **typesArray {nullptr};
128     unsigned int typesCount {0};
129     unsigned int recordsCount {0};
130 };
131 
132 struct OH_UdmfGetDataParams {
133     std::string destUri;
134     Udmf_FileConflictOptions fileConflictOptions;
135     Udmf_ProgressIndicator progressIndicator;
136     OH_Udmf_DataProgressListener dataProgressListener;
137     OH_UdmfDataLoadInfo acceptableInfo;
138 };
139 
140 struct OH_UdmfDataLoadParams {
141     OH_UdmfDataLoadInfo dataLoadInfo;
142     OH_Udmf_DataLoadHandler dataLoadHandler;
143 };
144 
145 struct OH_UdmfOptions {
146     std::string key;
147     Udmf_Intention intention {};
148     Udmf_Visibility visibility {};
149 };
150 
151 bool IsInvalidUdsObjectPtr(const UdsObject* pThis, int cid);
152 
153 bool IsInvalidUdsObjectByType(const UdsObject* pThis, const OHOS::UDMF::UDType& type);
154 
155 #endif
156