1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci */
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#include "plugin_manager.h"
17c29fa5a6Sopenharmony_ci
18c29fa5a6Sopenharmony_ci#include <string_view>
19c29fa5a6Sopenharmony_ci
20c29fa5a6Sopenharmony_ci#include "devicestatus_define.h"
21c29fa5a6Sopenharmony_ci
22c29fa5a6Sopenharmony_ci#undef LOG_TAG
23c29fa5a6Sopenharmony_ci#define LOG_TAG "PluginManager"
24c29fa5a6Sopenharmony_ci
25c29fa5a6Sopenharmony_cinamespace OHOS {
26c29fa5a6Sopenharmony_cinamespace Msdp {
27c29fa5a6Sopenharmony_cinamespace DeviceStatus {
28c29fa5a6Sopenharmony_ci
29c29fa5a6Sopenharmony_ci#if (defined(__aarch64__) || defined(__x86_64__))
30c29fa5a6Sopenharmony_ciconstexpr std::string_view LIB_COOPERATE_PATH { "/system/lib64/libintention_cooperate.z.so" };
31c29fa5a6Sopenharmony_ci#else
32c29fa5a6Sopenharmony_ciconstexpr std::string_view LIB_COOPERATE_PATH { "/system/lib/libintention_cooperate.z.so" };
33c29fa5a6Sopenharmony_ci#endif // defined(__x86_64__)
34c29fa5a6Sopenharmony_ci
35c29fa5a6Sopenharmony_ciICooperate* PluginManager::LoadCooperate()
36c29fa5a6Sopenharmony_ci{
37c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
38c29fa5a6Sopenharmony_ci    std::lock_guard guard(lock_);
39c29fa5a6Sopenharmony_ci    CHKPP(context_);
40c29fa5a6Sopenharmony_ci    if (cooperate_ == nullptr) {
41c29fa5a6Sopenharmony_ci        cooperate_ = LoadLibrary<ICooperate>(context_, LIB_COOPERATE_PATH.data());
42c29fa5a6Sopenharmony_ci    }
43c29fa5a6Sopenharmony_ci    return (cooperate_ != nullptr ? cooperate_->GetInstance() : nullptr);
44c29fa5a6Sopenharmony_ci}
45c29fa5a6Sopenharmony_ci
46c29fa5a6Sopenharmony_civoid PluginManager::UnloadCooperate()
47c29fa5a6Sopenharmony_ci{
48c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
49c29fa5a6Sopenharmony_ci    std::lock_guard guard(lock_);
50c29fa5a6Sopenharmony_ci    cooperate_.reset();
51c29fa5a6Sopenharmony_ci}
52c29fa5a6Sopenharmony_ci} // namespace DeviceStatus
53c29fa5a6Sopenharmony_ci} // namespace Msdp
54c29fa5a6Sopenharmony_ci} // namespace OHOS
55