2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "client/src/internal.hh"
28 #include "include/package-manager-plugin.h"
34 const std::map<std::string, std::string> kTypeMap = {
35 {"res/wgt/config.xml", "wgt"},
36 {"config.xml", "wgt"},
37 {"tizen-manifest.xml", "tpk"},
39 const char kPkgLibPath[] = "/etc/package-manager/backendlib/";
41 static pkg_plugin_set* plugin_set_list[24] = { 0, };
48 std::string GetTypeFromPath(const std::string& path) {
49 unzFile uf = unzOpen(path.c_str());
51 _E("failed to open zip file %s", path.c_str());
56 for (const auto& kv : kTypeMap) {
57 if (unzLocateFile(uf, kv.first.c_str(), 0) == UNZ_OK) {
58 _D("pkgtype of %s: [%s]", path.c_str(), kv.first.c_str());
68 pkg_plugin_set* LoadPluginSet(const std::string& type) {
70 for (i = 0; plugin_set_list[i]; i++) {
71 if (strcmp(plugin_set_list[i]->pkg_type, type.c_str()) == 0) {
72 _D("already loaded for [%s]", type.c_str());
73 return plugin_set_list[i];
77 std::string lib_path = kPkgLibPath + type + ".so";
78 void* handle = dlopen(lib_path.c_str(), RTLD_LAZY);
80 _E("failed to load library %s", lib_path.c_str());
84 bool (*on_load)(pkg_plugin_set* plugin);
85 on_load = reinterpret_cast<bool(*)(pkg_plugin_set*)>(
86 dlsym(handle, "pkg_plugin_on_load"));
87 if (!on_load || dlerror()) {
88 _E("can not find symbol");
93 if (on_load(plugin_set_list[i]) != 0) {
94 _E("pkg_plugin_on_load failed");
95 free(plugin_set_list[i]);
97 plugin_set_list[i] = nullptr;
101 plugin_set_list[i]->plugin_handle = handle;
102 snprintf(plugin_set_list[i]->pkg_type, sizeof(plugin_set_list[i]->pkg_type),
105 _D("library [%s] is loaded", lib_path.c_str());
107 return plugin_set_list[i];
110 } // namespace pkgmgr
111 } // namespace client