tizen 2.3 release
[framework/connectivity/bluez.git] / android / client / if-rc.c
1 /*
2  * Copyright (C) 2014 Intel Corporation
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<stdio.h>
19 #include<ctype.h>
20
21 #include<hardware/bluetooth.h>
22 #include<hardware/bt_hh.h>
23
24 #include "if-main.h"
25 #include "pollhandler.h"
26 #include "../hal-utils.h"
27
28 const btrc_interface_t *if_rc = NULL;
29
30 SINTMAP(btrc_play_status_t, -1, "(unknown)")
31         DELEMENT(BTRC_PLAYSTATE_STOPPED),
32         DELEMENT(BTRC_PLAYSTATE_PLAYING),
33         DELEMENT(BTRC_PLAYSTATE_PAUSED),
34         DELEMENT(BTRC_PLAYSTATE_FWD_SEEK),
35         DELEMENT(BTRC_PLAYSTATE_REV_SEEK),
36         DELEMENT(BTRC_PLAYSTATE_ERROR),
37 ENDMAP
38
39 SINTMAP(btrc_media_attr_t, -1, "(unknown)")
40         DELEMENT(BTRC_MEDIA_ATTR_TITLE),
41         DELEMENT(BTRC_MEDIA_ATTR_ARTIST),
42         DELEMENT(BTRC_MEDIA_ATTR_ALBUM),
43         DELEMENT(BTRC_MEDIA_ATTR_TRACK_NUM),
44         DELEMENT(BTRC_MEDIA_ATTR_NUM_TRACKS),
45         DELEMENT(BTRC_MEDIA_ATTR_GENRE),
46         DELEMENT(BTRC_MEDIA_ATTR_PLAYING_TIME),
47 ENDMAP
48
49 static char last_addr[MAX_ADDR_STR_LEN];
50
51 static void remote_features_cb(bt_bdaddr_t *bd_addr,
52                                         btrc_remote_features_t features)
53 {
54         haltest_info("%s: remote_bd_addr=%s features=%u\n", __func__,
55                                 bt_bdaddr_t2str(bd_addr, last_addr), features);
56 }
57
58 static void get_play_status_cb(void)
59 {
60         haltest_info("%s\n", __func__);
61 }
62
63 static void get_element_attr_cb(uint8_t num_attr, btrc_media_attr_t *attrs)
64 {
65         uint8_t i;
66
67         haltest_info("%s, num_of_attributes=%d\n", __func__, num_attr);
68
69         for (i = 0; i < num_attr; i++)
70                 haltest_info("attr id=%s\n", btrc_media_attr_t2str(attrs[i]));
71 }
72
73 static void register_notification_cb(btrc_event_id_t event_id, uint32_t param)
74 {
75         haltest_info("%s, event=%u param=%u\n", __func__, event_id, param);
76 }
77
78 static void volume_change_cb(uint8_t volume, uint8_t ctype)
79 {
80         haltest_info("%s, volume=%d ctype=%d\n", __func__, volume, ctype);
81 }
82
83 static btrc_callbacks_t rc_cbacks = {
84         .size = sizeof(rc_cbacks),
85         .remote_features_cb = remote_features_cb,
86         .get_play_status_cb = get_play_status_cb,
87         .get_element_attr_cb = get_element_attr_cb,
88         .register_notification_cb = register_notification_cb,
89         .volume_change_cb = volume_change_cb,
90 };
91
92 /* init */
93
94 static void init_p(int argc, const char **argv)
95 {
96         RETURN_IF_NULL(if_rc);
97
98         EXEC(if_rc->init, &rc_cbacks);
99 }
100
101 /* get_play_status_rsp */
102
103 static void get_play_status_rsp_c(int argc, const char **argv,
104                                         enum_func *enum_func, void **user)
105 {
106         if (argc == 3) {
107                 *user = TYPE_ENUM(btrc_play_status_t);
108                 *enum_func = enum_defines;
109         }
110 }
111
112 static void get_play_status_rsp_p(int argc, const char **argv)
113 {
114         btrc_play_status_t play_status;
115         uint32_t song_len, song_pos;
116
117         RETURN_IF_NULL(if_rc);
118
119         if (argc <= 2) {
120                 haltest_error("No play status specified");
121                 return;
122         }
123
124         if (argc <= 3) {
125                 haltest_error("No song length specified");
126                 return;
127         }
128
129         if (argc <= 4) {
130                 haltest_error("No song position specified");
131                 return;
132         }
133
134         play_status = str2btrc_play_status_t(argv[2]);
135         song_len = (uint32_t) atoi(argv[3]);
136         song_pos = (uint32_t) atoi(argv[4]);
137
138         EXEC(if_rc->get_play_status_rsp, play_status, song_len, song_pos);
139 }
140
141 /* get_element_attr_rsp */
142
143 static void get_element_attr_rsp_c(int argc, const char **argv,
144                                         enum_func *enum_func, void **user)
145 {
146         if (argc == 4) {
147                 *user = TYPE_ENUM(btrc_media_attr_t);
148                 *enum_func = enum_defines;
149         }
150 }
151
152 static void get_element_attr_rsp_p(int argc, const char **argv)
153 {
154         uint8_t num_attr;
155         btrc_element_attr_val_t attrs;
156
157         RETURN_IF_NULL(if_rc);
158
159         if (argc <= 2) {
160                 haltest_error("No number of attributes specified");
161                 return;
162         }
163
164         if (argc <= 4) {
165                 haltest_error("No attr id and value specified");
166                 return;
167         }
168
169         num_attr = (uint8_t) atoi(argv[2]);
170         attrs.attr_id = str2btrc_media_attr_t(argv[3]);
171         strcpy((char *)attrs.text, argv[4]);
172
173         EXEC(if_rc->get_element_attr_rsp, num_attr, &attrs);
174 }
175
176 /* set_volume */
177
178 static void set_volume_c(int argc, const char **argv,
179                                         enum_func *enum_func, void **user)
180 {
181 }
182
183 static void set_volume_p(int argc, const char **argv)
184 {
185         uint8_t volume;
186
187         RETURN_IF_NULL(if_rc);
188
189         if (argc <= 2) {
190                 haltest_error("No volume specified");
191                 return;
192         }
193
194         volume = (uint8_t) atoi(argv[2]);
195
196         EXEC(if_rc->set_volume, volume);
197 }
198
199 /* cleanup */
200
201 static void cleanup_p(int argc, const char **argv)
202 {
203         RETURN_IF_NULL(if_rc);
204
205         EXECV(if_rc->cleanup);
206         if_rc = NULL;
207 }
208
209 static struct method methods[] = {
210         STD_METHOD(init),
211         STD_METHODCH(get_play_status_rsp,
212                                         "<play_status> <song_len> <song_pos>"),
213         STD_METHODCH(get_element_attr_rsp, "<num_attr> <attrs_id> <value>"),
214         STD_METHODCH(set_volume, "<volume>"),
215         STD_METHOD(cleanup),
216         END_METHOD
217 };
218
219 const struct interface rc_if = {
220         .name = "rc",
221         .methods = methods
222 };