Modify AppCoreUiThreadBase class
[platform/core/appfw/app-core.git] / tizen-cpp / app-core-ui-cpp / app_core_ui_plugin_private.cc
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <dlfcn.h>
18 #include <unistd.h>
19
20 #include <new>
21
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"
25
26 namespace tizen_cpp {
27
28 namespace {
29
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";
34
35 }  // namespace
36
37 AppCoreUiPlugin::AppCoreUiPlugin(void* handle, PluginInitFunc init_func,
38     PluginFiniFunc fini_func)
39     : handle_(handle), init_func_(init_func), fini_func_(fini_func) {
40 }
41
42 AppCoreUiPlugin::~AppCoreUiPlugin() {
43   if (handle_)
44     dlclose(handle_);
45 }
46
47 AppCoreUiPlugin* AppCoreUiPlugin::Load() {
48   if (access(kPathLibAppCoreUiPlugin, F_OK) != 0)
49     return nullptr;
50
51   void* handle = dlopen(kPathLibAppCoreUiPlugin, RTLD_LAZY);
52   if (handle == nullptr) {
53     _E("dlopen() is failed. path(%s)", kPathLibAppCoreUiPlugin);
54     return nullptr;
55   }
56
57   auto init_func = reinterpret_cast<PluginInitFunc>(
58       dlsym(handle, kAppCoreUiPluginInit));
59   if (init_func == nullptr)
60     _W("dlsym() is failed. symbol(%s)", kAppCoreUiPluginInit);
61
62   auto fini_func = reinterpret_cast<PluginFiniFunc>(
63       dlsym(handle, kAppCoreUiPluginFini));
64   if (fini_func == nullptr)
65     _W("dlsym() is failed. symbol(%s)", kAppCoreUiPluginFini);
66
67   return new (std::nothrow) AppCoreUiPlugin(handle, init_func, fini_func);
68 }
69
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)
74     return;
75
76   init_func_(static_cast<app_core_ui_base_h>(base), ops, argc, argv, hint);
77 }
78
79 void AppCoreUiPlugin::Fini(AppCoreUiBase* base) {
80   _I("[__PLUGIN__] FINI");
81   if (fini_func_ == nullptr)
82     return;
83
84   fini_func_(static_cast<app_core_ui_base_h>(base));
85 }
86
87 }  // namespace tizen_cpp