From e63979fedeb5947ed8a7902ff57ec1137d8e739d Mon Sep 17 00:00:00 2001 From: Rajendraprasad K J Date: Mon, 30 Mar 2020 08:16:54 +0200 Subject: ilmControl: Implement a shutdown notification for ilm We should gracefully exit when we encounter some unrecoverable errors in ilmControl, e.g.: OOM or wayland errors. But before we exit, we have to send a notification to the application side that we are shutting down and releasing all resources. Signed-off-by: Rajendraprasad K J --- .../ilmControl/include/ilm_control_platform.h | 3 ++ .../ilmControl/src/ilm_control_wayland_platform.c | 57 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/ivi-layermanagement-api/ilmControl/include/ilm_control_platform.h b/ivi-layermanagement-api/ilmControl/include/ilm_control_platform.h index 4a92c9e..db672cc 100644 --- a/ivi-layermanagement-api/ilmControl/include/ilm_control_platform.h +++ b/ivi-layermanagement-api/ilmControl/include/ilm_control_platform.h @@ -58,6 +58,9 @@ struct ilm_control_context { pthread_mutex_t mutex; int shutdown_fd; uint32_t internal_id_surface; + + shutdownNotificationFunc notification; + void *notification_user_data; }; struct seat_context { diff --git a/ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c b/ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c index be7c5a3..f1e5404 100644 --- a/ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c +++ b/ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c @@ -1084,6 +1084,28 @@ static void send_shutdown_event(struct ilm_control_context *ctx) ; } +ILM_EXPORT ilmErrorTypes +ilmControl_registerShutdownNotification(shutdownNotificationFunc callback, void *user_data) +{ + ilmErrorTypes returnValue = ILM_FAILED; + struct ilm_control_context *ctx = sync_and_acquire_instance(); + + if (!callback) + { + fprintf(stderr, "[Error] shutdownNotificationFunc is invalid\n"); + goto error; + } + + ctx->notification = callback; + ctx->notification_user_data = user_data; + + returnValue = ILM_SUCCESS; + +error: + release_instance(); + return returnValue; +} + ILM_EXPORT void ilmControl_destroy(void) { @@ -1128,6 +1150,8 @@ ilmControl_init(t_ilm_nativedisplay nativedisplay) } ctx->shutdown_fd = -1; + ctx->notification = NULL; + ctx->notification_user_data = NULL; ctx->wl.display = (struct wl_display*)nativedisplay; @@ -1168,6 +1192,34 @@ ilmControl_init(t_ilm_nativedisplay nativedisplay) return ILM_SUCCESS; } +static void +handle_shutdown(struct ilm_control_context *ctx, + t_ilm_shutdown_error_type error_type) +{ + struct wayland_context *wl_ctx = &ctx->wl; + struct wl_display *display = wl_ctx->display; + int errornum; + + switch (error_type) + { + case ILM_ERROR_WAYLAND: + errornum = wl_display_get_error(display); + break; + case ILM_ERROR_POLL: + default: + errornum = errno; + } + + fprintf(stderr, "[Error] ilm services shutdown due to error %s\n", + strerror(errornum)); + + if (!ctx->notification) + return; + + ctx->notification(error_type, errornum, ctx->notification_user_data); +} + + static void* control_thread(void *p_ret) { @@ -1190,6 +1242,7 @@ control_thread(void *p_ret) if (wl_display_flush(display) == -1) { + handle_shutdown(ctx, ILM_ERROR_WAYLAND); break; } @@ -1209,11 +1262,15 @@ control_thread(void *p_ret) if (ret == -1) { + handle_shutdown(ctx, ILM_ERROR_WAYLAND); break; } } else { + if (pollret == -1) + handle_shutdown(ctx, ILM_ERROR_POLL); + wl_display_cancel_read(display); if (pollret == -1 || (pfd[1].revents & POLLIN)) -- cgit v1.2.1 From cc70d5349a190ef73c5b1b4ad4caf2bf6e39dc8c Mon Sep 17 00:00:00 2001 From: Rajendraprasad K J Date: Mon, 30 Mar 2020 08:20:38 +0200 Subject: ilmCommon: Implement a shutdown notification for ilm Added new ilm API using which user could register for the shutdown notification. Signed-off-by: Rajendraprasad K J --- ivi-layermanagement-api/ilmCommon/include/ilm_common.h | 13 +++++++++++++ ivi-layermanagement-api/ilmCommon/include/ilm_types.h | 17 +++++++++++++++++ ivi-layermanagement-api/ilmCommon/src/ilm_common.c | 9 +++++++++ 3 files changed, 39 insertions(+) diff --git a/ivi-layermanagement-api/ilmCommon/include/ilm_common.h b/ivi-layermanagement-api/ilmCommon/include/ilm_common.h index fa86824..61e240a 100644 --- a/ivi-layermanagement-api/ilmCommon/include/ilm_common.h +++ b/ivi-layermanagement-api/ilmCommon/include/ilm_common.h @@ -64,6 +64,19 @@ t_ilm_bool ilm_isInitialized(void); */ ilmErrorTypes ilm_commitChanges(void); +/** + * \brief register for notification on an event of ilm shutdown + * \ingroup ilmCommon + * \param[in] callback pointer to function to be called for notification + callback function is defined as: + void cb(t_ilm_shutdown_error_type error_type, int errornum, void *user_data) + * \param[in] user_data pointer to data which will be passed to a notification callback + * \return ILM_SUCCESS if the method call was successful + * \return ILM_FAILED if the client can not call the method on the service. + */ +ilmErrorTypes ilm_registerShutdownNotification(shutdownNotificationFunc callback, + void *user_data); + /** * \brief Destroys the IVI LayerManagement Client. * \ingroup ilmCommon diff --git a/ivi-layermanagement-api/ilmCommon/include/ilm_types.h b/ivi-layermanagement-api/ilmCommon/include/ilm_types.h index a88f2b0..98a8e62 100644 --- a/ivi-layermanagement-api/ilmCommon/include/ilm_types.h +++ b/ivi-layermanagement-api/ilmCommon/include/ilm_types.h @@ -248,6 +248,16 @@ typedef enum ILM_NOTIFICATION_ALL = 0xffff } t_ilm_notification_mask; +/** + * enum representing types of possible unrecoverable errors that could lead to ilm shutdown. + */ +typedef enum +{ + ILM_ERROR_WAYLAND = 1, /*!< ErrorCode if Wayland API returns an error */ + ILM_ERROR_POLL = 2 /*!< ErrorCode if Poll returns an error */ +}t_ilm_shutdown_error_type; + + /** * Typedef for notification callback on property changes of a layer */ @@ -270,4 +280,11 @@ typedef void(*notificationFunc)(ilmObjectType object, t_ilm_bool created, void* user_data); +/** + * Typedef for notification callback on ilm shutdown due to unrecoverable + * errors + */ +typedef void(*shutdownNotificationFunc)(t_ilm_shutdown_error_type error_type, + int errornum, + void* user_data); #endif /* _ILM_TYPES_H_*/ diff --git a/ivi-layermanagement-api/ilmCommon/src/ilm_common.c b/ivi-layermanagement-api/ilmCommon/src/ilm_common.c index b4f8818..63342b9 100644 --- a/ivi-layermanagement-api/ilmCommon/src/ilm_common.c +++ b/ivi-layermanagement-api/ilmCommon/src/ilm_common.c @@ -26,6 +26,9 @@ #include "ilm_types.h" ILM_EXPORT ilmErrorTypes ilmControl_init(t_ilm_nativedisplay); +ILM_EXPORT ilmErrorTypes ilmControl_registerShutdownNotification( + shutdownNotificationFunc callback, + void *user_data); ILM_EXPORT void ilmControl_destroy(void); static pthread_mutex_t g_initialize_lock = PTHREAD_MUTEX_INITIALIZER; @@ -97,6 +100,12 @@ ilm_isInitialized(void) return ILM_FALSE; } +ILM_EXPORT ilmErrorTypes +ilm_registerShutdownNotification(shutdownNotificationFunc callback, void *user_data) +{ + return ilmControl_registerShutdownNotification(callback, user_data); +} + ILM_EXPORT ilmErrorTypes ilm_destroy(void) { -- cgit v1.2.1 From efeaedd6b9e363cec82bf72617bf35269374b7ef Mon Sep 17 00:00:00 2001 From: Rajendraprasad K J Date: Wed, 8 Jul 2020 07:33:40 +0200 Subject: layer-add-surfaces: Register for ilm shutdown notification Register for ilm shutdown notification so that we would be notified when some unrecoverable error occurs in ilmControl. Signed-off-by: Rajendraprasad K J --- .../layer-add-surfaces/src/layer-add-surfaces.c | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ivi-layermanagement-examples/layer-add-surfaces/src/layer-add-surfaces.c b/ivi-layermanagement-examples/layer-add-surfaces/src/layer-add-surfaces.c index 5a31fa3..a271da2 100644 --- a/ivi-layermanagement-examples/layer-add-surfaces/src/layer-add-surfaces.c +++ b/ivi-layermanagement-examples/layer-add-surfaces/src/layer-add-surfaces.c @@ -96,6 +96,35 @@ static void callbackFunction(ilmObjectType object, t_ilm_uint id, t_ilm_bool cre } } +static void shutdownCallbackFunction(t_ilm_shutdown_error_type error_type, + int errornum, + void *user_data) +{ + (void) user_data; + + switch (error_type) { + case ILM_ERROR_WAYLAND: + { + printf("layer-add-surfaces: exit, ilm shutdown due to wayland error: %s\n", + strerror(errornum)); + break; + } + case ILM_ERROR_POLL: + { + printf("layer-add-surfaces: exit, ilm shutdown due to poll error: %s\n", + strerror(errornum)); + break; + } + default: + { + printf("layer-add-surfaces: exit, ilm shutdown due to unknown reason: %s\n", + strerror(errornum)); + } + } + + exit(1); +} + /* Choose the display with the largest resolution.*/ static t_ilm_uint choose_screen(void) { @@ -235,6 +264,8 @@ int main (int argc, char *argv[]) return -1; } + ilm_registerShutdownNotification(shutdownCallbackFunction, NULL); + screen_ID = choose_screen(); ilm_layerCreateWithDimension(&layer, screenWidth, screenHeight); printf("layer-add-surfaces: layer (%d) destination region: x:0 y:0 w:%u h:%u\n", layer, screenWidth, screenHeight); -- cgit v1.2.1