From: hyunho Date: Mon, 20 Jan 2020 01:08:56 +0000 (+0900) Subject: Implement a Launch function X-Git-Tag: submit/tizen/20200209.233938~2^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=48b073f9ca604a923a2d8186182697471d3e193e;p=platform%2Fcore%2Fappfw%2Fwidget-viewer.git Implement a Launch function Signed-off-by: hyunho --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 5de1b937..86bbc61e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ ADD_SUBDIRECTORY(unittest) ADD_DEPENDENCIES(widget-viewer_unittests widget_viewer_evas) ADD_DEPENDENCIES(widget_viewer_sdk widget_viewer_evas) +ADD_DEPENDENCIES(widget_viewer_sdk watch-holder) ENABLE_TESTING() SET(WIDGET_VIEWER_UNIT_TESTS widget-viewer_unittests) diff --git a/packaging/libwidget_viewer.spec b/packaging/libwidget_viewer.spec index 545bad37..c95b49ac 100644 --- a/packaging/libwidget_viewer.spec +++ b/packaging/libwidget_viewer.spec @@ -324,6 +324,7 @@ Header & package configuration of ambient-viewer %files -n watch-holder-devel %{_includedir}/watch-holder/*.h +%{_includedir}/watch-holder/*.hh %{_libdir}/pkgconfig/watch-holder.pc %{_libdir}/libwatch-holder.so diff --git a/watch-holder/CMakeLists.txt b/watch-holder/CMakeLists.txt index e90d04eb..f6d7566d 100644 --- a/watch-holder/CMakeLists.txt +++ b/watch-holder/CMakeLists.txt @@ -18,6 +18,8 @@ pkg_check_modules(watch-holder REQUIRED capi-appfw-application aul evas + screen_connector_remote_surface_evas + appsvc ) AUX_SOURCE_DIRECTORY(src BUILD_SOURCE) @@ -45,3 +47,7 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/api/watch.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/api/watch_holder.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/watch_holder.hh DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/watch.hh DESTINATION include/${PROJECT_NAME}) + + diff --git a/watch-holder/api/watch_holder.h b/watch-holder/api/watch_holder.h index 30cd8bb8..cc3b2ea3 100644 --- a/watch-holder/api/watch_holder.h +++ b/watch-holder/api/watch_holder.h @@ -41,7 +41,7 @@ typedef struct { * @since_tizen 5.5 * @return @c 0 on success, otherwise a negative error value */ -int watch_holder_create(watch_holder_h *handle); +int watch_holder_create(Evas_Object *viewer_win, watch_holder_h *handle); int watch_holder_destroy(watch_holder_h handle); diff --git a/watch-holder/src/common.hh b/watch-holder/src/common.hh new file mode 100644 index 00000000..3955fc2b --- /dev/null +++ b/watch-holder/src/common.hh @@ -0,0 +1,25 @@ +/* + * 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_COMMON_HH__ +#define __WATCH_HOLDER_COMMON_HH__ + +#ifdef EXPORT_API +#undef EXPORT_API +#endif +#define EXPORT_API __attribute__((visibility("default"))) + +#endif // __WATCH_HOLDER_COMMON_HH__ diff --git a/watch-holder/src/watch.cc b/watch-holder/src/watch.cc index 4a5bcc1f..e4de0a2b 100644 --- a/watch-holder/src/watch.cc +++ b/watch-holder/src/watch.cc @@ -16,7 +16,15 @@ #include "watch.hh" -namespace watch { +using namespace std; +using namespace screen_connector; +namespace watch_holder { + +Watch::Watch(string appid, Evas_Object* viewer_win, IWatchEventListener* holder) + : RemoteSurfaceEvas(appid, RemoteSurface::WATCH, + make_shared(viewer_win, false)), + appid_(appid), holder_(holder) { +} void Watch::Resume() { @@ -43,19 +51,31 @@ Evas_Object* Watch::GetCurrentImage() { } void Watch::OnAdded(Evas_Object* image) { - } void Watch::OnUpdated(Evas_Object* image) { - } void Watch::OnRemoved(Evas_Object* image) { +} + +void Watch::OnEvasAdded(const std::string& appId, const std::string& instId, + int pid, const screen_connector::EvasObject& image) { + holder_->OnWatchAdded(*this, image.GetRaw()); +} + +void Watch::OnEvasRemoved(const std::string& appId, const std::string& instId, + int pid, const screen_connector::EvasObject& image) { + holder_->OnWatchRemoved(*this, image.GetRaw()); +} +void Watch::OnEvasChanged(const std::string& appId, const std::string& instId, + int pid, const screen_connector::EvasObject& image) { + holder_->OnWatchUpdated(*this, image.GetRaw()); } float Watch::GetOpr() { return 0.0f; } -} // namspace watch +} // namspace watch_holder diff --git a/watch-holder/src/watch.hh b/watch-holder/src/watch.hh index d5b0d0ab..4d057712 100644 --- a/watch-holder/src/watch.hh +++ b/watch-holder/src/watch.hh @@ -19,10 +19,22 @@ #include -namespace watch { +#include +#include -class Watch { +#include "common.hh" + +namespace watch_holder { + +class EXPORT_API Watch : private screen_connector::RemoteSurfaceEvas { public: + class IWatchEventListener { + public: + virtual void OnWatchAdded(Watch& watch, Evas_Object* image) = 0; + virtual void OnWatchUpdated(Watch& watch, Evas_Object* image) = 0; + virtual void OnWatchRemoved(Watch& watch, Evas_Object* image) = 0; + }; + Watch(std::string appid, Evas_Object* viewer_win, IWatchEventListener* listener); void Resume(); void Pause(); void Terminate(); @@ -33,9 +45,20 @@ class Watch { void OnUpdated(Evas_Object* image); void OnRemoved(Evas_Object* image); float GetOpr(); + private: + 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; + + private: + std::string appid_; + IWatchEventListener* holder_; }; -} // namespace watch +} // namespace watch_holder #endif // __WATCH_HOLDER_WATCH_HH__ diff --git a/watch-holder/src/watch_holder.cc b/watch-holder/src/watch_holder.cc index ee17a07e..62797852 100644 --- a/watch-holder/src/watch_holder.cc +++ b/watch-holder/src/watch_holder.cc @@ -13,13 +13,59 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include +#include +#include +#include #include "watch_holder.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 { + +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"); + } + + 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; +} -namespace watch { - -void WatchHolder::Launch(std::string& appid, bool background, bundle* extra) { - +int WatchHolder::Launch( + app_control_h control, bool background, bundle* extra) { + Evas_Coord x, y, w, h; + evas_object_geometry_get(win_, &x, &y, &w, &h); + app_control_add_extra_data(control, "WATCH_WIDTH", std::to_string(w).c_str()); + app_control_add_extra_data(control, "WATCH_HEIGHT", std::to_string(h).c_str()); + + bundle* data; + app_control_to_bundle(control, &data); + bundle_add_str(data, AUL_K_WIDGET_VIEWER, appid_.c_str()); + int pid = appsvc_run_service(data, 0, nullptr, nullptr); + if (pid < 0) { + LOGE("Fail to run watch (%d)", pid); + return -1; + } + return 0; } void WatchHolder::EnableRendering() { @@ -47,7 +93,37 @@ void WatchHolder::OnWatchLaunched(Watch& watch) { } void WatchHolder::OnWatchBound(Watch& watch) { +} + +void WatchHolder::OnWatchAdded(Watch& watch, Evas_Object* image) { +} + +void WatchHolder::OnWatchUpdated(Watch& watch, Evas_Object* image) { +} + +void WatchHolder::OnWatchRemoved(Watch& watch, Evas_Object* image) { +} + +int WatchHolder::OnDeadSignal(const char *endpoint, aul_app_com_result_e e, + bundle *envelope, void *user_data) { + 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)", viewer_appid.c_str()); + return 0; + } + + string watch_appid = launch_data.GetString(AUL_K_APPID); + holder->stack_.push_back(make_shared(watch_appid, holder->win_, holder)); + holder->OnWatchLaunched(*holder->stack_.back()); + return 0; } } diff --git a/watch-holder/src/watch_holder.hh b/watch-holder/src/watch_holder.hh index eae510c2..92c09632 100644 --- a/watch-holder/src/watch_holder.hh +++ b/watch-holder/src/watch_holder.hh @@ -23,15 +23,18 @@ #include #include +#include +#include #include "watch.hh" +#include "common.hh" -namespace watch { +namespace watch_holder { -class WatchHolder { +class EXPORT_API WatchHolder : public Watch::IWatchEventListener { public: - WatchHolder(Evas_Object* win) : win_(win) {} - void Launch(std::string& appid, bool background, bundle* extra); + WatchHolder(Evas_Object* win); + int Launch(app_control_h control, bool background, bundle* extra); void EnableRendering(); void DisableRendering(int timeout); const std::list>& GetStack(); @@ -39,13 +42,25 @@ class WatchHolder { void OnWatchDead(Watch& watch); void OnWatchLaunched(Watch& watch); void OnWatchBound(Watch& watch); + void OnWatchAdded(Watch& watch, Evas_Object* image) override; + void OnWatchUpdated(Watch& watch, Evas_Object* image) override; + void OnWatchRemoved(Watch& watch, Evas_Object* image) override; 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_; Evas_Object* win_; std::list> stack_; + aul_app_com_connection_h launch_signal_conn_; + aul_app_com_connection_h dead_signal_conn_; }; -} // namespace watch +} // namespace watch_holder #endif // __WATCH_HOLDER_WATCH_HOLDER_HH__