4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (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
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * 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.
26 #include "bluetooth-api.h"
27 #include "bt-internal-types.h"
29 #include "bt-common.h"
30 #include "bt-request-sender.h"
31 #include "bt-event-handler.h"
33 static void __bt_get_file_size(char **files, unsigned long *file_size, int *count)
36 unsigned long size = 0;
38 while (files[file_count] != NULL) {
39 size = size + strlen(files[file_count]);
47 BT_EXPORT_API int bluetooth_opc_init(void)
49 bt_user_info_t *user_info;
51 user_info = _bt_get_user_data(BT_COMMON);
52 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
54 return _bt_register_event(BT_OPP_CLIENT_EVENT, user_info->cb, user_info->user_data);
57 BT_EXPORT_API int bluetooth_opc_deinit(void)
59 return _bt_unregister_event(BT_OPP_CLIENT_EVENT);
62 BT_EXPORT_API int bluetooth_opc_push_files(bluetooth_device_address_t *remote_address,
63 char **file_name_array)
69 bt_user_info_t *user_info;
70 char filename[BT_FILE_PATH_MAX];
72 BT_CHECK_PARAMETER(remote_address, return);
73 BT_CHECK_PARAMETER(file_name_array, return);
74 BT_CHECK_ENABLED(return);
76 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_OPP_PUSH_FILES)
77 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
78 BT_ERR("Don't have a privilege to use this API");
79 return BLUETOOTH_ERROR_PERMISSION_DEINED;
82 __bt_get_file_size(file_name_array, &size, &file_count);
83 retv_if(file_count == 0, BLUETOOTH_ERROR_INVALID_PARAM);
85 user_info = _bt_get_user_data(BT_COMMON);
86 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
89 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
91 g_array_append_vals(in_param1, remote_address, sizeof(bluetooth_device_address_t));
93 for (i = 0; i < file_count; i++) {
94 if (strlen(file_name_array[i]) >= sizeof(filename)) {
95 BT_ERR("[%s] has too long path.", file_name_array[i]);
96 BT_FREE_PARAMS(in_param1, in_param2, in_param3,
97 in_param4, out_param);
98 return BLUETOOTH_ERROR_INVALID_PARAM;
100 g_strlcpy(filename, file_name_array[i], sizeof(filename));
101 g_array_append_vals(in_param2, filename, BT_FILE_PATH_MAX);
104 g_array_append_vals(in_param3, &file_count, sizeof(int));
106 result = _bt_send_request_async(BT_OBEX_SERVICE, BT_OPP_PUSH_FILES,
107 in_param1, in_param2, in_param3, in_param4,
108 user_info->cb, user_info->user_data);
110 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
115 BT_EXPORT_API int bluetooth_opc_cancel_push(void)
119 BT_CHECK_ENABLED(return);
122 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
124 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_CANCEL_PUSH,
125 in_param1, in_param2, in_param3, in_param4, &out_param);
127 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
132 BT_EXPORT_API gboolean bluetooth_opc_session_is_exist(void)
135 gboolean exist = FALSE;
137 BT_CHECK_ENABLED(return);
140 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
142 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_IS_PUSHING_FILES,
143 in_param1, in_param2, in_param3, in_param4, &out_param);
145 if (result == BLUETOOTH_ERROR_NONE) {
146 exist = g_array_index(out_param, gboolean, 0);
147 BT_DBG("Exist %d", exist);
149 BT_ERR("Fail to send request");
152 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
157 BT_EXPORT_API int bluetooth_opc_is_sending(gboolean *is_sending)
163 BT_CHECK_ENABLED(return);
166 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
168 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_IS_PUSHING_FILES,
169 in_param1, in_param2, in_param3, in_param4, &out_param);
171 if (result == BLUETOOTH_ERROR_NONE) {
172 *is_sending = g_array_index(out_param, gboolean, 0);
174 BT_ERR("Fail to send request");
177 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);