4 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
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.
20 #define EDBUS_INIT_RETRY_COUNT 5
21 static int edbus_init_val;
22 static DBusConnection *conn;
23 static E_DBus_Connection *edbus_conn;
25 static const struct boot_control_type {
28 } boot_control_types [] = {
29 {"poweroffpopup", "pwroff-popup"},
30 {"poweroffpopup", "reboot"},
31 {"poweroffpopup", "reboot-recovery"},
32 {"poweroffpopup", "poweroff"},
33 {"poweroffpopup", "fota"},
36 static void edbus_init(void)
42 dbus_threads_init_default();
43 dbus_error_init(&error);
46 edbus_init_val = e_dbus_init();
49 if (retry == EDBUS_INIT_RETRY_COUNT) {
50 _E("fail to init edbus");
54 } while (retry <= EDBUS_INIT_RETRY_COUNT);
58 conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
61 if (retry == EDBUS_INIT_RETRY_COUNT) {
62 _E("fail to get dbus");
66 } while (retry <= EDBUS_INIT_RETRY_COUNT);
70 edbus_conn = e_dbus_connection_setup(conn);
73 if (retry == EDBUS_INIT_RETRY_COUNT) {
74 _E("fail to get edbus");
78 } while (retry <= EDBUS_INIT_RETRY_COUNT);
81 dbus_connection_set_exit_on_disconnect(conn, FALSE);
86 static void edbus_exit(void)
88 e_dbus_connection_close(edbus_conn);
92 static int broadcast_edbus_signal(const char *path, const char *interface,
93 const char *name, const char *sig, char *param[])
99 msg = dbus_message_new_signal(path, interface, name);
101 _E("fail to allocate new %s.%s signal", interface, name);
105 dbus_message_iter_init_append(msg, &iter);
106 r = append_variant(&iter, sig, param);
108 _E("append_variant error(%d)", r);
112 e_dbus_message_send(edbus_conn, msg, NULL, -1, NULL);
114 dbus_message_unref(msg);
118 static void poweroff_send_broadcast(char *status)
123 snprintf(str_status, sizeof(str_status), "%s", status);
126 _D("broadcast poweroff %s %s", arr[0], arr[1]);
129 broadcast_edbus_signal(DEVICED_OBJECT_PATH, DEVICED_INTERFACE_NAME,
130 "poweroffpopup", "si", arr);
134 static void unit(char *unit, char *status)
138 for (index = 0; index < ARRAY_SIZE(boot_control_types); index++) {
139 if (strcmp(unit, boot_control_types[index].name) != 0 ||
140 strcmp(status, boot_control_types[index].status) != 0)
142 if (strcmp(unit, "poweroffpopup") == 0)
143 poweroff_send_broadcast(boot_control_types[index].status);
148 static void boot_init(void *data)
152 static void boot_exit(void *data)
156 static int boot_unit(int argc, char **argv)
164 unit(argv[argc-2], argv[argc-1]);
169 static const struct test_ops boot_test_ops = {
170 .priority = TEST_PRIORITY_HIGH,
177 TEST_OPS_REGISTER(&boot_test_ops)