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_powerkey_popup(obj, msg, POWERKEY_SYSPOPUP);
88 static DBusMessage *overheat_popup(E_DBus_Object *obj, DBusMessage *msg)
90 set_timer_to_terminate();
91 return launch_overheat_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 /* Notification Off */
123 static DBusMessage *noti_off(E_DBus_Object *obj, DBusMessage *msg)
125 set_timer_to_terminate();
126 return deactivate_notification(obj, msg);
130 static DBusMessage *led_torch_noti_on(E_DBus_Object *obj, DBusMessage *msg)
132 set_timer_to_terminate();
133 return activate_notification_no_param(obj, msg, LED_TORCH);
136 /* USB host notifications */
137 static DBusMessage *usb_storage_noti_on(E_DBus_Object *obj, DBusMessage *msg)
139 set_timer_to_terminate();
140 return activate_notification_single_param(obj, msg, USB_STORAGE);
143 /* Cooldown notification */
144 static DBusMessage *cooldown_noti_on(E_DBus_Object *obj, DBusMessage *msg)
146 set_timer_to_terminate();
147 return activate_notification_no_param(obj, msg, TEMP_COOLDOWN);
150 static DBusMessage *usb_storage_ro_noti_on(E_DBus_Object *obj, DBusMessage *msg)
152 set_timer_to_terminate();
153 return activate_notification_single_param(obj, msg, USB_STORAGE_RO);
156 static DBusMessage *usb_device_noti_on(E_DBus_Object *obj, DBusMessage *msg)
158 set_timer_to_terminate();
159 return activate_notification_double_param(obj, msg, USB_DEVICE);
162 static DBusMessage *usb_device_noti_update(E_DBus_Object *obj, DBusMessage *msg)
164 set_timer_to_terminate();
165 return update_notification_double_param(obj, msg, USB_DEVICE);
168 static DBusMessage *media_device_noti_on(E_DBus_Object *obj, DBusMessage *msg)
170 set_timer_to_terminate();
171 return activate_notification_no_param(obj, msg, MEDIA_DEVICE);
174 static const struct edbus_method
175 dbus_powerkey_methods[] = {
176 { "PopupLaunch", NULL, "i", powerkey_popup },
177 /* Add methods here */
180 static const struct edbus_method
181 dbus_overheat_methods[] = {
182 { "PopupLaunch", "a{ss}", "i", overheat_popup },
183 /* Add methods here */
186 static const struct edbus_method
187 dbus_crash_methods[] = {
188 { "PopupLaunch", "a{ss}", "i", crash_popup },
189 /* Add methods here */
192 static const struct edbus_method
193 dbus_noti_methods[] = {
195 { "LedTorchNotiOn" , NULL , "i" , led_torch_noti_on },
196 { "LedTorhNotiOff" , "i" , "i" , noti_off },
198 { "UsbStorageNotiOn" , "s" , "i" , usb_storage_noti_on },
199 { "UsbStorageRoNotiOn" , "s" , "i" , usb_storage_ro_noti_on },
200 { "UsbStorageNotiOff" , "i" , "i" , noti_off },
201 { "UsbDeviceNotiOn" , "ss" , "i" , usb_device_noti_on },
202 { "UsbDeviceNotiUpdate" , "isss" , "i" , usb_device_noti_update },
203 { "UsbDeviceNotiOff" , "i" , "i" , noti_off },
205 { "MediaDeviceNotiOn" , NULL , "i" , media_device_noti_on },
206 { "MediaDeviceNotiOff" , "i" , "i" , noti_off },
208 { "BatteryFullNotiOn" , NULL , "i" , battery_full_noti_on },
209 { "BatteryFullNotiOff" , "i" , "i" , noti_off },
210 { "BatteryChargeNotiOn" , NULL , "i" , battery_charge_noti_on },
212 { "TempCooldownNotiOn" , NULL , "i" , cooldown_noti_on },
213 { "TempCooldownNotiOff" , "i" , "i" , noti_off },
214 /* Add notifications here */
217 static struct edbus_object
219 { POPUP_PATH_SYSTEM , POPUP_IFACE_SYSTEM , NULL , NULL ,
220 dbus_system_methods , ARRAY_SIZE(dbus_system_methods) },
221 { POPUP_PATH_POWERKEY , POPUP_IFACE_POWERKEY , NULL , NULL ,
222 dbus_powerkey_methods , ARRAY_SIZE(dbus_powerkey_methods) },
223 { POPUP_PATH_OVERHEAT , POPUP_IFACE_OVERHEAT , NULL , NULL ,
224 dbus_overheat_methods , ARRAY_SIZE(dbus_overheat_methods) },
225 { POPUP_PATH_NOTI , POPUP_IFACE_NOTI , NULL , NULL ,
226 dbus_noti_methods , ARRAY_SIZE(dbus_noti_methods) },
227 { POPUP_PATH_CRASH , POPUP_IFACE_CRASH , NULL , NULL ,
228 dbus_crash_methods , ARRAY_SIZE(dbus_crash_methods) },
229 /* Add new object & interface here*/
232 static int init_methods(void)
238 for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) {
239 for (j = 0; j < edbus_objects[i].methods_len; j++) {
240 ret = e_dbus_interface_method_add(edbus_objects[i].iface,
241 edbus_objects[i].methods[j].member,
242 edbus_objects[i].methods[j].signature,
243 edbus_objects[i].methods[j].reply_signature,
244 edbus_objects[i].methods[j].func);
246 _E("fail to add method %s!", edbus_objects[i].methods[j].member);
247 return -ECONNREFUSED;
254 static int register_dbus(void)
259 dbus_error_init(&error);
265 if (++retry == RETRY_MAX) {
266 _E("fail to init edbus");
267 return -ECONNREFUSED;
269 } while (retry <= RETRY_MAX);
273 edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
276 if (++retry == RETRY_MAX) {
277 _E("fail to get edbus");
281 } while (retry <= RETRY_MAX);
285 edbus_request_name = e_dbus_request_name(edbus_conn, BUS_NAME, 0, NULL, NULL);
286 if (edbus_request_name)
288 if (++retry == RETRY_MAX) {
289 _E("fail to request edbus name");
293 } while (retry <= RETRY_MAX);
295 for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) {
296 edbus_objects[i].obj = e_dbus_object_add(edbus_conn, edbus_objects[i].path, NULL);
297 if (!(edbus_objects[i].obj)) {
298 _E("fail to add edbus obj");
303 edbus_objects[i].iface = e_dbus_interface_new(edbus_objects[i].interface);
304 if (!(edbus_objects[i].iface)) {
305 _E("fail to add edbus interface");
310 e_dbus_object_interface_attach(edbus_objects[i].obj, edbus_objects[i].iface);
316 e_dbus_connection_close(edbus_conn);
323 int main(int argc, char *argv[])
329 ret = register_dbus();
333 ret = init_methods();
337 ecore_main_loop_begin();