Fix build warnings
[platform/core/system/deviced.git] / src / apps / apps.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2015 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 <stdarg.h>
20 #include "core/log.h"
21 #include "core/common.h"
22 #include "display/display-ops.h"
23 #include "apps.h"
24 #include "shared/plugin.h"
25
26 #define POPUP_METHOD "PopupLaunch"
27 #define BUFF_MAX        255
28
29 static struct display_plugin *disp_plgn;
30
31 static const struct app_dbus_match {
32         const char *type;
33         const char *bus;
34         const char *path;
35         const char *iface;
36         const char *method;
37 } app_match[] = {
38         { APP_DEFAULT , POPUP_BUS_NAME, POPUP_PATH_SYSTEM  , POPUP_INTERFACE_SYSTEM  , POPUP_METHOD },
39         { APP_POWERKEY, POPUP_BUS_NAME, POPUP_PATH_POWERKEY, POPUP_INTERFACE_POWERKEY, POPUP_METHOD },
40         { APP_OVERHEAT, POPUP_BUS_NAME, POPUP_PATH_OVERHEAT, POPUP_INTERFACE_OVERHEAT, POPUP_METHOD },
41         { APP_ABNORMAL, POPUP_BUS_NAME, POPUP_PATH_SYSTEM  , POPUP_INTERFACE_SYSTEM  , POPUP_METHOD },
42         { APP_REMOVE  , POPUP_BUS_NAME, POPUP_PATH_SYSTEM  , POPUP_INTERFACE_SYSTEM  , POPUP_METHOD },
43 };
44
45 static void __cb(GVariant *var, void *user_data, GError *err)
46 {
47          int ret;
48
49         if (!var) {
50                 _E("No message: %s", err->message);
51                 return;
52         }
53
54         if (!dh_get_param_from_var(var, "(i)", &ret)) {
55                 _E("No message: %s", g_variant_get_type_string(var));
56                 goto out;
57         }
58
59         _D("Reply value: %d", ret);
60
61 out:
62         g_variant_unref(var);
63 }
64
65
66 int launch_system_app(char *type, int num, ...)
67 {
68         char *app_type;
69         va_list args;
70         int i, match, ret;
71
72         if (type)
73                 app_type = type;
74         else
75                 app_type = APP_DEFAULT;
76
77         match = -1;
78         for (i = 0 ; i < ARRAY_SIZE(app_match) ; i++) {
79                 if (strncmp(app_type, app_match[i].type, strlen(app_type)))
80                 continue;
81                 match = i;
82                 break;
83         }
84         if (match < 0) {
85                 _E("Failed to find matched app type(%s).", app_type);
86                 return -EINVAL;
87         }
88
89         va_start(args, num);
90
91         ret = dbus_handle_method_async_pairs_with_reply(app_match[match].bus,
92                 app_match[match].path,
93                 app_match[match].iface,
94                 app_match[match].method,
95                 num,
96                 args,
97                 __cb,
98                 -1,
99                 NULL);
100
101         va_end(args);
102
103         if (disp_plgn->pm_change_internal)
104                 disp_plgn->pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL);
105
106         return ret;
107 }
108
109 int launch_message_post(char *type)
110 {
111         int ret;
112
113         if (!type)
114                 return -EINVAL;
115
116         ret = dbus_handle_method_async_with_reply_var(POPUP_BUS_NAME,
117                         POPUP_PATH_NOTI,
118                         POPUP_INTERFACE_NOTI,
119                         "MessagePostOn",
120                         g_variant_new("(s)", type),
121                         __cb, -1, NULL);
122
123         if (disp_plgn->pm_change_internal)
124                 disp_plgn->pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL);
125         return ret;
126 }
127
128 int add_async_notification(char *type, dbus_pending_cb func, char *sig, ...)
129 {
130         int ret;
131         int count;
132         int len;
133         char *data = NULL;
134         const char *param[BUFF_MAX] = {NULL};
135         va_list args;
136
137         if (!type)
138                 return -EINVAL;
139
140         if (sig) {
141                 len = strlen(sig);
142                 va_start(args, sig);
143
144                 for (count = 0; count < len; count++) {
145                         data = va_arg(args, char *);
146                         param[count] = data;
147                 }
148
149                 va_end(args);
150         }
151
152         ret = dbus_handle_method_async_with_reply(POPUP_BUS_NAME,
153                         POPUP_PATH_NOTI,
154                         POPUP_INTERFACE_NOTI,
155                         type,
156                         sig,
157                         param,
158                         func,
159                         -1,
160                         NULL);
161
162         return ret;
163 }
164
165 int remove_notification(char *type, int id)
166 {
167         if (!type || id < 0)
168                 return -EINVAL;
169
170         return dbus_handle_method_async_with_reply_var(POPUP_BUS_NAME,
171                         POPUP_PATH_NOTI,
172                         POPUP_INTERFACE_NOTI,
173                         type, g_variant_new("(i)", id),
174                         __cb, -1, NULL);
175 }
176
177 static void __CONSTRUCTOR__ initialize(void)
178 {
179         disp_plgn = get_display_plugin();
180         if (!disp_plgn) {
181                 _E("Failed to get display plugin.");
182         }
183 }