Separate rotation implementation from app-core-cpp
[platform/core/appfw/app-core.git] / tizen-cpp / app-core-ui-cpp / app_core_ui_base.cc
index 9b1c99f..beeef29 100644 (file)
@@ -35,6 +35,7 @@
 #include <utility>
 
 #include "app-core-cpp/app_core_base.hh"
+#include "app-core-rotation-cpp/app_core_rotation.hh"
 #include "app-core-ui-cpp/api/app_core_ui_base.h"
 #include "app-core-ui-cpp/app_core_task_base.hh"
 #include "app-core-ui-cpp/app_core_ui_delegator_private.hh"
 #include "common/ecore_handler.hh"
 #include "common/glib_private.hh"
 #include "common/log_private.hh"
+#include "common/log_tracer.hh"
 
 namespace tizen_cpp {
 
 constexpr const char K_SERVICE_THREAD[] = "__K_SERVICE_THREAD";
 constexpr const char K_HINT_RECENT_SCREEN_POSITION[] =
     "__K_HINT_RECENT_SCREEN_POSITION";
+const int APPID_MAX = 256;
 
-class AppCoreUiBase::Impl {
+class AppCoreUiBase::Impl : public AppCoreRotation::IEventListener {
  public:
   Impl(AppCoreUiBase* parent, unsigned int hint)
       : parent_(parent),
@@ -120,6 +123,9 @@ class AppCoreUiBase::Impl {
   Ecore_Wl2_Window* GetWindow() const;
   void Run(int argc, char** argv);
   void Exit();
+  void RotationInit();
+  void RotationShutdown();
+  void OnRotationChanged(int degree) override;
 
   std::list<std::shared_ptr<WinNode>> winnode_list_;
   unsigned int hint_;
@@ -140,6 +146,7 @@ class AppCoreUiBase::Impl {
   Ecore_Wl2_Window* window_ = nullptr;
   std::unique_ptr<WindowPositionManager> wp_manager_;
   std::unique_ptr<AppCoreUiThreadBase> thread_;
+  std::unique_ptr<AppCoreRotation> rotation_;
 };
 
 AppCoreUiBase::AppCoreUiBase(unsigned int hint)
@@ -278,6 +285,7 @@ void AppCoreUiBase::Impl::SetAppId() {
 }
 
 void AppCoreUiBase::Impl::PluginInit(int argc, char** argv) {
+  LogTracer tracer("AppCoreUiBase::Impl::PluginInit()");
   plugin_.reset(AppCoreUiPlugin::Load());
   if (plugin_ == nullptr)
     return;
@@ -477,7 +485,7 @@ void AppCoreUiBase::DoRun(int argc, char** argv) {
   impl_->handler_->Init();
   impl_->PluginInit(argc, argv);
 
-  char appid[PATH_MAX] = {0, };
+  char appid[APPID_MAX] = {0, };
   int ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
   if (ret != 0)
     _E("Fail to get appid. pid(%d)", getpid());
@@ -541,6 +549,22 @@ void AppCoreUiBase::Impl::Exit() {
   parent_->DoExit();
 }
 
+void AppCoreUiBase::Impl::RotationInit() {
+  if (!rotation_) rotation_.reset(new AppCoreRotation(this));
+
+  rotation_->Init();
+}
+
+void AppCoreUiBase::Impl::RotationShutdown() {
+  if (rotation_) rotation_->Dispose();
+}
+
+void AppCoreUiBase::Impl::OnRotationChanged(int degree) {
+  AppCoreBase::SetRotationState(
+      static_cast<AppCoreBase::RotationState>(degree));
+  parent_->RaiseEvent(degree, IEvent::Type::DEVICE_ORIENTATION_CHANGED);
+}
+
 void AppCoreUiBase::Run(int argc, char** argv) {
   impl_->Run(argc, argv);
 }
@@ -977,4 +1001,22 @@ int AppCoreUiBase::GetWindowPosition(int* x, int* y, int* w, int* h) {
   return 0;
 }
 
+int AppCoreUiBase::OnSetEvent(IEvent::Type event) {
+  AppCoreBase::OnSetEvent(event);
+
+  if (event == IEvent::Type::DEVICE_ORIENTATION_CHANGED)
+    impl_->RotationInit();
+
+  return 0;
+}
+
+int AppCoreUiBase::OnUnsetEvent(IEvent::Type event) {
+  AppCoreBase::OnUnsetEvent(event);
+
+  if (event == IEvent::Type::DEVICE_ORIENTATION_CHANGED)
+    impl_->RotationShutdown();
+
+  return 0;
+}
+
 }  // namespace tizen_cpp