From c43cad804c37c3281e3f7b997511d1f46347d2d9 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 24 Apr 2017 13:57:47 +0900 Subject: [PATCH] Support plugin for customizing appcore ui base - APPCORE_UI_PLUGIN_INIT function The function will be invoked while initializing appcore ui base. - APPCORE_UI_PLUGIN_FINI function The function will be invoked while finalizing appcore ui base. Change-Id: Ifd0ab64b994e3dcea388c96dedd74b5415387d0c Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 2 +- include/appcore_ui_plugin.h | 25 +++++++++++ src/ui_base/appcore_ui_base.c | 3 ++ src/ui_base/appcore_ui_plugin.c | 91 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 include/appcore_ui_plugin.h create mode 100644 src/ui_base/appcore_ui_plugin.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b4a9bd..bc52ac3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ ENDFOREACH(hfile) # Build appcore-efl Library # ------------------------------ SET(APPCORE_EFL "appcore-efl") -SET(SRCS_efl src/legacy/appcore-efl.c src/ui_base/appcore_ui_base.c) +SET(SRCS_efl src/legacy/appcore-efl.c src/ui_base/appcore_ui_base.c src/ui_base/appcore_ui_plugin.c) SET(HEADERS_efl appcore-efl.h appcore_ui_base.h) INCLUDE(FindPkgConfig) diff --git a/include/appcore_ui_plugin.h b/include/appcore_ui_plugin.h new file mode 100644 index 0000000..e254286 --- /dev/null +++ b/include/appcore_ui_plugin.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __APPCORE_UI_PLUGIN_H__ +#define __APPCORE_UI_PLUGIN_H__ + +#include "appcore_ui_base.h" + +void appcore_ui_plugin_init(appcore_ui_base_ops *ops, unsigned int *hint); +void appcore_ui_plugin_fini(void); + +#endif /* __APPCORE_UI_PLUGIN_H__ */ diff --git a/src/ui_base/appcore_ui_base.c b/src/ui_base/appcore_ui_base.c index b4b13b2..76681c5 100644 --- a/src/ui_base/appcore_ui_base.c +++ b/src/ui_base/appcore_ui_base.c @@ -49,6 +49,7 @@ #include "appcore_base.h" #include "appcore_ui_base.h" #include "appcore_ui_base_private.h" +#include "appcore_ui_plugin.h" enum app_state { AS_NONE, @@ -687,6 +688,7 @@ EXPORT_API int appcore_ui_base_init(appcore_ui_base_ops ops, int argc, char **ar int r; bool is_vc_vt_automode = false; + appcore_ui_plugin_init(&ops, &hint); aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)); __context.ops = ops; __context.data = data; @@ -745,6 +747,7 @@ EXPORT_API void appcore_ui_base_fini(void) int r; appcore_base_fini(); + appcore_ui_plugin_fini(); if (__context.hshow) ecore_event_handler_del(__context.hshow); diff --git a/src/ui_base/appcore_ui_plugin.c b/src/ui_base/appcore_ui_plugin.c new file mode 100644 index 0000000..f25b60e --- /dev/null +++ b/src/ui_base/appcore_ui_plugin.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE +#include +#include +#include + +#include "appcore_ui_plugin.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "APP_CORE_UI_PLUGIN" + +#define PATH_LIBAPPCORE_UI_PLUGIN \ + "/usr/share/appcore/plugins/libappcore-ui-plugin.so" +#define APPCORE_UI_PLUGIN_INIT "APPCORE_UI_PLUGIN_INIT" +#define APPCORE_UI_PLUGIN_FINI "APPCORE_UI_PLUGIN_FINI" + +static int (*__plugin_init)(appcore_ui_base_ops *ops, unsigned int *hint); +static int (*__plugin_fini)(void); +static void *__handle; + +static void __unload_appcore_ui_plugin(void) +{ + if (__handle) { + dlclose(__handle); + __handle = NULL; + } + + __plugin_init = NULL; + __plugin_fini = NULL; +} + +static void __load_appcore_ui_plugin(void) +{ + if (access(PATH_LIBAPPCORE_UI_PLUGIN, F_OK) != 0) + return; + + if (!__handle) { + __handle = dlopen(PATH_LIBAPPCORE_UI_PLUGIN, RTLD_LAZY); + if (!__handle) { + LOGE("Failed to open %s", PATH_LIBAPPCORE_UI_PLUGIN); + return; + } + } + + __plugin_init = dlsym(__handle, APPCORE_UI_PLUGIN_INIT); + if (!__plugin_init) + LOGW("Failed to load %s symbol", APPCORE_UI_PLUGIN_INIT); + + __plugin_fini = dlsym(__handle, APPCORE_UI_PLUGIN_FINI); + if (!__plugin_fini) + LOGW("Failed to load %s symbol", APPCORE_UI_PLUGIN_FINI); +} + +void appcore_ui_plugin_init(appcore_ui_base_ops *ops, unsigned int *hint) +{ + LOGI("[PLUGIN] init"); + + if (!__plugin_init && !__plugin_fini) + __load_appcore_ui_plugin(); + + if (__plugin_init) + __plugin_init(ops, hint); +} + +void appcore_ui_plugin_fini(void) +{ + LOGI("[PLUGIN] fini"); + + if (__plugin_fini) + __plugin_fini(); + + __unload_appcore_ui_plugin(); +} -- 2.7.4