Improve variable naming style
[platform/core/system/deviced.git] / src / libdeviced / led.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 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
20 #include <stdio.h>
21 #include <stdbool.h>
22 #include <errno.h>
23 #include <libsyscommon/dbus-system.h>
24
25 #include "log.h"
26 #include "common.h"
27
28 #define METHOD_GET_BRIGHTNESS           "GetBrightness"
29 #define METHOD_GET_MAX_BRIGHTNESS       "GetMaxBrightness"
30 #define METHOD_SET_BRIGHTNESS           "SetBrightness"
31 #define METHOD_SET_IR_COMMAND           "SetIrCommand"
32
33 API int led_get_brightness(void)
34 {
35         GVariant *reply = NULL;
36         int reply_val = 0;
37         int ret_dbus;
38
39         ret_dbus = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
40                                         DEVICED_PATH_LED,
41                                         DEVICED_INTERFACE_LED,
42                                         METHOD_GET_BRIGHTNESS,
43                                         NULL,
44                                         &reply);
45         if (ret_dbus < 0)
46                 return -EBADMSG;
47
48         if (!g_variant_get_safe(reply, "(i)", &reply_val)) {
49                 _E("Failed to get signature(%s): no message", g_variant_get_type_string(reply));
50                 reply_val = -EBADMSG;
51         }
52
53         g_variant_unref(reply);
54
55         return reply_val;
56 }
57
58 API int led_get_max_brightness(void)
59 {
60         GVariant *reply = NULL;
61         int reply_val, ret_dbus;
62
63         ret_dbus = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
64                                         DEVICED_PATH_LED,
65                                         DEVICED_INTERFACE_LED,
66                                         METHOD_GET_MAX_BRIGHTNESS,
67                                         NULL,
68                                         &reply);
69         if (ret_dbus < 0)
70                 return -EBADMSG;
71
72         if (!g_variant_get_safe(reply, "(i)", &reply_val)) {
73                 _E("Failed to get signature(%s): no message", g_variant_get_type_string(reply));
74                 reply_val = -EBADMSG;
75         }
76
77         g_variant_unref(reply);
78
79         return reply_val;
80 }
81
82 API int led_set_brightness_with_noti(int val, bool enable)
83 {
84         GVariant *reply = NULL;
85         int reply_val, ret_dbus;
86
87         ret_dbus = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
88                                                 DEVICED_PATH_LED,
89                                                 DEVICED_INTERFACE_LED,
90                                                 METHOD_SET_BRIGHTNESS,
91                                                 g_variant_new("(ii)", val, enable),
92                                                 &reply);
93         if (ret_dbus < 0)
94                 return -EBADMSG;
95
96         if (!g_variant_get_safe(reply, "(i)", &reply_val)) {
97                 _E("Failed to get signature(%s): no message", g_variant_get_type_string(reply));
98                 reply_val = -EBADMSG;
99         }
100
101         g_variant_unref(reply);
102
103         return reply_val;
104 }