From: Hwankyu Jhun Date: Tue, 16 May 2023 07:29:08 +0000 (+0000) Subject: Support appcore plugin X-Git-Tag: accepted/tizen/unified/20230601.162941~2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fappfw%2Fapp-core.git;a=commitdiff_plain;h=37f62734e90a99279072b6186a05ebcac653d4bc Support appcore plugin Some product developer wants to change the behavior at the start & end stages of the app-core. This patch supports the app-core plugin. Change-Id: I8516ec0bb8bb9d47c7bfbb05f31ee3f239c4280f Signed-off-by: Hwankyu Jhun --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 68f96dc..2f9fe37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall -Werror") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") SET(CMAKE_C_FLAGS_RELEASE "-O2") -SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ") +SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=c++17") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") SET(CMAKE_CXX_FLAGS_RELEASE "-O2") diff --git a/tizen-cpp/app-core-cpp/CMakeLists.txt b/tizen-cpp/app-core-cpp/CMakeLists.txt index a6c23aa..61cd425 100644 --- a/tizen-cpp/app-core-cpp/CMakeLists.txt +++ b/tizen-cpp/app-core-cpp/CMakeLists.txt @@ -31,4 +31,5 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_APP_CORE_CPP}.pc INSTALL(TARGETS ${TARGET_APP_CORE_CPP} DESTINATION ${LIB_INSTALL_DIR}) INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION include/appcore_cpp FILES_MATCHING + PATTERN "*_private.hh" EXCLUDE PATTERN "*.hh") diff --git a/tizen-cpp/app-core-cpp/app_core_base.cc b/tizen-cpp/app-core-cpp/app_core_base.cc index 9d22bb1..18e6e70 100644 --- a/tizen-cpp/app-core-cpp/app_core_base.cc +++ b/tizen-cpp/app-core-cpp/app_core_base.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "app-core-cpp/app_core_base.hh" + #include #include #include @@ -48,7 +50,7 @@ #include #include -#include "app-core-cpp/app_core_base.hh" +#include "app-core-cpp/app_core_plugin_private.hh" #include "common/glib_private.hh" #include "common/log_private.hh" @@ -241,6 +243,8 @@ class AppCoreBase::Impl { void VerifyLanguage(); void SetDefaultEvents(); void UnsetDefaultEvents(); + void PluginInit(int argc, char** argv); + void PluginFini(); private: friend class AppCoreBase; @@ -259,6 +263,7 @@ class AppCoreBase::Impl { IAppCore* core_delegator_ = nullptr; IMainLoop* loop_delegator_ = nullptr; guint signal_handler_source_ = 0; + std::unique_ptr plugin_; }; AppCoreBase::EventBase::EventBase(Type type) @@ -1249,6 +1254,10 @@ void AppCoreBase::Init(int argc, char** argv) { traceEnd(TTRACE_TAG_APPLICATION_MANAGER); + traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:PLUGIN_INIT"); + impl_->PluginInit(argc, argv); + traceEnd(TTRACE_TAG_APPLICATION_MANAGER); + if (impl_->feature_ & FEATURE_BACKGROUND_MANAGEMENT) GLib::IdleAdd(Impl::InitSuspendCb, this); @@ -1333,6 +1342,7 @@ void AppCoreBase::Dispose() { } RemoveSuspendTimer(); + impl_->PluginFini(); impl_->dirty_ = false; if (impl_->loop_delegator_) impl_->loop_delegator_->OnLoopFinish(); @@ -1348,4 +1358,19 @@ int AppCoreBase::GetFeature() const { return impl_->feature_; } +void AppCoreBase::Impl::PluginInit(int argc, char** argv) { + plugin_.reset(AppCorePlugin::Load()); + if (!plugin_) + return; + + plugin_->Init(argc, argv); +} + +void AppCoreBase::Impl::PluginFini() { + if (!plugin_) + return; + + plugin_->Fini(); +} + } // namespace tizen_cpp diff --git a/tizen-cpp/app-core-cpp/app_core_plugin_private.cc b/tizen-cpp/app-core-cpp/app_core_plugin_private.cc new file mode 100644 index 0000000..dd09331 --- /dev/null +++ b/tizen-cpp/app-core-cpp/app_core_plugin_private.cc @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#include "app-core-cpp/app_core_plugin_private.hh" + +#include +#include + +#include +#include + +#include "common/log_private.hh" + +namespace tizen_cpp { + +namespace { + +constexpr const char kPathLibAppCorePlugin[] = + "/usr/share/appcore/plugins/libappcore-plugin.so"; +constexpr const char kAppCorePluginInit[] = "APP_CORE_PLUGIN_INIT"; +constexpr const char kAppCorePluginFini[] = "APP_CORE_PLUGIN_FINI"; + +} // namespace + +AppCorePlugin::AppCorePlugin(void* handle, PluginInitFunc init_func, + PluginFiniFunc fini_func) + : handle_(handle), init_func_(init_func), fini_func_(fini_func) { +} + +AppCorePlugin::~AppCorePlugin() { + if (handle_) + dlclose(handle_); +} + +AppCorePlugin* AppCorePlugin::Load() { + if (!std::filesystem::exists(kPathLibAppCorePlugin)) + return nullptr; + + void* handle = dlopen(kPathLibAppCorePlugin, RTLD_LAZY); + if (handle == nullptr) { + _E("dlopen() is failed. path(%s), error(%s)", + kPathLibAppCorePlugin, dlerror()); + return nullptr; + } + + auto init_func = reinterpret_cast( + dlsym(handle, kAppCorePluginInit)); + auto fini_func = reinterpret_cast( + dlsym(handle, kAppCorePluginFini)); + if (init_func == nullptr && fini_func == nullptr) { + _W("There is no symbols"); + dlclose(handle); + return nullptr; + } + + _W("init_func(%p), fini_func(%p)", init_func, fini_func); + return new (std::nothrow) AppCorePlugin(handle, init_func, fini_func); +} + +void AppCorePlugin::Init(int argc, char** argv) { + _I("[PLUGIN] INIT"); + if (init_func_ == nullptr) + return; + + init_func_(argc, argv); +} + +void AppCorePlugin::Fini() { + _I("[PLUGIN] FINI"); + if (fini_func_ == nullptr) + return; + + fini_func_(); +} + +} // namespace tizen_cpp diff --git a/tizen-cpp/app-core-cpp/app_core_plugin_private.hh b/tizen-cpp/app-core-cpp/app_core_plugin_private.hh new file mode 100644 index 0000000..dc74a73 --- /dev/null +++ b/tizen-cpp/app-core-cpp/app_core_plugin_private.hh @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * 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 TIZEN_CPP_APP_CORE_CPP_APP_CORE_PLUGIN_PRIVATE_HH_ +#define TIZEN_CPP_APP_CORE_CPP_APP_CORE_PLUGIN_PRIVATE_HH_ + +namespace tizen_cpp { + +class AppCorePlugin { + public: + using PluginInitFunc = int (*)(int, char**); + using PluginFiniFunc = void (*)(); + + AppCorePlugin(void* handle, PluginInitFunc init_func, + PluginFiniFunc fini_func); + ~AppCorePlugin(); + + static AppCorePlugin* Load(); + + void Init(int argc, char** argv); + void Fini(); + + private: + void* handle_ = nullptr; + PluginInitFunc init_func_ = nullptr; + PluginFiniFunc fini_func_ = nullptr; +}; + +} // namespace tizen_cpp + +#endif // TIZEN_CPP_APP_CORE_CPP_APP_CORE_PLUGIN_PRIVATE_HH_