Add sharing AppCoreBase context
[platform/core/appfw/app-core.git] / tizen-cpp / app-core-cpp / app_core_base.cc
index 5bceb80..466c22d 100644 (file)
 #include <cstring>
 #include <list>
 #include <map>
+#include <memory>
 #include <set>
 #include <sstream>
+#include <utility>
 
 #include "app-core-cpp/app_core_base.hh"
 #include "common/glib_private.hh"
 #include "common/log_private.hh"
 
 extern "C" void aul_finalize();
-
 namespace tizen_cpp {
+
+AppCoreBase* AppCoreBase::context_ = nullptr;
+
 namespace {
 
 enum TizenProfile {
@@ -236,9 +240,26 @@ void AppCoreBase::EventBase::SetVal(int val) {
   impl_->val_ = std::move(val);
 }
 
-AppCoreBase::AppCoreBase() : impl_(std::make_unique<AppCoreBase::Impl>(this)) {}
+AppCoreBase::AppCoreBase()
+    : impl_(std::make_unique<AppCoreBase::Impl>(this)) {
+  if (context_ != nullptr) {
+    _E("Context is already initialized");
+  }
+
+  context_ = this;
+}
+
 AppCoreBase::~AppCoreBase() = default;
 
+AppCoreBase* AppCoreBase::GetContext() {
+  if (context_ == nullptr) {
+    _E("Context is not initialized.");
+    return nullptr;
+  }
+
+  return context_;
+}
+
 void AppCoreBase::Impl::ChangeLang() {
   const char* lang = getenv("LANG");
   if (lang == nullptr)