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")
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")
* limitations under the License.
*/
+#include "app-core-cpp/app_core_base.hh"
+
#include <aul.h>
#include <aul_app_lifecycle.h>
#include <aul_watchdog.h>
#include <utility>
#include <vector>
-#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"
void VerifyLanguage();
void SetDefaultEvents();
void UnsetDefaultEvents();
+ void PluginInit(int argc, char** argv);
+ void PluginFini();
private:
friend class AppCoreBase;
IAppCore* core_delegator_ = nullptr;
IMainLoop* loop_delegator_ = nullptr;
guint signal_handler_source_ = 0;
+ std::unique_ptr<AppCorePlugin> plugin_;
};
AppCoreBase::EventBase::EventBase(Type type)
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);
}
RemoveSuspendTimer();
+ impl_->PluginFini();
impl_->dirty_ = false;
if (impl_->loop_delegator_)
impl_->loop_delegator_->OnLoopFinish();
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
--- /dev/null
+/*
+ * 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 <dlfcn.h>
+#include <unistd.h>
+
+#include <filesystem>
+#include <new>
+
+#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<PluginInitFunc>(
+ dlsym(handle, kAppCorePluginInit));
+ auto fini_func = reinterpret_cast<PluginFiniFunc>(
+ 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
--- /dev/null
+/*
+ * 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_