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 r = dbus_connection_send(conn, msg, NULL);
113 dbus_message_unref(msg);
116 _E("dbus_connection_send error (%s:%s-%s)", path, interface, name);
122 static void poweroff_popup(char *status)
128 snprintf(str_status, sizeof(str_status), "%s", status);
131 _D("broadcast poweroff %s %s", arr[0], arr[1]);
134 val = broadcast_edbus_signal(DEVICED_OBJECT_PATH, DEVICED_INTERFACE_NAME,
135 "poweroffpopup", "si", arr);
137 _R("[NG] ---- %s", __func__);
139 _R("[OK] ---- %s : V(%s)", __func__, status);
143 static void unit(char *unit, char *status)
147 for (index = 0; index < ARRAY_SIZE(boot_control_types); index++) {
148 if (strcmp(unit, boot_control_types[index].name) != 0 ||
149 strcmp(status, boot_control_types[index].status) != 0)
151 if (strcmp(unit, "poweroffpopup") == 0)
152 poweroff_popup(boot_control_types[index].status);
157 static void boot_init(void *data)
161 static void boot_exit(void *data)
165 static int boot_unit(int argc, char **argv)
173 unit(argv[argc-2], argv[argc-1]);
178 static const struct test_ops boot_test_ops = {
179 .priority = TEST_PRIORITY_HIGH,
186 TEST_OPS_REGISTER(&boot_test_ops)