2 * Copyright (c) 2016 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.
20 #include "bluetooth-api.h"
21 #include "bt-internal-types.h"
23 #include "bt-common.h"
24 #include "bt-request-sender.h"
25 #include "bt-event-handler.h"
27 #ifdef TIZEN_DPM_ENABLE
31 BT_EXPORT_API int bluetooth_map_init(void)
33 BT_DBG("bluetooth_map_init");
34 bt_user_info_t *user_info;
36 user_info = _bt_get_user_data(BT_COMMON);
37 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
39 return _bt_register_event(BT_MAP_CLIENT_EVENT, user_info->cb, user_info->user_data);
42 BT_EXPORT_API int bluetooth_map_deinit(void)
44 BT_DBG("bluetooth_map_deinit");
45 return _bt_unregister_event(BT_MAP_CLIENT_EVENT);
48 BT_EXPORT_API int bluetooth_map_create_session(bt_map_session_info_s* session) {
49 BT_DBG("bluetooth_map_create_session");
52 BT_CHECK_ENABLED(return);
53 BT_CHECK_PARAMETER(session->remote_address, return);
56 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
58 g_array_append_vals(in_param1, session->remote_address, strlen(session->remote_address)+1);
60 result = _bt_send_request(BT_OBEX_SERVICE, BT_MAP_CREATE_SESSION,
61 in_param1, in_param2, in_param3, in_param4, &out_param);
63 if (result == BLUETOOTH_ERROR_NONE) {
64 if (out_param->len > 0) {
65 session->session_path = strdup(&g_array_index(out_param, char, 0));
66 BT_DBG("session id: %s", session->session_path);
68 BT_ERR("out_param length is 0!!");
69 return BLUETOOTH_ERROR_INTERNAL;
72 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
76 BT_EXPORT_API int bluetooth_map_destroy_session(bt_map_session_info_s* session) {
77 BT_DBG("bluetooth_map_destroy_session");
80 BT_CHECK_ENABLED(return);
81 BT_CHECK_PARAMETER(session->session_path, return);
84 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
86 g_array_append_vals(in_param1, session->session_path, strlen(session->session_path)+1);
88 result = _bt_send_request(BT_OBEX_SERVICE, BT_MAP_DESTROY_SESSION,
89 in_param1, in_param2, in_param3, in_param4, &out_param);
91 if (result == BLUETOOTH_ERROR_NONE) {
92 BT_DBG("session (%s) was destroyed", session->session_path);
93 free(session->remote_address);
94 free(session->session_path);
97 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
101 BT_EXPORT_API int bluetooth_map_set_folder(
102 bt_map_session_info_s* session,
105 BT_DBG("bluetooth_map_set_folder");
108 BT_CHECK_ENABLED(return);
109 BT_CHECK_PARAMETER(session->session_path, return);
110 BT_CHECK_PARAMETER(name, return);
113 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
115 g_array_append_vals(in_param1, session->session_path, strlen(session->session_path) + 1);
116 g_array_append_vals(in_param2, name, strlen(name) + 1);
118 result = _bt_send_request(BT_OBEX_SERVICE, BT_MAP_SET_FOLDER,
119 in_param1, in_param2, in_param3, in_param4, &out_param);
121 if (result != BLUETOOTH_ERROR_NONE) {
122 BT_ERR("bluetooth_map_set_folder failed");
123 return BLUETOOTH_ERROR_INTERNAL;
126 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
131 BT_EXPORT_API int bluetooth_map_update_inbox(bt_map_session_info_s* session)
133 BT_DBG("bluetooth_map_update_inbox");
136 BT_CHECK_ENABLED(return);
137 BT_CHECK_PARAMETER(session->session_path, return);
140 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
142 g_array_append_vals(in_param1, session->session_path, strlen(session->session_path)+1);
144 result = _bt_send_request(BT_OBEX_SERVICE, BT_MAP_UPDATE_INBOX,
145 in_param1, in_param2, in_param3, in_param4, &out_param);
147 if (result != BLUETOOTH_ERROR_NONE) {
148 BT_ERR("bluetooth_map_update_inbox failed");
149 return BLUETOOTH_ERROR_INTERNAL;
152 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);