Replace watch-control to watch-holder for SDK 53/225053/2
authorDaehyeon Jung <darrenh.jung@samsung.com>
Mon, 17 Feb 2020 05:22:13 +0000 (14:22 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Tue, 18 Feb 2020 01:29:54 +0000 (01:29 +0000)
Change-Id: I481a40469af77c47ee7ce84339df54cc539cfb07
Signed-off-by: Daehyeon Jung <darrenh.jung@samsung.com>
watch-holder/api/watch_holder.cc
watch-holder/api/watch_holder.h
widget_viewer_sdk/CMakeLists.txt
widget_viewer_sdk/src/main.c

index 6a1cd81..b21ced1 100644 (file)
@@ -27,61 +27,51 @@ using namespace watch_holder;
 
 struct watch_holder_s : public WatchHolder {
  public:
-  watch_holder_s(Evas_Object* win) : WatchHolder(win), cb_init_(false) {}
+  watch_holder_s(Evas_Object* win, watch_lifecycle_st cb, void* cb_data)
+    : WatchHolder(win), cb_(cb), cb_data_(cb_data) {}
 
   void OnLaunched(const Watch& watch) override {
-    if (cb_init_) {
-      Watch& w = const_cast<Watch&>(watch);
-      cb_.watch_holder_lifecycle_added_cb(reinterpret_cast<watch_h>(&w), cb_data_);
-    }
+    Watch& w = const_cast<Watch&>(watch);
+    cb_.watch_holder_lifecycle_added_cb(reinterpret_cast<watch_h>(&w), cb_data_);
   }
 
   void OnDead(const Watch& watch) override {
-    if (cb_init_) {
-      Watch& w = const_cast<Watch&>(watch);
-      cb_.watch_holder_lifecycle_dead_cb(reinterpret_cast<watch_h>(&w), false, cb_data_);
-    }
+    Watch& w = const_cast<Watch&>(watch);
+    cb_.watch_holder_lifecycle_dead_cb(reinterpret_cast<watch_h>(&w), false, cb_data_);
   }
 
   void OnBound(const Watch& watch) override {
-    if (cb_init_) {
-      Watch& w = const_cast<Watch&>(watch);
-      cb_.watch_holder_lifecycle_bound_cb(reinterpret_cast<watch_h>(&w), cb_data_);
-    }
+    Watch& w = const_cast<Watch&>(watch);
+    cb_.watch_holder_lifecycle_bound_cb(reinterpret_cast<watch_h>(&w), cb_data_);
   }
 
   void OnAdded(const Watch& watch) override {
-    if (cb_init_) {
-      Watch& w = const_cast<Watch&>(watch);
-      cb_.watch_holder_lifecycle_added_cb(reinterpret_cast<watch_h>(&w), cb_data_);
-    }
+    Watch& w = const_cast<Watch&>(watch);
+    cb_.watch_holder_lifecycle_added_cb(reinterpret_cast<watch_h>(&w), cb_data_);
   }
 
   void OnUpdated(const Watch& watch) override {
-    if (cb_init_) {
-      Watch& w = const_cast<Watch&>(watch);
-        cb_.watch_holder_lifecycle_updated_cb(reinterpret_cast<watch_h>(&w), watch.GetCurrentImage(), cb_data_);
-    }
+    Watch& w = const_cast<Watch&>(watch);
+    cb_.watch_holder_lifecycle_updated_cb(reinterpret_cast<watch_h>(&w), watch.GetCurrentImage(), cb_data_);
   }
 
   void OnRemoved(const Watch& watch) override {
-    if (cb_init_) {
-      Watch& w = const_cast<Watch&>(watch);
-      cb_.watch_holder_lifecycle_removed_cb(reinterpret_cast<watch_h>(&w), cb_data_);
-    }
+    Watch& w = const_cast<Watch&>(watch);
+    cb_.watch_holder_lifecycle_removed_cb(reinterpret_cast<watch_h>(&w), cb_data_);
   }
 
-  bool cb_init_;
   watch_lifecycle_st cb_;
   void* cb_data_;
 };
 
 C_EXPORT int watch_holder_create(Evas_Object *viewer_win,
-    watch_holder_h *handle) {
+    watch_lifecycle_st lifecycle, void *user_data, watch_holder_h *handle) {
+
   if (viewer_win == nullptr)
     return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
 
-  struct watch_holder_s *h = new struct watch_holder_s(viewer_win);
+  struct watch_holder_s *h = new struct watch_holder_s(viewer_win, lifecycle,
+                                                               user_data);
 
   if (h == nullptr)
     return WATCH_HOLDER_ERROR_OUT_OF_MEMORY;
@@ -132,21 +122,3 @@ C_EXPORT int watch_holder_get_current(watch_holder_h handle, watch_h *watch) {
   return WATCH_HOLDER_ERROR_NONE;
 }
 
-C_EXPORT int watch_holder_monitor(watch_holder_h handle, watch_lifecycle_st lifecycle, void *user_data) {
-  if (handle == nullptr)
-    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
-
-  handle->cb_init_ = true;
-  handle->cb_ = lifecycle;
-  handle->cb_data_ = user_data;
-
-  return WATCH_HOLDER_ERROR_NONE;
-}
-
-C_EXPORT int watch_holder_unmonitor(watch_holder_h handle) {
-
-  handle->cb_init_ = false;
-  handle->cb_data_ = nullptr;
-
-  return WATCH_HOLDER_ERROR_NONE;
-}
index 94bda42..549fd3c 100644 (file)
@@ -44,7 +44,7 @@ typedef struct {
  * @since_tizen 5.5
  * @return @c 0 on success, otherwise a negative error value
  */
-int watch_holder_create(Evas_Object *viewer_win, watch_holder_h *handle);
+int watch_holder_create(Evas_Object *viewer_win, watch_lifecycle_st lifecycle, void *user_data, watch_holder_h *handle);
 
 int watch_holder_destroy(watch_holder_h handle);
 
@@ -56,10 +56,6 @@ int watch_holder_disable_rendering(watch_holder_h handle, int timeout);
 
 int watch_holder_get_current(watch_holder_h handle, watch_h *watch);
 
-int watch_holder_monitor(watch_holder_h handle, watch_lifecycle_st lifecycle, void *user_data);
-
-int watch_holder_unmonitor(watch_holder_h handle);
-
 #ifdef __cplusplus
 }
 #endif
index 06ebfcb..10f3c70 100644 (file)
@@ -53,10 +53,11 @@ ADD_DEFINITIONS(${sdk_pkgs_CFLAGS})
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../widget_viewer_evas/include)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../watch-control/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../watch-holder/api)
+
 
 ADD_EXECUTABLE(${PROJECT_NAME} src/main.c)
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${sdk_pkgs_LDFLAGS} "-lm -pie -fPIC" widget_viewer_evas watch-control)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${sdk_pkgs_LDFLAGS} "-lm -pie -fPIC" widget_viewer_evas watch-holder)
 
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR})
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PKGNAME}.xml DESTINATION /usr/share/packages)
index 5c97304..43b3946 100644 (file)
@@ -20,6 +20,7 @@
 #include <app.h>
 #include <unistd.h>
 #include <errno.h>
+#include <watch_holder.h>
 #include <widget_errno.h>
 #include <widget_service.h>
 #include <widget_service_internal.h>
@@ -34,7 +35,6 @@
 #include <aul.h>
 #include <aul_debug_info.h>
 #include <appsvc.h>
-#include <watch_control.h>
 #include <pkgmgr-info.h>
 
 
@@ -103,6 +103,7 @@ static struct info {
 static char *__watch_pkgid;
 static Evas_Object *__clock;
 static bool __debug_info_initialized;
+static watch_holder_h __watch_holder;
 
 static void back_key_cb(void *data, Evas_Object *obj, void *event_info)
 {
@@ -266,23 +267,6 @@ static void layout_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info
        }
 }
 
-static void __watch_added(void *data, Evas_Object *obj, void *event_info)
-{
-       LOGD("watch added");
-       __clock = (Evas_Object *)event_info;
-
-       evas_object_resize(s_info.win, s_info.w, s_info.h);
-       evas_object_resize(__clock, s_info.w, s_info.h);
-
-       evas_object_show(__clock);
-       evas_object_show(s_info.win);
-}
-
-static void __watch_removed(void *data, Evas_Object *obj, void *event_info)
-{
-       LOGD("watch removed");
-}
-
 void  __clock_vconf_cb(keynode_t *node, void *data)
 {
        char *cur_watch = vconf_get_str(VCONFKEY_WMS_CLOCKS_SET_IDLE);
@@ -459,13 +443,27 @@ static void app_pause(void *data)
 {
        /* WIDGET pause */
        widget_viewer_evas_notify_paused_status_of_viewer();
-       watch_manager_notify_paused_status_of_viewer();
+       watch_h watch;
+       int ret = watch_holder_get_current(__watch_holder, &watch);
+       if (ret == WATCH_HOLDER_ERROR_NONE) {
+               ret = watch_pause(watch);
+               if (ret != WATCH_HOLDER_ERROR_NONE) {
+                       ErrPrint("watch_pause() failed: %d", ret);
+               }
+       }
 }
 
 static void __resume_process()
 {
        widget_viewer_evas_notify_resumed_status_of_viewer();
-       watch_manager_notify_resumed_status_of_viewer();
+       watch_h watch;
+       int ret = watch_holder_get_current(__watch_holder, &watch);
+       if (ret == WATCH_HOLDER_ERROR_NONE) {
+               ret = watch_resume(watch);
+               if (ret != WATCH_HOLDER_ERROR_NONE) {
+                       ErrPrint("watch_resume() failed: %d", ret);
+               }
+       }
 }
 
 static void app_resume(void *data)
@@ -742,7 +740,7 @@ static void __set_bundle_for_watchapp(bundle *app_control_b, bundle *b)
        bundle_get_str(app_control_b, AUL_K_SDK, &sdk_util);
        if (sdk_util != NULL) {
                aul_debug_info_init();
-               aul_debug_info_set(app_control_b, b);
+               aul_debug_info_set(app_control_b, b); // copies all the keys and values
                __debug_info_initialized = true;
                DbgPrint("util %s", sdk_util);
        }
@@ -771,20 +769,61 @@ static char *__get_pkgid_by_appid(char *appid)
        return ret_pkgid;
 }
 
+static void __watch_launched_cb(watch_h watch, void *data) {
+       DbgPrint("watch launched");
+}
+
+static void __watch_dead_cb(watch_h watch, bool is_faulted, void *data) {
+       DbgPrint("watch dead");
+}
+
+static void __watch_added_cb(watch_h watch, void *data) {
+       if (watch == NULL) {
+               ErrPrint("Wrong operation");
+               return;
+       }
+
+       const char* appid = NULL;
+       watch_get_appid(watch, &appid);
+       DbgPrint("watch added : %s", appid);
+       if (appid)
+         free(appid);
+
+       int ret = watch_get_current_image(watch, &__clock);
+       if (ret == WATCH_HOLDER_ERROR_NONE) {
+               evas_object_resize(s_info.win, s_info.w, s_info.h);
+               evas_object_resize(__clock, s_info.w, s_info.h);
+               evas_object_show(__clock);
+               evas_object_show(s_info.win);
+       } else {
+               ErrPrint("watch_get_current_image error:%d", ret);
+       }
+}
+
+static void __watch_removed_cb(watch_h watch, void *data) {
+       DbgPrint("watch removed");
+}
+
+static void __watch_updated_cb(watch_h watch, Evas_Object *image, void *data) {
+       DbgPrint("watch updated");
+}
+
+static void __watch_bound_cb(watch_h watch, void *data) {
+       DbgPrint("watch bound");
+}
+
 static void _app_control(app_control_h service, void *data)
 {
        char *widget_id = NULL;
        int ret;
        char *app_type = NULL;
        pkgmgrinfo_appinfo_h app_info;
-       app_control_h watch_control = NULL;
        bundle *b;
        bundle *app_control_b;
        char *lazy_loader = NULL;
        bool is_array;
        int array_len;
        char **widget_id_arr;
-       char *operation = NULL;
        int i;
        char *cur_watch = NULL;
 
@@ -815,26 +854,36 @@ static void _app_control(app_control_h service, void *data)
                }
 
                evas_object_resize(s_info.win, s_info.w, s_info.h);
-               watch_manager_init(s_info.win);
-               evas_object_smart_callback_add(s_info.win, WATCH_SMART_SIGNAL_ADDED, __watch_added, NULL);
-               evas_object_smart_callback_add(s_info.win, WATCH_SMART_SIGNAL_REMOVED, __watch_removed, NULL);
 
-               watch_manager_get_app_control(widget_id, &watch_control);
+               watch_lifecycle_st lifecycle;
+               lifecycle.watch_holder_lifecycle_launched_cb = __watch_launched_cb;
+               lifecycle.watch_holder_lifecycle_dead_cb = __watch_dead_cb;
+               lifecycle.watch_holder_lifecycle_added_cb = __watch_added_cb;
+               lifecycle.watch_holder_lifecycle_removed_cb = __watch_removed_cb;
+               lifecycle.watch_holder_lifecycle_updated_cb = __watch_updated_cb;
+               lifecycle.watch_holder_lifecycle_bound_cb = __watch_bound_cb;
+
+               ret = watch_holder_create(s_info.win, lifecycle, &s_info, &__watch_holder);
+               if (ret != WATCH_HOLDER_ERROR_NONE) {
+                       ErrPrint("Watch Holder Error:%d", ret);
+                       return;
+               }
 
-               app_control_get_operation(service, &operation);
-               if (operation) {
-                       app_control_set_operation(watch_control, operation);
-                       free(operation);
+               b = bundle_create();
+               if (b == NULL) {
+                       ErrPrint("Out of memory");
+                       return;
                }
 
-               app_control_to_bundle(watch_control, &b);
                app_control_to_bundle(service, &app_control_b);
-
                __set_bundle_for_watchapp(app_control_b, b);
+               ret = watch_holder_launch(__watch_holder, false, widget_id, b);
+               if (ret < 0)
+                       ErrPrint("Watch Holder Launch Error:%d", ret);
+               else
+                       DbgPrint("Watch Holder Launch pid(%d)", ret);
 
-               ret = aul_forward_app(widget_id, b);
-               DbgPrint("aul_forward_app returns [%d]", ret);
-               app_control_destroy(watch_control);
+               bundle_free(b);
        } else {
                ret = app_control_get_extra_data(service, LAZY_LOADER, &lazy_loader);
                app_control_to_bundle(service, &b);