client: add simple-dpms 07/278207/1
authorJunkyeong Kim <jk0430.kim@samsung.com>
Tue, 7 Jun 2022 04:34:43 +0000 (13:34 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 18 Jul 2022 05:58:50 +0000 (14:58 +0900)
Change-Id: Idf32c869b660f568ab6514d542396c40f32dc6c6
Signed-off-by: Junkyeong Kim <jk0430.kim@samsung.com>
packaging/libds.spec
src/clients/meson.build
src/clients/simple-dpms.c [new file with mode: 0644]

index aefff95..6260ed2 100644 (file)
@@ -23,6 +23,7 @@ BuildRequires:  pkgconfig(libtbm)
 BuildRequires:  pkgconfig(wayland-tbm-server)
 BuildRequires:  pkgconfig(wayland-tbm-client)
 BuildRequires:  pkgconfig(tizen-dpms-server)
+BuildRequires:  pkgconfig(tizen-dpms-client)
 BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(cynara-session)
 BuildRequires:  pkgconfig(libsmack)
@@ -108,6 +109,7 @@ ninja -C builddir install
 %{_bindir}/tinyds-tdm-libinput
 %{_bindir}/ds-simple-shm-shell
 %{_bindir}/tinyds-tdm-dpms
+%{_bindir}/ds-simple-dpms
 
 %files tizen-keyrouter
 %manifest %{name}.manifest
index 009016c..6fcd3f8 100644 (file)
@@ -55,3 +55,13 @@ executable('ds-simple-tbm',
   install_dir: libds_bindir,
   install: true,
 )
+
+executable('ds-simple-dpms',
+  'simple-dpms.c',
+  dependencies: [
+      dependency('wayland-client', required: true),
+      dependency('tizen-dpms-client', required: true),
+    ],
+  install_dir: libds_bindir,
+  install: true,
+)
diff --git a/src/clients/simple-dpms.c b/src/clients/simple-dpms.c
new file mode 100644 (file)
index 0000000..9b4d22c
--- /dev/null
@@ -0,0 +1,239 @@
+/*
+Copyright (C) 2015 - 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact:
+      SooChan Lim <sc1.lim@samsung.com>
+      Changyeon Lee <cyeon.lee@samsung.com>
+      JunKyeong Kim <jk0430.kim@samsung.com>
+      Boram Park <boram1288.park@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <sys/syscall.h>
+#include <poll.h>
+
+#include <wayland-client.h>
+#include <tizen-extension-client-protocol.h>
+#include <tizen-dpms-client-protocol.h>
+
+
+struct wl_dpms_info {
+       char *app_name;
+
+       struct wl_display *display;
+       struct wl_registry *registry;
+       struct wl_output *output;
+       struct tizen_dpms_manager *tz_dpms_mng;
+       int got_dpms_state;
+};
+
+void
+usage(const char *app_name)
+{
+       printf("usage: %s \n", app_name);
+       printf("%s output_num option(set1/get0) state\nex)\n", app_name);
+       printf("%s 1 0  => set dpms_on\n", app_name);
+       printf("%s 1 3  => set dpms_off\n", app_name);
+       printf("%s 0 0  => get state\n", app_name);
+}
+
+static struct wl_dpms_info *
+_create_wl_dpms_info (void)
+{
+       struct wl_dpms_info *test_info = NULL;
+
+       test_info = calloc(1, sizeof(struct wl_dpms_info));
+       if (test_info == NULL) {
+               printf("alloc fail");
+               return NULL;
+       }
+
+       return test_info;
+}
+
+static void
+_destroy_wl_dpms_info (struct wl_dpms_info *test_info)
+{
+       if (!test_info) return;
+
+       if (test_info->app_name)
+               free(test_info->app_name);
+       if (test_info->tz_dpms_mng)
+               tizen_dpms_manager_destroy(test_info->tz_dpms_mng);
+       if (test_info->registry)
+               wl_registry_destroy(test_info->registry);
+       if (test_info->display)
+               wl_display_disconnect(test_info->display);
+
+       free(test_info);
+}
+
+static void
+dpms_handle_set_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error)
+{
+       struct wl_dpms_info *test_info = (struct wl_dpms_info *)data;
+       printf("dpms_set_state_cb - mode:%d, error:%d\n", mode, error);
+       test_info->got_dpms_state = 1;
+}
+
+static void
+dpms_handle_get_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error)
+{
+       struct wl_dpms_info *test_info = (struct wl_dpms_info *)data;
+       printf("dpms_get_state_cb - mode:%d, error:%d\n", mode, error);
+       test_info->got_dpms_state = 1;
+}
+
+static const struct tizen_dpms_manager_listener dpms_listener = {
+       dpms_handle_set_state,
+       dpms_handle_get_state
+};
+
+static void
+handle_global(void *data, struct wl_registry *registry,
+                               uint32_t name, const char *interface, uint32_t version)
+{
+       struct wl_dpms_info *test_info = (struct wl_dpms_info *)data;
+
+       if (strcmp(interface, "wl_output") == 0) {
+               test_info->output = wl_registry_bind(registry, name, &wl_output_interface, 2);
+               if (!test_info->output)
+                       printf("bind wl_output fail\n");
+               else
+                       printf("bind wl_output\n");
+       } else if (strcmp(interface, "tizen_dpms_manager") == 0) {
+               test_info->tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1);
+               if (!test_info->tz_dpms_mng)
+                       printf("bind tizen_dpms_manager fail\n");
+               else {
+                       tizen_dpms_manager_add_listener(test_info->tz_dpms_mng, &dpms_listener, test_info);
+                       printf("bind tizen_dpms_manager\n");
+               }
+       }
+}
+
+static void
+handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
+{
+}
+
+static const struct wl_registry_listener registry_listener = {
+       handle_global,
+       handle_global_remove
+};
+
+int
+main(int argc, char *argv[])
+{
+       struct wl_dpms_info *test_info = NULL;
+       char *opt = NULL;
+       int option;
+       char *sta = NULL;
+       int state = 0;
+
+       test_info = _create_wl_dpms_info();
+       if (test_info == NULL) return 0;
+
+       test_info->app_name = strdup(argv[0]);
+       if (test_info->app_name == NULL) {
+               printf("alloc fail");
+               goto done;
+       }
+       if (argc != 3) {
+               usage(test_info->app_name);
+               goto done;
+       }
+
+       opt = strdup(argv[1]);
+       if (opt == NULL) {
+               printf("alloc fail");
+               goto done;
+       }
+       option = opt[0] - '0';
+       free(opt);
+       if (!(option == 0 || option == 1)) {
+               usage(test_info->app_name);
+               goto done;
+       }
+
+       if (option == 1) {
+               sta = strdup(argv[2]);
+               if (sta == NULL) {
+                       printf("alloc fail");
+                       goto done;
+               }
+               state = sta [0] - '0';
+               free(sta);
+               if (!(state == 0 || state == 1 || state == 2 || state == 3)) {
+                       usage(test_info->app_name);
+                       goto done;
+               }
+       }
+
+       test_info->display = wl_display_connect(NULL);
+       if (test_info->display == NULL) {
+               printf("wl_display_connect fail");
+               goto done;
+       }
+
+       test_info->registry = wl_display_get_registry(test_info->display);
+       if (test_info->registry == NULL) {
+               printf("wl_display_get_registry fail");
+               goto done;
+       }
+
+       wl_registry_add_listener(test_info->registry, &registry_listener, test_info);
+       wl_display_roundtrip(test_info->display);
+
+       if (!test_info->output || !test_info->tz_dpms_mng) {
+               printf("bind fail\n");
+               goto done;
+       }
+
+       if (option == 1) {
+               tizen_dpms_manager_set_dpms(test_info->tz_dpms_mng, test_info->output, state);
+               printf("set dpms %d\n", state);
+       } else {
+               tizen_dpms_manager_get_dpms(test_info->tz_dpms_mng, test_info->output);
+               printf("get dpms\n");
+       }
+
+       test_info->got_dpms_state = 0;
+       while (!test_info->got_dpms_state) {
+               wl_display_roundtrip(test_info->display);
+       }
+
+done:
+       _destroy_wl_dpms_info(test_info);
+
+       return 0;
+}
+