Fix internal bug and change the design of ico-app-samplenavi
[profile/ivi/ico-uxf-homescreen-sample-apps.git] / src / soundsample.c
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the 
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9 /**
10  * @brief   Sound Sample APP
11  *          Test use with which sound is sounded
12  *
13  * @date    Mar-04-2013
14  */
15
16 #ifdef HAVE_CONFIG_H
17
18 #include "config.h"
19 #define __UNUSED__
20 #else
21 #define __UNUSED__
22 #endif
23
24 #include <Ecore.h>
25 #include <Ecore_Evas.h>
26
27 #include <unistd.h>
28 #include <glib.h>
29 //#include "app_log.h"
30 #include "ico_apf.h"
31 #include "ico_apf_ecore.h"
32 #include "ico_apf_log.h"
33 #include "soundsample.h"
34
35 /*============================================================================*/
36 /* Define fixed parameters                                                    */
37 /*============================================================================*/
38 //#define WIDTH  (700)    /* Background width  */
39 //#define HEIGHT (934)    /* Background height */
40 //#define WIDTH  (400)    /* Background width  */
41 //#define HEIGHT (400)    /* Background height */
42 #define WIDTH  (600)            /* Background width  */
43 #define HEIGHT (600)            /* Background height */
44
45 //#define LOG_NAME       "/home/rpf/var/log/uifw/audioTP.log"
46 #define LOG_NAME       "/tmp/ico-app-soundsample.log"
47 //#define CONFIG_FILE    "/home/rpf/src/app/audioTP/soundsample_config.txt"
48 #define CONFIG_FILE    "/opt/apps/org.tizen.ico.app-soundsample/res/soundsample_config.txt"
49
50 #define MAX_BUTTON_NUM 3
51 #define MAX_DRAW_LEM   20
52
53 #define GROUP_DATA        "data"
54 #define KEY_WAVFILE_PATH  "wavfile_path"
55 #define KEY_SERVER_IP     "server_ip"
56 #define KEY_DEVICE_NAME   "device_name"
57 #define KEY_VOLUME1       "volume1"
58 #define KEY_VOLUME2       "volume2"
59 #define KEY_APP_NAME      "app_name"
60 #define KEY_STREAM_NAME   "stream_name"
61
62 /*============================================================================*/
63 /* Define data types                                                          */
64 /*============================================================================*/
65 struct color_val_t
66 {
67     int r;                      /* red   */
68     int g;                      /* green */
69     int b;                      /* blue  */
70     int a;                      /* alpha */
71 };
72
73 struct size_val_t
74 {
75     Evas_Coord w;               /* width  */
76     Evas_Coord h;               /* height */
77 };
78
79 struct font_val_t
80 {
81     char name[255];             /* font name */
82     Evas_Font_Size size;        /* font size */
83 };
84
85 struct pos_val_t
86 {
87     Evas_Coord x;               /* X position */
88     Evas_Coord y;               /* Y position */
89 };
90
91 struct object_text_val_t
92 {
93     struct color_val_t color;
94     struct size_val_t size;
95     struct font_val_t font;
96     struct pos_val_t pos;
97     char text[255];
98     void *func;
99 };
100
101 struct object_figure_val_t
102 {
103     struct color_val_t color;
104     struct size_val_t size;
105     struct pos_val_t pos;
106     void *func;
107 };
108
109 /*============================================================================*/
110 /* Function prototype for static(internal) functions                          */
111 /*============================================================================*/
112 static void _canvas_resize_cb(Ecore_Evas *ee);
113 static void _on_destroy(Ecore_Evas *ee __UNUSED__);
114 static Eina_Bool _timer_cb(void *data);
115 static void _on_mousedown1(void *data, Evas *evas, Evas_Object *o,
116                            void *einfo);
117 static void _on_mousedown2(void *data, Evas *evas, Evas_Object *o,
118                            void *einfo);
119 static void _on_mousedown3(void *data, Evas *evas, Evas_Object *o,
120                            void *einfo);
121 static int start_audio(void);
122 static Eina_Bool stop_audio(void *data, Ecore_Fd_Handler *fd_handler);
123 static void rcv_event(int event_num);
124 static void send_event_req(int event_num);
125 static void recv_event_res(int ret);
126 static void chg_state(int state_num);
127 static void conf_check_gerror(char *para_num, GError ** error);
128 static int read_config(void);
129 static void draw_text(Evas_Object *obj, struct object_text_val_t *text);
130 static void draw_figr(Evas_Object *obj, struct object_figure_val_t *figr);
131
132 /*============================================================================*/
133 /* Tables and Valiables                                                       */
134 /*============================================================================*/
135 extern int pulse_main(struct audio_config_t *, int);
136
137 /* state values */
138 static int StateNum = STATE_STOP;
139 static Evas_Object *State_text;
140
141 /* file descriptor */
142 static int Filedes[2];
143 static int Filedes2[2];
144
145 /* Child process ID */
146 static pid_t ChPid = 0;
147
148 /* Config data */
149 static struct audio_config_t AudioConfig = {
150     NULL, NULL, NULL, -1, -1, NULL, NULL
151 };
152
153 static struct object_text_val_t ButtonText[MAX_BUTTON_NUM] = {
154     {{255, 0, 0, 255}, {180, 50}, {"Sans", 48}, {15 + 12, 70}, "START", NULL},
155     {{0, 255, 0, 255}, {180, 50}, {"Sans", 48}, {210 + 24, 70}, "STOP", NULL},
156     {{0, 0, 255, 255}, {180, 50}, {"Sans", 48}, {405 + 12, 70}, "PAUSE", NULL}
157 };
158
159 static struct object_figure_val_t ButtonFigr[MAX_BUTTON_NUM] = {
160     {{255, 0, 0, 100}, {180, 95}, {15, 120}, (void *) _on_mousedown1},
161     {{0, 255, 0, 100}, {180, 95}, {210, 120}, (void *) _on_mousedown2},
162     {{0, 0, 255, 100}, {180, 95}, {405, 120}, (void *) _on_mousedown3}
163 };
164
165 static struct object_figure_val_t BgFigr = {
166     {255, 255, 255, 255}, {WIDTH, HEIGHT}, {0, 0}, NULL
167 };
168
169 static struct object_text_val_t TimeText = {
170     {0, 0, 0, 255}, {150, 50}, {"Sans", 24}, {0, 0}, {}, (void *) _timer_cb
171 };
172
173 static struct object_text_val_t StateInfoText = {
174     {0, 0, 0, 255}, {150, 50}, {"Sans", 48}, {140, 300}, "STATE : STOP", NULL
175 };
176
177 static struct object_text_val_t AppNameText = {
178     {0, 0, 0, 255}, {150, 50}, {"Sans", 32}, {25, 440}, "App Name :  ", NULL
179 };
180
181 static struct object_text_val_t StreamNameText = {
182     {0, 0, 0, 255}, {150, 50}, {"Sans", 32}, {25, 480}, "Stream Name :  ",
183         NULL
184 };
185
186 static struct object_text_val_t PidText = {
187     {0, 0, 0, 255}, {150, 50}, {"Sans", 36}, {50, 530}, "PID :  ", NULL
188 };
189
190 static Ecore_Evas *ee;
191 static Evas_Object *text, *bg;
192 static char ssndtype[32];
193
194 static const char commands[] =
195     "commands are:\n"
196     "\tm - impose a minumum size to the window\n"
197     "\tx - impose a maximum size to the window\n"
198     "\tb - impose a base size to the window\n"
199     "\ts - impose a step size (different than 1 px) to the window\n"
200     "\th - print help\n";
201
202
203 /* to inform current window's size */
204 static void _canvas_resize_cb(Ecore_Evas *ee)
205 {
206     int w, h;
207     char buf[256];
208
209     ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
210     snprintf(buf, sizeof(buf), "%s %d x %d", ssndtype, w, h);
211     evas_object_text_text_set(text, buf);
212     evas_object_move(text, 50, 25);
213     evas_object_resize(bg, w, h);
214 }
215
216 static void _on_destroy(Ecore_Evas *ee __UNUSED__)
217 {
218     ecore_main_loop_quit();
219 }
220
221 static Eina_Bool _timer_cb(void *data)
222 {
223     char str[32];
224     time_t timer;
225     struct tm *date;
226     timer = time(NULL);
227     date = localtime(&timer);
228     sprintf(str, "%s", asctime(date));
229     evas_object_text_text_set((Evas_Object *) data, str);
230
231     return EINA_TRUE;
232 }
233
234 static void _on_mousedown1(void *data, Evas *evas, Evas_Object *o,
235                            void *einfo)
236 {
237     uim_debug("_on_mousedown1: Enter");
238     uim_debug("Input event   : START");
239
240     rcv_event(START_REQ);
241
242     uim_debug("_on_mousedown1: Leave");
243 }
244
245 static void _on_mousedown2(void *data, Evas *evas, Evas_Object *o,
246                            void *einfo)
247 {
248     uim_debug("_on_mousedown2: Enter");
249     uim_debug("Input event  : STOP");
250
251     rcv_event(STOP_REQ);
252
253     uim_debug("_on_mousedown2: Leave");
254 }
255
256 static void _on_mousedown3(void *data, Evas *evas, Evas_Object *o,
257                            void *einfo)
258 {
259     uim_debug("_on_mousedown3: Enter");
260     uim_debug("Input event  : PAUSE");
261
262     rcv_event(PAUSE_REQ);
263
264     uim_debug("_on_mousedown3: Leave");
265 }
266
267 static int start_audio(void)
268 {
269     uim_debug("start_audio: Enter");
270
271     int ret = 0;
272
273     signal(SIGCLD, SIG_IGN);
274
275     if ((ChPid = fork()) < 0) {
276         uim_debug("Err fork");
277         return -1;
278     }
279     else if (ChPid == 0) {
280         /* Processing of child processes to start */
281         close(Filedes[1]);
282         close(Filedes2[0]);
283
284         uim_debug("Voice response : START");
285         ret = pulse_main(&AudioConfig, Filedes[0]);
286         uim_debug("Voice response : END");
287
288         uim_debug("pulse_main: ret = [%d]", ret);
289         recv_event_res(ret);
290
291         close(Filedes[0]);
292         close(Filedes2[1]);
293         /* Termination of child processes */
294         exit(0);
295     }
296
297     /* Processing of parent process */
298     uim_debug("Child process: ChPid = [%d]", ChPid);
299
300     uim_debug("start_audio: Leave");
301
302     return 0;
303 }
304
305 static Eina_Bool stop_audio(void *data, Ecore_Fd_Handler *fd_handler)
306 {
307     uim_debug("stop_audio: Enter");
308
309     char buff[255];
310     memset(buff, 0x00, sizeof(buff));
311
312     /* Reading from a pipe */
313     read(Filedes2[0], buff, sizeof(buff));
314     uim_debug("buff :%s", buff);
315
316     if (atoi(buff) != 0) {
317         uim_debug("pulse_main Err: ret= [%d]", atoi(buff));
318         _on_destroy(NULL);
319     }
320
321     /* State change */
322     chg_state(STATE_STOP);
323
324     /* Process id initialization */
325     ChPid = 0;
326
327     uim_debug("stop_audio: Leave");
328
329     return ECORE_CALLBACK_RENEW;
330 }
331
332 static void rcv_event(int event_num)
333 {
334     uim_debug("rcv_event: Enter");
335
336     int ret = 0;
337
338     switch (StateNum) {
339     case STATE_START:
340         switch (event_num) {
341         case STOP_REQ:
342             /* event send */
343             send_event_req(event_num);
344             /* State change */
345             chg_state(STATE_STOP);
346             break;
347
348         case PAUSE_REQ:
349             /* event send */
350             send_event_req(event_num);
351             /* State change */
352             chg_state(STATE_PAUSE);
353             break;
354
355         default:
356             uim_debug("Not receive: StateNum = [%d],event_num = [%d]",
357                         StateNum, event_num);
358             break;
359         }
360
361         break;
362
363     case STATE_STOP:
364         switch (event_num) {
365         case START_REQ:
366             /* Voice reproduction start */
367             ret = start_audio();
368             if (ret == 0) {
369                 /* State change */
370                 chg_state(STATE_START);
371             }
372             else {
373                 uim_debug("start_audio Err: ret= [%d]", ret);
374                 _on_destroy(NULL);
375             }
376             break;
377
378         default:
379             uim_debug("Not receive: StateNum = [%d],event_num = [%d]",
380                         StateNum, event_num);
381             break;
382         }
383
384         break;
385
386     case STATE_PAUSE:
387         switch (event_num) {
388         case STOP_REQ:
389             /* event send */
390             send_event_req(event_num);
391             /* State change */
392             chg_state(STATE_STOP);
393             break;
394
395         case PAUSE_REQ:
396             /* event send */
397             send_event_req(event_num);
398             /* State change */
399             chg_state(STATE_START);
400             break;
401
402         default:
403             uim_debug("Not receive: StateNum = [%d],event_num = [%d]",
404                         StateNum, event_num);
405             break;
406         }
407
408         break;
409
410     default:
411         uim_debug("Not support StateNum: StateNum = [%d]", StateNum);
412         break;
413     }
414
415     uim_debug("rcv_event: Leave");
416 }
417
418 static void send_event_req(int event_num)
419 {
420     uim_debug("send_event_req: Enter");
421
422     char msg[32];
423     memset(msg, 0x00, sizeof(msg));
424
425     snprintf(msg, sizeof(msg), "%d", event_num);
426     uim_debug("msg = %s", msg);
427
428     write(Filedes[1], msg, strlen(msg) + 1);
429     uim_debug("send_event_req: Leave");
430 }
431
432 static void recv_event_res(int ret)
433 {
434     uim_debug("recv_event_res: Enter");
435
436     char msg[32];
437     memset(msg, 0x00, sizeof(msg));
438
439     snprintf(msg, sizeof(msg), "%d", ret);
440     uim_debug("msg = %s", msg);
441
442     write(Filedes2[1], msg, strlen(msg) + 1);
443     uim_debug("recv_event_res: Leave");
444 }
445
446 static void chg_state(int state_num)
447 {
448     uim_debug("chg_state: Enter");
449     uim_debug("chg_state state_num = [%d]", state_num);
450
451     char buf[ICO_UXF_MAX_PROCESS_NAME + 1];
452     memset(buf, 0x00, sizeof(buf));
453
454     switch (state_num) {
455     case STATE_START:
456         snprintf(buf, sizeof(buf), "%s", "STATE : START");
457         evas_object_text_text_set(State_text, buf);
458         StateNum = state_num;
459         break;
460
461     case STATE_STOP:
462         snprintf(buf, sizeof(buf), "%s", "STATE : STOP");
463         evas_object_text_text_set(State_text, buf);
464         StateNum = state_num;
465         break;
466
467     case STATE_PAUSE:
468         snprintf(buf, sizeof(buf), "%s", "STATE : PAUSE");
469         evas_object_text_text_set(State_text, buf);
470         StateNum = state_num;
471         break;
472
473     default:
474         uim_debug("Not support State: state_num = [%d]", state_num);
475         break;
476     }
477
478     uim_debug("chg_state StateNum = [%d]", StateNum);
479     uim_debug("chg_state: Leave");
480 }
481
482 static void conf_check_gerror(char *para_num, GError ** error)
483 {
484     uim_debug("conf_check_gerror: Enter");
485
486     if (*error != NULL) {
487         uim_debug("Config [%s] : %s", para_num, (*error)->message);
488     }
489     g_clear_error(error);
490
491     uim_debug("conf_check_gerror: Leave");
492 }
493
494 static int read_config(void)
495 {
496     uim_debug("read_config: Enter");
497
498     GKeyFile *keyfile;
499     GKeyFileFlags flags;
500     GError *error = NULL;
501
502     keyfile = g_key_file_new();
503     flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
504     if (!g_key_file_load_from_file(keyfile, CONFIG_FILE, flags, &error)) {
505         conf_check_gerror(CONFIG_FILE, &error);
506         g_key_file_free(keyfile);
507         return -1;
508     }
509
510     AudioConfig.wavfile_path = g_key_file_get_string(keyfile, GROUP_DATA,
511                                                      KEY_WAVFILE_PATH,
512                                                      &error);
513     if ((error) || (strlen(AudioConfig.wavfile_path) <= 0)) {
514         uim_debug("No config data [%s]", KEY_WAVFILE_PATH);
515         conf_check_gerror(KEY_WAVFILE_PATH, &error);
516         g_key_file_free(keyfile);
517         return -1;
518     }
519
520     AudioConfig.server_ip = g_key_file_get_string(keyfile, GROUP_DATA,
521                                                   KEY_SERVER_IP, &error);
522     if ((error) || (strlen(AudioConfig.server_ip) <= 0)) {
523         uim_debug("No config data [%s]", KEY_SERVER_IP);
524         conf_check_gerror(KEY_SERVER_IP, &error);
525         AudioConfig.server_ip = NULL;
526     }
527
528     AudioConfig.device_name = g_key_file_get_string(keyfile, GROUP_DATA,
529                                                     KEY_DEVICE_NAME, &error);
530     if ((error) || (strlen(AudioConfig.device_name) <= 0)) {
531         uim_debug("No config data [%s]", KEY_DEVICE_NAME);
532         conf_check_gerror(KEY_DEVICE_NAME, &error);
533         AudioConfig.device_name = NULL;
534     }
535
536     AudioConfig.volume1 = g_key_file_get_integer(keyfile, GROUP_DATA,
537                                                  KEY_VOLUME1, &error);
538     if (error) {
539         uim_debug("No config data [%s]", KEY_VOLUME1);
540         conf_check_gerror(KEY_VOLUME1, &error);
541         AudioConfig.volume1 = -1;
542     }
543
544     AudioConfig.volume2 = g_key_file_get_integer(keyfile, GROUP_DATA,
545                                                  KEY_VOLUME2, &error);
546     if (error) {
547         uim_debug("No config data [%s]", KEY_VOLUME2);
548         conf_check_gerror(KEY_VOLUME2, &error);
549         AudioConfig.volume2 = -1;
550     }
551
552     AudioConfig.app_name = g_key_file_get_string(keyfile, GROUP_DATA,
553                                                  KEY_APP_NAME, &error);
554     if ((error) || (strlen(AudioConfig.app_name) <= 0)) {
555         uim_debug("No config data [%s]", KEY_APP_NAME);
556         conf_check_gerror(KEY_APP_NAME, &error);
557         AudioConfig.app_name = "TP_PulseAudio";
558     }
559
560     AudioConfig.stream_name = g_key_file_get_string(keyfile, GROUP_DATA,
561                                                     KEY_STREAM_NAME, &error);
562     if ((error) || (strlen(AudioConfig.stream_name) <= 0)) {
563         uim_debug("No config data [%s]", KEY_STREAM_NAME);
564         conf_check_gerror(KEY_DEVICE_NAME, &error);
565         AudioConfig.stream_name = "Pri0";
566     }
567
568     uim_debug("read_config: Leave");
569     return 0;
570 }
571
572 static void draw_text(Evas_Object *obj, struct object_text_val_t *text)
573 {
574     uim_debug("draw_text: Enter");
575
576     evas_object_color_set(obj, text->color.r, text->color.g, text->color.b,
577                           text->color.a);
578     evas_object_resize(obj, text->size.w, text->size.h);
579     evas_object_text_font_set(obj, text->font.name, text->font.size);
580     evas_object_move(obj, text->pos.x, text->pos.y);
581     evas_object_show(obj);
582     evas_object_text_text_set(obj, text->text);
583
584     uim_debug("draw_text: Leave");
585 }
586
587 static void draw_figr(Evas_Object *obj, struct object_figure_val_t *figr)
588 {
589     uim_debug("draw_figr: Enter");
590
591     evas_object_color_set(obj, figr->color.r, figr->color.g, figr->color.b,
592                           figr->color.a);
593     evas_object_resize(obj, figr->size.w, figr->size.h);
594     evas_object_move(obj, figr->pos.x, figr->pos.y);
595     evas_object_show(obj);
596
597     uim_debug("draw_figr: Leave");
598 }
599
600 static void res_callback(ico_apf_resource_notify_info_t *info,
601                          void *user_data)
602 {
603     int ret;
604
605     uim_debug
606         ("##==> Callbacked! evt=%d res=%d id=%d bid=%d appid=%s dev=%s "
607          "user_data=%d", info->state, info->resid, info->id, info->bid,
608          info->appid, info->device, (int) user_data);
609
610     switch (info->state) {
611     case ICO_APF_RESOURCE_STATE_ACQUIRED:
612     case ICO_APF_RESOURCE_STATE_DEPRIVED:
613     case ICO_APF_RESOURCE_STATE_WAITTING:
614     case ICO_APF_RESOURCE_STATE_RELEASED:
615         if (info->resid == ICO_APF_RESID_INT_SOUND) {
616             ret =
617                 ico_apf_resource_reply_int_sound_mode(info->device, info->id,
618                                                       1);
619             uim_debug("##==> callback reply int_sound(%s,%d,1) = %d",
620                         info->device, info->id, ret);
621         }
622         else {
623             ret =
624                 ico_apf_resource_reply_sound_mode(info->device, info->id, 1);
625             uim_debug("##==> callback reply sound(%s,%d,1) = %d",
626                         info->device, info->id, ret);
627         }
628         break;
629     default:
630         /* NOP  */
631         break;
632     }
633 }
634
635 int main(int argc, char *argv[])
636 {
637     int getsound;
638     char appid[64];
639
640     /* Log output setup */
641     if (ico_apf_get_app_id(0, appid) == ICO_APP_CTL_E_NONE) {
642         ico_apf_log_open(appid);
643     }
644
645     uim_debug("main: Enter");
646
647     Evas *evas;
648     Evas_Object *app_name_text;
649     Evas_Object *stream_name_text;
650     Evas_Object *pid_text;
651     Evas_Object *button_text[MAX_BUTTON_NUM];
652     Evas_Object *button_figr[MAX_BUTTON_NUM];
653     Evas_Object *time_text;
654     char buf[256];
655     char buf2[256];
656     int i = 0;
657
658     /* get resource control option  */
659     getsound = 0;
660     ssndtype[0] = 0;
661     for (i = 1; i < argc; i++) {
662         if (argv[i][0] == '-') {
663             if (strcasecmp(argv[i], "-basesound") == 0) {
664                 getsound = 1;   /* get base sound       */
665                 strcpy(ssndtype, "BasecSound");
666             }
667             else if (strcasecmp(argv[i], "-intsound") == 0) {
668                 getsound = 2;   /* get interrupt sound  */
669                 strcpy(ssndtype, "IntSound");
670             }
671             else if (strncasecmp(argv[i], "-int=", 5) == 0) {
672                 getsound = strtol(&argv[i][5], (char **) 0, 0);
673                 getsound += 2;  /* get interrupt sound  */
674                 sprintf(ssndtype, "IntSound.%d", getsound - 2);
675             }
676         }
677     }
678
679     StateNum = STATE_STOP;
680     ChPid = 0;
681     memset(buf, 0x00, sizeof(buf));
682     memset(buf2, 0x00, sizeof(buf));
683
684     if (pipe(Filedes) == -1) {
685         uim_debug("Err pipe Filedes");
686         return EXIT_FAILURE;
687     }
688
689     if (pipe(Filedes2) == -1) {
690         uim_debug("Err pipe Filedes2");
691         return EXIT_FAILURE;
692     }
693
694     if (read_config() == -1) {
695         uim_debug("Err Config Read NG");
696         return EXIT_FAILURE;
697     }
698
699     uim_debug("AudioConfig.wavfile_path = [%s]", AudioConfig.wavfile_path);
700     uim_debug("AudioConfig.server_ip = [%s]", AudioConfig.server_ip);
701     uim_debug("AudioConfig.device_name = [%s]", AudioConfig.device_name);
702     uim_debug("AudioConfig.volume1 = [%d]", AudioConfig.volume1);
703     uim_debug("AudioConfig.volume2 = [%d]", AudioConfig.volume2);
704     uim_debug("AudioConfig.app_name = [%s]", AudioConfig.app_name);
705     uim_debug("AudioConfig.stream_name = [%s]", AudioConfig.stream_name);
706
707     if (!ecore_evas_init()) {
708         return EXIT_FAILURE;
709     }
710
711     if (getsound > 0) {
712         /* initialize resource control for Ecore */
713         if (ico_apf_ecore_init(NULL) != ICO_APF_E_NONE) {
714             uim_debug("ico_apf_ecore_init() Error");
715             ecore_evas_shutdown();
716             return -1;
717         }
718
719         /* set resource request callback */
720         ico_apf_resource_set_event_cb(res_callback, NULL);
721
722         /* acquire a right to display a screen      */
723         if (getsound == 1) {
724             ico_apf_resource_get_sound_mode(NULL, 0, 0);
725         }
726         else {
727             ico_apf_resource_get_int_sound_mode(NULL, getsound - 2, 0);
728         }
729     }
730
731     /* this will give you a window with an Evas canvas under the first
732      * engine available */
733     ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, "frame=0");
734     if (!ee) {
735         goto error;
736     }
737
738     ecore_evas_callback_delete_request_set(ee, _on_destroy);
739     ecore_evas_title_set(ee, "Ecore_Evas window sizes example");
740     ecore_evas_callback_resize_set(ee, _canvas_resize_cb);
741     ecore_evas_show(ee);
742
743     evas = ecore_evas_get(ee);
744
745     /* Background painting */
746     bg = evas_object_rectangle_add(evas);
747     draw_figr(bg, &BgFigr);
748
749     evas_object_focus_set(bg, EINA_TRUE);
750
751     /* App Name drawing */
752     app_name_text = evas_object_text_add(evas);
753     draw_text(app_name_text, &AppNameText);
754
755     if (strlen(AudioConfig.app_name) > MAX_DRAW_LEM) {
756         snprintf(buf2, MAX_DRAW_LEM, "%s", AudioConfig.app_name);
757         snprintf(buf, sizeof(buf), "%s%s...", "App name :  ", buf2);
758     }
759     else {
760         snprintf(buf, sizeof(buf), "%s%s", "App name :  ",
761                  AudioConfig.app_name);
762     }
763
764     evas_object_text_text_set(app_name_text, buf);
765
766     /* Drawing window */
767     text = evas_object_text_add(evas);
768     evas_object_color_set(text, 255, 0, 0, 255);
769     evas_object_resize(text, 150, 50);
770     evas_object_text_font_set(text, "Sans", 20);
771     evas_object_show(text);
772
773     /* Stream Name drawing */
774     stream_name_text = evas_object_text_add(evas);
775     draw_text(stream_name_text, &StreamNameText);
776
777     if (strlen(AudioConfig.stream_name) > MAX_DRAW_LEM) {
778         snprintf(buf2, MAX_DRAW_LEM, "%s", AudioConfig.stream_name);
779         snprintf(buf, sizeof(buf), "%s%s...", "Stream name :  ", buf2);
780     }
781     else {
782         snprintf(buf, sizeof(buf), "%s%s", "Stream name :  ",
783                  AudioConfig.stream_name);
784     }
785
786     evas_object_text_text_set(stream_name_text, buf);
787
788     /* PID drawing */
789     pid_text = evas_object_text_add(evas);
790     draw_text(pid_text, &PidText);
791     snprintf(buf, sizeof(buf), "%s%d", "PID :  ", getpid());
792     evas_object_text_text_set(pid_text, buf);
793
794     /* Sound condition drawing */
795     State_text = evas_object_text_add(evas);
796     draw_text(State_text, &StateInfoText);
797
798     /** Button drawing */
799     for (i = 0; i < MAX_BUTTON_NUM; i++) {
800         /* Button name drawing */
801         button_text[i] = evas_object_text_add(evas);
802         draw_text(button_text[i], &ButtonText[i]);
803
804         /* Button Frame drawing */
805         button_figr[i] = evas_object_rectangle_add(evas);
806         draw_figr(button_figr[i], &ButtonFigr[i]);
807
808         /* Callback function entry */
809         evas_object_event_callback_add(button_figr[i],
810                                        EVAS_CALLBACK_MOUSE_DOWN,
811                                        (Evas_Object_Event_Cb) (ButtonFigr[i].
812                                                                func),
813                                        State_text);
814     }
815
816     /* Drawing of the current time */
817     time_text = evas_object_text_add(evas);
818     draw_text(time_text, &TimeText);
819
820     /* Timer callback function entry */
821     ecore_timer_add(0.1, (Ecore_Task_Cb) (TimeText.func), time_text);
822
823     /* File descriptor to monitor callback function entry */
824     ecore_main_fd_handler_add(Filedes2[0], ECORE_FD_READ, stop_audio, NULL,
825                               NULL, NULL);
826
827     _canvas_resize_cb(ee);
828     fprintf(stdout, commands);
829     ecore_main_loop_begin();
830
831     ico_apf_ecore_term();
832
833     ecore_evas_free(ee);
834     ecore_evas_shutdown();
835
836     close(Filedes[0]);
837     close(Filedes[1]);
838     close(Filedes2[0]);
839     close(Filedes2[1]);
840
841     /* Process check */
842     if ((ChPid > 0) && (kill(ChPid, 0) != EOF)) {
843         kill(ChPid, SIGKILL);
844         uim_debug("END Process ChPid = [%d]", ChPid);
845     }
846     uim_debug("main: Leave");
847
848     return 0;
849
850   error:
851     fprintf(stderr,
852             "You got to have at least one Evas engine built and linked up"
853             " to ecore-evas for this example to run properly.\n");
854     ecore_evas_shutdown();
855     return -1;
856 }