• 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 <mutex>
22 #include <cstdint>
23 
24 # define MAX_GENERAL_ENTRY_SIZE (100 * 1024 * 1024)
25 
26 struct UdsObject {
27     const int64_t cid;
28     std::shared_ptr<OHOS::UDMF::Object> obj;
29     std::mutex mutex;
30     explicit UdsObject(int cid);
31     template<typename T> bool HasObjectKey(const char* paramName);
32     template<typename T> T* GetUdsValue(const char* paramName);
33     template<typename T> int SetUdsValue(const char* paramName, const T pramValue);
34 };
35 
36 enum NdkStructId : std::int64_t {
37     UTD_STRUCT_ID = 1002930,
38     UDS_PLAIN_TEXT_STRUCT_ID,
39     UDS_HYPERLINK_STRUCT_ID,
40     UDS_HTML_STRUCT_ID,
41     UDS_APP_ITEM_STRUCT_ID,
42     UDMF_UNIFIED_DATA_STRUCT_ID,
43     UDMF_UNIFIED_RECORD_STRUCT_ID,
44     UDMF_UNIFIED_DATA_PROPERTIES_ID,
45     UDS_FILE_URI_STRUCT_ID,
46     UDS_PIXEL_MAP_STRUCT_ID,
47     UDS_ARRAY_BUFFER_STRUCT_ID,
48 };
49 
50 struct OH_Utd {
51     const int64_t cid = UTD_STRUCT_ID;
52     std::mutex mutex;
53     std::string typeId;
54     const char** belongingToTypes{nullptr};
55     unsigned int belongingToTypesCount{0};
56     const char** filenameExtensions{nullptr};
57     unsigned int filenameExtensionsCount{0};
58     const char** mimeTypes{nullptr};
59     unsigned int mimeTypeCount{0};
60     std::string description;
61     std::string referenceURL;
62     std::string iconFile;
63 };
64 
65 struct OH_UdsPlainText : public UdsObject {
66     OH_UdsPlainText();
67 };
68 struct OH_UdsHyperlink : public UdsObject {
69     OH_UdsHyperlink();
70 };
71 struct OH_UdsHtml : public UdsObject {
72     OH_UdsHtml();
73 };
74 struct OH_UdsAppItem : public UdsObject {
75     OH_UdsAppItem();
76 };
77 struct OH_UdsFileUri : public UdsObject {
78     OH_UdsFileUri();
79 };
80 struct OH_UdsPixelMap : public UdsObject {
81     OH_UdsPixelMap();
82 };
83 struct OH_UdsArrayBuffer : public UdsObject {
84     OH_UdsArrayBuffer();
85 };
86 
87 struct OH_UdmfRecord {
88     const int64_t cid = UDMF_UNIFIED_RECORD_STRUCT_ID;
89     std::shared_ptr<OHOS::UDMF::UnifiedRecord> record_;
90     unsigned char *recordData{nullptr};
91     unsigned int recordDataLen{0};
92     char **typesArray{nullptr};
93     unsigned int typesCount{0};
94     char *lastType{nullptr};
95     std::mutex mutex;
96 };
97 
98 struct OH_UdmfData {
99     const int64_t cid = UDMF_UNIFIED_DATA_STRUCT_ID;
100     std::shared_ptr<OHOS::UDMF::UnifiedData> unifiedData_;
101     char **typesArray{nullptr};
102     unsigned int typesCount{0};
103     OH_UdmfRecord **records{nullptr};
104     unsigned int recordsCount{0};
105     std::mutex mutex;
106 };
107 
108 struct OH_UdmfProperty {
109     const int64_t cid = UDMF_UNIFIED_DATA_PROPERTIES_ID;
110     std::shared_ptr<OHOS::UDMF::UnifiedDataProperties> properties_;
111     std::mutex mutex;
112     std::string extraStr;
113 };
114 
115 bool IsInvalidUdsObjectPtr(const UdsObject* pThis, int cid);
116 
117 bool IsInvalidUdsObjectByType(const UdsObject* pThis, const OHOS::UDMF::UDType& type);
118 
119 #endif
120