1 /* 2 * Copyright (c) 2024-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 #ifndef OHOS_RESOURCE_MANAGER_HAPRESOURCEMANAGER_H 16 #define OHOS_RESOURCE_MANAGER_HAPRESOURCEMANAGER_H 17 18 #include <shared_mutex> 19 #include "hap_resource.h" 20 #include "res_config_impl.h" 21 #include "res_desc.h" 22 #include "resource_manager.h" 23 24 #ifdef SUPPORT_GRAPHICS 25 #include <unicode/plurrule.h> 26 #endif 27 28 namespace OHOS { 29 namespace Global { 30 namespace Resource { 31 class HapResourceManager { 32 public: HapResourceManager()33 HapResourceManager() {} ~HapResourceManager()34 ~HapResourceManager() {} 35 36 static std::shared_ptr<HapResourceManager> GetInstance(); 37 38 /** 39 * Put hapResource into the map of HapResourceManager 40 * 41 * @param path the resources.index file path 42 * @param hapResource hapResource 43 * @return th resource 44 */ 45 std::shared_ptr<HapResource> PutAndGetResource(const std::string &path, std::shared_ptr<HapResource> hapResource); 46 47 /** 48 * Put patch resource 49 * 50 * @param path the resources.index file path 51 * @param patchPath the patch path 52 * @return Whether patch resource is put successfully 53 */ 54 bool PutPatchResource(const std::string &path, const std::string &patchPath); 55 56 /** 57 * get resource from map 58 * 59 * @return the resource 60 */ 61 std::shared_ptr<HapResource> GetHapResource(const std::string &path); 62 63 private: 64 static std::recursive_mutex mutex_; 65 static std::shared_ptr<HapResourceManager> instance_; 66 std::shared_mutex mutexRw_; 67 std::unordered_map<std::string, std::weak_ptr<HapResource>> hapResourceMap_; 68 }; 69 } // namespace Resource 70 } // namespace Global 71 } // namespace OHOS 72 #endif