From ebb5738eff9e8aa853233bb600330d069f61b0e1 Mon Sep 17 00:00:00 2001 From: hyunho Date: Thu, 11 Jun 2020 15:23:31 +0900 Subject: [PATCH] Implements WatchBase Change-Id: I548fe74dca493b229df8095b401d2ab06a9533c8 Signed-off-by: hyunho --- CMakeLists.txt | 2 + packaging/libwidget_viewer.spec | 38 +++- packaging/watch-holder-base.manifest | 5 + unittest/CMakeLists.txt | 4 + unittest/src/test_watch.cc | 40 ++--- unittest/src/test_watch_holder.cc | 54 +++--- unittest/src/test_watch_mirror.cc | 18 +- watch-holder-base/CMakeLists.txt | 53 ++++++ .../src/ambient_listener.cc | 4 +- .../src/ambient_listener.hh | 14 +- {watch-holder => watch-holder-base}/src/common.hh | 6 +- .../src/sharable_watch_base_interface.hh | 44 +++++ watch-holder-base/src/watch_base.cc | 198 +++++++++++++++++++++ watch-holder-base/src/watch_base.hh | 105 +++++++++++ watch-holder-base/src/watch_holder_base.cc | 173 ++++++++++++++++++ watch-holder-base/src/watch_holder_base.hh | 87 +++++++++ watch-holder-base/src/watch_mirror_base.cc | 132 ++++++++++++++ watch-holder-base/src/watch_mirror_base.hh | 75 ++++++++ watch-holder-base/watch-holder-base.pc.in | 12 ++ watch-holder/CMakeLists.txt | 4 +- watch-holder/api/sharable_watch.cc | 15 +- watch-holder/api/watch.cc | 36 ++-- watch-holder/api/watch_holder.cc | 35 ++-- watch-holder/api/watch_mirror.cc | 21 +-- watch-holder/src/sharable_watch_interface.hh | 18 +- watch-holder/src/util.cc | 40 +++++ watch-holder/src/util.hh | 29 +++ watch-holder/src/watch.cc | 159 ++++++----------- watch-holder/src/watch.hh | 74 +++----- watch-holder/src/watch_holder.cc | 158 +++------------- watch-holder/src/watch_holder.hh | 50 ++---- watch-holder/src/watch_mirror.cc | 108 +++-------- watch-holder/src/watch_mirror.hh | 36 ++-- watch-holder/watch-holder.pc.in | 8 +- 34 files changed, 1291 insertions(+), 564 deletions(-) create mode 100644 packaging/watch-holder-base.manifest create mode 100644 watch-holder-base/CMakeLists.txt rename {watch-holder => watch-holder-base}/src/ambient_listener.cc (96%) rename {watch-holder => watch-holder-base}/src/ambient_listener.hh (79%) rename {watch-holder => watch-holder-base}/src/common.hh (88%) create mode 100644 watch-holder-base/src/sharable_watch_base_interface.hh create mode 100644 watch-holder-base/src/watch_base.cc create mode 100644 watch-holder-base/src/watch_base.hh create mode 100644 watch-holder-base/src/watch_holder_base.cc create mode 100644 watch-holder-base/src/watch_holder_base.hh create mode 100644 watch-holder-base/src/watch_mirror_base.cc create mode 100644 watch-holder-base/src/watch_mirror_base.hh create mode 100644 watch-holder-base/watch-holder-base.pc.in create mode 100644 watch-holder/src/util.cc create mode 100644 watch-holder/src/util.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index 86bbc61..48bd42f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) ADD_SUBDIRECTORY(widget_viewer_evas) ADD_SUBDIRECTORY(widget_viewer_sdk) ADD_SUBDIRECTORY(watch-holder) +ADD_SUBDIRECTORY(watch-holder-base) ADD_SUBDIRECTORY(watch-control) ADD_SUBDIRECTORY(frame-broker) ADD_SUBDIRECTORY(frame-provider) @@ -10,6 +11,7 @@ ADD_SUBDIRECTORY(ambient-viewer) ADD_SUBDIRECTORY(tool) ADD_SUBDIRECTORY(unittest) +ADD_DEPENDENCIES(watch-holder watch-holder-base) ADD_DEPENDENCIES(widget-viewer_unittests widget_viewer_evas) ADD_DEPENDENCIES(widget_viewer_sdk widget_viewer_evas) ADD_DEPENDENCIES(widget_viewer_sdk watch-holder) diff --git a/packaging/libwidget_viewer.spec b/packaging/libwidget_viewer.spec index 7eaf189..839b04e 100644 --- a/packaging/libwidget_viewer.spec +++ b/packaging/libwidget_viewer.spec @@ -13,7 +13,9 @@ Source1004: watch-control.manifest Source1005: frame-broker.manifest Source1006: frame-provider.manifest Source1007: watch-holder.manifest -Source1008: ambient-viewer.manifest +Source1008: watch-holder-base.manifest +Source1009: ambient-viewer.manifest + BuildRequires: cmake, gettext-tools, coreutils, edje-bin BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(aul) @@ -61,6 +63,7 @@ cp %{SOURCE1005} . cp %{SOURCE1006} . cp %{SOURCE1007} . cp %{SOURCE1008} . +cp %{SOURCE1009} . %build export CFLAGS+=" -DEFL_BETA_API_SUPPORT " @@ -195,12 +198,36 @@ Header & package configuration of watch-control %postun -n watch-control -p /sbin/ldconfig ################################################ +# libwatch_holder_base +%package -n watch-holder-base +Summary: APIs to control watch applications +Version: 0.0.1 +License: Flora-1.1 +Group: Applications/Core Applications + +%description -n watch-holder-base +A set of APIs to control watch applications + +%package -n watch-holder-base-devel +Summary: APIs to control watch applications +Group: Development/Libraries +Requires: watch-holder-base + +%description -n watch-holder-base-devel +Header & package configuration of watch-holder-base + +%post -n watch-holder-base -p /sbin/ldconfig +%postun -n watch-holder-base -p /sbin/ldconfig + +################################################ # libwatch_holder %package -n watch-holder Summary: APIs to control watch applications Version: 0.0.1 License: Flora-1.1 Group: Applications/Core Applications +Requires: watch-holder-base + %description -n watch-holder A set of APIs to control watch applications @@ -329,6 +356,15 @@ Header & package configuration of ambient-viewer %{_libdir}/pkgconfig/watch-holder.pc %{_libdir}/libwatch-holder.so +%files -n watch-holder-base +%manifest watch-holder-base.manifest +%license LICENSE.Flora-1.1 LICENSE.Apache-2.0 +%{_libdir}/libwatch-holder-base.so.* + +%files -n watch-holder-base-devel +%{_includedir}/watch-holder-base/*.hh +%{_libdir}/pkgconfig/watch-holder-base.pc +%{_libdir}/libwatch-holder-base.so %files -n frame-broker %manifest frame-broker.manifest diff --git a/packaging/watch-holder-base.manifest b/packaging/watch-holder-base.manifest new file mode 100644 index 0000000..50eefc9 --- /dev/null +++ b/packaging/watch-holder-base.manifest @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index b1ede86..441ce72 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -45,22 +45,26 @@ SET(CMAKE_C_FLAGS_RELEASE "-O2") INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/include) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../watch-holder/src) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../watch-holder-base/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../unittest/mock) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock UNIT_TEST_SOURCES) AUX_SOURCE_DIRECTORY(src SOURCES) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/src AMBIENT_VIEWER_SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../watch-holder-base/src WATCH_HOLDER_BASE_SOURCES) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../watch-holder/src WATCH_HOLDER_SOURCES) ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES} ${UNIT_TEST_SOURCES} ${AMBIENT_VIEWER_SOURCES} + ${WATCH_HOLDER_BASE_SOURCES} ${WATCH_HOLDER_SOURCES} ) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${widget-viewer_unittests_LDFLAGS} gmock + watch-holder ) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/) diff --git a/unittest/src/test_watch.cc b/unittest/src/test_watch.cc index 771514f..ababe60 100644 --- a/unittest/src/test_watch.cc +++ b/unittest/src/test_watch.cc @@ -69,43 +69,40 @@ class WatchMirrorStub : public WatchMirror { : WatchMirror(win) { } - void OnChanged(const ISharableWatch& watch) override {} - void OnAdded(const ISharableWatch& watch) override {} - void OnUpdated(const ISharableWatch& watch) override {} - void OnRemoved(const ISharableWatch& watch) override {} + void OnChanged(const ISharableWatchBase& watch) override {} + void OnAdded(const ISharableWatchBase& watch) override {} + void OnUpdated(const ISharableWatchBase& watch) override {} + void OnRemoved(const ISharableWatchBase& watch) override {} }; -class WatchStub : public Watch{ +class WatchStub : public Watch { public: WatchStub(string appid, Evas_Object* win, WatchMirrorStub* listener) : Watch(appid, win, listener, true) { } - WatchStub(int rid, std::string id, string appid, Evas_Object* win, WatchMirrorStub* listener) + WatchStub(int rid, std::string id, string appid, Evas_Object* win, + WatchMirrorStub* listener) : Watch(rid, id, appid, win, listener, true) { } - WatchStub(string appid, Evas_Object* win, tizen_base::Bundle extra,WatchMirrorStub* listener) + WatchStub(string appid, Evas_Object* win, + tizen_base::Bundle extra, + WatchMirrorStub* listener) : Watch(appid, win, extra, listener, true) { } - WatchStub(int rid, std::string id, string appid, Evas_Object* win, tizen_base::Bundle extra, WatchMirrorStub* listener) + WatchStub(int rid, std::string id, string appid, Evas_Object* win, + tizen_base::Bundle extra, + WatchMirrorStub* listener) : Watch(rid, id, appid, win, extra, listener, true) { } void InvokeEvasAdded() { - screen_connector::EvasObject eo(reinterpret_cast(&__not_null), - false); - OnEvasAdded("TestAppId", "TestInstId", 99, eo); } void InvokeEvasRemoved() { - screen_connector::EvasObject eo(reinterpret_cast(&__not_null), - false); - OnEvasRemoved("TestAppId", "TestInstId", 99, eo); + OnRemoved("TestAppId", "TestInstId", 99, nullptr); } void InvokeEvasChanged() { - screen_connector::EvasObject eo(reinterpret_cast(&__not_null), - false); - OnEvasChanged("TestAppId", "TestInstId", 99, eo); } void InvokeSetFaulted(bool faulted) { @@ -167,7 +164,8 @@ TEST_F(WatchTest, CreateInstance4) { WatchMirrorStub* mirrorstub = new WatchMirrorStub(mirwin); EXPECT_NE(mirrorstub, nullptr); Evas_Object* win = elm_win_add(NULL, "Watch", ELM_WIN_BASIC); - WatchStub* stub = new WatchStub(0, string("id"), string("test"), win, b,mirrorstub); + WatchStub* stub = new WatchStub(0, string("id"), + string("test"), win, b, mirrorstub); EXPECT_NE(stub, nullptr); delete stub; delete mirrorstub; @@ -197,12 +195,6 @@ TEST_F(WatchTest, GetAppId) { EXPECT_EQ(appid, "test"); } -TEST_F(WatchTest, GetCurrentImage_N) { - Evas_Object* cur; - cur = WatchTest::stub->GetCurrentImage(); - EXPECT_EQ(cur, nullptr); -} - TEST_F(WatchTest, GetExtra) { Bundle b; b = WatchTest::stub->GetExtra(); diff --git a/unittest/src/test_watch_holder.cc b/unittest/src/test_watch_holder.cc index 6d11977..085d260 100644 --- a/unittest/src/test_watch_holder.cc +++ b/unittest/src/test_watch_holder.cc @@ -41,24 +41,22 @@ class WatchHolderStub : public WatchHolder { Bundle extra) { OnAmbientEvent(ev, sender, extra); } - void OnAdded(const Watch& watch) override {} - void OnUpdated(const Watch& watch) override {} - void OnRemoved(const Watch& watch) override {} - void OnLaunched(const Watch& watch) override {} - void OnDead(const Watch& watch) override {} - void OnBound(const Watch& watch) override {} - - std::shared_ptr CreateWatch(int rid, std::string id, - std::string appid, Evas_Object* viewer_win, - Watch::IEvent* listener, bool mock) override { - return WatchHolder::CreateWatch(rid, id, appid, viewer_win, listener, true); - } - std::shared_ptr CreateWatch(int rid, std::string id, - std::string appid, Evas_Object* viewer_win, tizen_base::Bundle extra, - Watch::IEvent* listener, bool mock) override { - return WatchHolder::CreateWatch(rid, id, appid, viewer_win, extra, listener, true); + void OnAdded(const WatchBase& watch) override {} + void OnUpdated(const WatchBase& watch) override {} + void OnRemoved(const WatchBase& watch) override {} + void OnLaunched(const WatchBase& watch) override {} + void OnDead(const WatchBase& watch) override {} + void OnBound(const WatchBase& watch) override {} + + std::shared_ptr CreateWatch(int rid, std::string id, + std::string appid, bool mock) override { + return WatchHolder::CreateWatch(rid, id, appid, true); } + std::shared_ptr CreateWatch(int rid, std::string id, + std::string appid, tizen_base::Bundle extra, bool mock) override { + return WatchHolder::CreateWatch(rid, id, appid, extra, true); + } }; static int (*__app_com_cb)(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data); @@ -120,17 +118,15 @@ TEST_F(WatchHolderTest, CreateInstance) { } TEST_F(WatchHolderTest, CreateWatch) { - Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC); - std::shared_ptr w = - WatchHolderTest::stub->CreateWatch(1, string("id"), string("appid"), - watchwin, WatchHolderTest::stub, true); + std::shared_ptr w = + WatchHolderTest::stub->CreateWatch(1, string("id"), string("appid"), true); EXPECT_NE(w, nullptr); Bundle b; b.Add("__APP_AMBIENT_EVENT__", "1"); - std::shared_ptr w2 = - WatchHolderTest::stub->CreateWatch(1, string("id"), string("appid"), - watchwin, b, WatchHolderTest::stub, true); + std::shared_ptr w2 = + WatchHolderTest::stub->CreateWatch(1, string("id"), + string("appid"), b, true); EXPECT_NE(w2, nullptr); } @@ -144,7 +140,7 @@ TEST_F(WatchHolderTest, LaunchWatch) { } TEST_F(WatchHolderTest, GetStack) { - std::list> list; + std::list> list; list = WatchHolderTest::stub->GetStack(); EXPECT_EQ(list.size(), 0); } @@ -185,16 +181,6 @@ TEST_F(WatchHolderTest, OnReceiveSignal) { __app_com_cb("end", AUL_APP_COM_R_OK, b.GetHandle(), stub); } -TEST_F(WatchHolderTest, EnableRendering) { - EXPECT_NE(WatchHolderTest::stub, nullptr); - WatchHolderTest::stub->EnableRendering(); -} - -TEST_F(WatchHolderTest, DisableRendering) { - EXPECT_NE(WatchHolderTest::stub, nullptr); - WatchHolderTest::stub->DisableRendering(0); -} - TEST_F(WatchHolderTest, OnAmbientChanged) { Bundle *b = nullptr; EXPECT_NE(WatchHolderTest::stub, nullptr); diff --git a/unittest/src/test_watch_mirror.cc b/unittest/src/test_watch_mirror.cc index a8e3774..aa6d765 100644 --- a/unittest/src/test_watch_mirror.cc +++ b/unittest/src/test_watch_mirror.cc @@ -32,22 +32,22 @@ class WatchMirrorStub : public WatchMirror { : WatchMirror(win) { } - void OnChanged(const ISharableWatch& watch) override {} - void OnAdded(const ISharableWatch& watch) override {} - void OnUpdated(const ISharableWatch& watch) override {} - void OnRemoved(const ISharableWatch& watch) override {} + void OnChanged(const ISharableWatchBase& watch) override {} + void OnAdded(const ISharableWatchBase& watch) override {} + void OnUpdated(const ISharableWatchBase& watch) override {} + void OnRemoved(const ISharableWatchBase& watch) override {} }; -class SharableWatchStub : public ISharableWatch { +class SharableWatchStub : public ISharableWatchBase { public: void Resume() override; void Pause() override; - Evas_Object* GetCurrentImage() const override; + std::shared_ptr GetCurrentImage() const override; bool IsBound() const override; std::string GetAppId() const override; int GetPid() const override; - tizen_base::Bundle GetExtra() const override; + virtual tizen_base::Bundle GetExtra() const override; bool IsFaulted() const override; void BlockUpdate(bool enable) override; }; @@ -112,14 +112,14 @@ TEST_F(WatchMirrorTest, MirrorListen_N) { } TEST_F(WatchMirrorTest, MirrorGetCurrent_N) { - shared_ptr sw; + shared_ptr sw; sw = WatchMirrorTest::mirrorstub->GetCurrent(); EXPECT_EQ(sw, nullptr); } TEST_F(WatchMirrorTest, OnChanged) { Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC); - Watch *w = new Watch(string("test"), watchwin, WatchMirrorTest::mirrorstub); + Watch *w = new Watch(string("test"), watchwin, nullptr, WatchMirrorTest::mirrorstub); EXPECT_NE(w, nullptr); WatchMirror *mr = new WatchMirror(watchwin); EXPECT_NE(mr, nullptr); diff --git a/watch-holder-base/CMakeLists.txt b/watch-holder-base/CMakeLists.txt new file mode 100644 index 0000000..ea85700 --- /dev/null +++ b/watch-holder-base/CMakeLists.txt @@ -0,0 +1,53 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(watch-holder-base CXX) + +SET(PREFIX "${CMAKE_INSTALL_PREFIX}") +SET(PROJECT_NAME "${PROJECT_NAME}") +SET(LIBDIR ${LIB_INSTALL_DIR}) +SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") +SET(VERSION_MAJOR "${MAJORVER}") +SET(VERSION "${FULLVER}") + +INCLUDE(FindPkgConfig) +pkg_check_modules(watch-holder-base REQUIRED + dlog + glib-2.0 + pkgmgr-info + capi-system-info + capi-system-device + capi-appfw-app-control + aul + screen_connector_remote_surface + appsvc + vconf +) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) + +AUX_SOURCE_DIRECTORY(src BUILD_SOURCE) + +FOREACH(flag ${watch-holder-base_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline") +MESSAGE("${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${BUILD_SOURCE}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${watch-holder-base_LDFLAGS}) + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc") + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/ DESTINATION include/${PROJECT_NAME} FILES_MATCHING + PATTERN "*.hh" + PATTERN "*.h" + PATTERN "*_implementation.h" EXCLUDE + ) \ No newline at end of file diff --git a/watch-holder/src/ambient_listener.cc b/watch-holder-base/src/ambient_listener.cc similarity index 96% rename from watch-holder/src/ambient_listener.cc rename to watch-holder-base/src/ambient_listener.cc index a36fa53..d037988 100644 --- a/watch-holder/src/ambient_listener.cc +++ b/watch-holder-base/src/ambient_listener.cc @@ -47,8 +47,8 @@ AmbientListener::AmbientListener() { } } -int AmbientListener::OnReceiveSignal(const char* endpoint, aul_app_com_result_e e, - bundle* envelope, void* user_data) { +int AmbientListener::OnReceiveSignal(const char* endpoint, + aul_app_com_result_e e, bundle* envelope, void* user_data) { LOGI("Receive aod ambient event"); AmbientListener* listener = (AmbientListener*)user_data; diff --git a/watch-holder/src/ambient_listener.hh b/watch-holder-base/src/ambient_listener.hh similarity index 79% rename from watch-holder/src/ambient_listener.hh rename to watch-holder-base/src/ambient_listener.hh index 332ce5a..23ebf16 100644 --- a/watch-holder/src/ambient_listener.hh +++ b/watch-holder-base/src/ambient_listener.hh @@ -14,12 +14,14 @@ * limitations under the License. */ -#ifndef __WATCH_HOLDER_AMBIENT_LISTENER_HH__ -#define __WATCH_HOLDER_AMBIENT_LISTENER_HH__ +#ifndef WATCH_HOLDER_BASE_SRC_AMBIENT_LISTENER_HH_ +#define WATCH_HOLDER_BASE_SRC_AMBIENT_LISTENER_HH_ #include #include +#include + #include "common.hh" namespace watch_holder { @@ -44,8 +46,10 @@ class AmbientListener { static int OnReceiveSignal(const char* endpoint, aul_app_com_result_e e, bundle* envelope, void* user_data); - virtual void OnAmbientChanged(bool enter, tizen_base::Bundle& extra) = 0; - virtual void OnAmbientEvent(EventType ev, std::string sender, tizen_base::Bundle extra) = 0; + virtual void OnAmbientChanged(bool enter, + const tizen_base::Bundle& extra) = 0; + virtual void OnAmbientEvent(EventType ev, std::string sender, + tizen_base::Bundle extra) = 0; private: aul_app_com_connection_h ambient_changed_signal_conn_ = nullptr; @@ -54,4 +58,4 @@ class AmbientListener { } // namespace watch_holder -#endif // __WATCH_HOLDER_AMBIENT_LISTENER_HH__ \ No newline at end of file +#endif // WATCH_HOLDER_BASE_SRC_AMBIENT_LISTENER_HH_ diff --git a/watch-holder/src/common.hh b/watch-holder-base/src/common.hh similarity index 88% rename from watch-holder/src/common.hh rename to watch-holder-base/src/common.hh index e1fccc3..6971943 100644 --- a/watch-holder/src/common.hh +++ b/watch-holder-base/src/common.hh @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __WATCH_HOLDER_COMMON_HH__ -#define __WATCH_HOLDER_COMMON_HH__ +#ifndef WATCH_HOLDER_BASE_SRC_COMMON_HH_ +#define WATCH_HOLDER_BASE_SRC_COMMON_HH_ #ifdef EXPORT_API #undef EXPORT_API @@ -26,4 +26,4 @@ #define NOTIFY_CHANGED_EVENT_APPID_KEY "__NOTIFY_CHANGED_EVENT_APPID_KEY__" #define NOTIFY_CHANGED_EVENT_RID_KEY "__NOTIFY_CHANGED_EVENT_RID_KEY__" -#endif // __WATCH_HOLDER_COMMON_HH__ +#endif // WATCH_HOLDER_BASE_SRC_COMMON_HH_ diff --git a/watch-holder-base/src/sharable_watch_base_interface.hh b/watch-holder-base/src/sharable_watch_base_interface.hh new file mode 100644 index 0000000..1717f49 --- /dev/null +++ b/watch-holder-base/src/sharable_watch_base_interface.hh @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 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 WATCH_HOLDER_BASE_SRC_SHARABLE_WATCH_BASE_INTERFACE_HH_ +#define WATCH_HOLDER_BASE_SRC_SHARABLE_WATCH_BASE_INTERFACE_HH_ + +#include +#include + +#include +#include + +namespace watch_holder { + +class ISharableWatchBase { + public: + virtual void Resume() = 0; + virtual void Pause() = 0; + virtual std::shared_ptr + GetCurrentImage() const = 0; + virtual bool IsBound() const = 0; + virtual std::string GetAppId() const = 0; + virtual int GetPid() const = 0; + virtual tizen_base::Bundle GetExtra() const = 0; + virtual bool IsFaulted() const = 0; + virtual void BlockUpdate(bool enable) = 0; +}; + +} // namespace watch_holder + +#endif // WATCH_HOLDER_BASE_SRC_SHARABLE_WATCH_BASE_INTERFACE_HH_ diff --git a/watch-holder-base/src/watch_base.cc b/watch-holder-base/src/watch_base.cc new file mode 100644 index 0000000..ed4d1f6 --- /dev/null +++ b/watch-holder-base/src/watch_base.cc @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2020 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 +#include +#include +#include + +#include "watch_base.hh" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "WATCH_HOLDER" + +using namespace std; +using namespace tizen_base; +using namespace screen_connector; +namespace watch_holder { + +WatchBase::WatchBase(std::string appid, + std::shared_ptr surface, + tizen_base::Bundle extra, IEvent* listener, bool mock) + : RemoteSurface(appid, RemoteSurface::WATCH, surface, mock), + appid_(appid), listener_(listener), extra_data_(extra) { +} + +WatchBase::WatchBase(int rid, std::string id, std::string appid, + std::shared_ptr surface, + tizen_base::Bundle extra, IEvent* listener, bool mock) + : RemoteSurface(rid, id, RemoteSurface::WATCH, surface, mock), + appid_(appid), listener_(listener), extra_data_(extra) { +} + +WatchBase::WatchBase(std::string appid, + std::shared_ptr surface, + IEvent* listener, bool mock) + : RemoteSurface(appid, RemoteSurface::WATCH, surface, mock), + appid_(appid), listener_(listener) { +} + +WatchBase::WatchBase(int rid, std::string id, std::string appid, + std::shared_ptr surface, + IEvent* listener, bool mock) + : RemoteSurface(rid, id, RemoteSurface::WATCH, surface, mock), + appid_(appid), listener_(listener) { +} + +WatchBase::~WatchBase() = default; +void WatchBase::Resume() { + RemoteSurface::SendVisibility(true); +} + +void WatchBase::Pause() { + RemoteSurface::SendVisibility(false); +} + +int WatchBase::Terminate() { + LOGW("Terminate (%d)", pid_); + return aul_terminate_pid(pid_); +} + +void WatchBase::BlockUpdate(bool enable) { + RemoteSurface::SetBlock(enable); +} + + +void WatchBase::CancelTouch() { + RemoteSurface::SendTouchCancel(); +} + +int WatchBase::GetRid() const { + return RemoteSurface::GetRid(); +} + +int WatchBase::GetPid() const { + return pid_; +} + +bool WatchBase::IsBound() const { + return is_bound_; +} + +string WatchBase::GetAppId() const { + return appid_; +} + +bool WatchBase::IsFaulted() const { + return is_faulted_; +} + +void WatchBase::Bind(std::shared_ptr surface) { + RemoteSurface::Bind(surface); + is_bound_ = true; +} + +void WatchBase::Unbind() { + RemoteSurface::Unbind(); + is_bound_ = false; +} + +std::shared_ptr WatchBase::GetCurrentImage() const { + return current_buffer_; +} + +tizen_base::Bundle WatchBase::GetExtra() const { + return extra_data_; +} + +void WatchBase::SetFaulted(bool faulted) { + is_faulted_ = faulted; +} + +void WatchBase::OnBufferAdded(const std::string& appId, + const std::string& instId, int pid) { + pid_ = pid; +} + +void WatchBase::OnBufferRemoved(const std::string& appId, + const std::string& instId, int pid) { + if (current_buffer_ == nullptr) + return; + + OnRemoved(appId, instId, pid, current_buffer_); + current_buffer_ = nullptr; +} + +void WatchBase::OnBufferChanged(int type, + std::shared_ptr tbm, + int fd, uint32_t size, uint32_t time) { + if (type != TIZEN_REMOTE_SURFACE_BUFFER_TYPE_TBM) + return; + + if (tbm.get() == nullptr || tbm->GetRaw() == nullptr) { + LOGW("Null tbm"); + return; + } + + if (GetType() == RemoteSurface::WATCH && RemoteSurface::IsBound()) + return; + + if (current_buffer_ == nullptr) { + LOGD("first added !!!! %d %s", type, GetAppId().c_str()); + OnAdded(GetAppId(), GetInstId(), GetPid(), tbm); + } else { + OnChanged(GetAppId(), GetInstId(), GetPid(), tbm); + } + current_buffer_ = tbm; +} + +void WatchBase::OnAdded(const std::string& appId, const std::string& instId, + int pid, std::shared_ptr tbm) { + pid_ = pid; + listener_->OnAdded(*this); +} + +void WatchBase::OnRemoved(const std::string& appId, const std::string& instId, + int pid, std::shared_ptr tbm) { + listener_->OnRemoved(*this); +} + +void WatchBase::OnChanged(const std::string& appId, const std::string& instId, + int pid, std::shared_ptr tbm) { + listener_->OnUpdated(*this); +} + +int WatchBase::NotifyChangedEvent() const { + tizen_base::Bundle b; + b.Add(NOTIFY_CHANGED_EVENT_APPID_KEY, appid_); + b.Add(NOTIFY_CHANGED_EVENT_RID_KEY, to_string(GetRid())); + int ret = vconf_set_str( + VCONFKEY_WATCH_CURRENT_WATCH_INFO, (const char*)b.ToRaw().first.get()); + if (ret != 0) { + LOGE("Fail to send noti (%d)", ret); + return -1; + } + return 0; +} + +WatchBase::IEvent* WatchBase::GetListener() { + return listener_; +} + +} // namespace watch_holder diff --git a/watch-holder-base/src/watch_base.hh b/watch-holder-base/src/watch_base.hh new file mode 100644 index 0000000..c5dd958 --- /dev/null +++ b/watch-holder-base/src/watch_base.hh @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2020 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 WATCH_HOLDER_BASE_SRC_WATCH_BASE_HH_ +#define WATCH_HOLDER_BASE_SRC_WATCH_BASE_HH_ + +#include + +#include +#include +#include + +#include "common.hh" +#include "sharable_watch_base_interface.hh" + +namespace watch_holder { + +class EXPORT_API WatchBase : public screen_connector::RemoteSurface, + public virtual ISharableWatchBase { + public: + class IEvent { + public: + virtual void OnBound(const WatchBase& watch) = 0; + virtual void OnAdded(const WatchBase& watch) = 0; + virtual void OnUpdated(const WatchBase& watch) = 0; + virtual void OnRemoved(const WatchBase& watch) = 0; + }; + + WatchBase(std::string appid, + std::shared_ptr surface, + tizen_base::Bundle extra, + IEvent* listener, bool mock = false); + WatchBase(int rid, std::string id, std::string appid, + std::shared_ptr surface, + tizen_base::Bundle extra, + IEvent* listener, bool mock = false); + WatchBase(std::string appid, + std::shared_ptr surface, + IEvent* listener, bool mock = false); + WatchBase(int rid, std::string id, std::string appid, + std::shared_ptr surface, + IEvent* listener, bool mock = false); + virtual ~WatchBase(); + + void Resume() override; + void Pause() override; + + int Terminate(); + void Bind(std::shared_ptr surface); + void Unbind(); + void CancelTouch(); + std::shared_ptr GetCurrentImage() const override; + int NotifyChangedEvent() const; + bool IsBound() const override; + std::string GetAppId() const; + int GetPid() const override; + int GetRid() const; + tizen_base::Bundle GetExtra() const override; + bool IsFaulted() const override; + void BlockUpdate(bool enable) override; + IEvent* GetListener(); + virtual void OnAdded(const std::string& appId, const std::string& instId, + int pid, std::shared_ptr tbm); + virtual void OnRemoved(const std::string& appId, const std::string& instId, + int pid, std::shared_ptr tbm); + virtual void OnChanged(const std::string& appId, const std::string& instId, + int pid, std::shared_ptr tbm); + + protected: + friend class WatchHolderBase; + void OnBufferAdded(const std::string& appId, + const std::string& instId, int pid) override; + void OnBufferRemoved(const std::string& appId, + const std::string& instId, int pid) override; + void OnBufferChanged(int type, + std::shared_ptr tbm, + int fd, uint32_t size, uint32_t time) override; + void SetFaulted(bool is_faulted); + + private: + int pid_ = 0; + std::string appid_; + IEvent* listener_; + std::shared_ptr current_buffer_ = nullptr; + tizen_base::Bundle extra_data_; + bool is_faulted_ = false; + bool is_bound_ = false; +}; + +} // namespace watch_holder + +#endif // WATCH_HOLDER_BASE_SRC_WATCH_BASE_HH_ diff --git a/watch-holder-base/src/watch_holder_base.cc b/watch-holder-base/src/watch_holder_base.cc new file mode 100644 index 0000000..e066e79 --- /dev/null +++ b/watch-holder-base/src/watch_holder_base.cc @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2020 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 +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "watch_holder_base.hh" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "WATCH_HOLDER" + +using namespace screen_connector; +using namespace tizen_base; +using namespace std; +namespace watch_holder { + +WatchHolderBase::~WatchHolderBase() { + if (dead_signal_conn_) + aul_app_com_leave(dead_signal_conn_); + if (launch_signal_conn_) + aul_app_com_leave(launch_signal_conn_); +} + +WatchHolderBase::WatchHolderBase( + std::shared_ptr surface, int w, int h) + : surface_(surface), w_(w), h_(h) { + if (aul_app_com_create("watch.dead", nullptr, + OnDeadSignal, this, &dead_signal_conn_) != AUL_R_OK) { + LOGE("failed to create status"); + } + + if (aul_app_com_create("watch.launch", nullptr, OnLaunchSignal, + this, &launch_signal_conn_) != AUL_R_OK) { + LOGE("Failed to listen watch.launch signal"); + } + + char appid_buf[512] = {0, }; + if (aul_app_get_appid_bypid( + getpid(), appid_buf, sizeof(appid_buf)) != AUL_R_OK) { + LOGE("Failed to get appid (%d)", getpid()); + } + appid_ = appid_buf; +} + +int WatchHolderBase::Launch( + string watch_appid, bool background, bundle* extra) { + Bundle data; + + if (extra != nullptr) + data = Bundle(extra, true, true); + aul_svc_set_appid(data.GetHandle(), watch_appid.c_str()); + data.Add("WATCH_WIDTH", std::to_string(w_)); + data.Add("WATCH_HEIGHT", std::to_string(h_)); + data.Add("WATCH_BG_LAUNCH", std::to_string((int)background)); + data.Add(AUL_K_WIDGET_VIEWER, appid_); + + if (extra != nullptr) + extra_map_[watch_appid] = Bundle(extra, true, true); + + int pid = appsvc_run_service(data.GetHandle(), 0, nullptr, nullptr); + if (pid < 0) { + LOGE("Fail to run watch (%d)", pid); + return -1; + } + LOGI("Launch (%s) done : (%d)", watch_appid.c_str(), pid); + return pid; +} + +const std::list>& WatchHolderBase::GetStack() const { + return stack_; +} + +std::shared_ptr WatchHolderBase::GetCurrent() const { + if (stack_.empty()) { + LOGW("Empty stack!"); + return nullptr; + } + return stack_.back(); +} + +void WatchHolderBase::OnAmbientChanged(bool enter, const Bundle& extra) { +} + +void WatchHolderBase::OnAmbientEvent(EventType ev, std::string sender, + tizen_base::Bundle extra) { +} + +int WatchHolderBase::OnDeadSignal(const char *endpoint, aul_app_com_result_e e, + bundle *envelope, void *user_data) { + WatchHolderBase* holder = (WatchHolderBase*)user_data; + Bundle data(envelope, false, false); + string appid = data.GetString(AUL_K_APPID); + string pid = data.GetString(AUL_K_PID); + string is_faulted = data.GetString(AUL_K_IS_FAULT); + LOGW("WatchBase(%s)(%s) DEAD", appid.c_str(), pid.c_str()); + list>::iterator it; + for (it = holder->stack_.begin(); it != holder->stack_.end(); ++it) { + if ((*it)->GetAppId() == appid && + pid == to_string((*it)->GetPid())) { + (*it)->SetFaulted(is_faulted == "true"); + holder->OnDead(**it); + holder->stack_.erase(it); + LOGW("REMOVE DEAD WATCH (%s)(%s)", appid.c_str(), pid.c_str()); + break; + } + } + LOGW("DEAD DONE (%s)(%s)", appid.c_str(), pid.c_str()); + return 0; +} + +int WatchHolderBase::OnLaunchSignal(const char *endpoint, + aul_app_com_result_e res, bundle *envelope, void *user_data) { + Bundle launch_data(envelope, false, false); + WatchHolderBase* holder = (WatchHolderBase*)user_data; + string viewer_appid = launch_data.GetString(AUL_K_WIDGET_VIEWER); + if (viewer_appid != holder->appid_) { + LOGE("It's not mine (%s:%s)", viewer_appid.c_str(), holder->appid_.c_str()); + return 0; + } + + string watch_appid = launch_data.GetString(AUL_K_APPID); + if (holder->extra_map_.find(watch_appid) != holder->extra_map_.end()) { + Bundle extra(holder->extra_map_[watch_appid]); + holder->stack_.push_back(holder->CreateWatch( + watch_appid, extra)); + holder->extra_map_.erase(watch_appid); + } else { + holder->stack_.push_back(holder->CreateWatch(watch_appid)); + } + holder->OnLaunched(*holder->GetCurrent()); + LOGI("LAUNCH DONE (%s)", viewer_appid.c_str()); + return 0; +} + +void WatchHolderBase::OnBound(const WatchBase& watch) { +} + +void WatchHolderBase::OnAdded(const WatchBase& watch) { +} + +void WatchHolderBase::OnUpdated(const WatchBase& watch) { +} + +void WatchHolderBase::OnRemoved(const WatchBase& watch) { +} + +} // namespace watch_holder diff --git a/watch-holder-base/src/watch_holder_base.hh b/watch-holder-base/src/watch_holder_base.hh new file mode 100644 index 0000000..eee44ad --- /dev/null +++ b/watch-holder-base/src/watch_holder_base.hh @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020 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 WATCH_HOLDER_BASE_SRC_WATCH_HOLDER_BASE_HH_ +#define WATCH_HOLDER_BASE_SRC_WATCH_HOLDER_BASE_HH_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "watch_base.hh" +#include "common.hh" +#include "ambient_listener.hh" + +namespace watch_holder { + +class EXPORT_API WatchHolderBase + : public WatchBase::IEvent, public AmbientListener { + public: + WatchHolderBase( + std::shared_ptr surface, int w, int h); + virtual ~WatchHolderBase() = 0; + int Launch(std::string appid, bool background, bundle* extra); + const std::list>& GetStack() const; + std::shared_ptr GetCurrent() const; + void AddWatch(std::shared_ptr watch); + virtual void OnLaunched(const WatchBase& watch) = 0; + virtual void OnDead(const WatchBase& watch) = 0; + void OnAmbientChanged(bool enter, + const tizen_base::Bundle& extra) override; + void OnAmbientEvent(EventType ev, std::string sender, + tizen_base::Bundle extra) override; + void OnBound(const WatchBase& watch) override; + void OnAdded(const WatchBase& watch) override; + void OnUpdated(const WatchBase& watch) override; + void OnRemoved(const WatchBase& watch) override; + + protected: + virtual std::shared_ptr CreateWatch(std::string appid, + bool mock = false) = 0; + virtual std::shared_ptr CreateWatch(int rid, std::string id, + std::string appid, bool mock = false) = 0; + virtual std::shared_ptr CreateWatch(std::string appid, + tizen_base::Bundle extra, bool mock = false) = 0; + virtual std::shared_ptr CreateWatch(int rid, std::string id, + std::string appid, tizen_base::Bundle extra, bool mock = false) = 0; + + private: + static int OnDeadSignal(const char *endpoint, aul_app_com_result_e e, + bundle *envelope, void *user_data); + static int OnLaunchSignal(const char *endpoint, + aul_app_com_result_e res, bundle *envelope, void *user_data); + + private: + std::string appid_; + std::map extra_map_; + std::list> stack_; + aul_app_com_connection_h launch_signal_conn_ = nullptr; + aul_app_com_connection_h dead_signal_conn_ = nullptr; + aul_app_com_connection_h ambient_changed_signal_conn_ = nullptr; + std::shared_ptr surface_; + int w_; + int h_; +}; + +} // namespace watch_holder + +#endif // WATCH_HOLDER_BASE_SRC_WATCH_HOLDER_BASE_HH_ diff --git a/watch-holder-base/src/watch_mirror_base.cc b/watch-holder-base/src/watch_mirror_base.cc new file mode 100644 index 0000000..b9c5482 --- /dev/null +++ b/watch-holder-base/src/watch_mirror_base.cc @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2020 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 +#include +#include +#include +#include + +#include "watch_mirror_base.hh" +#include "bundle_cpp.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "WATCH_HOLDER" + +using namespace tizen_base; +using namespace std; +namespace watch_holder { + +WatchMirrorBase::~WatchMirrorBase() = default; +WatchMirrorBase::WatchMirrorBase( + shared_ptr surface) { +} + +string WatchMirrorBase::GetUUID(string rid) const { + char uuid[37]; + uuid_t u; + + uuid_generate(u); + uuid_unparse(u, uuid); + return string(uuid) + rid; +} + +void WatchMirrorBase::OnChangedSignal(keynode_t *node, void *user_data) { + WatchMirrorBase* mirror = (WatchMirrorBase*)user_data; + const char* raw = vconf_get_str(VCONFKEY_WATCH_CURRENT_WATCH_INFO); + if (raw == nullptr || strlen(raw) == 0) { + if (raw != nullptr) + free((void*)raw); + return; + } + + string raw_str(raw); + free((void*)raw); + try { + Bundle data(raw_str); + string appid = data.GetString(NOTIFY_CHANGED_EVENT_APPID_KEY); + string rid = data.GetString(NOTIFY_CHANGED_EVENT_RID_KEY); + mirror->stack_.push_back(mirror->CreateWatch( + stoi(rid), mirror->GetUUID(rid), appid)); + mirror->OnChanged(stoi(rid), mirror->GetUUID(rid), appid); + } catch (const std::exception& e) { + LOGE("Exception occurred : %s", e.what()); + return; + } +} + +int WatchMirrorBase::Listen() { + if (vconf_notify_key_changed( + VCONFKEY_WATCH_CURRENT_WATCH_INFO, OnChangedSignal, this) != 0) { + LOGE("failed to listen on changed signal"); + return -1; + } + OnChangedSignal(nullptr, this); + return 0; +} + +std::shared_ptr WatchMirrorBase::GetCurrent() const { + if (stack_.empty()) { + LOGW("Empty stack!"); + return nullptr; + } + return stack_.back(); +} + +void WatchMirrorBase::AddWatch(shared_ptr watch) { + stack_.push_back(watch); +} + +void WatchMirrorBase::OnAmbientChanged(bool enter, const Bundle& extra) { +} + +void WatchMirrorBase::OnAmbientEvent(EventType ev, std::string sender, + tizen_base::Bundle extra) { +} + +void WatchMirrorBase::OnChanged(const ISharableWatchBase& watch) { +} + +void WatchMirrorBase::OnAdded(const ISharableWatchBase& watch) { +} + +void WatchMirrorBase::OnUpdated(const ISharableWatchBase& watch) { +} + +void WatchMirrorBase::OnRemoved(const ISharableWatchBase& watch) { +} + +void WatchMirrorBase::OnAdded(const WatchBase& watch) { + OnAdded((const ISharableWatchBase&)watch); +} + +void WatchMirrorBase::OnUpdated(const WatchBase& watch) { + OnUpdated((const ISharableWatchBase&)watch); +} + +void WatchMirrorBase::OnRemoved(const WatchBase& watch) { + OnRemoved((const ISharableWatchBase&)watch); +} + +void WatchMirrorBase::OnBound(const WatchBase& watch) { +} + +void WatchMirrorBase::OnChanged(int, std::string inst_id, std::string appid) { +} + +} // namespace watch_holder \ No newline at end of file diff --git a/watch-holder-base/src/watch_mirror_base.hh b/watch-holder-base/src/watch_mirror_base.hh new file mode 100644 index 0000000..dce0a47 --- /dev/null +++ b/watch-holder-base/src/watch_mirror_base.hh @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2020 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 WATCH_HOLDER_BASE_SRC_WATCH_MIRROR_BASE_HH_ +#define WATCH_HOLDER_BASE_SRC_WATCH_MIRROR_BASE_HH_ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "common.hh" +#include "watch_base.hh" +#include "ambient_listener.hh" + +namespace watch_holder { + +class EXPORT_API WatchMirrorBase : public WatchBase::IEvent, public AmbientListener { + public: + WatchMirrorBase(std::shared_ptr surface); + virtual ~WatchMirrorBase() = 0; + int Listen(); + std::shared_ptr GetCurrent() const; + virtual void OnChanged(const ISharableWatchBase& watch); + virtual void OnAdded(const ISharableWatchBase& watch); + virtual void OnUpdated(const ISharableWatchBase& watch); + virtual void OnRemoved(const ISharableWatchBase& watch); + void OnAmbientChanged(bool enter, + const tizen_base::Bundle& extra) override; + void OnAmbientEvent(EventType ev, std::string sender, + tizen_base::Bundle extra) override; + void AddWatch(std::shared_ptr watch); + + private: + std::string GetUUID(std::string rid) const; + void OnAdded(const WatchBase& watch) final; + void OnUpdated(const WatchBase& watch) final; + void OnRemoved(const WatchBase& watch) final; + void OnBound(const WatchBase& watch) final; + virtual void OnChanged(int, std::string inst_id, std::string appid); + static void OnChangedSignal(keynode_t *node, void *user_data); + + protected: + virtual std::shared_ptr CreateWatch(int rid, std::string id, + std::string appid, bool mock = false) = 0; + virtual std::shared_ptr CreateWatch(int rid, std::string id, + std::string appid, tizen_base::Bundle extra, bool mock = false) = 0; + + private: + std::string appid_; + aul_app_com_connection_h watch_changed_conn_ = nullptr; + std::list> stack_; +}; + +} // namespace watch_holder + +#endif // WATCH_HOLDER_BASE_SRC_WATCH_MIRROR_BASE_HH_ \ No newline at end of file diff --git a/watch-holder-base/watch-holder-base.pc.in b/watch-holder-base/watch-holder-base.pc.in new file mode 100644 index 0000000..01cdd23 --- /dev/null +++ b/watch-holder-base/watch-holder-base.pc.in @@ -0,0 +1,12 @@ +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: watch-holder-base +Description: Support development of the WatchBase Viewer +Version: @VERSION@ +Requires: screen_connector_remote_surface +Libs: -L${libdir} -lwatch-holder-base +Cflags: -I${includedir} +cppflags: -I${includedir} \ No newline at end of file diff --git a/watch-holder/CMakeLists.txt b/watch-holder/CMakeLists.txt index e7fe5e1..673d2a6 100644 --- a/watch-holder/CMakeLists.txt +++ b/watch-holder/CMakeLists.txt @@ -23,7 +23,9 @@ pkg_check_modules(watch-holder REQUIRED vconf ) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../watch-holder-base/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/api) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) AUX_SOURCE_DIRECTORY(src BUILD_SOURCE) AUX_SOURCE_DIRECTORY(api BUILD_SOURCE) @@ -41,7 +43,7 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED ${BUILD_SOURCE}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${watch-holder_LDFLAGS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${watch-holder_LDFLAGS} watch-holder-base) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc") diff --git a/watch-holder/api/sharable_watch.cc b/watch-holder/api/sharable_watch.cc index 4a28adc..6730637 100644 --- a/watch-holder/api/sharable_watch.cc +++ b/watch-holder/api/sharable_watch.cc @@ -13,12 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "watch.h" #include "sharable_watch.h" #include "../src/watch.hh" +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "WATCH_HOLDER" #ifndef C_EXPORT #define C_EXPORT extern "C" __attribute__((visibility("default"))) @@ -31,12 +37,14 @@ struct sharable_watch_s : public ISharableWatch {}; C_EXPORT int sharable_watch_resume(sharable_watch_h watch) { ISharableWatch* w = reinterpret_cast(watch); w->Resume(); + LOGI("resume"); return 0; } C_EXPORT int sharable_watch_pause(sharable_watch_h watch) { ISharableWatch* w = reinterpret_cast(watch); w->Pause(); + LOGI("resume"); return 0; } @@ -62,9 +70,10 @@ C_EXPORT int sharable_watch_get_extra(sharable_watch_h watch, bundle **extra) { return 0; } -C_EXPORT int sharable_watch_get_current_image(sharable_watch_h watch, Evas_Object **image) { +C_EXPORT int sharable_watch_get_current_image( + sharable_watch_h watch, Evas_Object **image) { ISharableWatch* w = reinterpret_cast(watch); - *image = w->GetCurrentImage(); + *image = w->GetCurrentImageEvas(); if (*image == nullptr) return WATCH_HOLDER_ERROR_INVALID_OPERATION; @@ -87,4 +96,4 @@ C_EXPORT int sharable_watch_block_update(sharable_watch_h watch, bool enable) { ISharableWatch* w = reinterpret_cast(watch); w->BlockUpdate(enable); return 0; -} +} \ No newline at end of file diff --git a/watch-holder/api/watch.cc b/watch-holder/api/watch.cc index 1883c28..961eeb2 100644 --- a/watch-holder/api/watch.cc +++ b/watch-holder/api/watch.cc @@ -23,10 +23,10 @@ using namespace watch_holder; -struct watch_s : public Watch {}; +struct watch_s : public WatchBase {}; C_EXPORT int watch_resume(watch_h watch) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -35,7 +35,7 @@ C_EXPORT int watch_resume(watch_h watch) { } C_EXPORT int watch_pause(watch_h watch) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -44,7 +44,7 @@ C_EXPORT int watch_pause(watch_h watch) { } C_EXPORT int watch_terminate(watch_h watch) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -53,16 +53,16 @@ C_EXPORT int watch_terminate(watch_h watch) { } C_EXPORT int watch_bind(watch_h watch, Evas_Object *win) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; - w->Bind(win); + ((Watch*)w)->Bind(win); return WATCH_HOLDER_ERROR_NONE; } C_EXPORT int watch_unbind(watch_h watch) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -71,7 +71,7 @@ C_EXPORT int watch_unbind(watch_h watch) { } C_EXPORT int watch_get_appid(watch_h watch, char **appid) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -84,7 +84,7 @@ C_EXPORT int watch_get_appid(watch_h watch, char **appid) { } C_EXPORT int watch_get_pid(watch_h watch, int *pid) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -100,12 +100,12 @@ C_EXPORT int watch_get_opr(watch_h watch, float *opr) { } C_EXPORT int watch_get_current_image(watch_h watch, Evas_Object **image) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr || image == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; - *image = w->GetCurrentImage(); + *image = ((Watch*)w)->GetCurrentImageEvas(); if (*image == nullptr) return WATCH_HOLDER_ERROR_INVALID_OPERATION; @@ -114,7 +114,7 @@ C_EXPORT int watch_get_current_image(watch_h watch, Evas_Object **image) { } C_EXPORT int watch_notify_changed_event(watch_h watch) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -126,7 +126,7 @@ C_EXPORT int watch_notify_changed_event(watch_h watch) { } C_EXPORT int watch_get_rid(watch_h watch, int *rid) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr || rid == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -136,7 +136,7 @@ C_EXPORT int watch_get_rid(watch_h watch, int *rid) { } C_EXPORT int watch_is_faulted(watch_h watch, bool *faulted) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr || faulted == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -146,7 +146,7 @@ C_EXPORT int watch_is_faulted(watch_h watch, bool *faulted) { } C_EXPORT int watch_is_bound(watch_h watch, bool *bound) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr || bound == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -156,7 +156,7 @@ C_EXPORT int watch_is_bound(watch_h watch, bool *bound) { } C_EXPORT int watch_cancel_touch(watch_h watch) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -166,7 +166,7 @@ C_EXPORT int watch_cancel_touch(watch_h watch) { } C_EXPORT int watch_get_extra(watch_h watch, bundle **extra) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr || extra == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; @@ -176,7 +176,7 @@ C_EXPORT int watch_get_extra(watch_h watch, bundle **extra) { } C_EXPORT int watch_block_update(watch_h watch, bool enable) { - Watch* w = reinterpret_cast(watch); + WatchBase* w = reinterpret_cast(watch); if (w == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; diff --git a/watch-holder/api/watch_holder.cc b/watch-holder/api/watch_holder.cc index 5585262..aebcc81 100644 --- a/watch-holder/api/watch_holder.cc +++ b/watch-holder/api/watch_holder.cc @@ -31,37 +31,38 @@ struct watch_holder_s : public WatchHolder { watch_holder_s(Evas_Object* win, watch_holder_lifecycle_st cb, void* cb_data) : WatchHolder(win), cb_(cb), cb_data_(cb_data) {} - void OnLaunched(const Watch& watch) override { - Watch& w = const_cast(watch); + void OnLaunched(const WatchBase& watch) override { + WatchBase& w = const_cast(watch); cb_.watch_holder_lifecycle_launched_cb(reinterpret_cast(&w), cb_data_); } - void OnDead(const Watch& watch) override { - Watch& w = const_cast(watch); + void OnDead(const WatchBase& watch) override { + WatchBase& w = const_cast(watch); cb_.watch_holder_lifecycle_dead_cb(reinterpret_cast(&w), false, cb_data_); } - void OnBound(const Watch& watch) override { - Watch& w = const_cast(watch); + void OnBound(const WatchBase& watch) override { + WatchBase& w = const_cast(watch); cb_.watch_holder_lifecycle_bound_cb(reinterpret_cast(&w), cb_data_); } - void OnAdded(const Watch& watch) override { - Watch& w = const_cast(watch); + void OnAdded(const WatchBase& watch) override { + WatchBase& w = const_cast(watch); cb_.watch_holder_lifecycle_added_cb(reinterpret_cast(&w), cb_data_); } - void OnUpdated(const Watch& watch) override { - Watch& w = const_cast(watch); - cb_.watch_holder_lifecycle_updated_cb(reinterpret_cast(&w), watch.GetCurrentImage(), cb_data_); + void OnUpdated(const WatchBase& watch) override { + WatchBase& w = const_cast(watch); + cb_.watch_holder_lifecycle_updated_cb(reinterpret_cast(&w), + ((const Watch&)watch).GetCurrentImageEvas(), cb_data_); } - void OnRemoved(const Watch& watch) override { - Watch& w = const_cast(watch); + void OnRemoved(const WatchBase& watch) override { + WatchBase& w = const_cast(watch); cb_.watch_holder_lifecycle_removed_cb(reinterpret_cast(&w), cb_data_); } - void OnAmbientChanged(bool enter, tizen_base::Bundle& extra) override { + void OnAmbientChanged(bool enter, const tizen_base::Bundle& extra) override { cb_.watch_holder_lifecycle_ambient_changed_cb(enter, extra.GetHandle(), cb_data_); } @@ -121,10 +122,10 @@ C_EXPORT int watch_holder_foreach_watch(watch_holder_h handle, watch_holder_fore if (handle == nullptr || callback == nullptr) return WATCH_HOLDER_ERROR_INVALID_PARAMETER; - std::list> list = handle->GetStack(); - for (std::shared_ptr wptr : list) { + std::list> list = handle->GetStack(); + for (std::shared_ptr wptr : list) { callback(reinterpret_cast(wptr.get()), user_data); } return WATCH_HOLDER_ERROR_NONE; -} +} \ No newline at end of file diff --git a/watch-holder/api/watch_mirror.cc b/watch-holder/api/watch_mirror.cc index b3996c6..3225e3b 100644 --- a/watch-holder/api/watch_mirror.cc +++ b/watch-holder/api/watch_mirror.cc @@ -30,27 +30,28 @@ struct watch_mirror_s : public WatchMirror { public: watch_mirror_s(Evas_Object* win, watch_mirror_lifecycle_st cb, void* cb_data) : WatchMirror(win), cb_(cb), cb_data_(cb_data) {} - void OnAdded(const ISharableWatch& watch) override { - ISharableWatch& w = const_cast(watch); + void OnAdded(const ISharableWatchBase& watch) override { + ISharableWatchBase& w = const_cast(watch); cb_.watch_mirror_lifecycle_added_cb(reinterpret_cast(&w), cb_data_); } - void OnUpdated(const ISharableWatch& watch) override { - ISharableWatch& w = const_cast(watch); - cb_.watch_mirror_lifecycle_updated_cb(reinterpret_cast(&w), watch.GetCurrentImage(), cb_data_); + void OnUpdated(const ISharableWatchBase& watch) override { + ISharableWatchBase& w = const_cast(watch); + const Watch& wa = dynamic_cast(watch); + cb_.watch_mirror_lifecycle_updated_cb(reinterpret_cast(&w), wa.GetCurrentImageEvas(), cb_data_); } - void OnRemoved(const ISharableWatch& watch) override { - ISharableWatch& w = const_cast(watch); + void OnRemoved(const ISharableWatchBase& watch) override { + ISharableWatchBase& w = const_cast(watch); cb_.watch_mirror_lifecycle_removed_cb(reinterpret_cast(&w), cb_data_); } - void OnChanged(const ISharableWatch& watch) override { - ISharableWatch& w = const_cast(watch); + void OnChanged(const ISharableWatchBase& watch) override { + ISharableWatchBase& w = const_cast(watch); cb_.watch_mirror_lifecycle_changed_cb(reinterpret_cast(&w), cb_data_); } - void OnAmbientChanged(bool enter, tizen_base::Bundle& extra) override { + void OnAmbientChanged(bool enter, const tizen_base::Bundle& extra) override { cb_.watch_mirror_lifecycle_ambient_changed_cb(enter, extra.GetHandle(), cb_data_); } diff --git a/watch-holder/src/sharable_watch_interface.hh b/watch-holder/src/sharable_watch_interface.hh index 8440fe8..64a0b4c 100644 --- a/watch-holder/src/sharable_watch_interface.hh +++ b/watch-holder/src/sharable_watch_interface.hh @@ -18,27 +18,15 @@ #define __WATCH_HOLDER_SHARABLE_WATCH_INTERFACE_HH__ #include -#include -#include +#include "sharable_watch_base_interface.hh" namespace watch_holder { -class ISharableWatch { +class ISharableWatch : public virtual ISharableWatchBase { public: - virtual ~ISharableWatch() = default; - - virtual void Resume() = 0; - virtual void Pause() = 0; - virtual Evas_Object* GetCurrentImage() const = 0; - virtual bool IsBound() const = 0; - virtual std::string GetAppId() const = 0; - virtual int GetPid() const = 0; - virtual tizen_base::Bundle GetExtra() const = 0; - virtual bool IsFaulted() const = 0; - virtual void BlockUpdate(bool enable) = 0; + virtual Evas_Object* GetCurrentImageEvas() const = 0; }; - } // namespace watch_holder #endif // __WATCH_HOLDER_SHARABLE_WATCH_INTERFACE_HH__ \ No newline at end of file diff --git a/watch-holder/src/util.cc b/watch-holder/src/util.cc new file mode 100644 index 0000000..986af85 --- /dev/null +++ b/watch-holder/src/util.cc @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 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 +#include "util.hh" +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "WATCH_HOLDER" + +namespace watch_holder { +namespace util { + int GetWidth(Evas_Object* win) { + int x, y, w, h; + evas_object_geometry_get(win, &x, &y, &w, &h); + return w; + } + + int GetHeight(Evas_Object* win) { + int x, y, w, h; + evas_object_geometry_get(win, &x, &y, &w, &h); + return h; + } + +} // namespace util +} // namespace watchface_complication \ No newline at end of file diff --git a/watch-holder/src/util.hh b/watch-holder/src/util.hh new file mode 100644 index 0000000..c02015b --- /dev/null +++ b/watch-holder/src/util.hh @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 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 __WATCH_HOLDER_UTIL_HH__ +#define __WATCH_HOLDER_UTIL_HH__ + +#include + +namespace watch_holder { +namespace util { + int GetWidth(Evas_Object* win); + int GetHeight(Evas_Object* win); +} // namespace util +} // namespace watch_holder + +#endif // __WATCH_HOLDER_UTIL_HH__ \ No newline at end of file diff --git a/watch-holder/src/watch.cc b/watch-holder/src/watch.cc index 13212b2..546eed1 100644 --- a/watch-holder/src/watch.cc +++ b/watch-holder/src/watch.cc @@ -16,8 +16,10 @@ #include #include +#include #include #include +#include #include "watch.hh" @@ -32,51 +34,40 @@ using namespace tizen_base; using namespace screen_connector; namespace watch_holder { -Watch::Watch(string appid, Evas_Object* viewer_win, Watch::IEvent* listener, bool mock) - : RemoteSurfaceEvas(appid, RemoteSurface::WATCH, - make_shared(viewer_win, false), mock), - appid_(appid), listener_(listener) { - RemoteSurfaceEvas::SetAutoVisibility(false); +Watch::Watch(std::string appid, Evas_Object* viewer_win, + tizen_base::Bundle extra, IEvent* listener, bool mock) + : WatchBase(appid, screen_connector::util::GetWlSurface(viewer_win), + extra, listener, mock), + viewer_win_(make_shared(viewer_win, false)), + image_event_listner_(make_shared(this)) { } -Watch::Watch(int rid, string id, string appid, Evas_Object* viewer_win, Watch::IEvent* listener, bool mock) - : RemoteSurfaceEvas(rid, id, RemoteSurface::WATCH, - make_shared(viewer_win, false), mock), - appid_(appid), listener_(listener) { - RemoteSurfaceEvas::SetAutoVisibility(false); +Watch::Watch(int rid, std::string id, std::string appid, + Evas_Object* viewer_win, tizen_base::Bundle extra, + WatchBase::IEvent* listener, bool mock) + : WatchBase(rid, id, appid, + screen_connector::util::GetWlSurface(viewer_win), extra, listener, mock), + viewer_win_(make_shared(viewer_win, false)), + image_event_listner_(make_shared(this)) { } -Watch::Watch(string appid, Evas_Object* viewer_win, tizen_base::Bundle extra, Watch::IEvent* listener, bool mock) - : RemoteSurfaceEvas(appid, RemoteSurface::WATCH, - make_shared(viewer_win, false), mock), - appid_(appid), listener_(listener), extra_data_(extra) { - RemoteSurfaceEvas::SetAutoVisibility(false); +Watch::Watch(std::string appid, Evas_Object* viewer_win, + IEvent* listener, bool mock) + : WatchBase(appid, screen_connector::util::GetWlSurface(viewer_win), + listener, mock), + viewer_win_(make_shared(viewer_win, false)), + image_event_listner_(make_shared(this)) { } -Watch::Watch(int rid, string id, string appid, Evas_Object* viewer_win, tizen_base::Bundle extra, Watch::IEvent* listener, bool mock) - : RemoteSurfaceEvas(rid, id, RemoteSurface::WATCH, - make_shared(viewer_win, false), mock), - appid_(appid), listener_(listener), extra_data_(extra) { - RemoteSurfaceEvas::SetAutoVisibility(false); -} - -void Watch::Resume() { - RemoteSurfaceEvas::NoRenderPush(300); - RemoteSurfaceEvas::SendVisibility(true); -} - -void Watch::Pause() { - RemoteSurfaceEvas::SendVisibility(false); -} - -int Watch::Terminate() { - return aul_terminate_pid(pid_); -} - -void Watch::BlockUpdate(bool enable) { - RemoteSurface::SetBlock(enable); +Watch::Watch(int rid, std::string id, std::string appid, + Evas_Object* viewer_win, WatchBase::IEvent* listener, bool mock) + : WatchBase(rid, id, appid, + screen_connector::util::GetWlSurface(viewer_win), listener, mock), + viewer_win_(make_shared(viewer_win, false)), + image_event_listner_(make_shared(this)) { } +Watch::~Watch() = default; void Watch::OnAuxMsg(void *data, Evas_Object *o, void *ev_info) { Watch* wa = (Watch*)data; if (wa->bind_win_ == nullptr) { @@ -94,93 +85,61 @@ void Watch::OnAuxMsg(void *data, Evas_Object *o, void *ev_info) { } if (!strcmp(key, "tz_remote_surface_mng") && !strcmp(val, "prebind")) { - wa->is_bound_ = true; - wa->listener_->OnBound(*wa); + wa->GetListener()->OnBound(*wa); LOGI("Start bind mode !!"); evas_object_smart_callback_del(wa->bind_win_, "aux,msg,received", OnAuxMsg); } } -void Watch::CancelTouch() { - RemoteSurface::SendTouchCancel(); -} - -int Watch::GetRid() const { - return RemoteSurface::GetRid(); -} - -int Watch::GetPid() const { - return pid_; -} - -bool Watch::IsBound() const { - return is_bound_; -} - -string Watch::GetAppId() const { - return appid_; -} - -bool Watch::IsFaulted() const { - return is_faulted_; -} - void Watch::Bind(Evas_Object* win) { bind_win_ = win; elm_win_aux_hint_add(win, "wm.policy.win.msg.use", "1"); evas_object_smart_callback_add(win, "aux,msg,received", OnAuxMsg, this); - RemoteSurfaceEvas::Bind(screen_connector::EvasObject(win, false)); -} - -void Watch::Unbind() { - RemoteSurfaceEvas::Unbind(); - is_bound_ = false; + WatchBase::Bind(screen_connector::util::GetWlSurface(win)); } -Evas_Object* Watch::GetCurrentImage() const { - return current_image_; +void Watch::NoRenderPush(int timeout) { + LOGI("No render push start"); + elm_win_norender_push(evas_object_evas_get(viewer_win_->GetRaw())); + no_render_timer_ = g_timeout_add(timeout, + [](gpointer user_data)->gboolean { + Watch* wa = static_cast(user_data); + elm_win_norender_pop(evas_object_evas_get(wa->viewer_win_->GetRaw())); + wa->no_render_timer_ = 0; + LOGW("No render push timeout!"); + return G_SOURCE_REMOVE; + }, this); } -Bundle Watch::GetExtra() const { - return extra_data_; +void Watch::Resume() { + NoRenderPush(200); + WatchBase::Resume(); } -void Watch::SetFaulted(bool faulted) { - is_faulted_ = faulted; +Evas_Object* Watch::GetCurrentImageEvas() const { + return current_image_->GetRaw(); } -void Watch::OnEvasAdded(const std::string& appId, const std::string& instId, - int pid, const screen_connector::EvasObject& image) { - current_image_ = image.GetRaw(); - pid_ = pid; - listener_->OnAdded(*this); +void Watch::OnAdded(const string& appid, const string& inst_id, + int pid, shared_ptr tbm) { + current_image_.reset(new Image(evas_object_image_filled_add( + evas_object_evas_get(viewer_win_->GetRaw())), + image_event_listner_.get(), inst_id, pid, this)); + WatchBase::OnAdded(appid, inst_id, pid, tbm); } -void Watch::OnEvasRemoved(const std::string& appId, const std::string& instId, - int pid, const screen_connector::EvasObject& image) { - listener_->OnRemoved(*this); +void Watch::OnRemoved(const string& appid, const string& inst_id, + int pid, shared_ptr tbm) { + WatchBase::OnRemoved(appid, inst_id, pid, tbm); current_image_ = nullptr; } -void Watch::OnEvasChanged(const std::string& appId, const std::string& instId, - int pid, const screen_connector::EvasObject& image) { - listener_->OnUpdated(*this); +void Watch::OnChanged(const string& appid, const string& inst_id, + int pid, shared_ptr tbm) { + current_image_->Update(tbm); + WatchBase::OnChanged(appid, inst_id, pid, tbm); } -int Watch::NotifyChangedEvent() const { - tizen_base::Bundle b; - b.Add(NOTIFY_CHANGED_EVENT_APPID_KEY, appid_); - b.Add(NOTIFY_CHANGED_EVENT_RID_KEY, to_string(GetRid())); - LOGW("Notify Changed(%s)", appid_.c_str()); - int ret = vconf_set_str( - VCONFKEY_WATCH_CURRENT_WATCH_INFO, (const char*)b.ToRaw().first.get()); - if (ret != 0) { - LOGE("Fail to send noti (%d)", ret); - return -1; - } - return 0; } - -} // namespace watch_holder diff --git a/watch-holder/src/watch.hh b/watch-holder/src/watch.hh index e03a392..6f3ea61 100644 --- a/watch-holder/src/watch.hh +++ b/watch-holder/src/watch.hh @@ -21,72 +21,52 @@ #include #include -#include +#include +#include +#include -#include "common.hh" +#include "watch_base.hh" #include "sharable_watch_interface.hh" namespace watch_holder { -class EXPORT_API Watch : private screen_connector::RemoteSurfaceEvas, - public ISharableWatch { +class EXPORT_API Watch : public WatchBase, public virtual ISharableWatch { public: - class IEvent { - public: - virtual void OnBound(const Watch& watch) = 0; - virtual void OnAdded(const Watch& watch) = 0; - virtual void OnUpdated(const Watch& watch) = 0; - virtual void OnRemoved(const Watch& watch) = 0; - }; - - Watch(std::string appid, Evas_Object* viewer_win, IEvent* listener, bool mock = false); + Watch(std::string appid, Evas_Object* viewer_win, + tizen_base::Bundle extra, + IEvent* listener, bool mock = false); Watch(int rid, std::string id, std::string appid, Evas_Object* viewer_win, - Watch::IEvent* listener, bool mock = false); - Watch(std::string appid, Evas_Object* viewer_win, tizen_base::Bundle extra, + tizen_base::Bundle extra, + IEvent* listener, bool mock = false); + Watch(std::string appid, Evas_Object* viewer_win, IEvent* listener, bool mock = false); Watch(int rid, std::string id, std::string appid, Evas_Object* viewer_win, - tizen_base::Bundle extra, Watch::IEvent* listener, bool mock = false); - virtual ~Watch() = default; - void Resume() override; - void Pause() override; + IEvent* listener, bool mock = false); + virtual ~Watch(); - int Terminate(); void Bind(Evas_Object* win); - void Unbind(); - void CancelTouch(); - Evas_Object* GetCurrentImage() const override; - int NotifyChangedEvent() const; - bool IsBound() const override; - std::string GetAppId() const; - int GetPid() const override; - int GetRid() const ; - tizen_base::Bundle GetExtra() const override; - bool IsFaulted() const override; - void BlockUpdate(bool enable) override; + Evas_Object* GetCurrentImageEvas() const override; + void Resume() override; + void NoRenderPush(int timeout); protected: friend class WatchHolder; - void OnEvasAdded(const std::string& appId, const std::string& instId, - int pid, const screen_connector::EvasObject& image) override; - void OnEvasRemoved(const std::string& appId, const std::string& instId, - int pid, const screen_connector::EvasObject& image) override; - void OnEvasChanged(const std::string& appId, const std::string& instId, - int pid, const screen_connector::EvasObject& image) override; + void OnAdded(const std::string& appId, const std::string& instId, + int pid, std::shared_ptr tbm) override; + void OnRemoved(const std::string& appId, const std::string& instId, + int pid, std::shared_ptr tbm) override; + void OnChanged(const std::string& appId, const std::string& instId, + int pid, std::shared_ptr tbm) override; static void OnAuxMsg(void *data, Evas_Object *o, void *ev_info); - void SetFaulted(bool is_faulted); private: - int pid_ = 0; - std::string appid_; - IEvent* listener_; - Evas_Object* current_image_ = nullptr; Evas_Object* bind_win_ = nullptr; - tizen_base::Bundle extra_data_; - bool is_faulted_ = false; - bool is_bound_ = false; + int no_render_timer_ = 0; + std::unique_ptr current_image_ = nullptr; + std::shared_ptr viewer_win_ = nullptr; + std::shared_ptr image_event_listner_ = nullptr; }; } // namespace watch_holder -#endif // __WATCH_HOLDER_WATCH_HH__ - +#endif // __WATCH_HOLDER_WATCH_HH__ \ No newline at end of file diff --git a/watch-holder/src/watch_holder.cc b/watch-holder/src/watch_holder.cc index ff7afac..99467bc 100644 --- a/watch-holder/src/watch_holder.cc +++ b/watch-holder/src/watch_holder.cc @@ -19,7 +19,9 @@ #include #include #include +#include +#include "util.hh" #include "watch_holder.hh" #include "bundle_cpp.h" @@ -33,154 +35,44 @@ using namespace tizen_base; using namespace std; namespace watch_holder { -WatchHolder::~WatchHolder() { - if (dead_signal_conn_) - aul_app_com_leave(dead_signal_conn_); - if (launch_signal_conn_) - aul_app_com_leave(launch_signal_conn_); -} - -WatchHolder::WatchHolder(Evas_Object* win) : win_(win) { - if (aul_app_com_create("watch.dead", nullptr, - OnDeadSignal, this, &dead_signal_conn_) != AUL_R_OK) { - LOGE("failed to create status"); - } - - if (aul_app_com_create("watch.launch", nullptr, OnLaunchSignal, - this, &launch_signal_conn_) != AUL_R_OK) { - LOGE("Failed to listen watch.launch signal"); - } +WatchHolder::~WatchHolder() = default; - char appid_buf[512] = {0, }; - if (aul_app_get_appid_bypid( - getpid(), appid_buf, sizeof(appid_buf)) != AUL_R_OK) { - LOGE("Failed to get appid (%d)", getpid()); - } - appid_ = appid_buf; +WatchHolder::WatchHolder(Evas_Object* win) : + WatchHolderBase(screen_connector::util::GetWlSurface(win), + util::GetWidth(win), util::GetHeight(win)), viewer_win_(win) { } -std::shared_ptr WatchHolder::CreateWatch(std::string appid, - Evas_Object* viewer_win, Watch::IEvent* listener, bool mock) { - return make_shared(std::move(appid), viewer_win, listener, mock); -} - -std::shared_ptr WatchHolder::CreateWatch(int rid, std::string id, - std::string appid, Evas_Object* viewer_win, Watch::IEvent* listener, +std::shared_ptr WatchHolder::CreateWatch(std::string appid, bool mock) { - return make_shared(rid, std::move(id), std::move(appid), viewer_win, - listener, mock); + return make_shared( + std::move(appid), viewer_win_, this, mock); } -std::shared_ptr WatchHolder::CreateWatch(std::string appid, - Evas_Object* viewer_win, tizen_base::Bundle extra, - Watch::IEvent* listener, bool mock) { - return make_shared(std::move(appid), viewer_win, std::move(extra), - listener, mock); +std::shared_ptr WatchHolder::CreateWatch(int rid, std::string id, + std::string appid, bool mock) { + return make_shared(rid, std::move(id), + std::move(appid), viewer_win_, this, mock); } -std::shared_ptr WatchHolder::CreateWatch(int rid, std::string id, - std::string appid, Evas_Object* viewer_win, tizen_base::Bundle extra, - Watch::IEvent* listener, bool mock) { - return make_shared(rid, std::move(id), std::move(appid), viewer_win, - std::move(extra), listener, mock); +std::shared_ptr WatchHolder::CreateWatch(std::string appid, + tizen_base::Bundle extra, bool mock) { + return make_shared(std::move(appid), viewer_win_, std::move(extra), + this, mock); } -int WatchHolder::Launch( - string watch_appid, bool background, bundle* extra) { - Evas_Coord x, y, w, h; - evas_object_geometry_get(win_, &x, &y, &w, &h); - Bundle data; - - if (extra != nullptr) - data = Bundle(extra, true, true); - aul_svc_set_appid(data.GetHandle(), watch_appid.c_str()); - data.Add("WATCH_WIDTH", std::to_string(w)); - data.Add("WATCH_HEIGHT", std::to_string(h)); - data.Add("WATCH_BG_LAUNCH", std::to_string((int)background)); - data.Add(AUL_K_WIDGET_VIEWER, appid_); - - if (extra != nullptr) - extra_map_[watch_appid] = Bundle(extra, true, true); - - int pid = appsvc_run_service(data.GetHandle(), 0, nullptr, nullptr); - if (pid < 0) { - LOGE("Fail to run watch (%d)", pid); - return -1; - } - LOGI("Launch (%s) done : (%d)", watch_appid.c_str(), pid); - return pid; +std::shared_ptr WatchHolder::CreateWatch(int rid, std::string id, + std::string appid, tizen_base::Bundle extra, bool mock) { + return make_shared(rid, std::move(id), std::move(appid), + viewer_win_, std::move(extra), this, mock); } -void WatchHolder::EnableRendering() { +shared_ptr WatchHolder::Cast(shared_ptr watch) { + return dynamic_pointer_cast(watch); } -void WatchHolder::DisableRendering(int timeout) { +const Watch& WatchHolder::Cast(const WatchBase& watch) { + return dynamic_cast(watch); } -const std::list>& WatchHolder::GetStack() const { - return stack_; -} - -std::shared_ptr WatchHolder::GetCurrent() const { - if (stack_.empty()) { - LOGW("Empty stack!"); - return nullptr; - } - return stack_.back(); -} - -void WatchHolder::OnAmbientChanged(bool enter, Bundle& extra) { -} - -void WatchHolder::OnAmbientEvent(EventType ev, std::string sender, - tizen_base::Bundle extra) { -} - -int WatchHolder::OnDeadSignal(const char *endpoint, aul_app_com_result_e e, - bundle *envelope, void *user_data) { - WatchHolder* holder = (WatchHolder*)user_data; - Bundle data(envelope, false, false); - string appid = data.GetString(AUL_K_APPID); - string pid = data.GetString(AUL_K_PID); - string is_faulted = data.GetString(AUL_K_IS_FAULT); - LOGW("Watch(%s)(%s) DEAD", appid.c_str(), pid.c_str()); - list>::iterator it; - for (it = holder->stack_.begin(); it != holder->stack_.end(); ++it) { - if ((*it)->GetAppId() == appid && - pid == to_string((*it)->GetPid())) { - (*it)->SetFaulted(is_faulted == "true"); - holder->OnDead(**it); - holder->stack_.erase(it); - LOGW("REMOVE DEAD WATCH (%s)(%s)", appid.c_str(), pid.c_str()); - break; - } - } - LOGW("DEAD DONE (%s)(%s)", appid.c_str(), pid.c_str()); - return 0; -} - -int WatchHolder::OnLaunchSignal(const char *endpoint, - aul_app_com_result_e res, bundle *envelope, void *user_data) { - Bundle launch_data(envelope, false, false); - WatchHolder* holder = (WatchHolder*)user_data; - string viewer_appid = launch_data.GetString(AUL_K_WIDGET_VIEWER); - if (viewer_appid != holder->appid_) { - LOGE("It's not mine (%s:%s)", viewer_appid.c_str(), holder->appid_.c_str()); - return 0; - } - - string watch_appid = launch_data.GetString(AUL_K_APPID); - - if (holder->extra_map_.find(watch_appid) != holder->extra_map_.end()) { - Bundle extra(holder->extra_map_[watch_appid]); - holder->stack_.push_back(holder->CreateWatch(watch_appid, holder->win_, extra, holder)); - holder->extra_map_.erase(watch_appid); - } else { - holder->stack_.push_back(holder->CreateWatch(watch_appid, holder->win_, holder)); - } - holder->OnLaunched(*holder->GetCurrent()); - LOGI("LAUNCH DONE (%s)", viewer_appid.c_str()); - return 0; -} } // namespace watch_holder diff --git a/watch-holder/src/watch_holder.hh b/watch-holder/src/watch_holder.hh index e4b61a3..2bef2f1 100644 --- a/watch-holder/src/watch_holder.hh +++ b/watch-holder/src/watch_holder.hh @@ -27,54 +27,32 @@ #include #include +#include "watch_holder_base.hh" #include "watch.hh" -#include "common.hh" #include "ambient_listener.hh" namespace watch_holder { -class EXPORT_API WatchHolder : public Watch::IEvent, public AmbientListener { +class EXPORT_API WatchHolder : public WatchHolderBase { public: WatchHolder(Evas_Object* win); virtual ~WatchHolder(); - int Launch(std::string appid, bool background, bundle* extra); - void EnableRendering(); - void DisableRendering(int timeout); - const std::list>& GetStack() const; - std::shared_ptr GetCurrent() const; - virtual void OnLaunched(const Watch& watch) = 0; - virtual void OnDead(const Watch& watch) = 0; - virtual void OnAmbientChanged(bool enter, tizen_base::Bundle& extra) override; - virtual void OnAmbientEvent(EventType ev, std::string sender, - tizen_base::Bundle extra) override; - protected: - virtual std::shared_ptr CreateWatch(std::string appid, - Evas_Object* viewer_win, Watch::IEvent* listener, bool mock = false); - virtual std::shared_ptr CreateWatch(int rid, std::string id, - std::string appid, Evas_Object* viewer_win, Watch::IEvent* listener, - bool mock = false); - virtual std::shared_ptr CreateWatch(std::string appid, - Evas_Object* viewer_win, tizen_base::Bundle extra, - Watch::IEvent* listener, bool mock = false); - virtual std::shared_ptr CreateWatch(int rid, std::string id, - std::string appid, Evas_Object* viewer_win, tizen_base::Bundle extra, - Watch::IEvent* listener, bool mock = false); + std::shared_ptr Cast(std::shared_ptr w_base); + const Watch& Cast(const WatchBase& w_base); - private: - static int OnDeadSignal(const char *endpoint, aul_app_com_result_e e, - bundle *envelope, void *user_data); - static int OnLaunchSignal(const char *endpoint, - aul_app_com_result_e res, bundle *envelope, void *user_data); + protected: + std::shared_ptr CreateWatch(std::string appid, + bool mock = false) override; + std::shared_ptr CreateWatch(int rid, std::string id, + std::string appid, bool mock = false) override; + std::shared_ptr CreateWatch(std::string appid, + tizen_base::Bundle extra, bool mock = false) override; + std::shared_ptr CreateWatch(int rid, std::string id, + std::string appid, tizen_base::Bundle extra, bool mock = false) override; private: - std::string appid_; - Evas_Object* win_; - std::map extra_map_; - std::list> stack_; - aul_app_com_connection_h launch_signal_conn_ = nullptr; - aul_app_com_connection_h dead_signal_conn_ = nullptr; - aul_app_com_connection_h ambient_changed_signal_conn_ = nullptr; + Evas_Object* viewer_win_; }; } // namespace watch_holder diff --git a/watch-holder/src/watch_mirror.cc b/watch-holder/src/watch_mirror.cc index d31b087..ebedf1e 100644 --- a/watch-holder/src/watch_mirror.cc +++ b/watch-holder/src/watch_mirror.cc @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include -#include -#include -#include +#include + +#include #include "watch_mirror.hh" -#include "bundle_cpp.h" +#include "watch.hh" +#include "util.hh" #ifdef LOG_TAG #undef LOG_TAG @@ -33,92 +33,42 @@ using namespace std; namespace watch_holder { WatchMirror::~WatchMirror() = default; -WatchMirror::WatchMirror(Evas_Object* win) : win_(win) { -} - -string WatchMirror::GetUUID(string rid) const { - char uuid[37]; - uuid_t u; - - uuid_generate(u); - uuid_unparse(u, uuid); - return string(uuid) + rid; -} - -void WatchMirror::OnChangedSignal(keynode_t *node, void *user_data) { - WatchMirror* mirror = (WatchMirror*)user_data; - const char* raw = vconf_get_str(VCONFKEY_WATCH_CURRENT_WATCH_INFO); - if (raw == nullptr || strlen(raw) == 0) { - if (raw != nullptr) - free((void*)raw); - return; - } - - string raw_str(raw); - free((void*)raw); - try { - Bundle data(raw_str); - string appid = data.GetString(NOTIFY_CHANGED_EVENT_APPID_KEY); - string rid = data.GetString(NOTIFY_CHANGED_EVENT_RID_KEY); - mirror->stack_.push_back(make_shared( - stoi(rid), mirror->GetUUID(rid), appid, mirror->win_, mirror)); - mirror->OnChanged(*mirror->stack_.back()); - } catch (const std::exception& e) { - LOGE("Exception occurred : %s", e.what()); - return; - } -} - -int WatchMirror::Listen() { - if (vconf_notify_key_changed( - VCONFKEY_WATCH_CURRENT_WATCH_INFO, OnChangedSignal, this) != 0) { - LOGE("failed to listen on changed signal"); - return -1; - } - OnChangedSignal(nullptr, this); - return 0; -} - -std::shared_ptr WatchMirror::GetCurrent() const { - if (stack_.empty()) { - LOGW("Empty stack!"); - return nullptr; - } - return stack_.back(); -} - -void WatchMirror::OnAmbientChanged(bool enter, Bundle& extra) { -} - -void WatchMirror::OnAmbientEvent(EventType ev, std::string sender, - tizen_base::Bundle extra) { -} - -void WatchMirror::OnChanged(const ISharableWatch& watch) { -} - -void WatchMirror::OnAdded(const ISharableWatch& watch) { +WatchMirror::WatchMirror(Evas_Object* win) + : WatchMirrorBase(screen_connector::util::GetWlSurface(win)), + viewer_win_(win) { } -void WatchMirror::OnUpdated(const ISharableWatch& watch) { +void WatchMirror::OnChanged(const ISharableWatchBase& watch) { } -void WatchMirror::OnRemoved(const ISharableWatch& watch) { +void WatchMirror::OnChanged(int rid, std::string inst_id, std::string appid) { + WatchMirrorBase::AddWatch(make_shared( + rid, inst_id, appid, viewer_win_, nullptr, this)); + shared_ptr cur = WatchMirrorBase::GetCurrent(); + OnChanged(*cur.get()); } -void WatchMirror::OnAdded(const Watch& watch) { - OnAdded((const ISharableWatch&)watch); +shared_ptr WatchMirror::Cast( + shared_ptr watch) { + shared_ptr wa = dynamic_pointer_cast(watch); + return static_pointer_cast(wa); } -void WatchMirror::OnUpdated(const Watch& watch) { - OnUpdated((const ISharableWatch&)watch); +const ISharableWatch& WatchMirror::Cast(const ISharableWatchBase& watch) { + const Watch& wa = dynamic_cast(watch); + return (ISharableWatch&)wa; } -void WatchMirror::OnRemoved(const Watch& watch) { - OnRemoved((const ISharableWatch&)watch); +std::shared_ptr WatchMirror::CreateWatch(int rid, std::string id, + std::string appid, bool mock) { + return make_shared(rid, std::move(id), std::move(appid), + viewer_win_, this, mock); } -void WatchMirror::OnBound(const Watch& watch) { +std::shared_ptr WatchMirror::CreateWatch(int rid, std::string id, + std::string appid, tizen_base::Bundle extra, bool mock) { + return make_shared(rid, std::move(id), std::move(appid), + viewer_win_, std::move(extra), this, mock); } } // namespace watch_holder diff --git a/watch-holder/src/watch_mirror.hh b/watch-holder/src/watch_mirror.hh index 67872f1..24e15fa 100644 --- a/watch-holder/src/watch_mirror.hh +++ b/watch-holder/src/watch_mirror.hh @@ -21,45 +21,35 @@ #include #include -#include #include #include #include #include -#include "common.hh" +#include "watch_mirror_base.hh" #include "watch.hh" -#include "ambient_listener.hh" namespace watch_holder { -class EXPORT_API WatchMirror : public Watch::IEvent, public AmbientListener { +class EXPORT_API WatchMirror : public WatchMirrorBase { public: WatchMirror(Evas_Object* win); virtual ~WatchMirror(); - int Listen(); - std::shared_ptr GetCurrent() const; - virtual void OnChanged(const ISharableWatch& watch); - virtual void OnAdded(const ISharableWatch& watch); - virtual void OnUpdated(const ISharableWatch& watch); - virtual void OnRemoved(const ISharableWatch& watch); - virtual void OnAmbientChanged(bool enter, tizen_base::Bundle& extra) override; - virtual void OnAmbientEvent(EventType ev, std::string sender, - tizen_base::Bundle extra) override; + void OnChanged(const ISharableWatchBase& watch) override; + std::shared_ptr Cast(std::shared_ptr watch); + const ISharableWatch& Cast(const ISharableWatchBase& watch); + + protected: + std::shared_ptr CreateWatch(int rid, std::string id, + std::string appid, bool mock = false) override; + std::shared_ptr CreateWatch(int rid, std::string id, + std::string appid, tizen_base::Bundle extra, bool mock = false) override; private: - std::string GetUUID(std::string rid) const; - void OnAdded(const Watch& watch) override final; - void OnUpdated(const Watch& watch) override final; - void OnRemoved(const Watch& watch) override final; - void OnBound(const Watch& watch) override final; - static void OnChangedSignal(keynode_t *node, void *user_data); + void OnChanged(int, std::string inst_id, std::string appid) override; private: - std::string appid_; - Evas_Object* win_; - aul_app_com_connection_h watch_changed_conn_ = nullptr; - std::list> stack_; + Evas_Object* viewer_win_; }; } // namespace watch_holder diff --git a/watch-holder/watch-holder.pc.in b/watch-holder/watch-holder.pc.in index 89126e7..ed5eea8 100644 --- a/watch-holder/watch-holder.pc.in +++ b/watch-holder/watch-holder.pc.in @@ -4,9 +4,9 @@ libdir=@LIBDIR@ includedir=@INCLUDEDIR@ Name: watch-holder -Description: Support development of the Watch Viewer +Description: Support development of the WatchBase Viewer Version: @VERSION@ -Requires: screen_connector_remote_surface_evas -Libs: -L${libdir} -lwatch-holder +Requires: watch-holder-base screen_connector_remote_surface_evas +Libs: -L${libdir} -lwatch-holder -lwatch-holder-base Cflags: -I${includedir} -cppflags: -I${includedir} +cppflags: -I${includedir} \ No newline at end of file -- 2.7.4