4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include "bluetooth-api.h"
23 #include "bt-internal-types.h"
25 #include "bt-common.h"
26 #include "bt-request-sender.h"
27 #include "bt-event-handler.h"
30 static void __bt_get_file_size(char **files, unsigned long *file_size, int *count)
33 unsigned long size = 0;
35 while (files[file_count] != NULL) {
36 size = size + strlen(files[file_count]);
44 BT_EXPORT_API int bluetooth_opc_init(void)
46 bt_user_info_t *user_info;
48 user_info = _bt_get_user_data(BT_COMMON);
49 retv_if(user_info == NULL, BLUETOOTH_ERROR_INTERNAL);
51 return _bt_register_event(BT_OPP_CLIENT_EVENT, user_info->cb, user_info->user_data);
54 BT_EXPORT_API int bluetooth_opc_deinit(void)
56 return _bt_unregister_event(BT_OPP_CLIENT_EVENT);
59 BT_EXPORT_API int bluetooth_opc_push_files(bluetooth_device_address_t *remote_address,
60 char **file_name_array)
66 bt_user_info_t *user_info;
67 char filename[BT_FILE_PATH_MAX];
69 BT_CHECK_PARAMETER(remote_address, return);
70 BT_CHECK_PARAMETER(file_name_array, return);
71 BT_CHECK_ENABLED(return);
73 __bt_get_file_size(file_name_array, &size, &file_count);
74 retv_if(file_count == 0, BLUETOOTH_ERROR_INVALID_PARAM);
77 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
79 user_info = _bt_get_user_data(BT_COMMON);
80 retv_if(user_info == NULL, BLUETOOTH_ERROR_INTERNAL);
82 g_array_append_vals(in_param1, remote_address, sizeof(bluetooth_device_address_t));
84 for (i = 0; i < file_count; i++) {
85 g_strlcpy(filename, file_name_array[i], sizeof(filename));
86 g_array_append_vals(in_param2, filename, BT_FILE_PATH_MAX);
89 g_array_append_vals(in_param3, &file_count, sizeof(int));
91 result = _bt_send_request_async(BT_OBEX_SERVICE, BT_OPP_PUSH_FILES,
92 in_param1, in_param2, in_param3, in_param4,
93 user_info->cb, user_info->user_data);
95 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
100 BT_EXPORT_API int bluetooth_opc_cancel_push(void)
104 BT_CHECK_ENABLED(return);
107 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
109 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_CANCEL_PUSH,
110 in_param1, in_param2, in_param3, in_param4, &out_param);
112 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
117 BT_EXPORT_API gboolean bluetooth_opc_session_is_exist(void)
120 gboolean exist = FALSE;
122 BT_CHECK_ENABLED(return);
125 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
127 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_IS_PUSHING_FILES,
128 in_param1, in_param2, in_param3, in_param4, &out_param);
130 if (result == BLUETOOTH_ERROR_NONE) {
131 exist = g_array_index(out_param, gboolean, 0);
133 BT_ERR("Fail to send request");
136 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
141 BT_EXPORT_API int bluetooth_opc_is_sending(gboolean *is_sending)
147 BT_CHECK_ENABLED(return);
150 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
152 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_IS_PUSHING_FILES,
153 in_param1, in_param2, in_param3, in_param4, &out_param);
155 if (result == BLUETOOTH_ERROR_NONE) {
156 *is_sending = g_array_index(out_param, gboolean, 0);
158 BT_ERR("Fail to send request");
161 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);