fb73270eceae1c26633a0d916020055b5c912769
[platform/core/connectivity/bluetooth-frwk.git] / test / media-control / bluetooth-media-control-test.c
1 /*
2  * Copyright (c) 2011 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 <stdio.h>
19 #include <stdlib.h>
20 #include "bluetooth-media-control.h"
21
22 #include <glib.h>
23 #include <dbus/dbus-glib.h>
24 #include <dbus/dbus-glib-lowlevel.h>
25
26 #define MEDIA_ATRRIBUTE_LENGTH  256
27
28 media_player_settings_t player_settings = {0x00, 0x00, 0x00, 0x00, 0x01, 1111};
29 media_metadata_attributes_t metadata = {"Test Track", "Chethan", "TNC", "Tumkur", 1, 1, 14400};
30
31 void static __choose_metadata_settings(void)
32 {
33         int cmd;
34         media_metadata_attributes_t metadata = {0,};
35
36         while (1) {
37                 printf("\nPlease enter\n");
38                 printf("\t0: return to main menu\n");
39                 printf("\t1: Meta data settings\n");
40                 printf("\tEnter your choice [ ]\b\b");
41
42                 scanf("%d", &cmd);
43
44                 switch (cmd) {
45                 case 0:
46                         return;
47                 case 1: /* Title */
48
49                         metadata.title = calloc(1, MEDIA_ATRRIBUTE_LENGTH);
50                         metadata.artist = calloc(1, MEDIA_ATRRIBUTE_LENGTH);
51                         metadata.album = calloc(1, MEDIA_ATRRIBUTE_LENGTH);
52                         metadata.genre = calloc(1, MEDIA_ATRRIBUTE_LENGTH);
53
54                         printf("Enter the \"Track\" name\n");
55                         scanf("%s", (char *)metadata.title);
56
57                         printf(" Enter the \"Artist\" name\n");
58                         scanf("%s", (char *)metadata.artist);
59
60                         printf(" Enter the \"Album\" name\n");
61                         scanf("%s", (char *)metadata.album);
62
63                         printf(" Enter the \"Genre\" \n");
64                         scanf("%s", (char *)metadata.genre);
65
66                         printf(" Enter the \" Totol NumberOfTracks\" \n");
67                         scanf("%d", &metadata.total_tracks);
68
69                         printf(" Enter the \" Track Number\" \n");
70                         scanf("%d", &metadata.number);
71
72                         printf(" Enter the \"Duration\" \n");
73                         scanf("%d", &metadata.duration);
74                         break;
75                 default:
76                         break;
77                 }
78                 bluetooth_media_player_change_track(&metadata);
79
80                 if (NULL !=  metadata.title) {
81                         free((void *)metadata.title);
82                         metadata.title = NULL;
83                 }
84                 if (NULL !=  metadata.artist) {
85                         free((void *)metadata.artist);
86                         metadata.artist = NULL;
87                 }
88                 if (NULL !=  metadata.album) {
89                         free((void *)metadata.album);
90                         metadata.album = NULL;
91                 }
92                 if (NULL !=  metadata.genre) {
93                         free((void *)metadata.genre);
94                         metadata.genre = NULL;
95                 }
96         }
97 }
98
99 void static __choose_player_settings(void)
100 {
101         int cmd;
102         media_player_property_type type;
103
104         while (1) {
105                 printf("\nPlease choose player settings\n");
106                 printf("\t0: return to main menu\n");
107                 printf("\t1. Equalizer\n");
108                 printf("\t2. Repeat\n");
109                 printf("\t3. Shuffle\n");
110                 printf("\t4. Scan \n");
111                 printf("\t5. Status \n");
112                 printf("\t6. Position \n");
113                 printf("\tEnter your choice [ ]\b\b");
114
115                 scanf("%d", &cmd);
116
117                 switch (cmd) {
118                 case 0:
119                         return;
120                 case 1: /* Equalizer */
121                 {
122                         printf("Possible Values - EQUALIZER_OFF = 0x00 and EQUALIZER_ON = 0x01,\n");
123                         scanf("%d", &player_settings.equalizer);
124                         type = EQUALIZER;
125
126                         bluetooth_media_player_change_property(type,
127                                 (unsigned int)player_settings.equalizer);
128
129                         break;
130                 }
131                 case 2: /*Repeat */
132                 {
133                         printf(" Possible Values - REPEAT_MODE_OFF = 0x00, REPEAT_SINGLE_TRACK = 0x01 , \
134                                         REPEAT_ALL_TRACK = 0x02,        REPEAT_GROUP = 0x03\n");
135                         scanf("%d", &player_settings.repeat);
136                         type = REPEAT;
137
138                         bluetooth_media_player_change_property(type,
139                                 (unsigned int)player_settings.repeat);
140                         break;
141                 }
142                 case 3: /* Shuffle */
143                 {
144                         printf(" Possible Values - SHUFFLE_MODE_OFF = 0x00, SHUFFLE_ALL_TRACK = 0x01 , \
145                                         SHUFFLE_GROUP = 0x02\n");
146                         scanf("%d", &player_settings.shuffle);
147                         type = SHUFFLE;
148
149                         bluetooth_media_player_change_property(type,
150                                 (unsigned int)player_settings.shuffle);
151                         break;
152                 }
153                 case 4: /* Scan */
154                 {
155                         printf(" Possible Values - SCAN_MODE_OFF = 0x00, SCAN_ALL_TRACK = 0x01 , \
156                                         SCAN_GROUP = 0x02\n");
157                         scanf("%d", &player_settings.scan);
158                         type = SCAN;
159
160                         bluetooth_media_player_change_property(type,
161                                 (unsigned int)player_settings.scan);
162                         break;
163                 }
164                 case 5: /* Status */
165                 {
166                         printf(" Possible Values - STATUS_PLAYING = 0x00, STATUS_STOPPED = 0x01 , \
167                                         STATUS_PAUSED = 0x02,STATUS_FORWARD_SEEK = 0x03 \
168                                         STATUS_REVERSE_SEEK = 0x04 STATUS_ERROR = 0x05\n");
169                         scanf("%d", &player_settings.status);
170                         type = STATUS;
171
172                         bluetooth_media_player_change_property(type,
173                                 (unsigned int)player_settings.status);
174                         break;
175                 }
176                 case 6: /* Position */
177                 {
178                         printf("Enter the possible value: ");
179                         scanf("%d", &player_settings.position);
180                         type = POSITION;
181
182                         bluetooth_media_player_change_property(type,
183                                 player_settings.position);
184                         break;
185                 }
186                 default:
187                         break;
188                 }
189         }
190 }
191
192 int main()
193 {
194         GMainLoop *agent_loop;
195         int cmd;
196
197         agent_loop = g_main_loop_new(NULL, FALSE);
198
199         printf("MP-AV test application started\n");
200         while (1) {
201                 printf("\n\n\t0. Exit\n");
202                 printf("\t1. bluetooth_media_player_property_changed\n");
203                 printf("\t2. bluetooth_media_player_track_changed\n");
204                 printf("\tEnter your choice [  ]\b\b");
205
206                 scanf("%d", &cmd);
207
208                 switch (cmd) {
209                 case 0: /* exit the application */
210                         {
211                                 exit(0);
212                                 break;
213                         }
214                 case 1:
215                         {
216                                 __choose_player_settings();
217                                 break;
218                         }
219                 case 2:
220                         {
221                                 __choose_metadata_settings();
222                                 break;
223                         }
224                 }
225         }
226         printf("gmain loop enter\n");
227         g_main_loop_run(agent_loop);
228         printf("gmain loop leave\n");
229         return 0;
230 }