[bluetooth-frwk] setFolder
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-map-client.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *              http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <string.h>
19
20 #include "bluetooth-api.h"
21 #include "bt-internal-types.h"
22
23 #include "bt-common.h"
24 #include "bt-request-sender.h"
25 #include "bt-event-handler.h"
26
27 #ifdef TIZEN_DPM_ENABLE
28 #include "bt-dpm.h"
29 #endif
30
31 BT_EXPORT_API int bluetooth_map_init(void)
32 {
33         BT_DBG("bluetooth_map_init");
34         bt_user_info_t *user_info;
35
36         user_info = _bt_get_user_data(BT_COMMON);
37         retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
38
39         return _bt_register_event(BT_MAP_CLIENT_EVENT, user_info->cb, user_info->user_data);
40 }
41
42 BT_EXPORT_API int bluetooth_map_deinit(void)
43 {
44         BT_DBG("bluetooth_map_deinit");
45         return _bt_unregister_event(BT_MAP_CLIENT_EVENT);
46 }
47
48 BT_EXPORT_API int bluetooth_map_create_session(bt_map_session_info_s* session) {
49         BT_DBG("bluetooth_map_create_session");
50         int result = 0;
51
52         BT_CHECK_ENABLED(return);
53         BT_CHECK_PARAMETER(session->remote_address, return);
54
55         BT_INIT_PARAMS();
56         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
57
58         g_array_append_vals(in_param1, session->remote_address, strlen(session->remote_address)+1);
59
60         result = _bt_send_request(BT_OBEX_SERVICE, BT_MAP_CREATE_SESSION,
61                 in_param1, in_param2, in_param3, in_param4, &out_param);
62
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);
67                 } else {
68                         BT_ERR("out_param length is 0!!");
69                         return BLUETOOTH_ERROR_INTERNAL;
70                 }
71         }
72         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
73         return result;
74 }
75
76 BT_EXPORT_API int bluetooth_map_destroy_session(bt_map_session_info_s* session) {
77         BT_DBG("bluetooth_map_destroy_session");
78         int result = 0;
79
80         BT_CHECK_ENABLED(return);
81         BT_CHECK_PARAMETER(session->session_path, return);
82
83         BT_INIT_PARAMS();
84         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
85
86         g_array_append_vals(in_param1, session->session_path, strlen(session->session_path)+1);
87
88         result = _bt_send_request(BT_OBEX_SERVICE, BT_MAP_DESTROY_SESSION,
89                 in_param1, in_param2, in_param3, in_param4, &out_param);
90
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);
95                 free(session);
96         }
97         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
98         return result;
99 }
100
101 BT_EXPORT_API int bluetooth_map_set_folder(
102         bt_map_session_info_s* session,
103         const char* name)
104 {
105         BT_DBG("bluetooth_map_set_folder");
106         int result;
107
108         BT_CHECK_ENABLED(return);
109         BT_CHECK_PARAMETER(session->session_path, return);
110         BT_CHECK_PARAMETER(name, return);
111
112         BT_INIT_PARAMS();
113         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
114
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);
117
118         result = _bt_send_request(BT_OBEX_SERVICE, BT_MAP_SET_FOLDER,
119                 in_param1, in_param2, in_param3, in_param4, &out_param);
120
121         if (result != BLUETOOTH_ERROR_NONE) {
122                 BT_ERR("bluetooth_map_set_folder failed");
123                 return BLUETOOTH_ERROR_INTERNAL;
124         }
125
126         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
127
128         return result;
129 }
130
131 BT_EXPORT_API int bluetooth_map_update_inbox(bt_map_session_info_s* session)
132 {
133         BT_DBG("bluetooth_map_update_inbox");
134         int result;
135
136         BT_CHECK_ENABLED(return);
137         BT_CHECK_PARAMETER(session->session_path, return);
138
139         BT_INIT_PARAMS();
140         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
141
142         g_array_append_vals(in_param1, session->session_path, strlen(session->session_path)+1);
143
144         result = _bt_send_request(BT_OBEX_SERVICE, BT_MAP_UPDATE_INBOX,
145                 in_param1, in_param2, in_param3, in_param4, &out_param);
146
147         if (result != BLUETOOTH_ERROR_NONE) {
148                 BT_ERR("bluetooth_map_update_inbox failed");
149                 return BLUETOOTH_ERROR_INTERNAL;
150         }
151
152         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
153
154         return result;
155 }
156
157 /* TODO: MAP API */