• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 UNIFIED_META_H
17 #define UNIFIED_META_H
18 
19 #include <array>
20 #include <cstdint>
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <unordered_map>
25 #include <variant>
26 #include <vector>
27 
28 #include "string_ex.h"
29 
30 namespace OHOS {
31 namespace UDMF {
32 enum UDType : int32_t {
33     TEXT = 0,
34     PLAIN_TEXT,
35     HYPERLINK,
36     HTML,
37     FILE,
38     FOLDER,
39     IMAGE,
40     VIDEO,
41     AUDIO,
42     SYSTEM_DEFINED_FORM,
43     SYSTEM_DEFINED_RECORD,
44     SYSTEM_DEFINED_APP_ITEM,
45     SYSTEM_DEFINED_PIXEL_MAP,
46     APPLICATION_DEFINED_RECORD,
47     UD_BUTT
48 };
49 
50 static const std::unordered_map<int32_t, std::string> UD_TYPE_MAP {
51     { TEXT, "general.text" },
52     { PLAIN_TEXT, "general.plain-text" },
53     { HYPERLINK, "general.hyperlink" },
54     { HTML, "general.html" },
55     { FILE, "general.file" },
56     { FOLDER, "general.folder" },
57     { IMAGE, "general.image" },
58     { VIDEO, "general.video" },
59     { AUDIO, "general.audio" },
60     { SYSTEM_DEFINED_RECORD, "SystemDefinedType" },
61     { SYSTEM_DEFINED_FORM, "openharmony.form" },
62     { SYSTEM_DEFINED_APP_ITEM, "openharmony.app-item" },
63     { SYSTEM_DEFINED_PIXEL_MAP, "openharmony.pixel-map" },
64     { APPLICATION_DEFINED_RECORD, "ApplicationDefinedType" },
65     { UD_BUTT, "INVALID" }
66 };
67 
68 static const std::unordered_map<int32_t, std::string> JS_UD_TYPE_NAME_MAP {
69     { TEXT, "TEXT" },
70     { PLAIN_TEXT, "PLAIN_TEXT" },
71     { HYPERLINK, "HYPERLINK" },
72     { HTML, "HTML" },
73     { FILE, "FILE" },
74     { IMAGE, "IMAGE" },
75     { VIDEO, "VIDEO" },
76     { AUDIO, "AUDIO" },
77     { FOLDER, "FOLDER" },
78     { SYSTEM_DEFINED_RECORD, "SYSTEM_DEFINED_RECORD" },
79     { SYSTEM_DEFINED_FORM, "OPENHARMONY_FORM" },
80     { SYSTEM_DEFINED_APP_ITEM, "OPENHARMONY_APP_ITEM" },
81     { SYSTEM_DEFINED_PIXEL_MAP, "OPENHARMONY_PIXEL_MAP" },
82     { APPLICATION_DEFINED_RECORD, "APPLICATION_DEFINED_RECORD" },
83 };
84 
85 /*
86  * UnifiedData variant definitions.
87  */
88 using UDVariant = std::variant<int32_t, int64_t, bool, double, std::string, std::vector<uint8_t>>;
89 using UDDetails = std::map<std::string, UDVariant>;
90 
91 /*
92  * UnifiedData Intention.
93  */
94 enum Intention : int32_t {
95     UD_INTENTION_BASE = 0,
96     UD_INTENTION_DRAG,
97     UD_INTENTION_DATA_HUB,
98     UD_INTENTION_BUTT,
99 };
100 
101 static const std::unordered_map<int32_t, std::string> UD_INTENTION_MAP {
102     { UD_INTENTION_DRAG, "drag" },
103     { UD_INTENTION_DATA_HUB, "DataHub" },
104 };
105 
106 static const std::unordered_map<int32_t, std::string> JS_UD_INTENTION_NAME_MAP {
107     { UD_INTENTION_DATA_HUB, "DATA_HUB" },
108 };
109 
110 class UnifiedDataUtils {
111 public:
112     static bool IsValidType(int32_t value);
113     static bool IsValidIntention(int32_t value);
114     static size_t GetVariantSize(UDVariant &variant);
115     static size_t GetDetailsSize(UDDetails &details);
116     static bool IsPersist(const Intention &intention);
117     static bool IsPersist(const std::string &intention);
118     static Intention GetIntentionByString(const std::string &intention);
119     static bool IsValidOptions(const std::string &key, std::string &intention);
120 };
121 } // namespace UDMF
122 } // namespace OHOS
123 #endif // UNIFIED_META_H