diff options
author | Eugen Friedrich <efriedrich@de.adit-jv.com> | 2021-01-03 20:04:27 +0100 |
---|---|---|
committer | Eugen Friedrich <efriedrich@de.adit-jv.com> | 2021-01-03 20:04:27 +0100 |
commit | b9ea324bba2dcc4587df8cadc110df12a2aa29a4 (patch) | |
tree | c0bb581d1d134c6ac47a665021f597b845f89b2a | |
parent | 2ec37542c8f5045c3ff313a38102f9725e0bfb16 (diff) | |
parent | efeaedd6b9e363cec82bf72617bf35269374b7ef (diff) | |
download | wayland-ivi-extension-b9ea324bba2dcc4587df8cadc110df12a2aa29a4.tar.gz |
Merge remote-tracking branch 'upstream/pull/115'
* upstream/pull/115
layer-add-surfaces: Register for ilm shutdown notification
ilmCommon: Implement a shutdown notification for ilm
ilmControl: Implement a shutdown notification for ilm
Reviewed-by: Eugen Friedrich <efriedrich@de.adit-jv.com>
6 files changed, 130 insertions, 0 deletions
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 @@ -65,6 +65,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 * \return ILM_SUCCESS if the method call was successful 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 @@ -249,6 +249,16 @@ typedef enum } 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 */ typedef void(*layerNotificationFunc)(t_ilm_layer 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; @@ -98,6 +101,12 @@ ilm_isInitialized(void) } ILM_EXPORT ilmErrorTypes +ilm_registerShutdownNotification(shutdownNotificationFunc callback, void *user_data) +{ + return ilmControl_registerShutdownNotification(callback, user_data); +} + +ILM_EXPORT ilmErrorTypes ilm_destroy(void) { ilmErrorTypes retVal; 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)) 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); |