2 Copyright (C) 2015 - 2016 Samsung Electronics co., Ltd. All Rights Reserved.
5 SooChan Lim <sc1.lim@samsung.com>
6 Changyeon Lee <cyeon.lee@samsung.com>
7 JunKyeong Kim <jk0430.kim@samsung.com>
8 Boram Park <boram1288.park@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the "Software"),
12 to deal in the Software without restriction, including without limitation
13 the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 and/or sell copies of the Software, and to permit persons to whom the
15 Software is furnished to do so, subject to the following conditions:
17 The above copyright notice and this permission notice (including the next
18 paragraph) shall be included in all copies or substantial portions of the
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
37 #include <sys/param.h>
40 #include <sys/syscall.h>
43 #include <wayland-client.h>
44 #include <tizen-extension-client-protocol.h>
45 #include <tizen-dpms-client-protocol.h>
51 struct wl_display *display;
52 struct wl_registry *registry;
53 struct wl_output *output;
54 struct tizen_dpms_manager *tz_dpms_mng;
59 usage(const char *app_name)
61 printf("usage: %s \n", app_name);
62 printf("%s output_num option(set1/get0) state\nex)\n", app_name);
63 printf("%s 1 0 => set dpms_on\n", app_name);
64 printf("%s 1 3 => set dpms_off\n", app_name);
65 printf("%s 0 0 => get state\n", app_name);
68 static struct wl_dpms_info *
69 _create_wl_dpms_info (void)
71 struct wl_dpms_info *test_info = NULL;
73 test_info = calloc(1, sizeof(struct wl_dpms_info));
74 if (test_info == NULL) {
83 _destroy_wl_dpms_info (struct wl_dpms_info *test_info)
85 if (!test_info) return;
87 if (test_info->app_name)
88 free(test_info->app_name);
89 if (test_info->tz_dpms_mng)
90 tizen_dpms_manager_destroy(test_info->tz_dpms_mng);
91 if (test_info->registry)
92 wl_registry_destroy(test_info->registry);
93 if (test_info->display)
94 wl_display_disconnect(test_info->display);
100 dpms_handle_set_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error)
102 struct wl_dpms_info *test_info = (struct wl_dpms_info *)data;
103 printf("dpms_set_state_cb - mode:%d, error:%d\n", mode, error);
104 test_info->got_dpms_state = 1;
108 dpms_handle_get_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error)
110 struct wl_dpms_info *test_info = (struct wl_dpms_info *)data;
111 printf("dpms_get_state_cb - mode:%d, error:%d\n", mode, error);
112 test_info->got_dpms_state = 1;
115 static const struct tizen_dpms_manager_listener dpms_listener = {
116 dpms_handle_set_state,
117 dpms_handle_get_state
121 handle_global(void *data, struct wl_registry *registry,
122 uint32_t name, const char *interface, uint32_t version)
124 struct wl_dpms_info *test_info = (struct wl_dpms_info *)data;
126 if (strcmp(interface, "wl_output") == 0) {
127 test_info->output = wl_registry_bind(registry, name, &wl_output_interface, 2);
128 if (!test_info->output)
129 printf("bind wl_output fail\n");
131 printf("bind wl_output\n");
132 } else if (strcmp(interface, "tizen_dpms_manager") == 0) {
133 test_info->tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1);
134 if (!test_info->tz_dpms_mng)
135 printf("bind tizen_dpms_manager fail\n");
137 tizen_dpms_manager_add_listener(test_info->tz_dpms_mng, &dpms_listener, test_info);
138 printf("bind tizen_dpms_manager\n");
144 handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
148 static const struct wl_registry_listener registry_listener = {
154 main(int argc, char *argv[])
156 struct wl_dpms_info *test_info = NULL;
162 test_info = _create_wl_dpms_info();
163 if (test_info == NULL) return 0;
165 test_info->app_name = strdup(argv[0]);
166 if (test_info->app_name == NULL) {
167 printf("alloc fail");
171 usage(test_info->app_name);
175 opt = strdup(argv[1]);
177 printf("alloc fail");
180 option = opt[0] - '0';
182 if (!(option == 0 || option == 1)) {
183 usage(test_info->app_name);
188 sta = strdup(argv[2]);
190 printf("alloc fail");
193 state = sta [0] - '0';
195 if (!(state == 0 || state == 1 || state == 2 || state == 3)) {
196 usage(test_info->app_name);
201 test_info->display = wl_display_connect(NULL);
202 if (test_info->display == NULL) {
203 printf("wl_display_connect fail");
207 test_info->registry = wl_display_get_registry(test_info->display);
208 if (test_info->registry == NULL) {
209 printf("wl_display_get_registry fail");
213 wl_registry_add_listener(test_info->registry, ®istry_listener, test_info);
214 wl_display_roundtrip(test_info->display);
216 if (!test_info->output || !test_info->tz_dpms_mng) {
217 printf("bind fail\n");
222 tizen_dpms_manager_set_dpms(test_info->tz_dpms_mng, test_info->output, state);
223 printf("set dpms %d\n", state);
225 tizen_dpms_manager_get_dpms(test_info->tz_dpms_mng, test_info->output);
226 printf("get dpms\n");
229 test_info->got_dpms_state = 0;
230 while (!test_info->got_dpms_state) {
231 wl_display_roundtrip(test_info->display);
235 _destroy_wl_dpms_info(test_info);