1 /* 2 * Copyright (c) 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 FOUNDATION_ACE_NAPI_MODULE_MANAGER_MODULE_LOAD_CHECKER_H 17 #define FOUNDATION_ACE_NAPI_MODULE_MANAGER_MODULE_LOAD_CHECKER_H 18 19 #include "module_checker_delegate.h" 20 21 #include <memory> 22 #include <shared_mutex> 23 24 /** 25 * @brief Module load checker. check whether module can be loaded 26 * 27 */ 28 class ModuleLoadChecker { 29 public: 30 ModuleLoadChecker() = default; 31 virtual ~ModuleLoadChecker() = default; 32 33 /** 34 * @brief Check whether the module is allowed to be loaded 35 * 36 * @param moduleName module name 37 * @return true The module can be loaded 38 * @return false The module cannot be loaded 39 */ 40 bool CheckModuleLoadable(const char* moduleName, std::unique_ptr<ApiAllowListChecker>& apiAllowListChecker); 41 42 /** 43 * @brief Whether loadable rules only work for disk case 44 * 45 * @return true Disk check only 46 * @return false Check both cache and disk 47 */ 48 bool DiskCheckOnly(); 49 50 /** 51 * @brief Set the moudle checker delegate 52 * 53 * @param moduleCheckerDelegate 54 */ 55 void SetDelegate(const std::shared_ptr<ModuleCheckerDelegate>& moduleCheckerDelegate); 56 57 private: 58 std::shared_mutex moduleCheckerDelegateMutex_; 59 std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate_ = nullptr; 60 }; 61 62 #endif /* FOUNDATION_ACE_NAPI_MODULE_MANAGER_MODULE_LOAD_CHECKER_H */ 63