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.
24 #include "core/common.h"
26 #define SYSTEM_POPUP_BUS_NAME "org.tizen.system.popup"
27 #define SYSTEM_POPUP_DBUS_PATH "/Org/Tizen/System/Popup"
29 #define SYSTEM_POPUP_PATH_TIMA SYSTEM_POPUP_DBUS_PATH"/Tima"
30 #define SYSTEM_POPUP_IFACE_TIMA SYSTEM_POPUP_BUS_NAME".Tima"
32 #define METHOD_PKM_NOTI_ON "PKMDetectionNotiOn"
33 #define METHOD_PKM_NOTI_OFF "PKMDetectionNotiOff"
34 #define METHOD_LKM_NOTI_ON "LKMPreventionNotiOn"
35 #define METHOD_LKM_NOTI_OFF "LKMPreventionNotiOff"
38 #define DBUS_REPLY_TIMEOUT (120 * 1000)
40 static int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
48 for (ch = (char*)sig, i = 0; *ch != '\0'; ++i, ++ch) {
51 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, ¶m[i]);
54 int_type = atoi(param[i]);
55 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type);
58 _E("ERROR: %s %c", sig, *ch);
65 DBusMessage *call_dbus_method(const char *dest, const char *path,
66 const char *interface, const char *method,
67 const char *sig, char *param[])
70 DBusMessage *msg = NULL;
76 conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
82 msg = dbus_message_new_method_call(dest, path, interface, method);
88 dbus_message_iter_init_append(msg, &iter);
89 r = append_variant(&iter, sig, param);
95 /*This function is for synchronous dbus method call */
96 dbus_error_init(&err);
97 ret = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
98 dbus_error_free(&err);
101 dbus_message_unref(msg);
106 int request_to_launch_by_dbus(char *bus, char *path, char *iface,
107 char *method, char *ptype, char *param[])
115 msg = call_dbus_method(bus, path, iface, method, ptype, param);
119 } while (i < RETRY_MAX);
121 _E("fail to call dbus method");
122 return -ECONNREFUSED;
125 dbus_error_init(&err);
127 r = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
129 _E("no message : [%s:%s]", err.name, err.message);
133 dbus_message_unref(msg);
134 dbus_error_free(&err);
139 /* This function returns notification ID (ID >= 0) */
140 int tima_lkm_prevention_noti_on(void)
142 return request_to_launch_by_dbus(SYSTEM_POPUP_BUS_NAME,
143 SYSTEM_POPUP_PATH_TIMA, SYSTEM_POPUP_IFACE_TIMA,
144 METHOD_LKM_NOTI_ON, NULL, NULL);
147 /* This function needs the notification ID to remove
148 * This function return 0 if success */
149 int tima_lkm_prevention_noti_off(int noti_id)
153 snprintf(str, sizeof(str), "%d", noti_id);
156 return request_to_launch_by_dbus(SYSTEM_POPUP_BUS_NAME,
157 SYSTEM_POPUP_PATH_TIMA, SYSTEM_POPUP_IFACE_TIMA,
158 METHOD_LKM_NOTI_OFF, "i", param);
161 /* This function returns notification ID (ID >= 0) */
162 int tima_pkm_detection_noti_on(void)
164 return request_to_launch_by_dbus(SYSTEM_POPUP_BUS_NAME,
165 SYSTEM_POPUP_PATH_TIMA, SYSTEM_POPUP_IFACE_TIMA,
166 METHOD_PKM_NOTI_ON, NULL, NULL);
169 /* This function needs the notification ID to remove
170 * This function return 0 if success */
171 int tima_pkm_detection_noti_off(int noti_id)
175 snprintf(str, sizeof(str), "%d", noti_id);
178 return request_to_launch_by_dbus(SYSTEM_POPUP_BUS_NAME,
179 SYSTEM_POPUP_PATH_TIMA, SYSTEM_POPUP_IFACE_TIMA,
180 METHOD_PKM_NOTI_OFF, "i", param);