• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef OHOS_RESOURCE_MANAGER_RESOURCEMANAGER_H
16 #define OHOS_RESOURCE_MANAGER_RESOURCEMANAGER_H
17 
18 #include <map>
19 #include <string>
20 #include <vector>
21 #include "res_config.h"
22 
23 namespace OHOS {
24 namespace Global {
25 namespace Resource {
26 class ResourceManager {
27 public:
28 
29     typedef struct {
30         /** the raw file fd */
31         int fd;
32 
33         /** the offset from where the raw file starts in the HAP */
34         long offset;
35 
36         /** the length of the raw file in the HAP. */
37         long length;
38     } RawFileDescriptor;
39 
40     virtual ~ResourceManager() = 0;
41 
42     virtual bool AddResource(const char *path) = 0;
43 
44     virtual RState UpdateResConfig(ResConfig &resConfig) = 0;
45 
46     virtual void GetResConfig(ResConfig &resConfig) = 0;
47 
48     virtual RState GetStringById(uint32_t id, std::string &outValue) = 0;
49 
50     virtual RState GetStringByName(const char *name, std::string &outValue) = 0;
51 
52     virtual RState GetStringFormatById(std::string &outValue, uint32_t id, ...) = 0;
53 
54     virtual RState GetStringFormatByName(std::string &outValue, const char *name, ...) = 0;
55 
56     virtual RState GetStringArrayById(uint32_t id, std::vector<std::string> &outValue) = 0;
57 
58     virtual RState GetStringArrayByName(const char *name, std::vector<std::string> &outValue) = 0;
59 
60     virtual RState GetPatternById(uint32_t id, std::map<std::string, std::string> &outValue) = 0;
61 
62     virtual RState GetPatternByName(const char *name, std::map<std::string, std::string> &outValue) = 0;
63 
64     virtual RState GetPluralStringById(uint32_t id, int quantity, std::string &outValue) = 0;
65 
66     virtual RState GetPluralStringByName(const char *name, int quantity, std::string &outValue) = 0;
67 
68     virtual RState GetPluralStringByIdFormat(std::string &outValue, uint32_t id, int quantity, ...) = 0;
69 
70     virtual RState GetPluralStringByNameFormat(std::string &outValue, const char *name, int quantity, ...) = 0;
71 
72     virtual RState GetThemeById(uint32_t id, std::map<std::string, std::string> &outValue) = 0;
73 
74     virtual RState GetThemeByName(const char *name, std::map<std::string, std::string> &outValue) = 0;
75 
76     virtual RState GetBooleanById(uint32_t id, bool &outValue) = 0;
77 
78     virtual RState GetBooleanByName(const char *name, bool &outValue) = 0;
79 
80     virtual RState GetIntegerById(uint32_t id, int &outValue) = 0;
81 
82     virtual RState GetIntegerByName(const char *name, int &outValue) = 0;
83 
84     virtual RState GetFloatById(uint32_t id, float &outValue) = 0;
85 
86     virtual RState GetFloatById(uint32_t id, float &outValue, std::string &unit) = 0;
87 
88     virtual RState GetFloatByName(const char *name, float &outValue) = 0;
89 
90     virtual RState GetFloatByName(const char *name, float &outValue, std::string &unit) = 0;
91 
92     virtual RState GetIntArrayById(uint32_t id, std::vector<int> &outValue) = 0;
93 
94     virtual RState GetIntArrayByName(const char *name, std::vector<int> &outValue) = 0;
95 
96     virtual RState GetColorById(uint32_t id, uint32_t &outValue) = 0;
97 
98     virtual RState GetColorByName(const char *name, uint32_t &outValue) = 0;
99 
100     virtual RState GetProfileById(uint32_t id, std::string &outValue) = 0;
101 
102     virtual RState GetProfileByName(const char *name, std::string &outValue) = 0;
103 
104     virtual RState GetMediaById(uint32_t id, std::string &outValue) = 0;
105 
106     virtual RState GetMediaByName(const char *name, std::string &outValue) = 0;
107 
108     virtual RState GetRawFilePathByName(const std::string &name, std::string &outValue) = 0;
109 
110     virtual RState GetRawFileDescriptor(const std::string &name, RawFileDescriptor &descriptor) = 0;
111 
112     virtual RState CloseRawFileDescriptor(const std::string &name) = 0;
113 };
114 
115 EXPORT_FUNC ResourceManager *CreateResourceManager();
116 } // namespace Resource
117 } // namespace Global
118 } // namespace OHOS
119 #endif