add watch_control 34/60634/5
authorDaehyeon Jung <darrenh.jung@samsung.com>
Mon, 29 Feb 2016 11:31:13 +0000 (20:31 +0900)
committerSemun Lee <sm79.lee@samsung.com>
Wed, 2 Mar 2016 12:18:28 +0000 (04:18 -0800)
Change-Id: I0df21ad4e7b27be7372ccdd366035b9878b8d7dd
Signed-off-by: Daehyeon Jung <darrenh.jung@samsung.com>
packaging/libwidget_viewer.spec
widget_viewer_evas/CMakeLists.txt
widget_viewer_evas/include/watch_control.h [new file with mode: 0644]
widget_viewer_evas/src/widget_viewer_evas.c

index 87b25a781b1724fde6dc9ca51ea2705b5cca282b..5e963aac2aba3b2a8066e452775a7f093dcb8aa6 100644 (file)
@@ -2,7 +2,7 @@
 
 Name: libwidget_viewer
 Summary: Library for developing the application
-Version: 1.2.2
+Version: 1.3
 Release: 1
 Group: Applications/Core Applications
 License: Flora-1.1
@@ -112,6 +112,7 @@ While developing the widget applications, this viewer will load it and execute i
 %manifest %{name}_evas.manifest
 %defattr(-,root,root,-)
 %{_includedir}/widget_viewer_evas/widget_viewer_evas.h
+%{_includedir}/widget_viewer_evas/watch_control.h
 %{_libdir}/pkgconfig/widget_viewer_evas.pc
 
 %files -n org.tizen.widget_viewer_sdk
index 0c66b27c74f2498e8daf7d23bcb306fb69871858..7831f58affcea536db6a22b7a84f344292b0472e 100644 (file)
@@ -20,6 +20,8 @@ pkg_check_modules(viewer_evas REQUIRED
        pkgmgr-info
        capi-system-info
        libpepper-efl
+       capi-appfw-application
+       aul
 )
 
 SET(BUILD_SOURCE
@@ -56,6 +58,7 @@ SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}
 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}/include/${PROJECT_NAME}.h DESTINATION include/${PROJECT_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/watch_control.h DESTINATION include/${PROJECT_NAME})
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME "lib${PROJECT_NAME}")
 
 #ADD_SUBDIRECTORY(res)
diff --git a/widget_viewer_evas/include/watch_control.h b/widget_viewer_evas/include/watch_control.h
new file mode 100644 (file)
index 0000000..22dee93
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef __WATCH_MANAGER_H__
+#define __WATCH_MANAGER_H__
+
+#include <tizen_type.h>
+#include <Evas.h>
+#include <app.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+       WATCH_OBJ_ADD = 1,
+       WATCH_OBJ_DEL = 2,
+} watch_control_event;
+
+typedef enum {
+       WATCH_POLICY_HINT_EXPAND = 1,
+} watch_policy_size_hint;
+
+struct watch_control_s;
+typedef struct watch_control_s *watch_control_h;
+
+typedef int (*watch_control_callback)(watch_control_h watch_control, void *data);
+
+extern int watch_manager_init(Evas_Object *win, void *data);
+extern int watch_manager_fini();
+extern int watch_manager_add_handler(watch_control_event e, watch_control_callback cb, void *data);
+extern int watch_manager_get_app_control(const char *app_id, app_control_h *app_control);
+extern int watch_policy_set_size_hint(watch_policy_size_hint hint);
+extern Evas_Object *watch_control_get_evas_object(watch_control_h watch_control);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index b8821e16a7a44dbdf00ee919be9f4a5587fff5cf..a8e5257f94a3dc212f73c88b47ed53500ceda99e 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <widget_instance.h>
 #include <Pepper_Efl.h>
+#include "watch_control.h"
 
 #if defined(LOG_TAG)
 #undef LOG_TAG
@@ -818,4 +819,177 @@ EAPI void widget_viewer_evas_set_permanent_delete(Evas_Object *widget, int flag)
        return;
 }
 
+#include <aul_svc.h>
+#include <bundle_internal.h>
+#include <app_control_internal.h>
+
+#undef LOG_TAG
+#define LOG_TAG "WATCH_CONTROL"
+
+#ifdef LOGE
+#define _E LOGE
+#endif
+
+#ifdef LOGD
+#define _D LOGD
+#endif
+
+struct watch_control_s {
+       Evas_Object *evas_obj;
+};
+
+static const char *compositor_name = NULL;
+
+static int __watch_viewer_initialized = 0;
+
+static watch_control_h __default_control = NULL;
+static watch_control_callback __default_handler = NULL;
+static void *__default_data = NULL;
+static int __watch_size_policy = WATCH_POLICY_HINT_EXPAND;
+
+static void __set_runtime_dir()
+{
+       char buf[256];
+
+       snprintf(buf, sizeof(buf) - 1, "/run/user/%d", getuid());
+       if (setenv("XDG_RUNTIME_DIR", buf, 0) < 0)
+               _E("Unable to set XDG_RUNTIME_DIR: %s (%s)\n", buf, strerror(errno));
+}
+
+void __obj_added_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       _E("obj added");
+       int w, h, x, y;
+       Evas_Object *surface = (Evas_Object *)event_info;
+       evas_object_geometry_get(surface, &x, &y, &w, &h);
+       _E("w: %d, h: %d, x: %d y: %d", w, h, x, y);
+       if (__default_control && __default_handler) {
+               __default_control->evas_obj = surface;
+               __default_handler(__default_control, __default_data);
+               _E("default handler called");
+       }
+}
+
+void __obj_deleted_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       _E("obj removed");
+       /* TODO */
+}
+
+static int __watch_viewer_init(Evas_Object *win)
+{
+       if (__watch_viewer_initialized)
+               return 0;
+
+       if (win == NULL) {
+               _E("invalid arguments");
+               return -1;
+       }
+
+       __set_runtime_dir();
+       _D("init pepper");
+       compositor_name = pepper_efl_compositor_create(win, "watchview");
+       if (compositor_name == NULL) {
+               _E("failed to create compositor");
+               return -1;
+       }
+
+       if (setenv("WAYLAND_DISPLAY", compositor_name, 1) < 0) {
+               _E("failed to set wayland display: %s", strerror(errno));
+       }
+
+       evas_object_smart_callback_add(win, PEPPER_EFL_OBJ_ADD, __obj_added_cb, NULL);
+       evas_object_smart_callback_add(win, PEPPER_EFL_OBJ_DEL, __obj_deleted_cb, NULL);
+       _D("pepper init done");
+       __watch_viewer_initialized = 1;
+
+       return 0;
+}
+
+static void __watch_viewer_fini()
+{
+       
+}
+
+EAPI int watch_manager_init(Evas_Object *win, void *data)
+{
+       __watch_viewer_init(win);
+
+       return 0;
+}
+
+EAPI Evas_Object *watch_control_get_evas_object(watch_control_h control)
+{
+       return control->evas_obj;
+}
+
+EAPI int watch_manager_add_handler(watch_control_event e, watch_control_callback cb, void *data)
+{
+       switch (e) {
+       case WATCH_OBJ_ADD:
+               __default_handler = cb;
+               __default_data = data;
+               break;
+       case WATCH_OBJ_DEL:
+               /* TODO */
+               break;
+       }
+
+       return 0;
+}
+
+static int __watch_screen_get_width()
+{
+       if (__watch_size_policy == WATCH_POLICY_HINT_EXPAND)
+               return 360; /* TODO get width from win */
+
+       return 0;
+}
+
+static int __watch_screen_get_height()
+{
+       if (__watch_size_policy == WATCH_POLICY_HINT_EXPAND)
+               return 360; /* TODO get width from win */
+
+       return 0;
+}
+
+EAPI int watch_manager_get_app_control(const char *app_id, app_control_h *app_control)
+{
+       char buf[10];
+       bundle *b = NULL;
+       app_control_create(app_control);
+       app_control_set_app_id(*app_control, app_id);
+
+       __default_control = (watch_control_h)malloc(sizeof(struct watch_control_s));
+
+       snprintf(buf, sizeof(buf), "%d", __watch_screen_get_width());
+       app_control_add_extra_data(*app_control, "WATCH_WIDTH", buf);
+       snprintf(buf, sizeof(buf), "%d", __watch_screen_get_height());
+       app_control_add_extra_data(*app_control, "WATCH_HEIGHT", buf);
+
+       app_control_add_extra_data(*app_control, "WAYLAND_DISPLAY", getenv("WAYLAND_DISPLAY"));
+       app_control_add_extra_data(*app_control, "XDG_RUNTIME_DIR", getenv("XDG_RUNTIME_DIR"));
+
+       app_control_set_operation(*app_control, APP_CONTROL_OPERATION_MAIN);
+
+       app_control_to_bundle(*app_control, &b);
+       aul_svc_set_loader_id(b, 1);
+
+       return 0;
+}
+
+EAPI int watch_manager_fini()
+{
+       __watch_viewer_fini();
+
+       return 0;
+}
+
+EAPI int watch_policy_set_size_hint(watch_policy_size_hint hint)
+{
+       __watch_size_policy = hint;
+
+       return 0;
+}
 /* End of a file */