4 * Copyright (c) 2012 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.
21 #include "core/common.h"
23 #include "core/edbus-handler.h"
25 #define LOWBAT_WARNING "warning"
26 #define LOWBAT_CRITICAL "critical"
27 #define LOWBAT_POWEROFF "poweroff"
35 static int lowbat_pid = 0;
37 static void lowbat_cb(void *data, DBusMessage *msg, DBusError *unused)
45 dbus_error_init(&err);
46 ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &id, DBUS_TYPE_INVALID);
48 _E("no message [%s:%s]", err.name, err.message);
49 dbus_error_free(&err);
54 _I("Created popup : %d", lowbat_pid);
57 static int lowbat_launch(void *data)
60 struct popup_data * key_data = (struct popup_data *)data;
63 param[0] = key_data->key;
64 param[1] = key_data->value;
66 ret = dbus_method_async_with_reply(POPUP_BUS_NAME,
68 POPUP_INTERFACE_LOWBAT,
70 "ss", param, lowbat_cb, -1, NULL);
72 if (strncmp(key_data->value, LOWBAT_WARNING, strlen(LOWBAT_WARNING)) &&
73 strncmp(key_data->value, LOWBAT_CRITICAL, strlen(LOWBAT_CRITICAL)) &&
74 strncmp(key_data->value, LOWBAT_POWEROFF, strlen(LOWBAT_POWEROFF)))
75 _I("%s(%d)",key_data->name, ret);
80 static int lowbat_terminate(void *data)
92 snprintf(buf, sizeof(buf), "%d", lowbat_pid);
95 ret = dbus_method_sync(POPUP_BUS_NAME,
98 POPUP_METHOD_TERMINATE, "i", param);
100 _E("FAIL: dbus_method_sync(): %d %d", ret, param);
106 static const struct apps_ops lowbat_ops = {
107 .name = "lowbat-syspopup",
108 .launch = lowbat_launch,
109 .terminate = lowbat_terminate,
112 APPS_OPS_REGISTER(&lowbat_ops)