From adc35911d3d6860040e10c52e9d9616f1f1ba9b6 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 21 Jul 2022 13:54:34 +0900 Subject: [PATCH] impelement libds-tizen-display-policy This is the server implementation for tizen_display_policy protocol. Change-Id: Idfa58ce16a1e6183cd3f44b5ac31d5a94e78233c --- include/libds-tizen/display_policy.h | 56 +++++++ packaging/libds-tizen.spec | 30 ++++ src/display_policy/display_policy.c | 305 +++++++++++++++++++++++++++++++++++ src/display_policy/meson.build | 29 ++++ src/meson.build | 1 + 5 files changed, 421 insertions(+) create mode 100644 include/libds-tizen/display_policy.h create mode 100644 src/display_policy/display_policy.c create mode 100644 src/display_policy/meson.build diff --git a/include/libds-tizen/display_policy.h b/include/libds-tizen/display_policy.h new file mode 100644 index 0000000..e0ee118 --- /dev/null +++ b/include/libds-tizen/display_policy.h @@ -0,0 +1,56 @@ +#ifndef LIBDS_TIZEN_DISPLAY_POLICY_H +#define LIBDS_TIZEN_DISPLAY_POLICY_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct ds_tizen_display_policy; +struct ds_tizen_display_policy_info; + +enum ds_tizen_display_policy_error_state +{ + DS_TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE, + DS_TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED, +}; + +struct ds_tizen_display_policy * +ds_tizen_display_policy_create(struct wl_display *display); + +void +ds_tizen_display_policy_add_destroy_listener( + struct ds_tizen_display_policy *display_policy, + struct wl_listener *listener); + +void +ds_tizen_display_policy_add_set_brightness_info_listener( + struct ds_tizen_display_policy *display_policy, + struct wl_listener *listener); + +void +ds_tizen_display_policy_info_add_destroy_listener( + struct ds_tizen_display_policy_info *info, + struct wl_listener *listener); + +struct ds_surface * +ds_tizen_display_policy_info_get_surface( + struct ds_tizen_display_policy_info *info); + +int32_t +ds_tizen_display_policy_info_get_brightness_value( + struct ds_tizen_display_policy_info *info); + +void +ds_tizen_display_policy_info_send_brightness_done( + struct ds_tizen_display_policy_info *info, + enum ds_tizen_display_policy_error_state error_state); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 27af91c..372f0c3 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -169,6 +169,21 @@ Group: Development/Libraries %description launch-devel Development package for tizen launch +## libds-tizen-display-policy +%package display-policy +Summary: Library for tizen display-policy +Group: Development/Libraries + +%description display-policy +Library for tizen display-policy + +%package display-policy-devel +Summary: Development package for tizen display-policy +Group: Development/Libraries + +%description display-policy-devel +Development package for tizen display-policy + %prep %setup -q cp %{SOURCE1001} . @@ -310,6 +325,7 @@ ninja -C builddir install %{_libdir}/libds-tizen-clipboard.so %{_bindir}/libds-tizen-clipboard-tests +<<<<<<< HEAD %files launch %manifest %{name}.manifest %defattr(-,root,root,-) @@ -324,3 +340,17 @@ ninja -C builddir install %{_libdir}/pkgconfig/libds-tizen-launch.pc %{_libdir}/libds-tizen-launch.so %{_bindir}/libds-tizen-launch-appinfo-tests + +%files display-policy +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_libdir}/libds-tizen-display-policy.so.* + +%files display-policy-devel +%manifest %{name}.manifest +%defattr(-,root,root,-) +%license LICENSE +%{_includedir}/libds-tizen/display_policy.h +%{_libdir}/pkgconfig/libds-tizen-display-policy.pc +%{_libdir}/libds-tizen-display-policy.so diff --git a/src/display_policy/display_policy.c b/src/display_policy/display_policy.c new file mode 100644 index 0000000..e278888 --- /dev/null +++ b/src/display_policy/display_policy.c @@ -0,0 +1,305 @@ +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "libds-tizen/display_policy.h" + +#define TIZEN_DISPLAY_POLICY_VERSION 1 + +struct ds_tizen_display_policy +{ + struct wl_global *global; + + struct wl_list clients; + + struct wl_listener destroy; + + struct { + struct wl_signal destroy; + struct wl_signal set_brightness; + } events; +}; + +struct ds_tizen_display_policy_client +{ + struct ds_tizen_display_policy *display_policy; + + struct wl_resource *resource; + struct wl_client *wl_client; + + struct wl_list infos; + + struct { + struct wl_signal destroy; + } events; + + struct wl_list link; // ds_tizen_display_policy::clients +}; + +struct ds_tizen_display_policy_info +{ + struct ds_tizen_display_policy_client *client; + + struct ds_surface *surface; + + int32_t brightness_value; + + struct wl_list link; // ds_tizen_display_policy_client::infos +}; + +static void display_policy_handle_display_destroy(struct wl_listener *listener, + void *data); + +static void display_policy_bind(struct wl_client *wl_client, void *data, + uint32_t version, uint32_t id); + +static struct ds_tizen_display_policy_info *tizen_display_policy_client_find_info( + struct ds_tizen_display_policy_client *client, + struct ds_surface *surface); + +static struct ds_tizen_display_policy_info *tizen_display_policy_client_get_info( + struct ds_tizen_display_policy_client *client, + struct ds_surface *surface); + +WL_EXPORT struct ds_tizen_display_policy * +ds_tizen_display_policy_create(struct wl_display *display) +{ + struct ds_tizen_display_policy *display_policy; + + display_policy = calloc(1, sizeof *display_policy); + if (!display_policy) { + ds_err("calloc() failed."); + return NULL; + } + + display_policy->global = wl_global_create(display, &tizen_display_policy_interface, + TIZEN_DISPLAY_POLICY_VERSION, display_policy, display_policy_bind); + if (!display_policy->global) { + ds_err("wl_global_create() failed. tizen_display_policy_interface"); + free(display_policy); + return NULL; + } + + wl_list_init(&display_policy->clients); + + display_policy->destroy.notify = display_policy_handle_display_destroy; + wl_display_add_destroy_listener(display, &display_policy->destroy); + + wl_signal_init(&display_policy->events.destroy); + wl_signal_init(&display_policy->events.set_brightness); + + ds_inf("Global created: tizen_display_policy(%p)", display_policy); + + return display_policy; +} + +WL_EXPORT void +ds_tizen_display_policy_add_destroy_listener(struct ds_tizen_display_policy *display_policy, + struct wl_listener *listener) +{ + wl_signal_add(&display_policy->events.destroy, listener); +} + +WL_EXPORT void +ds_tizen_display_policy_add_set_brightness_info_listener( + struct ds_tizen_display_policy *display_policy, + struct wl_listener *listener) +{ + wl_signal_add(&display_policy->events.set_brightness, listener); +} + +WL_EXPORT void +ds_tizen_display_policy_info_add_destroy_listener( + struct ds_tizen_display_policy_info *info, + struct wl_listener *listener) +{ + wl_signal_add(&info->client->events.destroy, listener); +} + +WL_EXPORT struct ds_surface * +ds_tizen_display_policy_info_get_surface( + struct ds_tizen_display_policy_info *info) +{ + return info->surface; +} + +WL_EXPORT int32_t +ds_tizen_display_policy_info_get_brightness_value( + struct ds_tizen_display_policy_info *info) +{ + return info->brightness_value; +} + +WL_EXPORT void +ds_tizen_display_policy_info_send_brightness_done( + struct ds_tizen_display_policy_info *info, + enum ds_tizen_display_policy_error_state error_state) +{ + tizen_display_policy_send_window_brightness_done(info->client->resource, + ds_surface_get_wl_resource(info->surface), info->brightness_value, + error_state); +} + +static struct ds_tizen_display_policy_info * +tizen_display_policy_client_find_info(struct ds_tizen_display_policy_client *client, + struct ds_surface *surface) +{ + struct ds_tizen_display_policy_info *info; + + wl_list_for_each(info, &client->infos, link) { + if (surface == info->surface) + return info; + } + + return NULL; +} + +static struct ds_tizen_display_policy_info * +tizen_display_policy_client_get_info(struct ds_tizen_display_policy_client *client, + struct ds_surface *surface) +{ + struct ds_tizen_display_policy_info *info; + + info = tizen_display_policy_client_find_info(client, surface); + if (info) + return info; + + info = calloc(1, sizeof *info); + if (info == NULL) { + ds_err("calloc() failed. tizen_display_policy"); + return NULL; + } + + info->client = client; + info->surface = surface; + + wl_list_insert(&client->infos, &info->link); + + return info; +} + +static void +display_policy_handle_display_destroy(struct wl_listener *listener, void *data) +{ + struct ds_tizen_display_policy *display_policy; + + display_policy = wl_container_of(listener, display_policy, destroy); + + ds_inf("Global destroy: display_policy(%p)", display_policy); + + wl_signal_emit(&display_policy->events.destroy, display_policy); + wl_list_remove(&display_policy->destroy.link); + wl_global_destroy(display_policy->global); + free(display_policy); +} + +static void +display_policy_handle_destroy(struct wl_client *wl_client, + struct wl_resource *resource) +{ + struct ds_tizen_display_policy_client *client; + + client = wl_resource_get_user_data(resource); + + if (!wl_list_empty(&client->infos)) { + ds_err("tizen_display_policy was destroyed before children"); + return; + } + + wl_resource_destroy(resource); +} + +static void +display_policy_handle_set_brightness(struct wl_client *wl_client, + struct wl_resource *resource, struct wl_resource *surface_resource, + int32_t brightness_value) +{ + struct ds_tizen_display_policy_client *client; + struct ds_tizen_display_policy_info *info; + struct ds_surface *surface; + + ds_inf("tizen_display_policy: set_brightness"); + + client = wl_resource_get_user_data(resource); + surface = ds_surface_from_resource(surface_resource); + + info = tizen_display_policy_client_get_info(client, surface); + if (info == NULL) { + ds_err("tizen_display_policy_client_get_info() failed. tizen_display_policy"); + wl_client_post_no_memory(wl_client); + return; + } + + info->brightness_value = brightness_value; + + wl_signal_emit(&client->display_policy->events.set_brightness, info); +} + +static const struct tizen_display_policy_interface display_policy_impl = +{ + display_policy_handle_set_brightness, + display_policy_handle_destroy, +}; + +static void +_tizen_display_policy_client_handle_destroy(struct wl_resource *resource) +{ + struct ds_tizen_display_policy_client *client; + struct ds_tizen_display_policy_info *info, *tmp; + + client = wl_resource_get_user_data(resource); + + ds_inf("_tizen_display_policy_client_handle_destroy (client:%p)", client); + + wl_list_for_each_safe(info, tmp, &client->infos, link) { + wl_signal_emit(&client->events.destroy, info); + wl_list_remove(&info->link); + free(info); + } + + wl_list_remove(&client->link); + free(client); +} + +static void +display_policy_bind(struct wl_client *wl_client, void *data, uint32_t version, + uint32_t id) +{ + struct ds_tizen_display_policy *display_policy = data; + struct ds_tizen_display_policy_client *client; + + client = calloc(1, sizeof *client); + if (client == NULL) { + ds_err("calloc() failed. tizen_display_policy"); + wl_client_post_no_memory(wl_client); + return; + } + + ds_inf("tizen_display_policy_client binds. (client:%p)", client); + + client->display_policy = display_policy; + client->wl_client = wl_client; + + wl_list_init(&client->infos); + + client->resource = wl_resource_create(wl_client, &tizen_display_policy_interface, + MIN(version, TIZEN_DISPLAY_POLICY_VERSION), id); + + if (client->resource == NULL) { + ds_err("tizen_display_policy : wl_resource_create() failed."); + free(client); + wl_client_post_no_memory(wl_client); + return; + } + + wl_resource_set_implementation(client->resource, &display_policy_impl, client, + _tizen_display_policy_client_handle_destroy); + + wl_signal_init(&client->events.destroy); + + wl_list_insert(&display_policy->clients, &client->link); +} diff --git a/src/display_policy/meson.build b/src/display_policy/meson.build new file mode 100644 index 0000000..1ad17e9 --- /dev/null +++ b/src/display_policy/meson.build @@ -0,0 +1,29 @@ +libds_tizen_display_policy_files = [ + 'display_policy.c', +] + +libds_tizen_display_policy_deps = [ + deps_libds_tizen, + dependency('tizen-extension-server', required: true), +] + +lib_libds_tizen_display_policy = shared_library('ds-tizen-display-policy', libds_tizen_display_policy_files, + dependencies: libds_tizen_display_policy_deps, + include_directories: [ common_inc, include_directories('.'), include_directories('..') ], + version: meson.project_version(), + install: true +) + +deps_libds_tizen_display_policy = declare_dependency( + link_with: lib_libds_tizen_display_policy, + dependencies: libds_tizen_display_policy_deps, + include_directories: [ common_inc, include_directories('.') ], +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds_tizen_display_policy, + version: meson.project_version(), + filebase: 'libds-tizen-display-policy', + name: 'libds-tizen-display-policy', + description: 'tizen display-policy extension of libds-tizen for tizen platform', +) diff --git a/src/meson.build b/src/meson.build index 3ea00d7..d0bb024 100644 --- a/src/meson.build +++ b/src/meson.build @@ -36,3 +36,4 @@ subdir('dpms') subdir('indicator') subdir('clipboard') subdir('launch') +subdir('display_policy') -- 2.7.4