4 #include <wayland-server.h>
6 #include <libds/output.h>
7 #include <tizen-dpms-server-protocol.h>
8 #include "libds-tizen/dpms.h"
13 struct wl_global *global;
14 struct wl_resource *res;
16 struct wl_listener destroy;
19 struct wl_signal destroy;
20 struct wl_signal set_dpms;
21 struct wl_signal get_dpms;
27 #define TIZEN_DPMS_VERSION 1
29 static void dpms_handle_display_destroy(struct wl_listener *listener,
31 static void dpms_bind(struct wl_client *wl_client, void *data,
32 uint32_t verison, uint32_t id);
34 WL_EXPORT struct ds_tizen_dpms *
35 ds_tizen_dpms_create(struct wl_display *display)
37 struct ds_tizen_dpms *dpms;
39 dpms = calloc(1, sizeof *dpms);
41 ds_err("dpms create fail : memory alloc failed");
45 dpms->global = wl_global_create(display, &tizen_dpms_manager_interface,
48 ds_err("global create fail : tizen_dpms_manager_interface failed");
53 wl_signal_init(&dpms->events.destroy);
54 wl_signal_init(&dpms->events.set_dpms);
55 wl_signal_init(&dpms->events.get_dpms);
57 dpms->destroy.notify = dpms_handle_display_destroy;
58 wl_display_add_destroy_listener(display, &dpms->destroy);
60 ds_inf("global create : tizen_dpms_manager(%p)", dpms);
66 ds_tizen_dpms_add_destroy_listener(struct ds_tizen_dpms *dpms,
67 struct wl_listener *listener)
69 wl_signal_add(&dpms->events.destroy, listener);
73 ds_tizen_dpms_add_set_dpms_listener(struct ds_tizen_dpms *dpms,
74 struct wl_listener *listener)
76 wl_signal_add(&dpms->events.set_dpms, listener);
80 ds_tizen_dpms_add_get_dpms_listener(struct ds_tizen_dpms *dpms,
81 struct wl_listener *listener)
83 wl_signal_add(&dpms->events.get_dpms, listener);
87 ds_tizen_dpms_send_set_result(struct ds_tizen_dpms *dpms,
88 enum ds_tizen_dpms_mode mode, enum ds_tizen_dpms_error error)
90 ds_dbg("dpms send set result : mode(%d), error(%d)", mode, error);
91 tizen_dpms_manager_send_set_state(dpms->res, mode, error);
95 ds_tizen_dpms_send_get_result(struct ds_tizen_dpms *dpms,
96 enum ds_tizen_dpms_mode mode, enum ds_tizen_dpms_error error)
98 ds_dbg("dpms send get result : mode(%d), error(%d)", mode, error);
99 tizen_dpms_manager_send_get_state(dpms->res, mode, error);
103 dpms_handle_display_destroy(struct wl_listener *listener, void *data)
105 struct ds_tizen_dpms *dpms;
107 dpms = wl_container_of(listener, dpms, destroy);
109 ds_inf("global destroy : tizen_dpms_manager(%p)", dpms);
111 wl_signal_emit(&dpms->events.destroy, dpms);
112 wl_list_remove(&dpms->destroy.link);
113 wl_resource_set_user_data(dpms->res, NULL);
114 wl_global_destroy(dpms->global);
119 _tizen_dpms_manager_handle_destroy(struct wl_client *client,
120 struct wl_resource *resource)
122 ds_inf("tizen_dpms_manager cb_destroy (res:%p)", resource);
123 wl_resource_destroy(resource);
127 _tizen_dpms_manager_handle_set_dpms(struct wl_client *client,
128 struct wl_resource *resource, struct wl_resource *output, uint32_t mode)
130 struct ds_tizen_dpms *dpms;
132 dpms = wl_resource_get_user_data(resource);
134 if (mode > DS_TIZEN_DPMS_MODE_OFF) {
135 ds_err("set dpms error : not supported mode(%d)", mode);
136 tizen_dpms_manager_send_set_state(resource, DS_TIZEN_DPMS_MODE_OFF,
137 DS_TIZEN_DPMS_ERROR_INVALID_PARAMETER);
141 struct ds_tizen_dpms_event event = {
145 wl_signal_emit(&dpms->events.set_dpms, &event);
149 _tizen_dpms_manager_handle_get_dpms(struct wl_client *client,
150 struct wl_resource *resource, struct wl_resource *output)
152 struct ds_tizen_dpms *dpms;
154 dpms = wl_resource_get_user_data(resource);
156 wl_signal_emit(&dpms->events.get_dpms, NULL);
159 static const struct tizen_dpms_manager_interface dpms_impl =
161 _tizen_dpms_manager_handle_destroy,
162 _tizen_dpms_manager_handle_set_dpms,
163 _tizen_dpms_manager_handle_get_dpms,
167 _tizen_dpms_client_cb_destroy(struct wl_resource *resource)
169 struct ds_tizen_dpms *dpms;
171 ds_inf("tizen_dpms_client_cb_destroy (res:%p)", resource);
173 dpms = wl_resource_get_user_data(resource);
175 dpms->binded = false;
181 dpms_bind(struct wl_client *client, void *data, uint32_t version,
184 struct ds_tizen_dpms *dpms = data;
186 if (dpms->binded == true) {
187 //support only one client.
188 ds_err("dpms bind error : already binded.");
192 dpms->res = wl_resource_create(client, &tizen_dpms_manager_interface,
193 MIN(version, TIZEN_DPMS_VERSION), id);
194 if (dpms->res == NULL) {
195 ds_err("dpms bind error : wl_resource_create failed.");
196 wl_client_post_no_memory(client);
200 wl_resource_set_implementation(dpms->res, &dpms_impl, dpms,
201 _tizen_dpms_client_cb_destroy);