1 /* 2 * Copyright (c) 2020-2021 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 OHOS_GLOBAL_UTILS_H 17 #define OHOS_GLOBAL_UTILS_H 18 19 #include "global.h" 20 21 #ifdef __cplusplus 22 #if __cplusplus 23 extern "C" { 24 #endif 25 #endif // __cplusplus 26 27 #define SCRIPT_LENGTH 4 28 #define LOCALE_ELEMENT_NUM 3 29 30 typedef enum KeyType { 31 LANGUAGES = 0, 32 REGION = 1, 33 RESOLUTION = 2, 34 ORIENTATION = 3, 35 DEVICETYPE = 4, 36 SCRIPT = 5, 37 KEY_TYPE_MAX 38 } KeyType; 39 40 typedef enum ResType { 41 VALUES = 0, 42 ANIMATION = 1, 43 DRAWABLE = 2, 44 LAYOUT = 3, 45 MENU = 4, 46 MIPMAP = 5, 47 RAW = 6, 48 XML = 7, 49 50 INTEGER = 8, 51 STRING = 9, 52 STRINGARRAY = 10, 53 INTARRAY = 11, 54 BOOLEAN_ = 12, 55 DIMEN = 13, 56 COLOR = 14, 57 ID = 15, 58 THEME = 16, 59 PLURALS = 17, 60 MY_FLOAT = 18, 61 MEDIA = 19, 62 PROF = 20, 63 SVG = 21, 64 INVALID_RES_TYPE = -1 65 } ResType; 66 67 typedef struct KeyParam { 68 KeyType type; 69 uint32_t value; 70 } KeyParam; 71 72 typedef struct Key { 73 uint32_t offset; 74 uint32_t keysCount; 75 KeyParam *keyParams; 76 } Key; 77 78 typedef struct IdParam { 79 uint32_t id; 80 uint32_t offset; 81 } IdParam; 82 83 typedef struct IdHeader { 84 uint32_t count; 85 IdParam *idParams; 86 } IdHeader; 87 88 typedef struct IdItem { 89 uint32_t size; 90 ResType resType; 91 uint32_t id; 92 uint16_t valueLen; 93 char *value; 94 uint16_t nameLen; 95 char *name; 96 } IdItem; 97 98 typedef struct GlobalUtilsImpl { 99 uint32_t (*GetOffsetByLocale)(const char *path, const char *locale, uint32_t length); 100 uint32_t (*GetDefaultOffsetValue)(int32_t file); 101 uint32_t (*GetKeyValue)(int32_t file); 102 int32_t (*GetIdItem)(int32_t file, uint32_t offset, IdItem *idItem); 103 uint32_t (*GetIdHeaderOffsetByLocale)(const char *locale, const Key *keys, uint32_t configNum); 104 int32_t (*GetIdHeaderByOffset)(int32_t file, uint32_t offset, IdHeader *idHeader); 105 int32_t (*SplitLocale)(const char *src, char **dest, int32_t *num); 106 int32_t (*CheckFilePath)(const char *path, char *realResourcePath, int32_t length); 107 } GlobalUtilsImpl; 108 109 typedef struct LocaleItem { 110 uint32_t language; 111 uint32_t script; 112 uint32_t region; 113 } LocaleItem; 114 115 GlobalUtilsImpl *GetGlobalUtilsImpl(void); 116 117 #define MC_FAILURE (-1) 118 #define MC_SUCCESS 0 119 120 #ifdef __cplusplus 121 #if __cplusplus 122 } 123 #endif 124 #endif // __cplusplus 125 126 #endif // OHOS_GLOBAL_UTILS_H 127