Code Sync [Tizen3.0]: Merged the tizen_2.4 Spin code to tizen.org
[platform/core/connectivity/bluetooth-frwk.git] / test / media-control / bluetooth-media-control-test.c
1 /*
2  *   bluetooth-media-control
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
7  *               Girishashok Joshi <girish.joshi@samsung.com>
8  *               Chanyeol Park <chanyeol.park@samsung.com>
9  *
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include "bluetooth-media-control.h"
28
29 #include <glib.h>
30 #include <dbus/dbus-glib.h>
31 #include <dbus/dbus-glib-lowlevel.h>
32
33 #define MEDIA_ATRRIBUTE_LENGTH  256
34
35 media_player_settings_t player_settings = {0x00, 0x00, 0x00, 0x00, 0x01, 1111};
36 media_metadata_attributes_t metadata = {"Test Track", "Chethan", "TNC", "Tumkur", 1, 1, 14400};
37
38 void static __choose_metadata_settings(void)
39 {
40         int cmd;
41         media_metadata_attributes_t metadata = {0,};
42
43         while (1) {
44                 printf("\nPlease enter\n");
45                 printf("\t0: return to main menu\n");
46                 printf("\t1: Meta data settings\n");
47                 printf("\tEnter your choice [ ]\b\b");
48
49                 scanf("%d", &cmd);
50
51                 switch (cmd) {
52                 case 0:
53                         return;
54                 case 1: /* Title */
55
56                         metadata.title = calloc(1, MEDIA_ATRRIBUTE_LENGTH);
57                         metadata.artist = calloc(1, MEDIA_ATRRIBUTE_LENGTH);
58                         metadata.album = calloc(1, MEDIA_ATRRIBUTE_LENGTH);
59                         metadata.genre = calloc(1, MEDIA_ATRRIBUTE_LENGTH);
60
61                         printf("Enter the \"Track\" name\n");
62                         scanf("%s", (char *)metadata.title);
63
64                         printf(" Enter the \"Artist\" name\n");
65                         scanf("%s", (char *)metadata.artist);
66
67                         printf(" Enter the \"Album\" name\n");
68                         scanf("%s", (char *)metadata.album);
69
70                         printf(" Enter the \"Genre\" \n");
71                         scanf("%s", (char *)metadata.genre);
72
73                         printf(" Enter the \" Totol NumberOfTracks\" \n");
74                         scanf("%d", &metadata.total_tracks);
75
76                         printf(" Enter the \" Track Number\" \n");
77                         scanf("%d", &metadata.number);
78
79                         printf(" Enter the \"Duration\" \n");
80                         scanf("%d", &metadata.duration);
81                         break;
82                 default:
83                         break;
84                 }
85                 bluetooth_media_player_change_track(&metadata);
86
87                 if (NULL !=  metadata.title) {
88                         free((void *)metadata.title);
89                         metadata.title = NULL;
90                 }
91                 if (NULL !=  metadata.artist) {
92                         free((void *)metadata.artist);
93                         metadata.artist = NULL;
94                 }
95                 if (NULL !=  metadata.album) {
96                         free((void *)metadata.album);
97                         metadata.album = NULL;
98                 }
99                 if (NULL !=  metadata.genre) {
100                         free((void *)metadata.genre);
101                         metadata.genre = NULL;
102                 }
103         }
104 }
105
106 void static __choose_player_settings(void)
107 {
108         int cmd;
109         media_player_property_type type;
110
111         while (1) {
112                 printf("\nPlease choose player settings\n");
113                 printf("\t0: return to main menu\n");
114                 printf("\t1. Equalizer\n");
115                 printf("\t2. Repeat\n");
116                 printf("\t3. Shuffle\n");
117                 printf("\t4. Scan \n");
118                 printf("\t5. Status \n");
119                 printf("\t6. Position \n");
120                 printf("\tEnter your choice [ ]\b\b");
121
122                 scanf("%d", &cmd);
123
124                 switch (cmd) {
125                 case 0:
126                         return;
127                 case 1: /* Equalizer */
128                 {
129                         printf("Possible Values - EQUALIZER_OFF = 0x00 and EQUALIZER_ON = 0x01,\n");
130                         scanf("%d", &player_settings.equalizer);
131                         type = EQUALIZER;
132
133                         bluetooth_media_player_change_property(type,
134                                 (unsigned int)player_settings.equalizer);
135
136                         break;
137                 }
138                 case 2: /*Repeat */
139                 {
140                         printf(" Possible Values - REPEAT_MODE_OFF = 0x00, REPEAT_SINGLE_TRACK = 0x01 , \
141                                         REPEAT_ALL_TRACK = 0x02,        REPEAT_GROUP = 0x03\n");
142                         scanf("%d", &player_settings.repeat);
143                         type = REPEAT;
144
145                         bluetooth_media_player_change_property(type,
146                                 (unsigned int)player_settings.repeat);
147                         break;
148                 }
149                 case 3: /* Shuffle */
150                 {
151                         printf(" Possible Values - SHUFFLE_MODE_OFF = 0x00, SHUFFLE_ALL_TRACK = 0x01 , \
152                                         SHUFFLE_GROUP = 0x02\n");
153                         scanf("%d", &player_settings.shuffle);
154                         type = SHUFFLE;
155
156                         bluetooth_media_player_change_property(type,
157                                 (unsigned int)player_settings.shuffle);
158                         break;
159                 }
160                 case 4: /* Scan */
161                 {
162                         printf(" Possible Values - SCAN_MODE_OFF = 0x00, SCAN_ALL_TRACK = 0x01 , \
163                                         SCAN_GROUP = 0x02\n");
164                         scanf("%d", &player_settings.scan);
165                         type = SCAN;
166
167                         bluetooth_media_player_change_property(type,
168                                 (unsigned int)player_settings.scan);
169                         break;
170                 }
171                 case 5: /* Status */
172                 {
173                         printf(" Possible Values - STATUS_PLAYING = 0x00, STATUS_STOPPED = 0x01 , \
174                                         STATUS_PAUSED = 0x02,STATUS_FORWARD_SEEK = 0x03 \
175                                         STATUS_REVERSE_SEEK = 0x04 STATUS_ERROR = 0x05\n");
176                         scanf("%d", &player_settings.status);
177                         type = STATUS;
178
179                         bluetooth_media_player_change_property(type,
180                                 (unsigned int)player_settings.status);
181                         break;
182                 }
183                 case 6: /* Position */
184                 {
185                         printf("Enter the possible value: ");
186                         scanf("%d", &player_settings.position);
187                         type = POSITION;
188
189                         bluetooth_media_player_change_property(type,
190                                 player_settings.position);
191                         break;
192                 }
193                 default:
194                         break;
195                 }
196         }
197 }
198
199 int main()
200 {
201         GMainLoop *agent_loop;
202         int cmd;
203
204         g_type_init();
205         agent_loop = g_main_loop_new(NULL, FALSE);
206
207         printf("MP-AV test application started\n");
208         while (1) {
209                 printf("\n\n\t0. Exit\n");
210                 printf("\t1. bluetooth_media_player_property_changed\n");
211                 printf("\t2. bluetooth_media_player_track_changed\n");
212                 printf("\tEnter your choice [  ]\b\b");
213
214                 scanf("%d", &cmd);
215
216                 switch (cmd) {
217                 case 0: /* exit the application */
218                         {
219                                 exit(0);
220                                 break;
221                         }
222                 case 1:
223                         {
224                                 __choose_player_settings();
225                                 break;
226                         }
227                 case 2:
228                         {
229                                 __choose_metadata_settings();
230                                 break;
231                         }
232                 }
233         }
234         printf("gmain loop enter\n");
235         g_main_loop_run(agent_loop);
236         printf("gmain loop leave\n");
237         return 0;
238 }