--- /dev/null
+#ifndef LIBDS_DPMS_H
+#define LIBDS_DPMS_H
+
+#include <stdint.h>
+#include <wayland-server.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ds_tizen_dpms;
+
+enum ds_tizen_dpms_mode
+{
+ DS_TIZEN_DPMS_MODE_ON = 0,
+ DS_TIZEN_DPMS_MODE_STANDBY = 1,
+ DS_TIZEN_DPMS_MODE_SUSPEND = 2,
+ DS_TIZEN_DPMS_MODE_OFF = 3,
+};
+
+enum ds_tizen_dpms_error
+{
+ DS_TIZEN_DPMS_ERROR_NONE = 0,
+ DS_TIZEN_DPMS_ERROR_INVALID_PERMISSION = 1,
+ DS_TIZEN_DPMS_ERROR_INVALID_PARAMETER = 2,
+ DS_TIZEN_DPMS_ERROR_NOT_SUPPORTED = 3,
+ DS_TIZEN_DPMS_ERROR_ALREADY_DONE = 4,
+};
+
+struct ds_tizen_dpms_event
+{
+ //struct ds_output *output;
+ ds_tizen_dpms_mode mode;
+};
+
+struct ds_tizen_dpms *
+ds_tizen_dpms_create(struct wl_display *display);
+
+void
+ds_tizen_dpms_add_destroy_listener(struct ds_tizen_dpms *dpms,
+ struct wl_listener *listener);
+
+void
+ds_tizen_dpms_add_set_dpms_listener(struct ds_tizen_dpms *dpms,
+ struct wl_listener *listener);
+
+void
+ds_tizen_dpms_add_get_dpms_listener(struct ds_tizen_dpms *dpms,
+ struct wl_listener *listener);
+
+void
+ds_tizen_dpms_send_set_result(struct ds_tizen_dpms *dpms,
+ enum ds_tizen_dpms_mode mode, enum ds_tizen_dpms_error error);
+
+void
+ds_tizen_dpms_send_get_result(struct ds_tizen_dpms *dpms,
+ enum ds_tizen_dpms_mode mode, enum ds_tizen_dpms_error error);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <wayland-server.h>
+#include "libds/log.h"
+#include "libds-tizen/dpms.h"
+#include "libds/output.h"
+#include "tizen-dpms-server-protocol.h"
+
+struct ds_tizen_dpms
+{
+ struct wl_global *global;
+ struct wl_resource *res;
+
+ struct wl_listener destroy;
+
+ struct {
+ struct wl_signal destroy;
+ struct wl_signal set_dpms;
+ struct wl_signal get_dpms;
+ } events;
+
+ bool binded;
+};
+
+#define TIZEN_DPMS_VERSION 1
+
+static void dpms_handle_display_destroy(struct wl_listener *listener,
+ void *data);
+static void dpms_bind(struct wl_client *wl_client, void *data,
+ uint32_t verison, uint32_t id);
+
+WL_EXPORT struct ds_tizen_dpms *
+ds_tizen_dpms_create(struct wl_display *display)
+{
+ struct ds_tizen_dpms *dpms;
+
+ dpms = calloc(1, sizeof *dpms);
+ if (!dpms) {
+ ds_err("dpms create fail : memory alloc failed");
+ return NULL;
+ }
+
+ dpms->global = wl_global_create(display, &tizen_dpms_manager_interface,
+ 1, dpms, dpms_bind);
+ if (!dpms->global) {
+ ds_err("global create fail : tizen_dpms_manager_interface failed");
+ free(dpms);
+ return NULL;
+ }
+
+ wl_signal_init(&dpms->events.destroy);
+ wl_signal_init(&dpms->events.set_dpms);
+ wl_signal_init(&dpms->events.get_dpms);
+
+ dpms->display_destroy.notify = dpms_handle_display_destroy;
+ wl_display_add_destroy_listener(display, &dpms->display_destroy);
+
+ ds_inf("global create : tizen_dpms_manager(%p)", dpms);
+
+ return dpms;
+}
+
+WL_EXPORT void
+ds_tizen_dpms_add_destroy_listener(struct ds_tizen_dpms *dpms,
+ struct wl_listener *listener)
+{
+ wl_signal_add(&dpms->events.destroy, listener);
+}
+
+WL_EXPORT void
+ds_tizen_dpms_add_set_dpms_listener(struct ds_tizen_dpms *dpms,
+ struct wl_listener *listener)
+{
+ wl_signal_add(&dpms->events.set_dpms, listener);
+}
+
+WL_EXPORT void
+ds_tizen_dpms_add_get_dpms_listener(struct ds_tizen_dpms *dpms,
+ struct wl_listener *listener)
+{
+ wl_signal_add(&dpms->events.get_dpms, listener);
+}
+
+WL_EXPORT void
+ds_tizen_dpms_send_set_result(struct ds_tizen_dpms *dpms,
+ enum ds_tizen_dpms_mode mode, enum ds_tizen_dpms_error error)
+{
+ ds_dbg("dpms send set result : mode(%d), error(%d)", mode, error);
+ tizen_dpms_manager_send_set_state(dpms->res, mode, error);
+}
+
+WL_EXPORT void
+ds_tizen_dpms_send_get_result(struct ds_tizen_dpms *dpms,
+ enum ds_tizen_dpms_mode mode, enum ds_tizen_dpms_error error)
+{
+ ds_dbg("dpms send get result : mode(%d), error(%d)", mode, error);
+ tizen_dpms_manager_send_get_state(dpms->res, mode, error);
+}
+
+static void
+dpms_handle_display_destroy(struct wl_listener *listener, void *data)
+{
+ struct ds_tizen_dpms *dpms;
+
+ dpms = wl_container_of(listener, dpms, display_destroy);
+
+ ds_inf("global destroy : tizen_dpms_manager(%p)", dpms);
+
+ wl_signal_emit(&dpms->events.destroy, dpms);
+ wl_list_remove(&dpms->display_destroy.link);
+ wl_resource_set_user_data(dpms->res, NULL);
+ wl_global_destroy(dpms->global);
+ free(dpms);
+}
+
+static void
+_tizen_dpms_manager_handle_destroy(struct wl_client *client,
+ struct wl_resource *resource)
+{
+ ds_inf("tizen_dpms_manager cb_destroy (res:%p)", resource);
+ wl_resource_destroy(resource);
+}
+
+static void
+_tizen_dpms_manager_handle_set_dpms(struct wl_client *client,
+ struct wl_resource *resource, struct wl_resource *output, uint32_t mode)
+{
+ struct ds_tizen_dpms *dpms;
+
+ dpms = wl_resource_get_user_data(resource);
+
+ if (mode > DS_TIZEN_DPMS_MODE_OFF) {
+ ds_err("set dpms error : not supported mode(%d)", mode);
+ tizen_dpms_manager_send_set_state(resource, E_DPMS_MODE_OFF,
+ E_DPMS_MANAGER_ERROR_INVALID_PARAMETER);
+ return;
+ }
+
+ struct ds_tizen_dpms_event event = {
+ .mode = mode,
+ };
+
+ wl_signal_emit(&dpms->events.set_dpms, &event);
+}
+
+static void
+_tizen_dpms_manager_handle_get_dpms(struct wl_client *client,
+ struct wl_resource *resource, struct wl_resource *output)
+{
+ struct ds_tizen_dpms *dpms;
+
+ dpms = wl_resource_get_user_data(resource);
+
+ wl_signal_emit(&dpms->events.get_dpms, NULL);
+}
+
+static const struct tizen_dpms_manager_interface dpms_impl =
+{
+ _tizen_dpms_manager_handle_destroy,
+ _tizen_dpms_manager_handle_set_dpms,
+ _tizen_dpms_manager_handle_get_dpms,
+};
+
+static void
+_tizen_dpms_client_cb_destroy(struct wl_resource *resource)
+{
+ struct ds_tizen_dpms *dpms;
+
+ ds_inf("tizen_dpms_client_cb_destroy (res:%p)", resource);
+
+ dpms = wl_resource_get_user_data(resource);
+ if (dpms) {
+ dpms->binded = false;
+ dpms->res = NULL;
+ }
+}
+
+static void
+dpms_bind(struct wl_client *client, void *data, uint32_t version,
+ uint32_t id)
+{
+ struct ds_tizen_dpms *dpms = data;
+
+ if (dpms->binded == true) {
+ //support only one client.
+ ds_err("dpms bind error : already binded.");
+ return;
+ }
+
+ dpms->res = wl_resource_create(client, &tizen_dpms_manager_interface,
+ MIN(version, TIZEN_DPMS_VERSION), id);
+ if (dpms->res == NULL) {
+ ds_err("dpms bind error : wl_resource_create failed.");
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ wl_resource_set_implementation(dpms->res, &dpms_impl, dpms,
+ _tizen_dpms_client_cb_destroy);
+
+ dpms->binded = true;
+}