From e1237e84418debd66fdd981f4ad8c9e01e5dec92 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 20 Feb 2017 21:17:58 +0900 Subject: [PATCH] Add APIs for multi-window app core Change-Id: I4fae85d6d18740df8d5cfdd956f144dde829462b Signed-off-by: Junghoon Park --- CMakeLists.txt | 35 +++ appcore-multiwindow.pc.in | 15 ++ include/appcore_multiwindow_base.h | 96 ++++++++ packaging/app-core.spec | 32 +++ src/multiwindow_base/appcore_multiwindow_base.c | 250 +++++++++++++++++++++ .../appcore_multiwindow_base_class.c | 101 +++++++++ .../appcore_multiwindow_base_instance.c | 213 ++++++++++++++++++ .../appcore_multiwindow_base_private.h | 77 +++++++ .../appcore_multiwindow_base_window.c | 147 ++++++++++++ src/ui_base/appcore_ui_base_private.h | 1 - 10 files changed, 966 insertions(+), 1 deletion(-) create mode 100644 appcore-multiwindow.pc.in create mode 100644 include/appcore_multiwindow_base.h create mode 100644 src/multiwindow_base/appcore_multiwindow_base.c create mode 100644 src/multiwindow_base/appcore_multiwindow_base_class.c create mode 100644 src/multiwindow_base/appcore_multiwindow_base_instance.c create mode 100644 src/multiwindow_base/appcore_multiwindow_base_private.h create mode 100644 src/multiwindow_base/appcore_multiwindow_base_window.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fa4b0e..a5b35b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,3 +80,38 @@ FOREACH(hfile ${HEADERS_efl}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/${hfile} DESTINATION include/appcore) ENDFOREACH(hfile) +################################################################# +# Build appcore-multiwindow Library +# ------------------------------ +SET(APPCORE_MULTIWINDOW "appcore-multiwindow") +SET(SRCS_mw src/multiwindow_base/appcore_multiwindow_base.c + src/multiwindow_base/appcore_multiwindow_base_class.c + src/multiwindow_base/appcore_multiwindow_base_instance.c + src/multiwindow_base/appcore_multiwindow_base_window.c + ) +SET(HEADERS_mw appcore_multiwindow_base.h) + +INCLUDE(FindPkgConfig) +SET(APPCORE_MULTIWINDOW_PKG_CHECK_MODULES "elementary dlog ecore gobject-2.0 glib-2.0 aul") + +pkg_check_modules(pkg_mw REQUIRED ${APPCORE_MULTIWINDOW_PKG_CHECK_MODULES}) + +FOREACH(flag ${pkg_mw_CFLAGS}) + SET(EXTRA_CFLAGS_mw "${EXTRA_CFLAGS_mw} ${flag}") +ENDFOREACH(flag) + +ADD_LIBRARY(${APPCORE_MULTIWINDOW} SHARED ${SRCS_mw}) +SET_TARGET_PROPERTIES(${APPCORE_MULTIWINDOW} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${APPCORE_MULTIWINDOW} PROPERTIES VERSION ${FULLVER}) +SET_TARGET_PROPERTIES(${APPCORE_MULTIWINDOW} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_mw}) +TARGET_LINK_LIBRARIES(${APPCORE_MULTIWINDOW} ${pkg_mw_LDFLAGS} ${APPCORE_COMMON}) + +CONFIGURE_FILE(${APPCORE_MULTIWINDOW}.pc.in ${APPCORE_MULTIWINDOW}.pc @ONLY) + +INSTALL(TARGETS ${APPCORE_MULTIWINDOW} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${APPCORE_MULTIWINDOW}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +FOREACH(hfile ${HEADERS_mw}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/${hfile} DESTINATION include/appcore) +ENDFOREACH(hfile) + + diff --git a/appcore-multiwindow.pc.in b/appcore-multiwindow.pc.in new file mode 100644 index 0000000..db0e6e9 --- /dev/null +++ b/appcore-multiwindow.pc.in @@ -0,0 +1,15 @@ +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIB_INSTALL_DIR@ +includedir=@INCLUDEDIR@ + +Name: app-core-multiwindow +Description: application core library for multiwindow +Version: @VERSION@ +Requires.private: elementary dlog +Requires: appcore-common +Libs: -L${libdir} -lappcore-multiwindow +Cflags: -I${includedir} -I${includedir}/appcore + diff --git a/include/appcore_multiwindow_base.h b/include/appcore_multiwindow_base.h new file mode 100644 index 0000000..b5604ed --- /dev/null +++ b/include/appcore_multiwindow_base.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + */ + +#pragma once + +#include +#include +#include +#include +#include + +typedef struct _appcore_ui_base_window_ops { + void (*show)(int type, void *event, void *data); + void (*hide)(int type, void *event, void *data); + void (*lower)(int type, void *event, void *data); + void (*visibility)(int type, void *event, void *data); +} appcore_ui_base_window_ops; + +typedef struct _appcore_multiwindow_base_ops { + appcore_base_ops base; + appcore_ui_base_window_ops window; +} appcore_multiwindow_base_ops; + +typedef void *appcore_multiwindow_base_instance_h; + +typedef struct _appcore_multiwindow_base_class { + char *id; + void *data; + void (*create)(appcore_multiwindow_base_instance_h context, void *data); + void (*terminate)(appcore_multiwindow_base_instance_h context, void *data); + void (*pause)(appcore_multiwindow_base_instance_h context, void *data); + void (*resume)(appcore_multiwindow_base_instance_h context, void *data); +} appcore_multiwindow_base_class; + +typedef void (*appcore_multiwindow_base_instance_cb)(const char *class_id, + const char *id, appcore_multiwindow_base_instance_h context, void *data); + +#ifdef __cplusplus +extern "C" { +#endif + +int appcore_multiwindow_base_init(appcore_multiwindow_base_ops ops, int argc, char **argv, void *data); +void appcore_multiwindow_base_fini(void); +void appcore_multiwindow_base_exit(void); +appcore_multiwindow_base_ops appcore_multiwindow_base_get_default_ops(void); +int appcore_multiwindow_base_on_receive(aul_type type, bundle *b); +int appcore_multiwindow_base_on_create(void); +int appcore_multiwindow_base_on_terminate(void); +int appcore_multiwindow_base_on_control(bundle *b); +void appcore_multiwindow_base_window_on_show(int type, void *event); +void appcore_multiwindow_base_window_on_hide(int type, void *event); +void appcore_multiwindow_base_window_on_lower(int type, void *event); +void appcore_multiwindow_base_window_on_visibility(int type, void *event); +void appcore_multiwindow_base_window_bind(appcore_multiwindow_base_instance_h h, Evas_Object *win); + +appcore_multiwindow_base_class appcore_multiwindow_base_class_get_default(void); +void appcore_multiwindow_base_class_add(appcore_multiwindow_base_class cls); +void appcore_multiwindow_base_class_on_create(appcore_multiwindow_base_instance_h context); +void appcore_multiwindow_base_class_on_terminate(appcore_multiwindow_base_instance_h context); +void appcore_multiwindow_base_class_on_pause(appcore_multiwindow_base_instance_h context); +void appcore_multiwindow_base_class_on_resume(appcore_multiwindow_base_instance_h context); + +appcore_multiwindow_base_instance_h appcore_multiwindow_base_instance_run(const char *class_id, const char *id, void *extra); +void appcore_multiwindow_base_instance_exit(appcore_multiwindow_base_instance_h context); +void appcore_multiwindow_base_instance_drop(appcore_multiwindow_base_instance_h context); +void *appcore_multiwindow_base_instance_get_extra(appcore_multiwindow_base_instance_h context); +void appcore_multiwindow_base_instance_set_extra(appcore_multiwindow_base_instance_h context, void *extra); +bool appcore_multiwindow_base_instance_is_resumed(appcore_multiwindow_base_instance_h context); +void appcore_multiwindow_base_instance_pause(appcore_multiwindow_base_instance_h context); +void appcore_multiwindow_base_instance_resume(appcore_multiwindow_base_instance_h context); +const char *appcore_multiwindow_base_instance_get_id(appcore_multiwindow_base_instance_h context); +const char *appcore_multiwindow_base_instance_get_class_id(appcore_multiwindow_base_instance_h context); +const appcore_multiwindow_base_class *appcore_multiwindow_base_instance_get_class(appcore_multiwindow_base_instance_h context); +appcore_multiwindow_base_instance_h appcore_multiwindow_base_instance_find(const char *id); +void appcore_multiwindow_base_instance_foreach(const char *class_id, appcore_multiwindow_base_instance_cb cb, void *data); +void appcore_multiwindow_base_instance_foreach_full(appcore_multiwindow_base_instance_cb cb, void *data); +int appcore_multiwindow_base_instance_get_cnt(void); + +#ifdef __cplusplus +} +#endif + + diff --git a/packaging/app-core.spec b/packaging/app-core.spec index a5a4d52..a665d87 100644 --- a/packaging/app-core.spec +++ b/packaging/app-core.spec @@ -48,6 +48,23 @@ Requires: %{name}-common-devel = %{version}-%{release} %description efl-devel Application basic EFL (devel) +%package multiwindow +Summary: Application core for multiwindow +Group: Development/Libraries +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description multiwindow +Application core for multiwindow + +%package multiwindow-devel +Summary: Application core for multiwindow (devel) +Group: Development/Libraries +Requires: %{name}-multiwindow = %{version}-%{release} +Requires: %{name}-common-devel = %{version}-%{release} + +%description multiwindow-devel +Application core for multiwindow (devel) %package common Summary: App basics common @@ -102,6 +119,10 @@ rm -rf %{buildroot} %postun -n app-core-efl -p /sbin/ldconfig +%post -n app-core-multiwindow -p /sbin/ldconfig + +%postun -n app-core-multiwindow -p /sbin/ldconfig + %post -n app-core-common -p /sbin/ldconfig %postun -n app-core-common -p /sbin/ldconfig @@ -119,6 +140,17 @@ rm -rf %{buildroot} %{_libdir}/libappcore-efl.so %{_libdir}/pkgconfig/appcore-efl.pc +%files multiwindow +%manifest %{name}.manifest +%{_libdir}/libappcore-multiwindow.so.* +%license LICENSE + +%files multiwindow-devel +%manifest %{name}.manifest +%{_includedir}/appcore/appcore_multiwindow_base.h +%{_libdir}/libappcore-multiwindow.so +%{_libdir}/pkgconfig/appcore-multiwindow.pc + %files common %manifest %{name}.manifest %{_libdir}/libappcore-common.so.* diff --git a/src/multiwindow_base/appcore_multiwindow_base.c b/src/multiwindow_base/appcore_multiwindow_base.c new file mode 100644 index 0000000..854a6c9 --- /dev/null +++ b/src/multiwindow_base/appcore_multiwindow_base.c @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "appcore_base.h" +#include "appcore_multiwindow_base.h" +#include "appcore_multiwindow_base_private.h" + +appcore_multiwindow_base_context _appcore_mw_context; + +static Eina_Bool __stub_show_cb(void *data, int type, void *event) +{ + if (_appcore_mw_context.ops.window.show) + _appcore_mw_context.ops.window.show(type, event, _appcore_mw_context.data); + + return ECORE_CALLBACK_RENEW; +} + +static Eina_Bool __stub_hide_cb(void *data, int type, void *event) +{ + if (_appcore_mw_context.ops.window.hide) + _appcore_mw_context.ops.window.hide(type, event, _appcore_mw_context.data); + + return ECORE_CALLBACK_RENEW; +} + +static Eina_Bool __stub_visibility_cb(void *data, int type, void *event) +{ + if (_appcore_mw_context.ops.window.visibility) + _appcore_mw_context.ops.window.visibility(type, event, _appcore_mw_context.data); + + return ECORE_CALLBACK_RENEW; +} + +static Eina_Bool __stub_lower_cb(void *data, int type, void *event) +{ + if (_appcore_mw_context.ops.window.lower) + _appcore_mw_context.ops.window.lower(type, event, _appcore_mw_context.data); + + return ECORE_CALLBACK_RENEW; +} + +EXPORT_API int appcore_multiwindow_base_init(appcore_multiwindow_base_ops ops, int argc, char **argv, void *data) +{ + _appcore_mw_context.ops = ops; + _appcore_mw_context.data = data; + _appcore_mw_context.argc = argc; + _appcore_mw_context.argv = argv; + + elm_init(argc, argv); + _appcore_mw_context.hshow = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __stub_show_cb, NULL); + _appcore_mw_context.hhide = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __stub_hide_cb, NULL); + _appcore_mw_context.hvchange = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, + __stub_visibility_cb, NULL); + _appcore_mw_context.hlower = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER, __stub_lower_cb, NULL); + + return appcore_base_init(ops.base, argc, argv, data); +} + +static void __destroy_iter(gpointer data, gpointer user_data) +{ + appcore_multiwindow_base_instance *inst = data; + + if (!inst) + return; + + appcore_multiwindow_base_instance_exit(inst); +} + +static void __destroy_all(void) +{ + g_list_foreach(_appcore_mw_context.instances, __destroy_iter, NULL); +} + +static void __free_class(gpointer data) +{ + appcore_multiwindow_base_class *cls = data; + + free(cls->id); + free(cls); +} + +EXPORT_API void appcore_multiwindow_base_fini(void) +{ + appcore_base_fini(); + + __destroy_all(); + g_list_free_full(_appcore_mw_context.classes, __free_class); + _appcore_mw_context.classes = NULL; + + if (_appcore_mw_context.hshow) { + ecore_event_handler_del(_appcore_mw_context.hshow); + _appcore_mw_context.hshow = NULL; + } + + if (_appcore_mw_context.hhide) { + ecore_event_handler_del(_appcore_mw_context.hhide); + _appcore_mw_context.hhide = NULL; + } + + if (_appcore_mw_context.hvchange) { + ecore_event_handler_del(_appcore_mw_context.hvchange); + _appcore_mw_context.hvchange = NULL; + } + + if (_appcore_mw_context.hlower) { + ecore_event_handler_del(_appcore_mw_context.hlower); + _appcore_mw_context.hlower = NULL; + } + + elm_shutdown(); + + /* Check loader case */ + if (getenv("AUL_LOADER_INIT")) { + unsetenv("AUL_LOADER_INIT"); + elm_shutdown(); + } +} + +EXPORT_API void appcore_multiwindow_base_exit(void) +{ + if (_appcore_mw_context.ops.base.exit) + _appcore_mw_context.ops.base.exit(_appcore_mw_context.data); +} + +static int __on_receive(aul_type type, bundle *b, void *data) +{ + return appcore_multiwindow_base_on_receive(type, b); +} + +static int __on_create(void *data) +{ + return appcore_multiwindow_base_on_create(); +} + +static int __on_terminate(void *data) +{ + return appcore_multiwindow_base_on_terminate(); +} + +static void __window_on_show(int type, void *event, void *data) +{ + appcore_multiwindow_base_window_on_show(type, event); +} + +static void __window_on_hide(int type, void *event, void *data) +{ + appcore_multiwindow_base_window_on_hide(type, event); +} + +static void __window_on_lower(int type, void *event, void *data) +{ + appcore_multiwindow_base_window_on_lower(type, event); +} + +static void __window_on_visibility(int type, void *event, void *data) +{ + appcore_multiwindow_base_window_on_visibility(type, event); +} + +static void __run(void *data) +{ + elm_run(); +} + +static void __exit(void *data) +{ + elm_exit(); +} + +EXPORT_API appcore_multiwindow_base_ops appcore_multiwindow_base_get_default_ops(void) +{ + appcore_multiwindow_base_ops ops; + + ops.base = appcore_base_get_default_ops(); + + /* override methods */ + ops.base.create = __on_create; + ops.base.terminate = __on_terminate; + ops.base.receive = __on_receive; + ops.base.run = __run; + ops.base.exit = __exit; + + ops.window.show = __window_on_show; + ops.window.hide = __window_on_hide; + ops.window.lower = __window_on_lower; + ops.window.visibility = __window_on_visibility; + + return ops; +} + +EXPORT_API int appcore_multiwindow_base_on_receive(aul_type type, bundle *b) +{ + appcore_base_on_receive(type, b); + + return 0; +} + +EXPORT_API int appcore_multiwindow_base_on_create(void) +{ + appcore_base_on_create(); + + return 0; +} + +EXPORT_API int appcore_multiwindow_base_on_terminate(void) +{ + appcore_base_on_terminate(); + + return 0; +} + +EXPORT_API int appcore_multiwindow_base_on_control(bundle *b) +{ + appcore_base_on_control(b); + + return 0; +} + diff --git a/src/multiwindow_base/appcore_multiwindow_base_class.c b/src/multiwindow_base/appcore_multiwindow_base_class.c new file mode 100644 index 0000000..e0ce143 --- /dev/null +++ b/src/multiwindow_base/appcore_multiwindow_base_class.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 + +#include "appcore_base.h" +#include "appcore_multiwindow_base.h" +#include "appcore_multiwindow_base_private.h" + +extern appcore_multiwindow_base_context _appcore_mw_context; + +static void __on_create(appcore_multiwindow_base_instance_h context, void *data) +{ + appcore_multiwindow_base_class_on_create(context); +} + +static void __on_terminate(appcore_multiwindow_base_instance_h context, void *data) +{ + appcore_multiwindow_base_class_on_terminate(context); +} + +static void __on_pause(appcore_multiwindow_base_instance_h context, void *data) +{ + appcore_multiwindow_base_class_on_pause(context); +} + +static void __on_resume(appcore_multiwindow_base_instance_h context, void *data) +{ + appcore_multiwindow_base_class_on_resume(context); +} + +EXPORT_API appcore_multiwindow_base_class appcore_multiwindow_base_class_get_default(void) +{ + appcore_multiwindow_base_class cls; + + cls.create = __on_create; + cls.terminate = __on_terminate; + cls.pause = __on_pause; + cls.resume = __on_resume; + + return cls; +} + +EXPORT_API void appcore_multiwindow_base_class_add(appcore_multiwindow_base_class cls) +{ + appcore_multiwindow_base_class *c; + + if (!cls.id) + return; + + c = malloc(sizeof(appcore_multiwindow_base_class)); + + if (!c) + return; + + *c = cls; + c->id = strdup(cls.id); + _appcore_mw_context.classes = g_list_append(_appcore_mw_context.classes, c); +} + +EXPORT_API void appcore_multiwindow_base_class_on_create(appcore_multiwindow_base_instance_h context) +{ +} + +EXPORT_API void appcore_multiwindow_base_class_on_terminate(appcore_multiwindow_base_instance_h context) +{ +} + +EXPORT_API void appcore_multiwindow_base_class_on_pause(appcore_multiwindow_base_instance_h context) +{ +} + +EXPORT_API void appcore_multiwindow_base_class_on_resume(appcore_multiwindow_base_instance_h context) +{ +} + + diff --git a/src/multiwindow_base/appcore_multiwindow_base_instance.c b/src/multiwindow_base/appcore_multiwindow_base_instance.c new file mode 100644 index 0000000..f5c75c1 --- /dev/null +++ b/src/multiwindow_base/appcore_multiwindow_base_instance.c @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 "appcore_base.h" +#include "appcore_multiwindow_base.h" +#include "appcore_multiwindow_base_private.h" + +extern appcore_multiwindow_base_context _appcore_mw_context; + +static gint __comp(gconstpointer a, gconstpointer b) +{ + const appcore_multiwindow_base_class *cls = a; + + return strcmp(cls->id, b); +} + +EXPORT_API appcore_multiwindow_base_instance_h appcore_multiwindow_base_instance_run(const char *class_id, const char *id, void *extra) +{ + appcore_multiwindow_base_instance *inst; + GList * class_node = g_list_find_custom(_appcore_mw_context.classes, class_id, __comp); + + if (!class_node) + return NULL; + inst = malloc(sizeof(appcore_multiwindow_base_instance)); + if (!inst) + return NULL; + + inst->shell = class_node->data; + inst->window_id = 0; + inst->id = strdup(id); + inst->extra = extra; + inst->is_resumed = false; + + _appcore_mw_context.instances = g_list_append(_appcore_mw_context.instances, inst); + if (inst->shell->create) + inst->shell->create(inst, inst->shell->data); + + return inst; +} + +EXPORT_API void appcore_multiwindow_base_instance_exit(appcore_multiwindow_base_instance_h context) +{ + appcore_multiwindow_base_instance *inst = context; + + appcore_multiwindow_base_instance_pause(inst); + if (inst->shell->terminate) + inst->shell->terminate(inst, inst->shell->data); + + _appcore_mw_context.instances = g_list_remove(_appcore_mw_context.instances, inst); + free(inst->id); + free(inst); +} + +EXPORT_API void appcore_multiwindow_base_instance_drop(appcore_multiwindow_base_instance_h context) +{ + appcore_multiwindow_base_instance *inst = context; + + inst->shell->terminate(inst, inst->shell->data); + + _appcore_mw_context.instances = g_list_remove(_appcore_mw_context.instances, inst); + free(inst->id); + free(inst); +} + +EXPORT_API void *appcore_multiwindow_base_instance_get_extra(appcore_multiwindow_base_instance_h context) +{ + appcore_multiwindow_base_instance *inst = context; + + return inst->extra; +} + +EXPORT_API void appcore_multiwindow_base_instance_set_extra(appcore_multiwindow_base_instance_h context, void *extra) +{ + appcore_multiwindow_base_instance *inst = context; + + inst->extra = extra; +} + +EXPORT_API bool appcore_multiwindow_base_instance_is_resumed(appcore_multiwindow_base_instance_h context) +{ + appcore_multiwindow_base_instance *inst = context; + + return inst->is_resumed; +} + +EXPORT_API void appcore_multiwindow_base_instance_pause(appcore_multiwindow_base_instance_h context) +{ + appcore_multiwindow_base_instance *inst = context; + + if (!inst->is_resumed) + return; + + if (inst->shell->pause) + inst->shell->pause(inst, inst->shell->data); + inst->is_resumed = false; +} + +EXPORT_API void appcore_multiwindow_base_instance_resume(appcore_multiwindow_base_instance_h context) +{ + appcore_multiwindow_base_instance *inst = context; + + if (inst->is_resumed) + return; + + if (inst->shell->resume) + inst->shell->resume(inst, inst->shell->data); + inst->is_resumed = true; +} + +EXPORT_API const char *appcore_multiwindow_base_instance_get_id(appcore_multiwindow_base_instance_h context) +{ + appcore_multiwindow_base_instance *inst = context; + + return inst->id; +} + +EXPORT_API const char *appcore_multiwindow_base_instance_get_class_id(appcore_multiwindow_base_instance_h context) +{ + appcore_multiwindow_base_instance *inst = context; + + return inst->shell->id; +} + +EXPORT_API const appcore_multiwindow_base_class *appcore_multiwindow_base_instance_get_class(appcore_multiwindow_base_instance_h context) +{ + appcore_multiwindow_base_instance *inst = context; + + return inst->shell; +} + +static gint __comp_id(gconstpointer a, gconstpointer b) +{ + const appcore_multiwindow_base_instance *inst = a; + + return strcmp(inst->id, b); +} + +EXPORT_API appcore_multiwindow_base_instance_h appcore_multiwindow_base_instance_find(const char *id) +{ + GList * inst_node = g_list_find_custom(_appcore_mw_context.instances, id, __comp_id); + + if (!inst_node) + return NULL; + + return inst_node->data; +} + +EXPORT_API void appcore_multiwindow_base_instance_foreach(const char *class_id, + appcore_multiwindow_base_instance_cb cb, void *data) +{ + GList * inst_node = _appcore_mw_context.instances; + appcore_multiwindow_base_instance *inst; + + if (!class_id || !cb) + return; + + while (inst_node) { + inst = inst_node->data; + + if (!strcmp(class_id, inst->shell->id)) + cb(class_id, inst->id, inst, data); + + inst_node = g_list_next(inst_node); + } +} + +EXPORT_API void appcore_multiwindow_base_instance_foreach_full(appcore_multiwindow_base_instance_cb cb, + void *data) +{ + GList * inst_node = _appcore_mw_context.instances; + appcore_multiwindow_base_instance *inst; + + if (!cb) + return; + + while (inst_node) { + inst = inst_node->data; + cb(inst->shell->id, inst->id, inst, data); + inst_node = g_list_next(inst_node); + } +} + +EXPORT_API int appcore_multiwindow_base_instance_get_cnt(void) +{ + return g_list_length(_appcore_mw_context.instances); +} + + diff --git a/src/multiwindow_base/appcore_multiwindow_base_private.h b/src/multiwindow_base/appcore_multiwindow_base_private.h new file mode 100644 index 0000000..b28576d --- /dev/null +++ b/src/multiwindow_base/appcore_multiwindow_base_private.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + */ + +#pragma once + +#define LOG_TAG "APP_CORE_MULTIWINDOW_BASE" + +#include +#include +#include +#include + +#include "appcore_base.h" +#include "appcore_multiwindow_base.h" + +#ifndef EXPORT_API +# define EXPORT_API __attribute__ ((visibility("default"))) +#endif + +#ifndef _DLOG_H_ +# define _ERR(fmt, arg...) \ + do { fprintf(stderr, "appcore: "fmt"\n", ##arg); } while (0) + +# define _INFO(fmt, arg...) \ + do { fprintf(stdout, fmt"\n", ##arg); } while (0) + +# define _DBG(fmt, arg...) \ + do { \ + if (getenv("APPCORE_DEBUG")) { \ + fprintf(stdout, fmt"\n", ##arg); \ + } \ + } while (0) +#else +# define _ERR(fmt, arg...) \ + do { \ + fprintf(stderr, "appcore: "fmt"\n", ##arg); \ + LOGE(fmt, ##arg); \ + } while (0) +# define _INFO(...) LOGI(__VA_ARGS__) +# define _DBG(...) LOGD(__VA_ARGS__) +#endif + +typedef struct _appcore_multiwindow_base_context { + appcore_multiwindow_base_ops ops; + void *data; + int argc; + char **argv; + GList *classes; + GList *instances; + + Ecore_Event_Handler *hshow; + Ecore_Event_Handler *hhide; + Ecore_Event_Handler *hvchange; + Ecore_Event_Handler *hlower; +} appcore_multiwindow_base_context; + +typedef struct _appcore_multiwindow_base_instance { + unsigned int window_id; + char *id; + void *extra; + appcore_multiwindow_base_class *shell; + bool is_resumed; +} appcore_multiwindow_base_instance; + diff --git a/src/multiwindow_base/appcore_multiwindow_base_window.c b/src/multiwindow_base/appcore_multiwindow_base_window.c new file mode 100644 index 0000000..3aea29b --- /dev/null +++ b/src/multiwindow_base/appcore_multiwindow_base_window.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 +#include + +#include "appcore_base.h" +#include "appcore_multiwindow_base.h" +#include "appcore_multiwindow_base_private.h" + +typedef struct _win_context { + appcore_multiwindow_base_instance_h inst; + int win_id; +} win_context; + +static GList *__win_contexts; + +static gint __comp(gconstpointer a, gconstpointer b) +{ + const win_context *cxt = a; + + if (!a || !b) + return -1; + + if (cxt->inst == b) + return 0; + + return -1; +} + +static gint __comp_wid(gconstpointer a, gconstpointer b) +{ + int wid = GPOINTER_TO_INT(b); + const win_context *cxt = a; + + if (!a || !b) + return -1; + + if (cxt->win_id == wid) + return 0; + + return -1; +} + +static win_context *__find_win_context(appcore_multiwindow_base_instance_h h) +{ + GList *node = g_list_find_custom(__win_contexts, h, __comp); + + if (!node) + return NULL; + + return node->data; +} + +static win_context *__find_win_context_by_wid(int wid) +{ + GList *node = g_list_find_custom(__win_contexts, GINT_TO_POINTER(wid), __comp_wid); + + if (!node) + return NULL; + + return node->data; +} + +EXPORT_API void appcore_multiwindow_base_window_on_show(int type, void *event) +{ +} + +EXPORT_API void appcore_multiwindow_base_window_on_hide(int type, void *event) +{ + Ecore_Wl_Event_Window_Hide *ev = event; + win_context *cxt = __find_win_context_by_wid(ev->win); + + if (!cxt) + return; + + __win_contexts = g_list_remove(__win_contexts, cxt); + free(cxt); +} + +EXPORT_API void appcore_multiwindow_base_window_on_lower(int type, void *event) +{ +} + +EXPORT_API void appcore_multiwindow_base_window_on_visibility(int type, void *event) +{ + Ecore_Wl_Event_Window_Visibility_Change *ev = event; + win_context *cxt = __find_win_context_by_wid(ev->win); + + if (!cxt) + return; + + if (ev->fully_obscured) + appcore_multiwindow_base_instance_pause(cxt->inst); + else + appcore_multiwindow_base_instance_resume(cxt->inst); +} + +EXPORT_API void appcore_multiwindow_base_window_bind(appcore_multiwindow_base_instance_h h, Evas_Object *win) +{ + win_context *cxt; + Ecore_Wl_Window *wl_win; + int id; + + cxt = __find_win_context(h); + if (cxt) { + _ERR("This instance is already binded"); + return; + } + + wl_win = elm_win_wl_window_get(win); + if (!wl_win) { + _ERR("failed to get wayland window"); + return; + } + + id = ecore_wl_window_id_get(wl_win); + + cxt = malloc(sizeof(win_context)); + cxt->win_id = id; + cxt->inst = h; + __win_contexts = g_list_append(__win_contexts, cxt); +} diff --git a/src/ui_base/appcore_ui_base_private.h b/src/ui_base/appcore_ui_base_private.h index cfa0c28..0e8b2ae 100644 --- a/src/ui_base/appcore_ui_base_private.h +++ b/src/ui_base/appcore_ui_base_private.h @@ -50,4 +50,3 @@ #endif - -- 2.7.4