2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.
21 #include <mime_type.h>
26 #include "bluetooth-api.h"
27 #include "bt-internal-types.h"
29 #include "bt-service-common.h"
30 #include "bt-service-event.h"
31 #include "bt-service-util.h"
32 #include "bt-service-map-client.h"
33 #include "bt-service-obex-agent.h"
34 #include "bt-service-adapter.h"
36 #define DBUS_TIEMOUT 20 * 1000 /* 20 Seconds */
38 bt_session_info_t *session_info;
40 static void __bt_free_session_info(bt_session_info_t *info)
44 /* TODO: MAP bt_session_info_t, see bt-service-opp-client.c */
46 g_free(info->address);
50 static void __bt_free_session_data(gpointer data)
52 bt_session_data_t *info = data;
56 _bt_delete_request_id(info->request_id);
58 /* TODO: MAP bt_session_data_t, see bt-service-opp-client.c */
60 g_free(info->address);
64 static void __bt_session_release_cb(GDBusProxy *proxy,
65 GAsyncResult *res, gpointer user_data)
68 ret_if(session_info == NULL);
71 int result = BLUETOOTH_ERROR_NONE;
72 GVariant *param = NULL;
73 g_dbus_proxy_call_finish(proxy, res, &error);
75 g_object_unref(proxy);
78 BT_ERR("%s", error->message);
81 result = BLUETOOTH_ERROR_INTERNAL;
83 BT_DBG("Session Removed");
86 session_info->result = result;
87 param = g_variant_new("(isi)", session_info->result,
88 session_info->address,
89 session_info->request_id);
90 /* Send the event in only error none case */
91 _bt_send_event(BT_OPP_CLIENT_EVENT,
92 BLUETOOTH_EVENT_OPC_DISCONNECTED,
95 __bt_free_session_info(session_info);
98 _bt_map_client_event_deinit();
100 /* Operate remain works */
111 static int _bt_remove_session()
113 GDBusConnection *g_conn;
114 GDBusProxy *session_proxy;
117 g_conn = _bt_gdbus_get_session_gconn();
118 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
119 retv_if(session_info->session_path == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
121 session_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
122 NULL, BT_OBEXD_DBUS_NAME,
124 BT_OBEX_CLIENT_INTERFACE,
127 retv_if(session_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
129 g_dbus_proxy_call(session_proxy, "RemoveSession",
130 g_variant_new("(o)", session_info->session_path),
131 G_DBUS_CALL_FLAGS_NONE,
133 (GAsyncReadyCallback)__bt_session_release_cb,
136 return BLUETOOTH_ERROR_NONE;
139 void _bt_map_disconnected(const char *session_path)
142 GVariant *param = NULL;
143 ret_if(session_info == NULL);
145 if (g_strcmp0(session_info->session_path,
146 session_path) != 0) {
147 BT_INFO("Path mismatch, previous transfer failed! Returning");
151 param = g_variant_new("(isi)", session_info->result,
152 session_info->address,
153 session_info->request_id);
154 _bt_send_event(BT_MAP_CLIENT_EVENT,
155 BLUETOOTH_EVENT_MAP_DISCONNECTED,
158 __bt_free_session_info(session_info);
164 static void __bt_create_session_cb(GDBusProxy *proxy,
165 GAsyncResult *res, gpointer user_data)
169 GError *error = NULL;
171 int result = BLUETOOTH_ERROR_NONE;
172 char *session_path = NULL;
173 GVariant *param = NULL;
175 value = g_dbus_proxy_call_finish(proxy, res, &error);
177 g_variant_get(value, "(o)", &session_path);
178 g_variant_unref(value);
182 BT_ERR("%s", error->message);
183 g_clear_error(&error);
185 result = BLUETOOTH_ERROR_INTERNAL;
187 BT_DBG("Session created");
188 if (session_info != NULL)
189 session_info->session_path = g_strdup(session_path);
191 g_free(session_path);
192 g_object_unref(proxy);
193 ret_if(session_info == NULL);
195 session_info->result = result;
196 param = g_variant_new("(isi)", result,
197 session_info->address,
198 session_info->request_id);
199 /* Send the event in only error none case */
200 _bt_send_event(BT_MAP_CLIENT_EVENT,
201 BLUETOOTH_EVENT_MAP_CONNECTED,
204 if (result != BLUETOOTH_ERROR_NONE) {
205 BT_ERR("Calling __bt_session_release");
206 gboolean ret = __bt_session_release();
208 __bt_free_session_info(session_info);
212 BT_DBG("ReleaseSession Not called");
213 /* Operate remain works */
227 static int __bt_opp_client_start_XXXXXXXXXX(int request_id, char *address
228 /* parameters................... */)