Initialize Tizen 2.3
[apps/connectivity/bt-connection-popup.git] / src / bt-connection-ipc.c
1 /*
2 * bt-connection-popup
3 *
4 * Copyright 2012 Samsung Electronics Co., Ltd
5 *
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 *           Injun Yang <injun.yang@samsung.com>
8 *           Seungyoun Ju <sy39.ju@samsung.com>
9 *
10 * Licensed under the Flora License, Version 1.1 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.tizenopensource.org/license
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 */
23
24 #include <dbus/dbus.h>
25 #include <dbus/dbus-glib-bindings.h>
26
27 #include "bt-connection-main.h"
28 #include "bt-connection-view.h"
29 #include "bt-connection-handler.h"
30
31 #define DBUS_SENSOR_PATH "/org/tizen/sensor/context/gesture"
32 #define DBUS_SENSOR_INTERFACE "org.tizen.sensor.context.gesture"
33 #define DBUS_SENSOR_WAKEUP "wakeup"
34 #define DBUS_CORE_APPS_PATH "/Org/Tizen/Coreapps/home/raise"
35 #define DBUS_CORE_APPS_INTERFACE "org.tizen.coreapps.home.raise"
36 #define DBUS_CORE_APPS_MEMBER "homeraise"
37
38 static void __handle_dbus_signal(void *data, DBusMessage *msg)
39 {
40         bt_app_data_t *ad;
41         const char *member;
42
43         retm_if(data == NULL, "Invalid argument: data is NULL");
44         retm_if(msg == NULL, "Invalid argument: msg is NULL");
45
46         ad = (bt_app_data_t *)data;
47         member = dbus_message_get_member(msg);
48         retm_if(member == NULL, "member value is NULL");
49
50         if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
51                 return;
52
53         if (!dbus_message_has_interface(msg, DBUS_SENSOR_INTERFACE) &&
54                 !dbus_message_has_interface(msg, DBUS_CORE_APPS_INTERFACE))
55                 return;
56
57         if (!dbus_message_has_path(msg, DBUS_SENSOR_PATH) &&
58                 !dbus_message_has_path(msg, DBUS_CORE_APPS_PATH))
59                 return;
60
61         DBG("Received signal : %s", member);
62
63         if ((strcasecmp(member, DBUS_SENSOR_WAKEUP) == 0) ||
64                 (strcasecmp(member, DBUS_CORE_APPS_MEMBER) == 0)) {
65                 _bt_destroy_app(ad);
66         }
67 }
68
69 void _bt_dbus_signal_init(bt_app_data_t *ad)
70 {
71         DBG("");
72
73         E_DBus_Connection *conn = NULL;
74         E_DBus_Signal_Handler *sh = NULL;
75
76         e_dbus_init();
77
78         conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
79         retm_if(conn == NULL, "conn is NULL");
80
81         sh = e_dbus_signal_handler_add(conn,
82                                        NULL,
83                                        DBUS_SENSOR_PATH,
84                                        DBUS_SENSOR_INTERFACE,
85                                        DBUS_SENSOR_WAKEUP,
86                                        __handle_dbus_signal, ad);
87         retm_if(sh == NULL, "Connect Event register failed");
88         ad->gesture_sh = sh;
89
90         sh = e_dbus_signal_handler_add(conn,
91                                        NULL,
92                                        DBUS_CORE_APPS_PATH,
93                                        DBUS_CORE_APPS_INTERFACE,
94                                        DBUS_CORE_APPS_MEMBER,
95                                        __handle_dbus_signal, ad);
96         retm_if(sh == NULL, "Connect Event register failed");
97         ad->app_core_sh = sh;
98
99         ad->dbus_conn = conn;
100         return;
101 }
102
103
104 void _bt_dbus_signal_deinit(bt_app_data_t *ad)
105 {
106         ret_if(ad == NULL);
107
108         DBG("");
109         e_dbus_signal_handler_del(ad->dbus_conn, ad->gesture_sh);
110         e_dbus_signal_handler_del(ad->dbus_conn, ad->app_core_sh);
111         return;
112 }
113