1 /* 2 * Copyright (C) 2025 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 #include "string" 16 #include "map" 17 #include "thread" 18 #include <dlfcn.h> 19 #include "include/service_plugin.h" 20 #include "include/sp_log.h" 21 22 namespace OHOS { 23 namespace SmartPerf { ServicePluginHandler()24 ServicePluginHandler::ServicePluginHandler() 25 { 26 pluginHandle.resize(PLUGIN_COUNT, nullptr); 27 } ~ServicePluginHandler()28 ServicePluginHandler::~ServicePluginHandler() 29 { 30 for (int i = 0; i < PLUGIN_COUNT; i++) { 31 if (pluginHandle[i] != nullptr) { 32 dlclose(pluginHandle[i]); 33 pluginHandle[i] = nullptr; 34 } 35 } 36 } 37 ItemData()38 std::map<std::string, std::string> ServicePluginHandler::ItemData() 39 { 40 return std::map<std::string, std::string>(); 41 } 42 GetSoHandler(enum ServicePluginType type)43 void* ServicePluginHandler::GetSoHandler(enum ServicePluginType type) 44 { 45 if (pluginHandle[type] == nullptr) { 46 char soFilePathChar[PATH_MAX] = {0x00}; 47 if ((realpath(pluginSoPath[type].c_str(), soFilePathChar) == nullptr)) { 48 WLOGE("%s is not exist.", pluginSoPath[type].c_str()); 49 return nullptr; 50 } 51 52 pluginHandle[type] = dlopen(soFilePathChar, RTLD_LAZY); 53 if (!pluginHandle[type]) { 54 WLOGE("open ServicePlugin so file error."); 55 return nullptr; 56 } 57 } 58 return pluginHandle[type]; 59 } 60 } 61 }