• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "base/resource/internal_resource.h"
17 
18 #include <functional>
19 #include <map>
20 #include <utility>
21 
22 // binary/errorcode.json
23 // Use objcopy transform to compiled object file.
24 // The following parameters represent the beginning and end of the file.
25 extern uint8_t _binary_errorcode_json_start[];
26 extern uint8_t _binary_errorcode_json_end[];
27 
28 // binary/tv_rate_star_big_off.svg
29 // Use objcopy transform to compiled object file.
30 // The following parameters represent the beginning and end of the file.
31 extern uint8_t _binary_tv_rate_star_big_off_svg_start[];
32 extern uint8_t _binary_tv_rate_star_big_off_svg_end[];
33 
34 // binary/tv_rate_star_big_on.svg
35 // Use objcopy transform to compiled object file.
36 // The following parameters represent the beginning and end of the file.
37 extern uint8_t _binary_tv_rate_star_big_on_svg_start[];
38 extern uint8_t _binary_tv_rate_star_big_on_svg_end[];
39 
40 // binary/tv_rate_star_small_off.svg
41 // Use objcopy transform to compiled object file.
42 // The following parameters represent the beginning and end of the file.
43 extern uint8_t _binary_tv_rate_star_small_off_svg_start[];
44 extern uint8_t _binary_tv_rate_star_small_off_svg_end[];
45 
46 // binary/tv_rate_star_small_on.png
47 // Use objcopy transform to compiled object file.
48 // The following parameters represent the beginning and end of the file.
49 extern uint8_t _binary_tv_rate_star_small_on_svg_start[];
50 extern uint8_t _binary_tv_rate_star_small_on_svg_end[];
51 
52 // binary/indexletter_bar.json
53 // Use objcopy transform to compiled object file.
54 // The following parameters represent the beginning and end of the file.
55 extern uint8_t _binary_indexletter_bar_json_start[];
56 extern uint8_t _binary_indexletter_bar_json_end[];
57 
58 // binary/entry.json
59 // Use objcopy transform to compiled object file.
60 // The following parameters represent the beginning and end of the file.
61 extern uint8_t _binary_entry_json_start[];
62 extern uint8_t _binary_entry_json_end[];
63 
64 namespace OHOS::Ace {
65 namespace {
66 
67 struct ResourceData final {
ResourceDataOHOS::Ace::__anond19fbaed0111::ResourceData68     ResourceData(const uint8_t* buf, size_t size) : buf(buf), size(size) {}
69     ~ResourceData() = default;
70 
71     const uint8_t* buf;
72     size_t size;
73 };
74 
75 } // namespace
76 
77 InternalResource::InternalResource() = default;
78 
79 InternalResource::~InternalResource() = default;
80 
GetResource(const ResourceId id,size_t & size) const81 const uint8_t* InternalResource::GetResource(const ResourceId id, size_t& size) const
82 {
83     static const std::map<InternalResource::ResourceId, ResourceData> RESOURCE_MAP = {
84         { InternalResource::ResourceId::TV_RATE_STAR_BIG_ON_SVG,
85             ResourceData(_binary_tv_rate_star_big_on_svg_start,
86                 static_cast<size_t>(_binary_tv_rate_star_big_on_svg_end - _binary_tv_rate_star_big_on_svg_start)) },
87         { InternalResource::ResourceId::TV_RATE_STAR_BIG_OFF_SVG,
88             ResourceData(_binary_tv_rate_star_big_off_svg_start,
89                 static_cast<size_t>(_binary_tv_rate_star_big_off_svg_end - _binary_tv_rate_star_big_off_svg_start)) },
90         { InternalResource::ResourceId::TV_RATE_STAR_SMALL_ON_SVG,
91             ResourceData(_binary_tv_rate_star_small_on_svg_start,
92                 static_cast<size_t>(_binary_tv_rate_star_small_on_svg_end - _binary_tv_rate_star_small_on_svg_start)) },
93         { InternalResource::ResourceId::TV_RATE_STAR_SMALL_OFF_SVG,
94             ResourceData(_binary_tv_rate_star_small_off_svg_start,
95                 static_cast<size_t>(
96                     _binary_tv_rate_star_small_off_svg_end - _binary_tv_rate_star_small_off_svg_start)) },
97         { InternalResource::ResourceId::ERRORINFO_JSON,
98             ResourceData(_binary_errorcode_json_start,
99                 static_cast<size_t>(_binary_errorcode_json_end - _binary_errorcode_json_start)) },
100         { InternalResource::ResourceId::INDEXLETTER_BAR_JSON,
101             ResourceData(_binary_indexletter_bar_json_start,
102                 static_cast<size_t>(_binary_indexletter_bar_json_end - _binary_indexletter_bar_json_start)) },
103         { InternalResource::ResourceId::ENTRY_JSON,
104             ResourceData(
105                 _binary_entry_json_start, static_cast<size_t>(_binary_entry_json_end - _binary_entry_json_start)) },
106     };
107     auto iter = RESOURCE_MAP.find(id);
108     if (iter != RESOURCE_MAP.end()) {
109         size = iter->second.size;
110         return iter->second.buf;
111     }
112     return nullptr;
113 }
114 
115 } // namespace OHOS::Ace
116