From e4e734343163a1516010287d8369a01572966b9d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 3 Feb 2020 07:58:24 +0900 Subject: [PATCH] Add extension API Adds: - frame_broker_add_event_handler() - frame_broker_remove_event_handler() Requires: - https://review.tizen.org/gerrit/#/c/platform/core/appfw/widget-viewer/+/223659/ - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/223665/ - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/223673/ Change-Id: Ia78d277c7035a4787ca85fb04c7837b5e008e38f Signed-off-by: Hwankyu Jhun --- frame-broker/CMakeLists.txt | 1 + frame-broker/include/frame_broker_extension.h | 95 ++++++++++++++++++ frame-broker/src/frame_broker_extension.c | 136 ++++++++++++++++++++++++++ frame-broker/src/frame_context.c | 6 ++ 4 files changed, 238 insertions(+) create mode 100644 frame-broker/include/frame_broker_extension.h create mode 100644 frame-broker/src/frame_broker_extension.c diff --git a/frame-broker/CMakeLists.txt b/frame-broker/CMakeLists.txt index f925b71..6b0f7d9 100644 --- a/frame-broker/CMakeLists.txt +++ b/frame-broker/CMakeLists.txt @@ -45,6 +45,7 @@ SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME} SET(HEADERS_LIB_FRAME_BROKER frame.h frame_broker.h + frame_broker_extension.h frame_context.h frame_types.h ) diff --git a/frame-broker/include/frame_broker_extension.h b/frame-broker/include/frame_broker_extension.h new file mode 100644 index 0000000..538201c --- /dev/null +++ b/frame-broker/include/frame_broker_extension.h @@ -0,0 +1,95 @@ +/* + * 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 __FRAME_BROKER_EXTENSION_H__ +#define __FRAME_BROKER_EXTENSION_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The frame broker event handle. + * @since_tizen 5.5 + */ +typedef struct frame_broker_event_s *frame_broker_event_h; + +/** + * @brief Enumeration for frame context event. + * @since_tizen 5.5 + */ +typedef enum { + FRAME_CONTEXT_EVENT_STARTED, /** The animation is started. */ + FRAME_CONTEXT_EVENT_FINISHED, /** The animation is finished. */ +} frame_context_event_e; + +/** + * @brief Called when the animation of the application is started or finished. + * @since_tizen 5.5 + * + * @param[in] app_id The application ID + * @param[in] pid The process ID + * @param[in] event The frame context event + * @param[in] user_data Ther user data passed from the registration function + * + * @see frame_broker_add_event_handler() + * @see #frame_context_event_e + */ +typedef void (*frame_broker_event_cb)(const char *app_id, int pid, frame_context_event_e event, void *user_data); + +/** + * @brief Adds the event handle of the frame broker. + * @since_tizen 5.5 + * + * @param[in] app_id The application ID + * @param[in] callback The callback function + * @param[in] user_data The user data to be passed to the callback function + * @param[out] handle The frame broker event handle + * @return 0 on success, + * otherwise a negative error value + * + * @retval #FRAME_BROKER_ERROR_NONE Successful + * @retval #FRAME_BROKER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #FRAME_BROKER_ERROR_IO_ERROR I/O error + * @retval #FRAME_BROKER_ERROR_OUT_OF_MEMORY Out of memory + * + * @see frame_broker_remove_event_handler() + * @see frame_broker_event_cb() + */ +int frame_broker_add_event_handler(const char *app_id, frame_broker_event_cb callback, void *user_data, frame_broker_event_h *handle); + +/** + * @brief Removes the event handle of the frame broker. + * @since_tizen 5.5 + * + * @param[in] handle The frame broker event handle + * @return 0 on success, + * otherwise a negative error value + * + * @retval #FRAME_BROKER_ERROR_NONE Successful + * @retval #FRAME_BROKER_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see frame_broker_add_event_handler() + */ +int frame_broker_remove_event_handler(frame_broker_event_h handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __FRAME_BROKER_EXTENSION_H__ */ diff --git a/frame-broker/src/frame_broker_extension.c b/frame-broker/src/frame_broker_extension.c new file mode 100644 index 0000000..04bf6cf --- /dev/null +++ b/frame-broker/src/frame_broker_extension.c @@ -0,0 +1,136 @@ +/* + * 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. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +#include "frame_broker_extension.h" +#include "log_private.h" +#include "private.h" + +struct frame_broker_event_s { + aul_app_com_connection_h conn; + char *app_id; + frame_broker_event_cb callback; + void *user_data; +}; + +static int __launcher_service_event_cb(const char *endpoint, + aul_app_com_result_e res, bundle *envelope, void *user_data) +{ + struct frame_broker_event_s *handle = user_data; + char *app_id = NULL; + char *instance_id = NULL; + char *pid_str = NULL; + int pid; + char *event_str = NULL; + frame_context_event_e event; + + bundle_get_str(envelope, AUL_K_APPID, &app_id); + if (!app_id) { + _E("Failed to get application ID"); + return -1; + } + + bundle_get_str(envelope, AUL_K_INSTANCE_ID, &instance_id); + if (!instance_id) { + _E("Failed to get instance ID"); + return -1; + } + + bundle_get_str(envelope, AUL_K_PID, &pid_str); + if (!pid_str) { + _E("Failed to get process ID"); + return -1; + } + pid = atoi(pid_str); + + bundle_get_str(envelope, AUL_K_LAUNCHER_SERVICE_EVENT, &event_str); + if (!event_str) { + _E("Failed to get frame broker event"); + return -1; + } + event = atoi(event_str); + + handle->callback(app_id, pid, event, handle->user_data); + _I("[__FRAME_BROKER_EVENT__] app_id(%s), id(%s), pid(%d), event(%d)", + app_id, instance_id, pid, event); + + return 0; +} + +API int frame_broker_add_event_handler(const char *app_id, + frame_broker_event_cb callback, void *user_data, + frame_broker_event_h *handle) +{ + struct frame_broker_event_s *h; + char endpoint[512]; + int ret; + + if (!app_id || !callback || !handle) { + _E("Invalid parameter"); + return FRAME_BROKER_ERROR_INVALID_PARAMETER; + } + + h = calloc(1, sizeof(struct frame_broker_event_s)); + if (!h) { + _E("Out of memory"); + return FRAME_BROKER_ERROR_OUT_OF_MEMORY; + } + + snprintf(endpoint, sizeof(endpoint), "launcher_service_event:%s", + app_id); + ret = aul_app_com_create(endpoint, NULL, __launcher_service_event_cb, + h, &h->conn); + if (ret < 0) { + _E("aul_app_com_create() is failed. error(%d)", ret); + frame_broker_remove_event_handler(h); + return FRAME_BROKER_ERROR_IO_ERROR; + } + + h->app_id = strdup(app_id); + if (!h->app_id) { + _E("Failed to duplicate app_id(%s)", app_id); + frame_broker_remove_event_handler(h); + return FRAME_BROKER_ERROR_OUT_OF_MEMORY; + } + + h->callback = callback; + h->user_data = user_data; + + *handle = h; + + return FRAME_BROKER_ERROR_NONE; +} + +API int frame_broker_remove_event_handler(frame_broker_event_h handle) +{ + if (!handle) { + _E("Invalid parameter"); + return FRAME_BROKER_ERROR_INVALID_PARAMETER; + } + + aul_app_com_leave(handle->conn); + free(handle->app_id); + free(handle); + + return FRAME_BROKER_ERROR_NONE; +} diff --git a/frame-broker/src/frame_context.c b/frame-broker/src/frame_context.c index 2e35843..9277b67 100644 --- a/frame-broker/src/frame_context.c +++ b/frame-broker/src/frame_context.c @@ -14,11 +14,13 @@ * limitations under the License. */ +#define _GNU_SOURCE #include #include #include #include #include +#include #include "frame_broker.h" #include "frame_broker_private.h" @@ -136,6 +138,8 @@ API int frame_context_start_animation(frame_context_h handle) return FRAME_BROKER_ERROR_IO_ERROR; } + aul_launcher_service_notify_animation_started(); + handle->started = true; return FRAME_BROKER_ERROR_NONE; @@ -200,6 +204,8 @@ API int frame_context_finish_animation(frame_context_h handle) return FRAME_BROKER_ERROR_IO_ERROR; } + aul_launcher_service_notify_animation_finished(); + return FRAME_BROKER_ERROR_NONE; } -- 2.7.4