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);
122 static DBusMessage *battery_low_noti_on(E_DBus_Object *obj, DBusMessage *msg)
124 set_timer_to_terminate();
125 return activate_notification_no_param(obj, msg, BATTERY_LOW);
128 static DBusMessage *battery_critical_noti_on(E_DBus_Object *obj, DBusMessage *msg)
130 set_timer_to_terminate();
131 return activate_notification_no_param(obj, msg, BATTERY_CRITICAL);
134 static DBusMessage *battery_low_actnoti_on(E_DBus_Object *obj, DBusMessage *msg)
136 set_timer_to_terminate();
137 return activate_notification_single_param(obj, msg, BATTERY_LOW_ACT);
140 static DBusMessage *battery_critical_actnoti_on(E_DBus_Object *obj, DBusMessage *msg)
142 set_timer_to_terminate();
143 return activate_notification_single_param(obj, msg, BATTERY_CRITICAL_ACT);
146 static DBusMessage *battery_low_actnoti_usb_on(E_DBus_Object *obj, DBusMessage *msg)
148 set_timer_to_terminate();
149 return activate_notification_no_param(obj, msg, BATTERY_LOW_USB_ACT);
152 static DBusMessage *battery_critical_actnoti_usb_on(E_DBus_Object *obj, DBusMessage *msg)
154 set_timer_to_terminate();
155 return activate_notification_no_param(obj, msg, BATTERY_CRITICAL_USB_ACT);
158 static DBusMessage *battery_low_actnoti_chg_on(E_DBus_Object *obj, DBusMessage *msg)
160 set_timer_to_terminate();
161 return activate_notification_no_param(obj, msg, BATTERY_LOW_CHG_ACT);
164 static DBusMessage *battery_critical_actnoti_chg_on(E_DBus_Object *obj, DBusMessage *msg)
166 set_timer_to_terminate();
167 return activate_notification_no_param(obj, msg, BATTERY_CRITICAL_CHG_ACT);
171 static DBusMessage *data_warning_noti_on(E_DBus_Object *obj, DBusMessage *msg)
173 set_timer_to_terminate();
174 return activate_notification_no_param(obj, msg, DATAUSAGE_WARNING);
177 static DBusMessage *data_disabled_noti_on(E_DBus_Object *obj, DBusMessage *msg)
179 set_timer_to_terminate();
180 return activate_notification_no_param(obj, msg, DATAUSAGE_DISABLED);
183 /* Notification Off */
184 static DBusMessage *noti_off(E_DBus_Object *obj, DBusMessage *msg)
186 set_timer_to_terminate();
187 return deactivate_notification(obj, msg);
191 static DBusMessage *sdcard_noti(E_DBus_Object *obj, DBusMessage *msg)
193 set_timer_to_terminate();
194 return activate_notification_single_param(obj, msg, SDCARD_DEVICE);
198 static DBusMessage *led_torch_noti_on(E_DBus_Object *obj, DBusMessage *msg)
200 set_timer_to_terminate();
201 return activate_notification_no_param(obj, msg, LED_TORCH);
204 /* USB host notifications */
205 static DBusMessage *usb_storage_noti_on(E_DBus_Object *obj, DBusMessage *msg)
207 set_timer_to_terminate();
208 return activate_notification_single_param(obj, msg, USB_STORAGE);
211 /* Cooldown notification */
212 static DBusMessage *cooldown_noti_on(E_DBus_Object *obj, DBusMessage *msg)
214 set_timer_to_terminate();
215 return activate_notification_no_param(obj, msg, TEMP_COOLDOWN);
218 static DBusMessage *usb_storage_ro_noti_on(E_DBus_Object *obj, DBusMessage *msg)
220 set_timer_to_terminate();
221 return activate_notification_single_param(obj, msg, USB_STORAGE_RO);
224 static DBusMessage *usb_device_noti_on(E_DBus_Object *obj, DBusMessage *msg)
226 set_timer_to_terminate();
227 return activate_notification_double_param(obj, msg, USB_DEVICE);
230 static DBusMessage *usb_device_noti_update(E_DBus_Object *obj, DBusMessage *msg)
232 set_timer_to_terminate();
233 return update_notification_double_param(obj, msg, USB_DEVICE);
236 static DBusMessage *media_device_noti_on(E_DBus_Object *obj, DBusMessage *msg)
238 set_timer_to_terminate();
239 return activate_notification_no_param(obj, msg, MEDIA_DEVICE);
242 static const struct edbus_method
243 dbus_powerkey_methods[] = {
244 { "PopupLaunch", "a{ss}", "i", powerkey_popup },
245 /* Add methods here */
248 static const struct edbus_method
249 dbus_overheat_methods[] = {
250 { "PopupLaunch", "a{ss}", "i", overheat_popup },
251 /* Add methods here */
254 static const struct edbus_method
255 dbus_crash_methods[] = {
256 { "PopupLaunch", "a{ss}", "i", crash_popup },
257 /* Add methods here */
260 static const struct edbus_method
261 dbus_noti_methods[] = {
263 { "LedTorchNotiOn" , NULL , "i" , led_torch_noti_on },
264 { "LedTorchNotiOff" , "i" , "i" , noti_off },
266 { "UsbStorageNotiOn" , "s" , "i" , usb_storage_noti_on },
267 { "UsbStorageRoNotiOn" , "s" , "i" , usb_storage_ro_noti_on },
268 { "UsbStorageNotiOff" , "i" , "i" , noti_off },
269 { "UsbDeviceNotiOn" , "ss" , "i" , usb_device_noti_on },
270 { "UsbDeviceNotiUpdate" , "isss" , "i" , usb_device_noti_update },
271 { "UsbDeviceNotiOff" , "i" , "i" , noti_off },
273 { "MediaDeviceNotiOn" , NULL , "i" , media_device_noti_on },
274 { "MediaDeviceNotiOff" , "i" , "i" , noti_off },
275 /* Battery Event noti*/
276 { "BatteryFullNotiOn" , NULL , "i" , battery_full_noti_on },
277 { "BatteryFullNotiOff" , "i" , "i" , noti_off },
278 { "BatteryChargeNotiOn" , NULL , "i" , battery_charge_noti_on },
279 { "BatteryLowNotiOn" , NULL , "i" , battery_low_noti_on },
280 { "BatteryCriticalNotiOn" , NULL , "i" , battery_critical_noti_on },
281 { "BatteryLowCriticalNotiOff" , "i" , "i" , noti_off },
282 /* Battery Active noti*/
283 { "BatteryLowActNotiOn" , "s" , "i" , battery_low_actnoti_on },
284 { "BatteryCriticalActNotiOn", "s" , "i" , battery_critical_actnoti_on },
285 { "BatteryLowActNotiUsbOn" , NULL , "i" , battery_low_actnoti_usb_on },
286 { "BatteryCriticalActNotiUsbOn" , NULL , "i" , battery_critical_actnoti_usb_on },
287 { "BatteryLowActNotiChgOn" , NULL , "i" , battery_low_actnoti_chg_on },
288 { "BatteryCriticalActNotiChgOn" , NULL , "i" , battery_critical_actnoti_chg_on },
290 { "TempCooldownNotiOn" , NULL , "i" , cooldown_noti_on },
291 { "TempCooldownNotiOff" , "i" , "i" , noti_off },
293 { "SDcardNoti" , "s" , "i" , sdcard_noti },
295 { "DataWarningNotiOn" , NULL , "i" , data_warning_noti_on },
296 { "DataWarningNotiOff" , "i" , "i" , noti_off },
297 { "DataDisabledNotiOn" , NULL , "i" , data_disabled_noti_on },
298 { "DataDisabledNotiOff" , "i" , "i" , noti_off },
299 /* Add notifications here */
302 static struct edbus_object
304 { POPUP_PATH_SYSTEM , POPUP_IFACE_SYSTEM , NULL , NULL ,
305 dbus_system_methods , ARRAY_SIZE(dbus_system_methods) },
306 { POPUP_PATH_POWERKEY , POPUP_IFACE_POWERKEY , NULL , NULL ,
307 dbus_powerkey_methods , ARRAY_SIZE(dbus_powerkey_methods) },
308 { POPUP_PATH_OVERHEAT , POPUP_IFACE_OVERHEAT , NULL , NULL ,
309 dbus_overheat_methods , ARRAY_SIZE(dbus_overheat_methods) },
310 { POPUP_PATH_NOTI , POPUP_IFACE_NOTI , NULL , NULL ,
311 dbus_noti_methods , ARRAY_SIZE(dbus_noti_methods) },
312 { POPUP_PATH_CRASH , POPUP_IFACE_CRASH , NULL , NULL ,
313 dbus_crash_methods , ARRAY_SIZE(dbus_crash_methods) },
314 /* Add new object & interface here*/
317 static int init_methods(void)
323 for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) {
324 for (j = 0; j < edbus_objects[i].methods_len; j++) {
325 ret = e_dbus_interface_method_add(edbus_objects[i].iface,
326 edbus_objects[i].methods[j].member,
327 edbus_objects[i].methods[j].signature,
328 edbus_objects[i].methods[j].reply_signature,
329 edbus_objects[i].methods[j].func);
331 _E("fail to add method %s!", edbus_objects[i].methods[j].member);
332 return -ECONNREFUSED;
339 static int register_dbus(void)
344 dbus_error_init(&error);
350 if (++retry == RETRY_MAX) {
351 _E("fail to init edbus");
352 return -ECONNREFUSED;
354 } while (retry <= RETRY_MAX);
358 edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
361 if (++retry == RETRY_MAX) {
362 _E("fail to get edbus");
366 } while (retry <= RETRY_MAX);
370 edbus_request_name = e_dbus_request_name(edbus_conn, BUS_NAME, 0, NULL, NULL);
371 if (edbus_request_name)
373 if (++retry == RETRY_MAX) {
374 _E("fail to request edbus name");
378 } while (retry <= RETRY_MAX);
380 for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) {
381 edbus_objects[i].obj = e_dbus_object_add(edbus_conn, edbus_objects[i].path, NULL);
382 if (!(edbus_objects[i].obj)) {
383 _E("fail to add edbus obj");
388 edbus_objects[i].iface = e_dbus_interface_new(edbus_objects[i].interface);
389 if (!(edbus_objects[i].iface)) {
390 _E("fail to add edbus interface");
395 e_dbus_object_interface_attach(edbus_objects[i].obj, edbus_objects[i].iface);
401 e_dbus_connection_close(edbus_conn);
408 int main(int argc, char *argv[])
414 ret = register_dbus();
418 ret = init_methods();
422 ecore_main_loop_begin();