2 * Copyright (c) 2021 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.
22 #include "app-core-ui-cpp/app_core_ui_plugin_private.hh"
23 #include "app-core-ui-cpp/appcore_ui_base.h"
24 #include "common/log_private.hh"
30 constexpr const char kPathLibAppCoreUiPlugin[] =
31 "/usr/share/appcore/plugins/libappcore-ui-plugin.so";
32 constexpr const char kAppCoreUiPluginInit[] = "APP_CORE_UI_PLUGIN_INIT";
33 constexpr const char kAppCoreUiPluginFini[] = "APP_CORE_UI_PLUGIN_FINI";
37 AppCoreUiPlugin::AppCoreUiPlugin(void* handle, PluginInitFunc init_func,
38 PluginFiniFunc fini_func)
39 : handle_(handle), init_func_(init_func), fini_func_(fini_func) {
42 AppCoreUiPlugin::~AppCoreUiPlugin() {
47 AppCoreUiPlugin* AppCoreUiPlugin::Load() {
48 if (access(kPathLibAppCoreUiPlugin, F_OK) != 0)
51 void* handle = dlopen(kPathLibAppCoreUiPlugin, RTLD_LAZY);
52 if (handle == nullptr) {
53 _E("dlopen() is failed. path(%s)", kPathLibAppCoreUiPlugin);
57 auto init_func = reinterpret_cast<PluginInitFunc>(
58 dlsym(handle, kAppCoreUiPluginInit));
59 if (init_func == nullptr)
60 _W("dlsym() is failed. symbol(%s)", kAppCoreUiPluginInit);
62 auto fini_func = reinterpret_cast<PluginFiniFunc>(
63 dlsym(handle, kAppCoreUiPluginFini));
64 if (fini_func == nullptr)
65 _W("dlsym() is failed. symbol(%s)", kAppCoreUiPluginFini);
67 return new (std::nothrow) AppCoreUiPlugin(handle, init_func, fini_func);
70 void AppCoreUiPlugin::Init(AppCoreUiBase* base, app_core_ui_base_ops* ops,
71 int argc, char** argv, unsigned int* hint) {
72 _I("[__PLUGIN__] INIT");
73 if (init_func_ == nullptr)
76 init_func_(static_cast<app_core_ui_base_h>(base), ops, argc, argv, hint);
79 void AppCoreUiPlugin::Fini(AppCoreUiBase* base) {
80 _I("[__PLUGIN__] FINI");
81 if (fini_func_ == nullptr)
84 fini_func_(static_cast<app_core_ui_base_h>(base));
87 } // namespace tizen_cpp