2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dbus/dbus-protocol.h>
19 #include <dbus/dbus-glib.h>
20 #include <dbus/dbus-glib-bindings.h>
21 #include <dbus/dbus-glib-lowlevel.h>
23 #include "voice-call-dbus.h"
24 #include "voice-call-engine.h"
28 /* Voice Call <-- BT */
29 #define DBUS_BT_MATCH_RULE "type='signal',path='/org/projectx/bluetooth_event',interface='User.Bluetooth.AG'"
30 #define DBUS_BT_OBJECT_REQUEST "/org/projectx/bluetooth_event"
31 #define DBUS_BT_INTERFACE_REQUEST "User.Bluetooth.AG"
32 #define DBUS_BT_METHOD_REQUEST "Request"
34 /* Voice Call --> BT */
35 #define DBUS_BT_SERVICE "org.projectx.bluetooth"
36 #define DBUS_BT_OBJECT_RESPONSE "/org/projectx/btcall_event"
37 #define DBUS_BT_INTERFACE_RESPONSE "User.Bluetooth.AG"
38 #define DBUS_BT_METHOD_RESPONSE "Response"
39 /*#define DBUS_BT_METHOD_CONNECT "Connect"*/
41 #define BT_PKG "org.tizen.bluetooth"
43 static DBusGConnection *gconnection = NULL;
45 typedef struct _dbus_dest_t {
52 static int vc_engine_send_via_dbus(DBusGConnection *conn, dbus_dest_t *dest, int first_arg_type, ...)
63 CALL_ENG_DEBUG(ENG_DEBUG, "path:%s, interface:%s, method:%s", dest->object_path, dest->interface, dest->method);
64 msg = dbus_message_new_signal(dest->object_path, dest->interface, dest->method);
66 CALL_ENG_DEBUG(ENG_DEBUG, "dbus_message_new_signal failed.");
69 dbus_message_set_destination(msg, dest->service);
71 dbus_message_iter_init_append(msg, &iter);
73 type = first_arg_type;
75 va_start(list, first_arg_type);
76 while (type != DBUS_TYPE_INVALID) {
79 val_int = *(int *)(va_arg(list, dbus_int32_t));
80 dbus_message_iter_append_basic(&iter, type, &val_int);
83 case DBUS_TYPE_STRING:
84 val_str = va_arg(list, char *);
85 dbus_message_iter_append_basic(&iter, type, &val_str);
88 type = va_arg(list, int);
92 ret = dbus_connection_send(dbus_g_connection_get_connection(conn), msg, NULL);
93 dbus_connection_flush(dbus_g_connection_get_connection(conn));
94 dbus_message_unref(msg);
102 void vc_engine_on_dbus_send_connect_to_bt(void)
105 kb = bundle_create();
106 bundle_add(kb, "launch-type", "call");
107 aul_launch_app(BT_PKG, kb);
109 CALL_ENG_DEBUG(ENG_DEBUG, "End..");
112 void vc_engine_on_dbus_send_response_to_bt(connectivity_bt_ag_param_info_t bt_resp_info)
114 dbus_dest_t bt_dbus_dest = {
116 DBUS_BT_OBJECT_RESPONSE,
117 DBUS_BT_INTERFACE_RESPONSE,
118 DBUS_BT_METHOD_RESPONSE
120 CALL_ENG_DEBUG(ENG_DEBUG, "..");
122 vc_engine_send_via_dbus(gconnection, &bt_dbus_dest, DBUS_TYPE_INT32, &bt_resp_info.param1, \
123 DBUS_TYPE_INT32, &bt_resp_info.param2, DBUS_TYPE_INT32, &bt_resp_info.param3, DBUS_TYPE_STRING, bt_resp_info.param4, \
127 /* Handle all bluetooth relative signal */
128 static void vc_engine_on_dbus_parsing_bt(void *user_data, DBusMessage *message)
130 DBusMessageIter iter;
131 connectivity_bt_ag_param_info_t bt_event_info = { 0, };
132 call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)vcall_engine_get_core_state();
134 if (dbus_message_iter_init(message, &iter))
135 dbus_message_iter_get_basic(&iter, &bt_event_info.param1);
137 if (dbus_message_iter_next(&iter))
138 dbus_message_iter_get_basic(&iter, &bt_event_info.param2);
140 if (dbus_message_iter_next(&iter))
141 dbus_message_iter_get_basic(&iter, &bt_event_info.param3);
143 if (dbus_message_iter_next(&iter))
144 dbus_message_iter_get_basic(&iter, &bt_event_info.param4);
146 CALL_ENG_DEBUG(ENG_DEBUG, "param1:[%d], param2[%d], param3[%d], param4[%s]",
147 bt_event_info.param1, bt_event_info.param2, bt_event_info.param3, bt_event_info.param4);
149 _vc_bt_handle_bt_events(pcall_core, &bt_event_info);
152 /* Handle all dbus signal */
153 static DBusHandlerResult vc_engine_on_dbus_receive(DBusConnection *connection, DBusMessage *message, void *user_data)
157 const char *interface_name = dbus_message_get_interface(message);
158 const char *method_name = dbus_message_get_member(message);
159 const char *object_path = dbus_message_get_path(message);
161 type = dbus_message_get_type(message);
162 if (type != DBUS_MESSAGE_TYPE_SIGNAL) {
166 * METHOD_CALL_RETURN: 2
170 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
173 if (object_path == NULL) {
174 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
176 if (interface_name == NULL) {
177 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
179 if (method_name == NULL) {
180 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
183 /* Check BT Signal */
184 if ((strcmp(object_path, DBUS_BT_OBJECT_REQUEST) == 0) && (strcmp(interface_name, DBUS_BT_INTERFACE_REQUEST) == 0)) {
185 CALL_ENG_DEBUG(ENG_DEBUG, "received DBus BT signal!");
186 if (strcmp(method_name, DBUS_BT_METHOD_REQUEST) == 0) {
187 CALL_ENG_DEBUG(ENG_DEBUG, "BT Method :[Request]");
188 vc_engine_on_dbus_parsing_bt(user_data, message);
189 return DBUS_HANDLER_RESULT_HANDLED;
193 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
196 int vc_engine_dbus_receiver_setup()
198 GError *error = NULL;
202 /*connectio to dbus-daemon.*/
203 gconnection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
205 CALL_ENG_DEBUG(ENG_ERR,"Could not get connection: %s", error->message);
209 dbus_error_init(&derror);
211 dbus_bus_add_match(dbus_g_connection_get_connection(gconnection), DBUS_BT_MATCH_RULE, &derror);
212 if (dbus_error_is_set(&derror)) { /*failure*/
213 CALL_ENG_DEBUG(ENG_ERR, "Failed to dbus_bus_add_match(%s): %s", DBUS_BT_MATCH_RULE, derror.message);
214 dbus_error_free(&derror);
217 /*register event filter to handle received dbus-message.*/
218 ret = dbus_connection_add_filter(dbus_g_connection_get_connection(gconnection), vc_engine_on_dbus_receive, NULL, NULL);
220 CALL_ENG_DEBUG(ENG_ERR, "Failed to dbus_connection_add_filter");