1 /*
2 * Copyright (c) 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
16 #include "notifictaion_load_utils.h"
17
18 #include <dlfcn.h>
19 #include "ans_log_wrapper.h"
20
21 namespace OHOS {
22 namespace Notification {
23
NotificationLoadUtils(const std::string & path)24 NotificationLoadUtils::NotificationLoadUtils(const std::string& path) : path_(path)
25 {
26 proxyHandle_ = dlopen(path_.c_str(), RTLD_NOW);
27 if (proxyHandle_ == nullptr) {
28 ANS_LOGE("Open symbol failed %{public}s, error: %{public}s", path_.c_str(), dlerror());
29 }
30 ANS_LOGI("Open symbol name: %{public}s", path_.c_str());
31 }
32
~NotificationLoadUtils()33 NotificationLoadUtils::~NotificationLoadUtils()
34 {
35 if (proxyHandle_ == nullptr) {
36 return;
37 }
38 int result = dlclose(proxyHandle_);
39 ANS_LOGI("Release symbol %{public}d, name: %{public}s", result, path_.c_str());
40 proxyHandle_ = nullptr;
41 }
42
GetProxyFunc(const std::string & func)43 void* NotificationLoadUtils::GetProxyFunc(const std::string& func)
44 {
45 if (proxyHandle_ == nullptr) {
46 ANS_LOGE("Get func failed: %{public}s %{public}s", path_.c_str(), func.c_str());
47 return nullptr;
48 }
49
50 return dlsym(proxyHandle_, func.c_str());
51 }
52
IsValid()53 bool NotificationLoadUtils::IsValid()
54 {
55 return (proxyHandle_ != nullptr);
56 }
57
58 }
59 }
60