5352b5f9b533295c59f30106cc62e5b69ce6275f
[platform/core/system/system-popup.git] / src / watchdog / watchdog.c
1 /*
2  *  system-popup
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18 */
19
20 #include "popup-common.h"
21
22 #define DBUS_RESOURCED_WATCHDOG_PATH   "/Org/Tizen/ResourceD/Process"
23 #define DBUS_RESOURCED_WATCHDOG_IFACE  "org.tizen.resourced.process"
24 #define DBUS_RESOURCED_WATCHDOG_SIGNAL "WatchdogResult"
25
26 #define APP_NAME       "_APP_NAME_"
27
28 enum button_selected {
29         WATCHDOG_WAIT,
30         WATCHDOG_OK,
31 };
32
33 static int watchdog_get_content(const struct popup_ops *ops, char *content, unsigned int len)
34 {
35         char *text, *name;
36         struct object_ops *obj;
37         int ret;
38
39         if (!ops || !content)
40                 return -EINVAL;
41
42         ret = get_object_by_ops(ops, &obj);
43         if (ret < 0) {
44                 _E("Failed to get object (%d)", ret);
45                 return -ENOENT;
46         }
47
48         name = (char *)bundle_get_val(obj->b, APP_NAME);
49         if (!name) {
50                 _E("Failed to get app name");
51                 return -ENOENT;
52         }
53
54         text = _("IDS_ST_BODY_PS_IS_NOT_RESPONDING_CLOSE_PS_Q");
55
56         snprintf(content, len, text, name, name);
57
58         return 0;
59 }
60
61 static void send_result_dbus_signal(int result)
62 {
63         int ret;
64         char buf[8];
65         char *param[1];
66
67         snprintf(buf, sizeof(buf), "%d", result);
68         param[0] = buf;
69         ret = broadcast_dbus_signal(DBUS_RESOURCED_WATCHDOG_PATH,
70                         DBUS_RESOURCED_WATCHDOG_IFACE,
71                         DBUS_RESOURCED_WATCHDOG_SIGNAL,
72                         "i", param);
73         if (ret < 0)
74                 _E("FAIL: broadcast_dbus_signal(%d)", ret);
75 }
76
77 static void watchdog_wait(const struct popup_ops *ops)
78 {
79         _I("Wait is selected");
80
81         unload_simple_popup(ops);
82
83         send_result_dbus_signal(WATCHDOG_WAIT);
84
85         terminate_if_no_popup();
86 }
87
88 static void watchdog_ok(const struct popup_ops *ops)
89 {
90         _I("OK is selected");
91
92         unload_simple_popup(ops);
93
94         send_result_dbus_signal(WATCHDOG_OK);
95
96         terminate_if_no_popup();
97 }
98
99 static const struct popup_ops watchdog_ops = {
100         .name                   = "watchdog",
101         .show                   = load_simple_popup,
102         .title                  = "IDS_CLD_HEADER_NO_RESPONSE",
103         .get_content    = watchdog_get_content,
104         .left_text              = "IDS_CST_OPT_WAIT",
105         .left                   = watchdog_wait,
106         .right_text             = "IDS_COM_SK_OK",
107         .right                  = watchdog_ok,
108 };
109
110 /* Constructor to register watchdog button */
111 static __attribute__ ((constructor)) void watchdog_register_popup(void)
112 {
113         register_popup(&watchdog_ops);
114 }