summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRajendraprasad K J <KarammelJayakumar.Rajendraprasad@in.bosch.com>2020-03-30 08:16:54 +0200
committerRajendraprasad K J <KarammelJayakumar.Rajendraprasad@in.bosch.com>2020-07-08 07:24:38 +0200
commite63979fedeb5947ed8a7902ff57ec1137d8e739d (patch)
tree7819d0f13459f64003933f4b7a06d66a809d7221
parent9bc63f152c48c5078bca8353c8d8f30293603257 (diff)
downloadwayland-ivi-extension-e63979fedeb5947ed8a7902ff57ec1137d8e739d.tar.gz
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 <KarammelJayakumar.Rajendraprasad@in.bosch.com>
-rw-r--r--ivi-layermanagement-api/ilmControl/include/ilm_control_platform.h3
-rw-r--r--ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c57
2 files changed, 60 insertions, 0 deletions
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))