TizenRefApp-7996 [MomentBar] Implement common WatchApp class 06/113006/1 tizen_dev
authorIgor Olshevskyi <i.olshevskyi@samsung.com>
Thu, 2 Feb 2017 15:48:33 +0000 (17:48 +0200)
committerIgor Olshevskyi <i.olshevskyi@samsung.com>
Fri, 3 Feb 2017 14:10:05 +0000 (16:10 +0200)
Change-Id: Ia1fbed8b9f51445db24902a0a72f24eb990d053e

common/inc/appfw/WatchApp.h [new file with mode: 0644]
common/src/appfw/WatchApp.cpp [new file with mode: 0644]

diff --git a/common/inc/appfw/WatchApp.h b/common/inc/appfw/WatchApp.h
new file mode 100644 (file)
index 0000000..54afac8
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * 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 __MBAR_COMMON_WATCH_APP_H__
+#define __MBAR_COMMON_WATCH_APP_H__
+
+#include <watch_app.h>
+
+#include "appfw/IInstanceContext.h"
+
+namespace com {
+       class IInstanceManager;
+       class IInstance;
+
+       class WatchApp:
+                       public IInstanceContext,
+                       private NonCopyable {
+       public:
+               WatchApp(IInstanceManager &instanceMngr);
+               virtual ~WatchApp();
+
+               int run(int argc, char* argv[]);
+
+               /* IInstanceContext */
+
+               AppType getAppType() const final;
+               void exitApp() const final;
+               Evas_Object *getWindow() const final;
+               void getWindowSize(int &w, int &h) const final;
+
+       private:
+               bool onCreate(int w, int h);
+               void onTerminate();
+               void onPause();
+               void onResume();
+               void onAppControl(app_control_h appControl);
+               void onTimeTick(watch_time_h watchTime);
+               void omAmbientTick(watch_time_h watchTime);
+               void omAmbientChanged(bool ambientMode);
+
+       private:
+               IInstanceManager &m_instanceMngr;
+               IInstance *m_instance;
+               Evas_Object *m_window;
+               int m_winW;
+               int m_winH;
+       };
+
+}
+
+#endif /* __MBAR_COMMON_WATCH_APP_H__ */
diff --git a/common/src/appfw/WatchApp.cpp b/common/src/appfw/WatchApp.cpp
new file mode 100644 (file)
index 0000000..09c2d94
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * 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 "appfw/WatchApp.h"
+
+#include <Elementary.h>
+#include <watch_app_efl.h>
+
+#include "appfw/IInstanceManager.h"
+#include "appfw/IInstanceAppControlExt.h"
+#include "appfw/IInstanceWatchExt.h"
+#include "appfw/SystemEventProvider.h"
+#include "../Debug.h"
+
+namespace com {
+
+       namespace {
+               using CreateCb =  CallbackAlt<bool(int, int)>;
+               using TerminateCb = CallbackAlt<void()>;
+               using PauseCb = CallbackAlt<void()>;
+               using ResumeCb = CallbackAlt<void()>;
+               using AppControlCb = CallbackAlt<void(app_control_h)>;
+               using TimeTickCb = CallbackAlt<void(watch_time_h)>;
+               using AmbientTickCb = CallbackAlt<void(watch_time_h)>;
+               using AmbientChangedCb = CallbackAlt<void(bool)>;
+       }
+
+       WatchApp::WatchApp(IInstanceManager &instanceMngr):
+                       m_instanceMngr(instanceMngr),
+                       m_instance(nullptr),
+                       m_window(nullptr),
+                       m_winW(0),
+                       m_winH(0)
+       {
+       }
+
+       WatchApp::~WatchApp()
+       {
+               if (m_instance)
+                       delete m_instance;
+       }
+
+       int WatchApp::run(int argc, char* argv[])
+       {
+               Variant varTemp;
+               const auto appParams = m_instanceMngr.getAppParams();
+
+               varTemp = appParams.get(AppParam::BASE_SCALE);
+               if (varTemp != Variant::Type::FLOAT) {
+                       ELOG("Base scale does not set");
+               } else {
+                       elm_app_base_scale_set(varTemp.toFloat());
+               }
+
+               ISystemEventProviderUPtr eventProvider(new SystemEventProvider(
+                               &watch_app_add_event_handler,
+                               &watch_app_remove_event_handler));
+               m_instanceMngr.setSystemEventProvider(std::move(eventProvider));
+
+               watch_app_lifecycle_callback_s wlcc = { 0, };
+               wlcc.create = CreateCb::make<WatchApp, &WatchApp::onCreate>();
+               wlcc.terminate = TerminateCb::make<WatchApp, &WatchApp::onTerminate>();
+               wlcc.pause = PauseCb::make<WatchApp, &WatchApp::onPause>();
+               wlcc.resume = ResumeCb::make<WatchApp, &WatchApp::onResume>();
+               wlcc.app_control = AppControlCb::make<WatchApp, &WatchApp::onAppControl>();
+               wlcc.time_tick = TimeTickCb::make<WatchApp, &WatchApp::onTimeTick>();
+               wlcc.ambient_tick = AmbientTickCb::make<WatchApp, &WatchApp::omAmbientTick>();
+               wlcc.ambient_changed = AmbientChangedCb::make<WatchApp, &WatchApp::omAmbientChanged>();
+
+               int ret = watch_app_main(argc, argv, &wlcc, this);
+               if (ret != APP_ERROR_NONE) {
+                       ELOG("watch_app_main() failed. ret[%d]", ret);
+               }
+               return ret;
+       }
+
+       Evas_Object *WatchApp::getWindow() const
+       {
+               return m_window;
+       }
+
+       void WatchApp::getWindowSize(int &w, int &h) const
+       {
+               w = m_winW;
+               h = m_winH;
+       }
+
+       AppType WatchApp::getAppType() const
+       {
+               return AppType::WATCH;
+       }
+
+       void WatchApp::exitApp() const
+       {
+               watch_app_exit();
+       }
+
+       bool WatchApp::onCreate(int w, int h)
+       {
+               int ret = watch_app_get_elm_win(&m_window);
+               RETVM_IF(ret != APP_ERROR_NONE || !m_window, false,
+                               "watch_app_get_elm_win() failed. ret[%d]", ret);
+
+               m_winW = w;
+               m_winH = h;
+
+               m_instance = m_instanceMngr.createInstance();
+               RETVM_IF(!m_instance, nullptr, "Create instance failed");
+
+               if (!m_instance->onCreate(this)) {
+                       ELOG("Widget instance onCreate() failed");
+                       delete m_instance;
+                       return false;
+               }
+               return true;
+       }
+
+       void WatchApp::onTerminate()
+       {
+               if (m_instance) {
+                       m_instance->onDestroy();
+               } else {
+                       ELOG("Instance is NULL");
+               }
+
+               delete m_instance;
+               m_instance = nullptr;
+       }
+
+       void WatchApp::onPause()
+       {
+               RETM_IF(!m_instance, "Instance is NULL");
+               m_instance->onPause();
+       }
+
+       void WatchApp::onResume()
+       {
+               RETM_IF(!m_instance, "Instance is NULL");
+               m_instance->onResume();
+       }
+
+       void WatchApp::onAppControl(app_control_h appControl)
+       {
+               RETM_IF(!m_instance, "Instance is NULL");
+               auto instance = dynamic_cast<IInstanceAppControlExt *>(m_instance);
+               if (instance) {
+                       instance->onAppControl(appControl);
+               }
+       }
+
+       void WatchApp::onTimeTick(watch_time_h watchTime)
+       {
+               RETM_IF(!m_instance, "Instance is NULL");
+               auto instance = dynamic_cast<IInstanceWatchExt *>(m_instance);
+               if (instance) {
+                       instance->onTimeTick(watchTime);
+               }
+       }
+
+       void WatchApp::omAmbientTick(watch_time_h watchTime)
+       {
+               RETM_IF(!m_instance, "Instance is NULL");
+               auto instance = dynamic_cast<IInstanceWatchExt *>(m_instance);
+               if (instance) {
+                       instance->onAmbientTick(watchTime);
+               }
+       }
+
+       void WatchApp::omAmbientChanged(bool ambientMode)
+       {
+               RETM_IF(!m_instance, "Instance is NULL");
+               auto instance = dynamic_cast<IInstanceWatchExt *>(m_instance);
+               if (instance) {
+                       instance->onAmbientChanged(ambientMode);
+               }
+       }
+
+} /* namespace common */