133eb0b6dSopenharmony_ci/*
233eb0b6dSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
333eb0b6dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
433eb0b6dSopenharmony_ci * you may not use this file except in compliance with the License.
533eb0b6dSopenharmony_ci * You may obtain a copy of the License at
633eb0b6dSopenharmony_ci *
733eb0b6dSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
833eb0b6dSopenharmony_ci *
933eb0b6dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1033eb0b6dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1133eb0b6dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1233eb0b6dSopenharmony_ci * See the License for the specific language governing permissions and
1333eb0b6dSopenharmony_ci * limitations under the License.
1433eb0b6dSopenharmony_ci */
1533eb0b6dSopenharmony_ci
1633eb0b6dSopenharmony_ci#ifndef FOUNDATION_ACE_NAPI_MODULE_MANAGER_MODULE_LOAD_CHECKER_H
1733eb0b6dSopenharmony_ci#define FOUNDATION_ACE_NAPI_MODULE_MANAGER_MODULE_LOAD_CHECKER_H
1833eb0b6dSopenharmony_ci
1933eb0b6dSopenharmony_ci#include "module_checker_delegate.h"
2033eb0b6dSopenharmony_ci
2133eb0b6dSopenharmony_ci#include <memory>
2233eb0b6dSopenharmony_ci#include <shared_mutex>
2333eb0b6dSopenharmony_ci
2433eb0b6dSopenharmony_ci/**
2533eb0b6dSopenharmony_ci * @brief Module load checker. check whether module can be loaded
2633eb0b6dSopenharmony_ci *
2733eb0b6dSopenharmony_ci */
2833eb0b6dSopenharmony_ciclass ModuleLoadChecker {
2933eb0b6dSopenharmony_cipublic:
3033eb0b6dSopenharmony_ci    ModuleLoadChecker() = default;
3133eb0b6dSopenharmony_ci    virtual ~ModuleLoadChecker() = default;
3233eb0b6dSopenharmony_ci
3333eb0b6dSopenharmony_ci    /**
3433eb0b6dSopenharmony_ci     * @brief Check whether the module is allowed to be loaded
3533eb0b6dSopenharmony_ci     *
3633eb0b6dSopenharmony_ci     * @param moduleName module name
3733eb0b6dSopenharmony_ci     * @return true The module can be loaded
3833eb0b6dSopenharmony_ci     * @return false The module cannot be loaded
3933eb0b6dSopenharmony_ci     */
4033eb0b6dSopenharmony_ci    bool CheckModuleLoadable(const char* moduleName, std::unique_ptr<ApiAllowListChecker>& apiAllowListChecker);
4133eb0b6dSopenharmony_ci
4233eb0b6dSopenharmony_ci    /**
4333eb0b6dSopenharmony_ci     * @brief Whether loadable rules only work for disk case
4433eb0b6dSopenharmony_ci     *
4533eb0b6dSopenharmony_ci     * @return true Disk check only
4633eb0b6dSopenharmony_ci     * @return false Check both cache and disk
4733eb0b6dSopenharmony_ci     */
4833eb0b6dSopenharmony_ci    bool DiskCheckOnly();
4933eb0b6dSopenharmony_ci
5033eb0b6dSopenharmony_ci    /**
5133eb0b6dSopenharmony_ci     * @brief Set the moudle checker delegate
5233eb0b6dSopenharmony_ci     *
5333eb0b6dSopenharmony_ci     * @param moduleCheckerDelegate
5433eb0b6dSopenharmony_ci     */
5533eb0b6dSopenharmony_ci    void SetDelegate(const std::shared_ptr<ModuleCheckerDelegate>& moduleCheckerDelegate);
5633eb0b6dSopenharmony_ci
5733eb0b6dSopenharmony_ciprivate:
5833eb0b6dSopenharmony_ci    std::shared_mutex moduleCheckerDelegateMutex_;
5933eb0b6dSopenharmony_ci    std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate_ = nullptr;
6033eb0b6dSopenharmony_ci};
6133eb0b6dSopenharmony_ci
6233eb0b6dSopenharmony_ci#endif /* FOUNDATION_ACE_NAPI_MODULE_MANAGER_MODULE_LOAD_CHECKER_H */
63