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> bool HasObjectKey(const char* paramName); 33 template<typename T> T* GetUdsValue(const char* paramName); 34 template<typename T> int SetUdsValue(const char* paramName, const T &pramValue); 35 }; 36 37 enum NdkStructId : std::int64_t { 38 UTD_STRUCT_ID = 1002930, 39 UDS_PLAIN_TEXT_STRUCT_ID, 40 UDS_HYPERLINK_STRUCT_ID, 41 UDS_HTML_STRUCT_ID, 42 UDS_APP_ITEM_STRUCT_ID, 43 UDMF_UNIFIED_DATA_STRUCT_ID, 44 UDMF_UNIFIED_RECORD_STRUCT_ID, 45 UDMF_UNIFIED_DATA_PROPERTIES_ID, 46 UDS_FILE_URI_STRUCT_ID, 47 UDS_PIXEL_MAP_STRUCT_ID, 48 UDS_ARRAY_BUFFER_STRUCT_ID, 49 UDS_CONTENT_FORM_STRUCT_ID 50 }; 51 52 struct OH_Utd { 53 const int64_t cid = UTD_STRUCT_ID; 54 std::mutex mutex; 55 std::string typeId; 56 const char** belongingToTypes{nullptr}; 57 unsigned int belongingToTypesCount{0}; 58 const char** filenameExtensions{nullptr}; 59 unsigned int filenameExtensionsCount{0}; 60 const char** mimeTypes{nullptr}; 61 unsigned int mimeTypeCount{0}; 62 std::string description; 63 std::string referenceURL; 64 std::string iconFile; 65 }; 66 67 struct OH_UdsPlainText : public UdsObject { 68 OH_UdsPlainText(); 69 }; 70 struct OH_UdsHyperlink : public UdsObject { 71 OH_UdsHyperlink(); 72 }; 73 struct OH_UdsHtml : public UdsObject { 74 OH_UdsHtml(); 75 }; 76 struct OH_UdsAppItem : public UdsObject { 77 OH_UdsAppItem(); 78 }; 79 struct OH_UdsFileUri : public UdsObject { 80 OH_UdsFileUri(); 81 }; 82 struct OH_UdsPixelMap : public UdsObject { 83 OH_UdsPixelMap(); 84 }; 85 struct OH_UdsArrayBuffer : public UdsObject { 86 OH_UdsArrayBuffer(); 87 }; 88 struct OH_UdsContentForm : public UdsObject { 89 OH_UdsContentForm(); 90 }; 91 92 struct OH_UdmfRecord { 93 const int64_t cid = UDMF_UNIFIED_RECORD_STRUCT_ID; 94 std::shared_ptr<OHOS::UDMF::UnifiedRecord> record_; 95 unsigned char *recordData{nullptr}; 96 unsigned int recordDataLen{0}; 97 char **typesArray{nullptr}; 98 unsigned int typesCount{0}; 99 char *lastType{nullptr}; 100 std::mutex mutex; 101 }; 102 103 struct OH_UdmfData { 104 const int64_t cid = UDMF_UNIFIED_DATA_STRUCT_ID; 105 std::shared_ptr<OHOS::UDMF::UnifiedData> unifiedData_; 106 char **typesArray{nullptr}; 107 unsigned int typesCount{0}; 108 OH_UdmfRecord **records{nullptr}; 109 unsigned int recordsCount{0}; 110 std::mutex mutex; 111 }; 112 113 struct OH_UdmfProperty { 114 const int64_t cid = UDMF_UNIFIED_DATA_PROPERTIES_ID; 115 std::shared_ptr<OHOS::UDMF::UnifiedDataProperties> properties_; 116 std::mutex mutex; 117 std::string extraStr; 118 }; 119 120 struct OH_Udmf_ProgressInfo { 121 int progress; 122 int status; 123 }; 124 125 126 struct OH_UdmfGetDataParams { 127 std::string destUri; 128 Udmf_FileConflictOptions fileConflictOptions; 129 Udmf_ProgressIndicator progressIndicator; 130 OH_Udmf_DataProgressListener dataProgressListener; 131 }; 132 133 bool IsInvalidUdsObjectPtr(const UdsObject* pThis, int cid); 134 135 bool IsInvalidUdsObjectByType(const UdsObject* pThis, const OHOS::UDMF::UDType& type); 136 137 #endif 138