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