display: Add rotation angle interface
[platform/core/system/deviced.git] / plugins / iot-headless / display / core.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <shared/common.h>
20 #include <shared/devices.h>
21 #include <hal/device/hal-display.h>
22 #include <libsyscommon/libgdbus.h>
23
24 static GVariant *dbus_lockstate(GDBusConnection *conn,
25         const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
26         GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
27 {
28         return g_variant_new("(i)", 0);
29 }
30
31 static GVariant *dbus_unlockstate(GDBusConnection *conn,
32         const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
33         GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
34 {
35         return g_variant_new("(i)", 0);
36 }
37
38 static GVariant *dbus_getrotationangle(GDBusConnection *conn,
39         const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
40         GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
41 {
42         int ret;
43         int display_index;
44         enum hal_device_display_rotation_angle angle;
45
46         g_variant_get(param, "(i)", &display_index);
47         ret = hal_device_display_get_rotation_angle(display_index, &angle);
48         if (ret < 0)
49                 angle = HAL_DEVICE_DISPLAY_ROTATION_ANGLE_UNKNOWN;
50
51         return g_variant_new("(ii)", ret, angle);
52 }
53
54 static GVariant *dbus_setrotationangle(GDBusConnection *conn,
55         const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
56         GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
57 {
58         int ret;
59         int display_index;
60         enum hal_device_display_rotation_angle angle;
61         enum hal_device_display_rotation_direction direction;
62
63         g_variant_get(param, "(iii)", &display_index, &angle, &direction);
64         ret = hal_device_display_set_rotation_angle(display_index, angle, direction);
65
66         return g_variant_new("(i)", ret);
67 }
68
69 static const dbus_method_s dbus_methods[] = {
70         { "lockstate",        "sssi", "i", dbus_lockstate },
71         { "unlockstate",      "ss",   "i", dbus_unlockstate },
72         { "GetRotationAngle", "i",    "ii", dbus_getrotationangle },
73         { "SetRotationAngle", "iii",   "i", dbus_setrotationangle }
74 };
75
76 static const dbus_interface_u dbus_interface = {
77         .oh = NULL,
78         .name = DEVICED_INTERFACE_DISPLAY,
79         .methods = dbus_methods,
80         .nr_methods = ARRAY_SIZE(dbus_methods),
81 };
82
83 static void display_init(void *data)
84 {
85         gdbus_add_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface);
86 }
87
88 static const struct device_ops display_device_ops = {
89         .priority = DEVICE_PRIORITY_HIGH,
90         DECLARE_NAME_LEN("display"),
91         .init     = display_init,
92 };
93
94 DEVICE_OPS_REGISTER(&display_device_ops)