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.
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 static void __bt_get_file_size(char **files, unsigned long *file_size, int *count)
30 unsigned long size = 0;
32 while (files[file_count] != NULL) {
33 size = size + strlen(files[file_count]);
41 BT_EXPORT_API int bluetooth_opc_init(void)
43 bt_user_info_t *user_info;
45 user_info = _bt_get_user_data(BT_COMMON);
46 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
48 return _bt_register_event(BT_OPP_CLIENT_EVENT, user_info->cb, user_info->user_data);
51 BT_EXPORT_API int bluetooth_opc_deinit(void)
53 return _bt_unregister_event(BT_OPP_CLIENT_EVENT);
56 BT_EXPORT_API int bluetooth_opc_push_files(bluetooth_device_address_t *remote_address,
57 char **file_name_array)
63 bt_user_info_t *user_info;
64 char filename[BT_FILE_PATH_MAX];
66 BT_CHECK_PARAMETER(remote_address, return);
67 BT_CHECK_PARAMETER(file_name_array, return);
68 BT_CHECK_ENABLED(return);
70 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_OPP_PUSH_FILES)
71 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
72 BT_ERR("Don't have a privilege to use this API");
73 return BLUETOOTH_ERROR_PERMISSION_DEINED;
76 __bt_get_file_size(file_name_array, &size, &file_count);
77 retv_if(file_count == 0, BLUETOOTH_ERROR_INVALID_PARAM);
79 user_info = _bt_get_user_data(BT_COMMON);
80 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
83 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
85 g_array_append_vals(in_param1, remote_address, sizeof(bluetooth_device_address_t));
87 for (i = 0; i < file_count; i++) {
88 if (strlen(file_name_array[i]) >= sizeof(filename)) {
89 BT_ERR("[%s] has too long path.", file_name_array[i]);
90 BT_FREE_PARAMS(in_param1, in_param2, in_param3,
91 in_param4, out_param);
92 return BLUETOOTH_ERROR_INVALID_PARAM;
94 g_strlcpy(filename, file_name_array[i], sizeof(filename));
95 g_array_append_vals(in_param2, filename, BT_FILE_PATH_MAX);
98 g_array_append_vals(in_param3, &file_count, sizeof(int));
100 result = _bt_send_request_async(BT_OBEX_SERVICE, BT_OPP_PUSH_FILES,
101 in_param1, in_param2, in_param3, in_param4,
102 user_info->cb, user_info->user_data);
104 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
109 BT_EXPORT_API int bluetooth_opc_cancel_push(void)
113 BT_CHECK_ENABLED(return);
116 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
118 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_CANCEL_PUSH,
119 in_param1, in_param2, in_param3, in_param4, &out_param);
121 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
126 BT_EXPORT_API gboolean bluetooth_opc_session_is_exist(void)
129 gboolean exist = FALSE;
131 BT_CHECK_ENABLED(return);
134 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
136 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_IS_PUSHING_FILES,
137 in_param1, in_param2, in_param3, in_param4, &out_param);
139 if (result == BLUETOOTH_ERROR_NONE) {
140 exist = g_array_index(out_param, gboolean, 0);
141 BT_DBG("Exist %d", exist);
143 BT_ERR("Fail to send request");
146 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
151 BT_EXPORT_API int bluetooth_opc_is_sending(gboolean *is_sending)
157 BT_CHECK_ENABLED(return);
160 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
162 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_IS_PUSHING_FILES,
163 in_param1, in_param2, in_param3, in_param4, &out_param);
165 if (result == BLUETOOTH_ERROR_NONE) {
166 *is_sending = g_array_index(out_param, gboolean, 0);
168 BT_ERR("Fail to send request");
171 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);