4 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #define TERMINATE_TIMEOUT 5
24 static E_DBus_Connection *edbus_conn;
25 static DBusPendingCall *edbus_request_name;
26 static Ecore_Timer *term_timer = NULL;
28 extern DBusMessage *activate_notification_no_param(E_DBus_Object *obj, DBusMessage *msg, int type);
29 extern DBusMessage *launch_system_servant_app(E_DBus_Object *obj, DBusMessage *msg, char **argv);
30 extern DBusMessage *activate_notification_single_param(E_DBus_Object *obj, DBusMessage *msg, int type);
31 extern DBusMessage *activate_notification_double_param(E_DBus_Object *obj, DBusMessage *msg, int type);
32 extern DBusMessage *deactivate_notification(E_DBus_Object *obj, DBusMessage *msg);
33 extern DBusMessage *update_notification_double_param(E_DBus_Object *obj, DBusMessage *msg, int type);
35 static Eina_Bool exit_idler_cb(void *data)
37 e_dbus_connection_close(edbus_conn);
40 ecore_main_loop_quit();
41 return ECORE_CALLBACK_CANCEL;
44 static Eina_Bool terminate_launcher(void *data)
47 ecore_timer_del(term_timer);
49 if (ecore_idler_add(exit_idler_cb, NULL))
50 return ECORE_CALLBACK_CANCEL;
53 return ECORE_CALLBACK_CANCEL;
56 static void set_timer_to_terminate(void)
59 ecore_timer_reset(term_timer);
61 term_timer = ecore_timer_add(TERMINATE_TIMEOUT, terminate_launcher, NULL);
63 terminate_launcher(NULL);
68 static DBusMessage *system_popup(E_DBus_Object *obj, DBusMessage *msg)
70 set_timer_to_terminate();
71 return launch_popup(obj, msg, SYSTEM_SYSPOPUP);
74 static const struct edbus_method
75 dbus_system_methods[] = {
76 { "PopupLaunch", "a{ss}", "i", system_popup },
77 /* Add methods here */
81 static DBusMessage *powerkey_popup(E_DBus_Object *obj, DBusMessage *msg)
83 set_timer_to_terminate();
84 return launch_popup(obj, msg, POWERKEY_SYSPOPUP);
88 static DBusMessage *overheat_popup(E_DBus_Object *obj, DBusMessage *msg)
90 set_timer_to_terminate();
91 return launch_popup(obj, msg, OVERHEAT_SYSPOPUP);
95 static DBusMessage *crash_popup(E_DBus_Object *obj, DBusMessage *msg)
97 set_timer_to_terminate();
98 return launch_popup(obj, msg, CRASH_SYSPOPUP);
101 /* Battery notifications */
102 static DBusMessage *battery_full_noti_on(E_DBus_Object *obj, DBusMessage *msg)
104 set_timer_to_terminate();
105 return activate_notification_no_param(obj, msg, BATTERY_FULL);
108 static DBusMessage *battery_charge_noti_on(E_DBus_Object *obj, DBusMessage *msg)
113 set_timer_to_terminate();
115 args[0] = SERVANT_APP_NAME;
116 snprintf(param, sizeof(param), "%d", CHARGER_CONNECTION);
119 return launch_system_servant_app(obj, msg, args);
123 static DBusMessage *data_warning_noti_on(E_DBus_Object *obj, DBusMessage *msg)
125 set_timer_to_terminate();
126 return activate_notification_no_param(obj, msg, DATAUSAGE_WARNING);
129 static DBusMessage *data_disabled_noti_on(E_DBus_Object *obj, DBusMessage *msg)
131 set_timer_to_terminate();
132 return activate_notification_no_param(obj, msg, DATAUSAGE_DISABLED);
135 /* Notification Off */
136 static DBusMessage *noti_off(E_DBus_Object *obj, DBusMessage *msg)
138 set_timer_to_terminate();
139 return deactivate_notification(obj, msg);
143 static DBusMessage *sdcard_noti(E_DBus_Object *obj, DBusMessage *msg)
145 set_timer_to_terminate();
146 return activate_notification_single_param(obj, msg, SDCARD_DEVICE);
150 static DBusMessage *led_torch_noti_on(E_DBus_Object *obj, DBusMessage *msg)
152 set_timer_to_terminate();
153 return activate_notification_no_param(obj, msg, LED_TORCH);
156 /* USB host notifications */
157 static DBusMessage *usb_storage_noti_on(E_DBus_Object *obj, DBusMessage *msg)
159 set_timer_to_terminate();
160 return activate_notification_single_param(obj, msg, USB_STORAGE);
163 /* Cooldown notification */
164 static DBusMessage *cooldown_noti_on(E_DBus_Object *obj, DBusMessage *msg)
166 set_timer_to_terminate();
167 return activate_notification_no_param(obj, msg, TEMP_COOLDOWN);
170 static DBusMessage *usb_storage_ro_noti_on(E_DBus_Object *obj, DBusMessage *msg)
172 set_timer_to_terminate();
173 return activate_notification_single_param(obj, msg, USB_STORAGE_RO);
176 static DBusMessage *usb_device_noti_on(E_DBus_Object *obj, DBusMessage *msg)
178 set_timer_to_terminate();
179 return activate_notification_double_param(obj, msg, USB_DEVICE);
182 static DBusMessage *usb_device_noti_update(E_DBus_Object *obj, DBusMessage *msg)
184 set_timer_to_terminate();
185 return update_notification_double_param(obj, msg, USB_DEVICE);
188 static DBusMessage *media_device_noti_on(E_DBus_Object *obj, DBusMessage *msg)
190 set_timer_to_terminate();
191 return activate_notification_no_param(obj, msg, MEDIA_DEVICE);
194 static const struct edbus_method
195 dbus_powerkey_methods[] = {
196 { "PopupLaunch", "a{ss}", "i", powerkey_popup },
197 /* Add methods here */
200 static const struct edbus_method
201 dbus_overheat_methods[] = {
202 { "PopupLaunch", "a{ss}", "i", overheat_popup },
203 /* Add methods here */
206 static const struct edbus_method
207 dbus_crash_methods[] = {
208 { "PopupLaunch", "a{ss}", "i", crash_popup },
209 /* Add methods here */
212 static const struct edbus_method
213 dbus_noti_methods[] = {
215 { "LedTorchNotiOn" , NULL , "i" , led_torch_noti_on },
216 { "LedTorchNotiOff" , "i" , "i" , noti_off },
218 { "UsbStorageNotiOn" , "s" , "i" , usb_storage_noti_on },
219 { "UsbStorageRoNotiOn" , "s" , "i" , usb_storage_ro_noti_on },
220 { "UsbStorageNotiOff" , "i" , "i" , noti_off },
221 { "UsbDeviceNotiOn" , "ss" , "i" , usb_device_noti_on },
222 { "UsbDeviceNotiUpdate" , "isss" , "i" , usb_device_noti_update },
223 { "UsbDeviceNotiOff" , "i" , "i" , noti_off },
225 { "MediaDeviceNotiOn" , NULL , "i" , media_device_noti_on },
226 { "MediaDeviceNotiOff" , "i" , "i" , noti_off },
227 /* Battery Event noti*/
228 { "BatteryFullNotiOn" , NULL , "i" , battery_full_noti_on },
229 { "BatteryFullNotiOff" , "i" , "i" , noti_off },
230 { "BatteryChargeNotiOn" , NULL , "i" , battery_charge_noti_on },
232 { "TempCooldownNotiOn" , NULL , "i" , cooldown_noti_on },
233 { "TempCooldownNotiOff" , "i" , "i" , noti_off },
235 { "SDcardNoti" , "s" , "i" , sdcard_noti },
237 { "DataWarningNotiOn" , NULL , "i" , data_warning_noti_on },
238 { "DataWarningNotiOff" , "i" , "i" , noti_off },
239 { "DataDisabledNotiOn" , NULL , "i" , data_disabled_noti_on },
240 { "DataDisabledNotiOff" , "i" , "i" , noti_off },
241 /* Add notifications here */
244 static struct edbus_object
246 { POPUP_PATH_SYSTEM , POPUP_IFACE_SYSTEM , NULL , NULL ,
247 dbus_system_methods , ARRAY_SIZE(dbus_system_methods) },
248 { POPUP_PATH_POWERKEY , POPUP_IFACE_POWERKEY , NULL , NULL ,
249 dbus_powerkey_methods , ARRAY_SIZE(dbus_powerkey_methods) },
250 { POPUP_PATH_OVERHEAT , POPUP_IFACE_OVERHEAT , NULL , NULL ,
251 dbus_overheat_methods , ARRAY_SIZE(dbus_overheat_methods) },
252 { POPUP_PATH_NOTI , POPUP_IFACE_NOTI , NULL , NULL ,
253 dbus_noti_methods , ARRAY_SIZE(dbus_noti_methods) },
254 { POPUP_PATH_CRASH , POPUP_IFACE_CRASH , NULL , NULL ,
255 dbus_crash_methods , ARRAY_SIZE(dbus_crash_methods) },
256 /* Add new object & interface here*/
259 static int init_methods(void)
265 for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) {
266 for (j = 0; j < edbus_objects[i].methods_len; j++) {
267 ret = e_dbus_interface_method_add(edbus_objects[i].iface,
268 edbus_objects[i].methods[j].member,
269 edbus_objects[i].methods[j].signature,
270 edbus_objects[i].methods[j].reply_signature,
271 edbus_objects[i].methods[j].func);
273 _E("Failed to add method(%s).", edbus_objects[i].methods[j].member);
274 return -ECONNREFUSED;
281 static int register_dbus(void)
286 dbus_error_init(&error);
292 if (++retry == RETRY_MAX) {
293 _E("Failed to init edbus.");
294 return -ECONNREFUSED;
296 } while (retry <= RETRY_MAX);
300 edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
303 if (++retry == RETRY_MAX) {
304 _E("Failed to get edbus.");
308 } while (retry <= RETRY_MAX);
310 for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) {
311 edbus_objects[i].obj = e_dbus_object_add(edbus_conn, edbus_objects[i].path, NULL);
312 if (!(edbus_objects[i].obj)) {
313 _E("Failed to add edbus obj.");
318 edbus_objects[i].iface = e_dbus_interface_new(edbus_objects[i].interface);
319 if (!(edbus_objects[i].iface)) {
320 _E("Failed to add edbus interface.");
325 e_dbus_object_interface_attach(edbus_objects[i].obj, edbus_objects[i].iface);
330 edbus_request_name = e_dbus_request_name(edbus_conn, BUS_NAME, 0, NULL, NULL);
331 if (edbus_request_name)
333 if (++retry == RETRY_MAX) {
334 _E("Failed to request edbus name.");
338 } while (retry <= RETRY_MAX);
343 e_dbus_connection_close(edbus_conn);
350 int main(int argc, char *argv[])
356 ret = register_dbus();
360 ret = init_methods();
364 ecore_main_loop_begin();