Updated package changelog.
[profile/ivi/ico-uxf-homescreen.git] / ico-app-framework / ico_apf_resource_control.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   header file of Apprication Framework (Resource Control)
11  *
12  * @date    Feb-28-2013
13  */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include "ico_apf_private.h"
19 #include "ico_uxf_conf.h"
20
21 /*  type user callback information          */
22 typedef struct _resmgr_user_cb_info {
23     ico_apf_resource_notify_cb_t    callbacks;
24     void                            *user_data;
25 } resmgr_user_cb_info_t;
26
27 /*  communication handle management table   */
28 typedef struct _remgr_com_handle    {
29     struct _remgr_com_handle    *next;
30     ico_apf_com_handle_t        *handle;    /* communication handle     */
31     int                         pid;        /* client process id        */
32     char                        appid[ICO_UXF_MAX_PROCESS_NAME+1];
33                                             /* client application id    */
34 } remgr_com_handle_t;
35
36 /*  private variable                */
37 static ico_apf_com_handle_t     *appsctl_handle = NULL;
38 static ico_apf_com_handle_t     *soundmgr_handle = NULL;
39 static resmgr_user_cb_info_t    user_cb_info = {NULL, NULL};
40 static int                      resmgr_initialized = 0;
41 static remgr_com_handle_t       *handles = NULL;
42 static remgr_com_handle_t       *freehandles = NULL;
43 static Ico_Uxf_Sys_Config       *sysconf = NULL;
44 static Ico_Uxf_Sys_Config       *ifsysconf = NULL;
45
46 /*--------------------------------------------------------------------------*/
47 /**
48  *  @brief  Callback at received from AppsController for client
49  *
50  *  @param[in]  handle          communication handle
51  *  @param[in]  cmd             command(event) code
52  *  @param[in]  res             target resource
53  *  @param[in]  pid             request client pid (server only)
54  *  @param[in]  appid           request client application id (server only)
55  *  @param[in]  msg             received message
56  *  @param[in]  user_data       (unused)
57  *  @return     none
58  */
59 /*--------------------------------------------------------------------------*/
60 static void
61 ico_apf_resmgr_client_event(ico_apf_com_handle_t *handle, int cmd, int res,
62                             int pid, char *appid, char *msg, void* user_data)
63 {
64     int     i;
65     ico_apf_resource_notify_info_t  info;
66
67     apfw_trace("ico_apf_resmgr_client_event: cmd=%d res=%d pid=%d(%s) msg=<%s>",
68                cmd, res, pid, appid, msg);
69
70     if (user_cb_info.callbacks != NULL) {
71         memset(&info, 0, sizeof(info));
72
73         /* get device and id                */
74         for (i = 0; msg[i]; i++)    {
75             if( msg[i] == ' ')  break;
76             if (i < ICO_UXF_MAX_DEVICE_NAME)    {
77                 info.device[i] = msg[i];
78             }
79         }
80         if (msg[i] == ' ')  {
81             info.id = strtol(&msg[i+1], (char **)0, 0);
82         }
83         info.state = (ico_apf_resource_state_e)cmd;
84         info.resid = res;
85         info.pid = pid;
86         strncpy(info.appid, appid, ICO_UXF_MAX_PROCESS_NAME);
87         user_cb_info.callbacks(&info, user_cb_info.user_data);
88     }
89 }
90
91 /*--------------------------------------------------------------------------*/
92 /**
93  *  @brief  Callback at received from Application for server
94  *
95  *  @param[in]  handle          communication handle
96  *  @param[in]  cmd             command(event) code
97  *  @param[in]  res             target resource
98  *  @param[in]  pid             request client pid (server only)
99  *  @param[in]  appid           request client application id (server only)
100  *  @param[in]  msg             received message
101  *  @param[in]  user_data       (unused)
102  *  @return     none
103  */
104 /*--------------------------------------------------------------------------*/
105 static void
106 ico_apf_resmgr_server_event(ico_apf_com_handle_t *handle, int cmd, int res,
107                             int pid, char *appid, char *msg, void* user_data)
108 {
109     int     i;
110     ico_apf_resource_notify_info_t  info;
111     remgr_com_handle_t  *p;
112     remgr_com_handle_t  *bp;
113
114     apfw_trace("ico_apf_resmgr_server_event: handle=%08x cmd=%d res=%d pid=%d(%s) msg=<%s>",
115                (int)handle, cmd, res, pid, appid, msg);
116
117     /* regist communication handle table    */
118     p = handles;
119     while (p)   {
120         if (p->handle == handle)    break;
121         p = p->next;
122     }
123     if (! p)    {
124         apfw_trace("ico_apf_resmgr_server_event: new client");
125         if (freehandles)    {
126             p = freehandles;
127             freehandles = p->next;
128         }
129         else    {
130             p = malloc(sizeof(remgr_com_handle_t));
131         }
132         if (p)  {
133             memset(p, 0, sizeof(remgr_com_handle_t));
134             if (! handles)  {
135                 handles = p;
136             }
137             else    {
138                 p->next = handles;
139                 handles = p;
140             }
141             p->handle = handle;
142             p->pid = pid;
143         }
144     }
145
146     memset(&info, 0, sizeof(info));
147
148     /* get device and id            */
149     for (i = 0; msg[i] ; i++)   {
150         if (msg[i] == ' ')  break;
151         if (i < ICO_UXF_MAX_DEVICE_NAME)    {
152             info.device[i] = msg[i];
153         }
154     }
155     if (msg[i] == ' ')  {
156         sscanf(&msg[i+1], "%d %d", &info.id, &info.bid);
157     }
158     info.state = (ico_apf_resource_state_e)cmd;
159     info.resid = res;
160     info.pid = pid;
161     if (appid[0] )  {
162         strncpy(info.appid, appid, ICO_UXF_MAX_PROCESS_NAME);
163         strcpy(p->appid, info.appid);
164     }
165     else if (pid != 0)  {
166         info.pid = pid;
167         ico_apf_get_app_id(pid, info.appid);
168         strcpy(p->appid, info.appid);
169     }
170
171     if (info.state == ICO_APF_RESOURCE_STATE_CONNECTED) {
172         /* regist communication handle table    */
173         p = handles;
174         while (p)   {
175             if (p->handle == handle)    break;
176             p = p->next;
177         }
178         if (! p)    {
179             if (freehandles)    {
180                 p = freehandles;
181                 freehandles = p->next;
182             }
183             else    {
184                 p = malloc(sizeof(remgr_com_handle_t));
185             }
186             if (p)  {
187                 memset(p, 0, sizeof(remgr_com_handle_t));
188                 if (! handles)  {
189                     handles = p;
190                 }
191                 else    {
192                     p->next = handles;
193                     handles = p;
194                 }
195                 p->handle = handle;
196                 p->pid = pid;
197                 strncpy(p->appid, info.appid, ICO_UXF_MAX_PROCESS_NAME);
198             }
199         }
200     }
201     else if (info.state == ICO_APF_RESOURCE_STATE_DISCONNECTED) {
202         /* destory communiction handle table    */
203         p = handles;
204         bp = NULL;
205         while (p)   {
206             if (p->handle == handle)    break;
207             bp = p;
208             p = p->next;
209         }
210         if (p)  {
211             if (bp) {
212                 bp->next = p->next;
213             }
214             else    {
215                 handles = p->next;
216             }
217             p->next = freehandles;
218             freehandles = p;
219         }
220     }
221     if (user_cb_info.callbacks != NULL) {
222         user_cb_info.callbacks(&info, user_cb_info.user_data);
223     }
224 }
225
226 /*--------------------------------------------------------------------------*/
227 /**
228  *  @brief  Initialize resouce manager component for client Application
229  *
230  *  @param[in]  uri         server URI
231  *  @return result status
232  *  @retval ICO_APF_RESOURCE_E_NONE                 success
233  *  @retval ICO_APF_RESOURCE_E_INIT_COM_FAILD       can not create connection
234  *  @retval ICO_APF_RESOURCE_E_INIT_COMMUNICATION   initialize communication error
235  */
236 /*--------------------------------------------------------------------------*/
237 ICO_APF_API int
238 ico_apf_resource_init_client(const char *uri)
239 {
240     apfw_trace("ico_apf_resource_init_client: Enter(%s)", uri ? uri : "NULL");
241
242     if (resmgr_initialized & 1) {
243         apfw_warn("ico_apf_resource_init_client: Leave(already intialiezed)");
244         return ICO_APF_RESOURCE_E_NONE;
245     }
246
247     /* initialize connection for AppsController */
248     appsctl_handle = ico_apf_com_init_client(uri, ICO_APF_COM_TYPE_APPSCTL);
249
250     if (! appsctl_handle)   {
251         apfw_error("ico_apf_resource_init_client: Leave(can not create connection)");
252         return ICO_APF_RESOURCE_E_INIT_COM_FAILD;
253     }
254
255     /* get system configuration                 */
256     ifsysconf = (Ico_Uxf_Sys_Config *)ico_uxf_ifGetSysConfig();
257     if (ifsysconf)  {
258         /* Another module already reads config file                             */
259         /* In this case, you don't release sysconf at finished this function.   */
260         sysconf = (Ico_Uxf_Sys_Config *)ifsysconf;
261     }
262     else    {
263         /* never read a system config                   */
264         sysconf = (Ico_Uxf_Sys_Config *)ico_uxf_getSysConfig();
265     }
266     if (!sysconf)   {
267         apfw_error("ico_apf_resource_init_client: Leave(can not read configuration files)");
268         return ICO_APF_RESOURCE_E_INIT_COM_FAILD;
269     }
270
271     if (ico_apf_com_addeventlistener(NULL, ico_apf_resmgr_client_event, NULL)
272             != ICO_APF_E_NONE) {
273         apfw_error("ico_apf_resource_init_client: Leave(can not set callback)");
274         return ICO_APF_RESOURCE_E_INIT_COM_FAILD;
275     }
276
277     /* chanage resmgr_client_intialized flag */
278     resmgr_initialized |= 1;
279
280     apfw_trace("ico_apf_resource_init_client: Leave(OK)");
281     return ICO_APF_RESOURCE_E_NONE;
282 }
283
284 /*--------------------------------------------------------------------------*/
285 /**
286  *  @brief  Terminame resouce manager component
287  *
288  *  @param      none
289  *  @return     none
290  */
291 /*--------------------------------------------------------------------------*/
292 ICO_APF_API void
293 ico_apf_resource_term_client(void)
294 {
295     apfw_trace("ico_apf_resource_term_client: Enter");
296
297     /* unset callback functions */
298     ico_apf_resource_unset_event_cb();
299
300     /* terminate resourece server communication */
301     (void) ico_apf_com_term_client(appsctl_handle);
302     appsctl_handle = NULL;
303
304     /* close system configuration   */
305     if (! ifsysconf)    {
306         ico_uxf_closeSysConfig();
307     }
308
309     /* chanage resmgr_client_intialized flag */
310     resmgr_initialized &= ~1;
311
312     apfw_trace("ico_apf_resource_term_client: Leave");
313 }
314
315 /*--------------------------------------------------------------------------*/
316 /**
317  *  @brief  Initialize resouce manager component for server Application
318  *
319  *  @param[in]  uri         my URI
320  *  @return result status
321  *  @retval ICO_APF_RESOURCE_E_NONE                 success
322  *  @retval ICO_APF_RESOURCE_E_INIT_COM_FAILD       can not create connection
323  *  @retval ICO_APF_RESOURCE_E_INIT_COMMUNICATION   initialize communication error
324  */
325 /*--------------------------------------------------------------------------*/
326 ICO_APF_API int
327 ico_apf_resource_init_server(const char *uri)
328 {
329     apfw_trace("ico_apf_resource_init_server: Enter(%s)", uri ? uri : "NULL");
330
331     if (resmgr_initialized & 2) {
332         apfw_warn("ico_apf_resource_init_server: Leave(already intialiezed)");
333         return ICO_APF_RESOURCE_E_NONE;
334     }
335
336     /* initialize connection for AppsController */
337     appsctl_handle = ico_apf_com_init_server(uri, ICO_APF_COM_TYPE_APPSCTL);
338     if (! appsctl_handle)   {
339         apfw_error("ico_apf_resource_init_server: Leave(can not create connection)");
340         return ICO_APF_RESOURCE_E_INIT_COM_FAILD;
341     }
342
343     /* get system configuration                 */
344     ifsysconf = (Ico_Uxf_Sys_Config *)ico_uxf_ifGetSysConfig();
345     if (ifsysconf)  {
346         /* Another module already reads config file                             */
347         /* In this case, you don't release sysconf at finished this function.   */
348         sysconf = (Ico_Uxf_Sys_Config *)ifsysconf;
349     }
350     else    {
351         /* never read a system config                   */
352         sysconf = (Ico_Uxf_Sys_Config *)ico_uxf_getSysConfig();
353     }
354     if (!sysconf)   {
355         apfw_error("ico_apf_resource_init_server: Leave(can not read configuration files)");
356         return ICO_APF_RESOURCE_E_INIT_COM_FAILD;
357     }
358
359     if (ico_apf_com_addeventlistener(NULL, ico_apf_resmgr_server_event, NULL)
360             != ICO_APF_E_NONE) {
361         apfw_error("ico_apf_resource_init_server: Leave(can not set callback)");
362         return ICO_APF_RESOURCE_E_INIT_COM_FAILD;
363     }
364
365     /* chanage resmgr_server_intialized flag    */
366     resmgr_initialized = 2;
367
368     /* initialize connection for Multi Sound Manager    */
369     soundmgr_handle = ico_apf_com_init_client(NULL, ICO_APF_COM_TYPE_SOUNDMGR);
370     if (! soundmgr_handle)  {
371         apfw_error("ico_apf_resource_init_server: Leave(can not connect MSM)");
372         return ICO_APF_RESOURCE_E_INIT_COM_FAILD;
373     }
374
375     /* chanage resmgr_client_intialized flag */
376     resmgr_initialized |= 1;
377
378     apfw_trace("ico_apf_resource_init_server: Leave(OK)");
379     return ICO_APF_RESOURCE_E_NONE;
380 }
381
382 /*--------------------------------------------------------------------------*/
383 /**
384  *  @brief  Terminame resouce manager component
385  *
386  *  @param      none
387  *  @return     none
388  */
389 /*--------------------------------------------------------------------------*/
390 ICO_APF_API void
391 ico_apf_resource_term_server(void)
392 {
393     apfw_trace("ico_apf_resource_term_server: Enter");
394
395     /* unset callback functions */
396     ico_apf_resource_unset_event_cb();
397
398     /* terminate resourece server communication */
399     (void) ico_apf_com_term_server(appsctl_handle);
400     appsctl_handle = NULL;
401
402     /* terminate Multi Sound Manager client communication */
403     (void) ico_apf_com_term_client(soundmgr_handle);
404     soundmgr_handle = NULL;
405
406     /* close system configuration   */
407     if (! ifsysconf)    {
408         ico_uxf_closeSysConfig();
409     }
410
411     /* chanage resmgr_client_intialized flag */
412     resmgr_initialized = 0;
413
414     apfw_trace("ico_apf_resource_term_server: Leave");
415 }
416
417 /*--------------------------------------------------------------------------*/
418 /**
419  *  @brief  Set event callback function
420  *
421  *  @param[in]  callbacks   callback functions
422  *  @param[in]  user_data   passed data on called callback function
423  *  @return     result status
424  *  @retval     ICO_APF_RESOURCE_E_NONE     success
425  *  @retval     ICO_APF_RESOURCE_E_INVAL    callbacks is null
426  */
427 /*--------------------------------------------------------------------------*/
428 ICO_APF_API int
429 ico_apf_resource_set_event_cb(ico_apf_resource_notify_cb_t callbacks,
430                               void *user_data)
431 {
432     apfw_trace("ico_apf_resource_set_event_cb: Enter(0x%08x, 0x%08x)",
433               (int)callbacks, (int)user_data);
434
435     if (callbacks == NULL) {
436         apfw_error("ico_apf_resource_set_event_cb: Leave(callbacks is NULL)");
437         return ICO_APF_RESOURCE_E_INVAL;
438     }
439     user_cb_info.callbacks = callbacks;
440     user_cb_info.user_data = user_data;
441
442     apfw_trace("ico_apf_resource_set_event_cb: Leave(OK)");
443     return ICO_APF_RESOURCE_E_NONE;
444 }
445
446 /*--------------------------------------------------------------------------*/
447 /**
448  *  @brief  Unset event callback function
449  *
450  *  @param      none
451  *  @return     result status
452  *  @retval     ICO_APF_RESOURCE_E_NONE     success(At present, always give back this)
453  */
454 /*--------------------------------------------------------------------------*/
455 ICO_APF_API int
456 ico_apf_resource_unset_event_cb(void)
457 {
458     apfw_trace("ico_apf_resource_unset_event_cb:");
459
460     user_cb_info.callbacks = NULL;
461     user_cb_info.user_data = NULL;
462
463     return ICO_APF_RESOURCE_E_NONE;
464 }
465
466 /*--------------------------------------------------------------------------*/
467 /**
468  *  @brief  Get the rights of basic screen
469  *
470  *  @param[in]  disp_dev    display device uri
471  *  @param[in]  src_id      id of basic screen
472  *  @return     result status
473  *  @retval     ICO_APF_RESOURCE_E_NONE               success
474  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
475  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
476  */
477 /*--------------------------------------------------------------------------*/
478 ICO_APF_API int
479 ico_apf_resource_get_screen_mode(const char* disp_dev, int scr_id)
480 {
481     char    msg[ICO_APF_RESOURCE_MSG_LEN];
482
483     apfw_trace("ico_apf_resource_get_screen_mode: Enter(%s,%d)",
484                disp_dev ? disp_dev : "(NULL)", scr_id);
485
486     if ((! resmgr_initialized) || (! appsctl_handle))   {
487         apfw_error("ico_apf_resource_get_screen_mode: Leave(not initialized)");
488         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
489     }
490
491     /* set send message parameter */
492     if (disp_dev)   {
493         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", disp_dev, scr_id);
494     }
495     else    {
496         /* no display URI, default display  */
497         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
498                  sysconf->display[sysconf->misc.default_displayId].
499                      zone[sysconf->misc.default_dispzoneId].name, scr_id);
500     }
501     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_GET,
502                          ICO_APF_RESID_BASIC_SCREEN, NULL, msg)
503             != ICO_APF_RESOURCE_E_NONE) {
504         apfw_error("ico_apf_resource_get_screen_mode: Leave(commnad send error)");
505         return ICO_APF_RESOURCE_E_COMMUNICATION;
506     }
507
508     apfw_trace("ico_apf_resource_get_screen_mode: Leave(OK)");
509     return ICO_APF_RESOURCE_E_NONE;
510 }
511
512 /*--------------------------------------------------------------------------*/
513 /**
514  *  @brief  Release the rights of basic screen
515  *
516  *  @param[in]  disp_dev    display device uri
517  *  @param[in]  src_id      id of basic screen
518  *  @return     result status
519  *  @retval     ICO_APF_RESOURCE_E_NONE               success
520  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
521  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
522  */
523 /*--------------------------------------------------------------------------*/
524 ICO_APF_API int
525 ico_apf_resource_release_screen_mode(const char* disp_dev, int scr_id)
526 {
527     char    msg[ICO_APF_RESOURCE_MSG_LEN];
528
529     apfw_trace("ico_apf_resource_release_screen_mode: Enter(%s,%d)",
530                disp_dev ? disp_dev : "(NULL)", scr_id);
531
532     if ((! resmgr_initialized) || (! appsctl_handle))   {
533         apfw_error("ico_apf_resource_release_screen_mode: Leave(not initialized)");
534         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
535     }
536
537     /* set send message parameter */
538     if (disp_dev)   {
539         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", disp_dev, scr_id);
540     }
541     else    {
542         /* no display URI, default display  */
543         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
544                  sysconf->display[sysconf->misc.default_displayId].
545                      zone[sysconf->misc.default_dispzoneId].name, scr_id);
546     }
547     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_RELEASE,
548                          ICO_APF_RESID_BASIC_SCREEN, NULL, msg)
549             != ICO_APF_RESOURCE_E_NONE) {
550         apfw_warn("ico_apf_resource_release_screen_mode: Leave(commnad send error)");
551         return ICO_APF_RESOURCE_E_COMMUNICATION;
552     }
553
554     apfw_trace("ico_apf_resource_release_screen_mode: Leave(OK)");
555     return ICO_APF_RESOURCE_E_NONE;
556 }
557
558 /*--------------------------------------------------------------------------*/
559 /**
560  *  @brief  Reply the rights of basic screen
561  *
562  *  @param[in]  disp_dev    display device uri
563  *  @param[in]  src_id      id of basic screen
564  *  @param[in]  ok          OK(1) or NG(0)
565  *  @return     result status
566  *  @retval     ICO_APF_RESOURCE_E_NONE               success
567  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
568  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
569  */
570 /*--------------------------------------------------------------------------*/
571 ICO_APF_API int
572 ico_apf_resource_reply_screen_mode(const char* disp_dev, int scr_id, const int ok)
573 {
574     char    msg[ICO_APF_RESOURCE_MSG_LEN];
575
576     apfw_trace("ico_apf_resource_reply_screen_mode: Enter(%s,%d,%d)",
577                disp_dev ? disp_dev : "(NULL)", scr_id, ok);
578
579     if ((! resmgr_initialized) || (! appsctl_handle))   {
580         apfw_error("ico_apf_resource_reply_screen_mode: Leave(not initialized)");
581         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
582     }
583
584     /* set send message parameter */
585     if (disp_dev)   {
586         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", disp_dev, scr_id);
587     }
588     else    {
589         /* no display URI, default display  */
590         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
591                  sysconf->display[sysconf->misc.default_displayId].
592                      zone[sysconf->misc.default_dispzoneId].name, scr_id);
593     }
594     if (ico_apf_com_send(appsctl_handle,
595                          (ok != 0) ? ICO_APF_RESOURCE_REPLY_OK
596                                    : ICO_APF_RESOURCE_REPLY_NG,
597                          ICO_APF_RESID_BASIC_SCREEN, NULL, msg)
598             != ICO_APF_RESOURCE_E_NONE) {
599         apfw_warn("ico_apf_resource_reply_screen_mode: Leave(commnad send error)");
600         return ICO_APF_RESOURCE_E_COMMUNICATION;
601     }
602
603     apfw_trace("ico_apf_resource_reply_screen_mode: Leave(OK)");
604     return ICO_APF_RESOURCE_E_NONE;
605 }
606
607 /*--------------------------------------------------------------------------*/
608 /**
609  *  @brief  Release the rights of interrupt screen
610  *
611  *  @param[in]  disp_dev    display device uri
612  *  @param[in]  src_id      id of basic screen
613  *  @param[in]  int_src_id  id of interrupt screen
614  *  @return     result status
615  *  @retval     ICO_APF_RESOURCE_E_NONE               success
616  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
617  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
618  */
619 /*--------------------------------------------------------------------------*/
620 ICO_APF_API int
621 ico_apf_resource_get_int_screen_mode(const char* disp_dev,
622                                      int scr_id, int int_scr_id)
623 {
624     char    msg[ICO_APF_RESOURCE_MSG_LEN];
625
626     apfw_trace("ico_apf_resource_get_int_screen_mode: Enter(%s,%d,%d)",
627                disp_dev ? disp_dev : "(NULL)", scr_id, int_scr_id);
628
629     if ((! resmgr_initialized) || (! appsctl_handle))   {
630         apfw_error("ico_apf_resource_get_int_screen_mode: Leave(not initialized)");
631         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
632     }
633
634     /* set send message parameter */
635     if (disp_dev)   {
636         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d %d",
637                  disp_dev, int_scr_id, scr_id);
638     }
639     else    {
640         /* no display URI, default display  */
641         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d %d",
642                  sysconf->display[sysconf->misc.default_displayId].
643                      zone[sysconf->misc.default_dispzoneId].name,
644                  int_scr_id, scr_id);
645     }
646     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_GET,
647                          ICO_APF_RESID_INT_SCREEN, NULL, msg)
648             != ICO_APF_RESOURCE_E_NONE) {
649         apfw_error("ico_apf_resource_get_int_screen_mode: Leave(commnad send error)");
650         return ICO_APF_RESOURCE_E_COMMUNICATION;
651     }
652
653     apfw_trace("ico_apf_resource_get_int_screen_mode: Leave(OK)");
654     return ICO_APF_RESOURCE_E_NONE;
655 }
656
657 /*--------------------------------------------------------------------------*/
658 /**
659  *  @brief  Release the rights of interrupt screen on basic screen
660  *
661  *  @param[in]  disp_dev    display device uri
662  *  @param[in]  src_id      id of basic screen
663  *  @param[in]  int_scr_id  id of interrupt screen
664  *  @return     result status
665  *  @retval     ICO_APF_RESOURCE_E_NONE               success
666  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
667  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
668  */
669 /*--------------------------------------------------------------------------*/
670 ICO_APF_API int
671 ico_apf_resource_release_int_screen_mode(const char* disp_dev,
672                                          int scr_id, int int_scr_id)
673 {
674     char    msg[ICO_APF_RESOURCE_MSG_LEN];
675
676     apfw_trace("ico_apf_resource_release_int_screen_mode: Enter(%s,%d,%d)",
677                disp_dev ? disp_dev : "(NULL)", scr_id, int_scr_id);
678
679     if ((! resmgr_initialized) || (! appsctl_handle))   {
680         apfw_error("ico_apf_resource_release_int_screen_mode: Leave(not initialized)");
681         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
682     }
683
684     /* set send message parameter */
685     if (disp_dev)   {
686         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d %d",
687                  disp_dev, int_scr_id, scr_id);
688     }
689     else    {
690         /* no display URI, default display  */
691         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d %d",
692                  sysconf->display[sysconf->misc.default_displayId].
693                      zone[sysconf->misc.default_dispzoneId].name,
694                  int_scr_id, scr_id);
695     }
696     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_RELEASE,
697                          ICO_APF_RESID_INT_SCREEN, NULL, msg)
698             != ICO_APF_RESOURCE_E_NONE) {
699         apfw_warn("ico_apf_resource_release_int_screen_mode: Leave(commnad send error)");
700         return ICO_APF_RESOURCE_E_COMMUNICATION;
701     }
702
703     apfw_trace("ico_apf_resource_release_int_screen_mode: Leave(OK)");
704     return ICO_APF_RESOURCE_E_NONE;
705 }
706
707 /*--------------------------------------------------------------------------*/
708 /**
709  *  @brief  Reply the rights of interrupt screen on basic screen
710  *
711  *  @param[in]  disp_dev    display device uri
712  *  @param[in]  src_id      id of basic screen
713  *  @param[in]  int_scr_id  id of interrupt screen
714  *  @param[in]  ok          OK(1) or NG(0)
715  *  @return     result status
716  *  @retval     ICO_APF_RESOURCE_E_NONE               success
717  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
718  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
719  */
720 /*--------------------------------------------------------------------------*/
721 ICO_APF_API int
722 ico_apf_resource_reply_int_screen_mode(const char* disp_dev,
723                                        int scr_id, int int_scr_id, const int ok)
724 {
725     char    msg[ICO_APF_RESOURCE_MSG_LEN];
726
727     apfw_trace("ico_apf_resource_reply_int_screen_mode: Enter(%s,%d,%d,%d)",
728                disp_dev ? disp_dev : "(NULL)", scr_id, int_scr_id, ok);
729
730     if ((! resmgr_initialized) || (! appsctl_handle))   {
731         apfw_error("ico_apf_resource_reply_int_screen_mode: Leave(not initialized)");
732         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
733     }
734
735     /* set send message parameter */
736     if (disp_dev)   {
737         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d %d",
738                  disp_dev, int_scr_id, scr_id);
739     }
740     else    {
741         /* no display URI, default display  */
742         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d %d",
743                  sysconf->display[sysconf->misc.default_displayId].
744                      zone[sysconf->misc.default_dispzoneId].name,
745                  int_scr_id, scr_id);
746     }
747     if (ico_apf_com_send(appsctl_handle,
748                          (ok != 0) ? ICO_APF_RESOURCE_REPLY_OK
749                                    : ICO_APF_RESOURCE_REPLY_NG,
750                          ICO_APF_RESID_INT_SCREEN, NULL, msg)
751             != ICO_APF_RESOURCE_E_NONE) {
752         apfw_warn("ico_apf_resource_reply_int_screen_mode: Leave(commnad send error)");
753         return ICO_APF_RESOURCE_E_COMMUNICATION;
754     }
755
756     apfw_trace("ico_apf_resource_reply_int_screen_mode: Leave(OK)");
757     return ICO_APF_RESOURCE_E_NONE;
758 }
759
760 /*--------------------------------------------------------------------------*/
761 /**
762  *  @brief  Get the rights of interrupt screen on display
763  *
764  *  @param[in]  disp_dev    display device uri
765  *  @param[in]  int_scr_id  id of interrupt screen
766  *  @return     result status
767  *  @retval     ICO_APF_RESOURCE_E_NONE               success
768  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
769  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
770  */
771 /*--------------------------------------------------------------------------*/
772 ICO_APF_API int
773 ico_apf_resource_get_int_screen_mode_disp(const char* disp_dev, int int_scr_id)
774 {
775     char    msg[ICO_APF_RESOURCE_MSG_LEN];
776
777     apfw_trace("ico_apf_resource_get_int_screen_mode_disp: Enter(%s,%d)",
778                disp_dev ? disp_dev : "(NULL)", int_scr_id);
779
780     if ((! resmgr_initialized) || (! appsctl_handle))   {
781         apfw_error("ico_apf_resource_get_int_screen_mode_disp: Leave(not initialized)");
782         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
783     }
784
785     /* set send message parameter */
786     if (disp_dev)   {
787         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", disp_dev, int_scr_id);
788     }
789     else    {
790         /* no display URI, default display  */
791         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
792                  sysconf->display[sysconf->misc.default_displayId].
793                      zone[sysconf->misc.default_dispzoneId].name, int_scr_id);
794     }
795     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_GET,
796                          ICO_APF_RESID_ON_SCREEN, NULL, msg)
797             != ICO_APF_RESOURCE_E_NONE) {
798         apfw_error("ico_apf_resource_get_int_screen_mode_disp: Leave(commnad send error)");
799         return ICO_APF_RESOURCE_E_COMMUNICATION;
800     }
801
802     apfw_trace("ico_apf_resource_get_int_screen_mode_disp: Leave(OK)");
803     return ICO_APF_RESOURCE_E_NONE;
804 }
805
806 /*--------------------------------------------------------------------------*/
807 /**
808  *  @brief  Release the rights of interrupt screen on display
809  *
810  *  @param[in]  disp_dev    display device uri
811  *  @param[in]  int_scr_id  id of interrupt screen
812  *  @return     result status
813  *  @retval     ICO_APF_RESOURCE_E_NONE               success
814  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
815  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
816  */
817 /*--------------------------------------------------------------------------*/
818 ICO_APF_API int
819 ico_apf_resource_release_int_screen_mode_disp(const char* disp_dev,
820                                               int int_scr_id)
821 {
822     char    msg[ICO_APF_RESOURCE_MSG_LEN];
823
824     apfw_trace("ico_apf_resource_release_int_screen_mode_disp: Enter(%s,%d)",
825                disp_dev ? disp_dev : "(NULL)", int_scr_id);
826
827     if ((! resmgr_initialized) || (! appsctl_handle))   {
828         apfw_error("ico_apf_resource_release_int_screen_mode_disp: Leave(not initialized)");
829         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
830     }
831
832     /* set send message parameter */
833     if (disp_dev)   {
834         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", disp_dev, int_scr_id);
835     }
836     else    {
837         /* no display URI, default display  */
838         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
839                  sysconf->display[sysconf->misc.default_displayId].
840                      zone[sysconf->misc.default_dispzoneId].name, int_scr_id);
841     }
842     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_RELEASE,
843                          ICO_APF_RESID_ON_SCREEN, NULL, msg)
844             != ICO_APF_RESOURCE_E_NONE) {
845         apfw_warn("ico_apf_resource_release_int_screen_mode_disp: Leave(commnad send error)");
846         return ICO_APF_RESOURCE_E_COMMUNICATION;
847     }
848
849     apfw_trace("ico_apf_resource_release_int_screen_mode_disp: Leave(OK)");
850     return ICO_APF_RESOURCE_E_NONE;
851 }
852
853 /*--------------------------------------------------------------------------*/
854 /**
855  *  @brief  Reply the rights of interrupt screen on display
856  *
857  *  @param[in]  disp_dev    display device uri
858  *  @param[in]  int_scr_id  id of interrupt screen
859  *  @param[in]  ok          OK(1) or NG(0)
860  *  @return     result status
861  *  @retval     ICO_APF_RESOURCE_E_NONE               success
862  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
863  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
864  */
865 /*--------------------------------------------------------------------------*/
866 ICO_APF_API int
867 ico_apf_resource_reply_int_screen_mode_disp(const char* disp_dev,
868                                             int int_scr_id, const int ok)
869 {
870     char    msg[ICO_APF_RESOURCE_MSG_LEN];
871
872     apfw_trace("ico_apf_resource_reply_int_screen_mode_disp: Enter(%s,%d,%d)",
873                disp_dev ? disp_dev : "(NULL)", int_scr_id, ok);
874
875     if ((! resmgr_initialized) || (! appsctl_handle))   {
876         apfw_error("ico_apf_resource_reply_int_screen_mode_disp: Leave(not initialized)");
877         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
878     }
879
880     /* set send message parameter */
881     if (disp_dev)   {
882         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", disp_dev, int_scr_id);
883     }
884     else    {
885         /* no display URI, default display  */
886         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
887                  sysconf->display[sysconf->misc.default_displayId].
888                      zone[sysconf->misc.default_dispzoneId].name, int_scr_id);
889     }
890     if (ico_apf_com_send(appsctl_handle,
891                          (ok != 0) ? ICO_APF_RESOURCE_REPLY_OK
892                                    : ICO_APF_RESOURCE_REPLY_NG,
893                          ICO_APF_RESID_ON_SCREEN, NULL, msg)
894             != ICO_APF_RESOURCE_E_NONE) {
895         apfw_warn("ico_apf_resource_reply_int_screen_mode_disp: Leave(commnad send error)");
896         return ICO_APF_RESOURCE_E_COMMUNICATION;
897     }
898
899     apfw_trace("ico_apf_resource_reply_int_screen_mode_disp: Leave(OK)");
900     return ICO_APF_RESOURCE_E_NONE;
901 }
902
903 /*--------------------------------------------------------------------------*/
904 /**
905  *  @brief  Get the rights of basic sound on zone
906  *
907  *  @param[in]  zone        sound device uri
908  *  @param[in]  snd_id      id of basic sound
909  *  @param[in]  adjust      adjust acction
910  *  @return     result status
911  *  @retval     ICO_APF_RESOURCE_E_NONE               success
912  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
913  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
914  */
915 /*--------------------------------------------------------------------------*/
916 ICO_APF_API int
917 ico_apf_resource_get_sound_mode(const char* zone, int snd_id, int adjust)
918 {
919     char    msg[ICO_APF_RESOURCE_MSG_LEN];
920
921     apfw_trace("ico_apf_resource_get_sound_mode: Enter(%s,%d,%d)",
922                zone ? zone : "(NULL)", snd_id, adjust);
923
924     if ((! resmgr_initialized) || (! appsctl_handle))   {
925         apfw_error("ico_apf_resource_get_sound_mode: Leave(not initialized)");
926         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
927     }
928
929     /* set send message parameter */
930     if (zone)   {
931         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d %d", zone, snd_id, adjust);
932     }
933     else    {
934         /* no zone, default zone    */
935         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d %d",
936                  sysconf->sound[sysconf->misc.default_soundId].
937                      zone[sysconf->misc.default_soundzoneId].name,
938                  snd_id, adjust);
939     }
940     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_GET,
941                          ICO_APF_RESID_BASIC_SOUND, NULL, msg)
942             != ICO_APF_RESOURCE_E_NONE) {
943         apfw_error("ico_apf_resource_get_sound_mode: Leave(commnad send error)");
944         return ICO_APF_RESOURCE_E_COMMUNICATION;
945     }
946
947     apfw_trace("ico_apf_resource_get_sound_mode: Leave(OK)");
948     return ICO_APF_RESOURCE_E_NONE;
949 }
950
951 /*--------------------------------------------------------------------------*/
952 /**
953  *  @brief  Release the rights of basic sound on zone
954  *
955  *  @param[in]  zone        sound device uri
956  *  @param[in]  snd_id      id of basic sound
957  *  @return     result status
958  *  @retval     ICO_APF_RESOURCE_E_NONE               success
959  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
960  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
961  */
962 /*--------------------------------------------------------------------------*/
963 ICO_APF_API int
964 ico_apf_resource_release_sound_mode(const char* zone, int snd_id)
965 {
966     char    msg[ICO_APF_RESOURCE_MSG_LEN];
967
968     apfw_trace("ico_apf_resource_release_sound_mode: Enter(%s,%d)",
969                zone ? zone : "(NULL)", snd_id);
970
971     if ((! resmgr_initialized) || (! appsctl_handle))   {
972         apfw_error("ico_apf_resource_release_sound_mode: Leave(not initialized)");
973         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
974     }
975
976     /* set send message parameter */
977     if (zone)   {
978         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", zone, snd_id);
979     }
980     else    {
981         /* no zone, default zone    */
982         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
983                  sysconf->sound[sysconf->misc.default_soundId].
984                      zone[sysconf->misc.default_soundzoneId].name, snd_id);
985     }
986     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_RELEASE,
987                          ICO_APF_RESID_BASIC_SOUND, NULL, msg)
988             != ICO_APF_RESOURCE_E_NONE) {
989         apfw_warn("ico_apf_resource_release_sound_mode: Leave(commnad send error)");
990         return ICO_APF_RESOURCE_E_COMMUNICATION;
991     }
992
993     apfw_trace("ico_apf_resource_release_sound_mode: Leave(OK)");
994     return ICO_APF_RESOURCE_E_NONE;
995 }
996
997 /*--------------------------------------------------------------------------*/
998 /**
999  *  @brief  Reply the rights of basic sound on zone
1000  *
1001  *  @param[in]  zone        sound device uri
1002  *  @param[in]  snd_id      id of basic sound
1003  *  @param[in]  ok          OK(1) or NG(0)
1004  *  @return     result status
1005  *  @retval     ICO_APF_RESOURCE_E_NONE               success
1006  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
1007  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
1008  */
1009 /*--------------------------------------------------------------------------*/
1010 ICO_APF_API int
1011 ico_apf_resource_reply_sound_mode(const char* zone, int snd_id, const int ok)
1012 {
1013     char    msg[ICO_APF_RESOURCE_MSG_LEN];
1014
1015     apfw_trace("ico_apf_resource_reply_sound_mode: Enter(%s,%d,%d)",
1016                zone ? zone : "(NULL)", snd_id, ok);
1017
1018     if ((! resmgr_initialized) || (! appsctl_handle))   {
1019         apfw_error("ico_apf_resource_reply_sound_mode: Leave(not initialized)");
1020         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
1021     }
1022
1023     /* set send message parameter */
1024     if (zone)   {
1025         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", zone, snd_id);
1026     }
1027     else    {
1028         /* no zone, default zone    */
1029         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
1030                  sysconf->sound[sysconf->misc.default_soundId].
1031                      zone[sysconf->misc.default_soundzoneId].name, snd_id);
1032     }
1033     if (ico_apf_com_send(appsctl_handle,
1034                          (ok != 0) ? ICO_APF_RESOURCE_REPLY_OK
1035                                    : ICO_APF_RESOURCE_REPLY_NG,
1036                          ICO_APF_RESID_BASIC_SOUND, NULL, msg)
1037             != ICO_APF_RESOURCE_E_NONE) {
1038         apfw_warn("ico_apf_resource_reply_sound_mode: Leave(commnad send error)");
1039         return ICO_APF_RESOURCE_E_COMMUNICATION;
1040     }
1041
1042     apfw_trace("ico_apf_resource_reply_sound_mode: Leave(OK)");
1043     return ICO_APF_RESOURCE_E_NONE;
1044 }
1045
1046 /*--------------------------------------------------------------------------*/
1047 /**
1048  *  @brief  Get the rights of interrupt sound on zone
1049  *
1050  *  @param[in]  zone        sound device uri
1051  *  @param[in]  int_snd_id  id of basic sound
1052  *  @param[in]  adjust      adjust action
1053  *  @return     result status
1054  *  @retval     ICO_APF_RESOURCE_E_NONE               success
1055  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
1056  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
1057  */
1058 /*--------------------------------------------------------------------------*/
1059 ICO_APF_API int
1060 ico_apf_resource_get_int_sound_mode(const char* zone,
1061                                     int int_snd_id, int adjust)
1062 {
1063     char    msg[ICO_APF_RESOURCE_MSG_LEN];
1064
1065     apfw_trace("ico_apf_resource_get_int_sound_mode: Enter(%s,%d,%d)",
1066                zone ? zone : "(NULL)", int_snd_id, adjust);
1067
1068     if ((! resmgr_initialized) || (! appsctl_handle))   {
1069         apfw_error("ico_apf_resource_get_int_sound_mode: Leave(not initialized)");
1070         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
1071     }
1072
1073     /* set send message parameter */
1074     if (zone)   {
1075         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d %d", zone, int_snd_id, adjust);
1076     }
1077     else    {
1078         /* no zone, default zone    */
1079         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d %d",
1080                  sysconf->sound[sysconf->misc.default_soundId].
1081                      zone[sysconf->misc.default_soundzoneId].name,
1082                  int_snd_id, adjust);
1083     }
1084     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_GET,
1085                          ICO_APF_RESID_INT_SOUND, NULL, msg)
1086             != ICO_APF_RESOURCE_E_NONE) {
1087         apfw_error("ico_apf_resource_get_int_sound_mode: Leave(commnad send error)");
1088         return ICO_APF_RESOURCE_E_COMMUNICATION;
1089     }
1090
1091     apfw_trace("ico_apf_resource_get_int_sound_mode: Leave(OK)");
1092     return ICO_APF_RESOURCE_E_NONE;
1093 }
1094
1095 /*--------------------------------------------------------------------------*/
1096 /**
1097  *  @brief  Release the rights of interrupt sound on zone
1098  *
1099  *  @param[in]  zone        sound device uri
1100  *  @param[in]  int_snd_id  id of interrupt sound
1101  *  @return     result status
1102  *  @retval     ICO_APF_RESOURCE_E_NONE               success
1103  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
1104  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
1105  */
1106 /*--------------------------------------------------------------------------*/
1107 ICO_APF_API int
1108 ico_apf_resource_release_int_sound_mode(const char* zone, int int_snd_id)
1109 {
1110     char    msg[ICO_APF_RESOURCE_MSG_LEN];
1111
1112     apfw_trace("ico_apf_resource_release_int_sound_mode: Enter(%s,%d)",
1113                zone ? zone : "(NULL)", int_snd_id);
1114
1115     if ((! resmgr_initialized) || (! appsctl_handle))   {
1116         apfw_error("ico_apf_resource_release_int_sound_mode: Leave(not initialized)");
1117         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
1118     }
1119
1120     /* set send message parameter */
1121     if (zone)   {
1122         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", zone, int_snd_id);
1123     }
1124     else    {
1125         /* no zone, default zone    */
1126         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
1127                  sysconf->sound[sysconf->misc.default_soundId].
1128                      zone[sysconf->misc.default_soundzoneId].name, int_snd_id);
1129     }
1130     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_RELEASE,
1131                          ICO_APF_RESID_INT_SOUND, NULL, msg)
1132             != ICO_APF_RESOURCE_E_NONE) {
1133         apfw_warn("ico_apf_resource_release_int_sound_mode: Leave(commnad send error)");
1134         return ICO_APF_RESOURCE_E_COMMUNICATION;
1135     }
1136
1137     apfw_trace("ico_apf_resource_release_int_sound_mode: Leave(OK)");
1138     return ICO_APF_RESOURCE_E_NONE;
1139 }
1140
1141 /*--------------------------------------------------------------------------*/
1142 /**
1143  *  @brief  Reply the rights of interrupt sound on zone
1144  *
1145  *  @param[in]  zone        sound device uri
1146  *  @param[in]  int_snd_id  id of interrupt sound
1147  *  @param[in]  ok          OK(1) or NG(0)
1148  *  @return     result status
1149  *  @retval     ICO_APF_RESOURCE_E_NONE               success
1150  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
1151  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
1152  */
1153 /*--------------------------------------------------------------------------*/
1154 ICO_APF_API int
1155 ico_apf_resource_reply_int_sound_mode(const char* zone, int int_snd_id, const int ok)
1156 {
1157     char    msg[ICO_APF_RESOURCE_MSG_LEN];
1158
1159     apfw_trace("ico_apf_resource_reply_int_sound_mode: Enter(%s,%d,%d)",
1160                zone ? zone : "(NULL)", int_snd_id, ok);
1161
1162     if ((! resmgr_initialized) || (! appsctl_handle))   {
1163         apfw_error("ico_apf_resource_reply_int_sound_mode: Leave(not initialized)");
1164         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
1165     }
1166
1167     /* set send message parameter */
1168     if (zone)   {
1169         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", zone, int_snd_id);
1170     }
1171     else    {
1172         /* no zone, default zone    */
1173         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
1174                  sysconf->sound[sysconf->misc.default_soundId].
1175                      zone[sysconf->misc.default_soundzoneId].name, int_snd_id);
1176     }
1177     if (ico_apf_com_send(appsctl_handle,
1178                          (ok != 0) ? ICO_APF_RESOURCE_REPLY_OK
1179                                    : ICO_APF_RESOURCE_REPLY_NG,
1180                          ICO_APF_RESID_INT_SOUND, NULL, msg)
1181             != ICO_APF_RESOURCE_E_NONE) {
1182         apfw_warn("ico_apf_resource_reply_int_sound_mode: Leave(commnad send error)");
1183         return ICO_APF_RESOURCE_E_COMMUNICATION;
1184     }
1185
1186     apfw_trace("ico_apf_resource_reply_int_sound_mode: Leave(OK)");
1187     return ICO_APF_RESOURCE_E_NONE;
1188 }
1189
1190 /*--------------------------------------------------------------------------*/
1191 /**
1192  *  @brief  Add the input event notification from input device
1193  *
1194  *  @param[in]  input_dev   input device uri
1195  *  @param[in]  events      notify input events
1196  *  @return     result status
1197  *  @retval     ICO_APF_RESOURCE_E_NONE               success
1198  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
1199  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
1200  */
1201 /*--------------------------------------------------------------------------*/
1202 ICO_APF_API int
1203 ico_apf_resource_add_input_event(const char* input_dev, int events)
1204 {
1205     char    msg[ICO_APF_RESOURCE_MSG_LEN];
1206
1207     apfw_trace("ico_apf_resource_add_input_event: Enter(%s,%d)",
1208                input_dev ? input_dev : "(NULL)", events);
1209
1210     if ((! resmgr_initialized) || (! appsctl_handle))   {
1211         apfw_error("ico_apf_resource_add_input_event: Leave(not initialized)");
1212         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
1213     }
1214
1215     /* set send message parameter */
1216     if (input_dev)  {
1217         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", input_dev, events);
1218     }
1219     else    {
1220         /* no input device, default device  */
1221         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
1222                  sysconf->inputdev[sysconf->misc.default_inputdevId].name, events);
1223     }
1224     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_ADD,
1225                          ICO_APF_RESID_INPUT_DEV, NULL, msg)
1226             != ICO_APF_RESOURCE_E_NONE) {
1227         apfw_error("ico_apf_resource_add_input_event: Leave(commnad send error)");
1228         return ICO_APF_RESOURCE_E_COMMUNICATION;
1229     }
1230
1231     apfw_trace("ico_apf_resource_add_input_event: Leave(OK)");
1232     return ICO_APF_RESOURCE_E_NONE;
1233 }
1234
1235 /*--------------------------------------------------------------------------*/
1236 /**
1237  *  @brief  Change the input event notification from input device
1238  *
1239  *  @param[in]  input_dev   input device uri
1240  *  @param[in]  events      notify input events
1241  *  @return     result status
1242  *  @retval     ICO_APF_RESOURCE_E_NONE               success
1243  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
1244  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
1245  */
1246 /*--------------------------------------------------------------------------*/
1247 ICO_APF_API int
1248 ico_apf_resource_change_input_event(const char* input_dev, int events)
1249 {
1250     char    msg[ICO_APF_RESOURCE_MSG_LEN];
1251
1252     apfw_trace("ico_apf_resource_change_input_event: Enter(%s,%d)",
1253                input_dev ? input_dev : "(NULL)", events);
1254
1255     if ((! resmgr_initialized) || (! appsctl_handle))   {
1256         apfw_error("ico_apf_resource_change_input_event: Leave(not initialized)");
1257         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
1258     }
1259
1260     /* set send message parameter */
1261     if (input_dev)  {
1262         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", input_dev, events);
1263     }
1264     else    {
1265         /* no input device, default device  */
1266         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
1267                  sysconf->inputdev[sysconf->misc.default_inputdevId].name, events);
1268     }
1269     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_CHANGE,
1270                          ICO_APF_RESID_INPUT_DEV, NULL, msg)
1271             != ICO_APF_RESOURCE_E_NONE) {
1272         apfw_error("ico_apf_resource_change_input_event: Leave(commnad send error)");
1273         return ICO_APF_RESOURCE_E_COMMUNICATION;
1274     }
1275
1276     apfw_trace("ico_apf_resource_change_input_event: Leave(OK)");
1277     return ICO_APF_RESOURCE_E_NONE;
1278 }
1279
1280 /*--------------------------------------------------------------------------*/
1281 /**
1282  *  @brief  Delete the input event notification from input device
1283  *
1284  *  @param[in]  input_dev   input device uri
1285  *  @param[in]  events      notify input events
1286  *  @return     result status
1287  *  @retval     ICO_APF_RESOURCE_E_NONE               success
1288  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED    not initialized
1289  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION      communication error
1290  */
1291 /*--------------------------------------------------------------------------*/
1292 ICO_APF_API int
1293 ico_apf_resource_delete_input_event(const char* input_dev, int events)
1294 {
1295     char    msg[ICO_APF_RESOURCE_MSG_LEN];
1296
1297     apfw_trace("ico_apf_resource_delete_input_event: Enter(%s,%d)",
1298                input_dev ? input_dev : "(NULL)", events);
1299
1300     if ((! resmgr_initialized) || (! appsctl_handle))   {
1301         apfw_error("ico_apf_resource_delete_input_event: Leave(not initialized)");
1302         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
1303     }
1304
1305     /* set send message parameter */
1306     if (input_dev)  {
1307         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", input_dev, events);
1308     }
1309     else    {
1310         /* no input device, default device  */
1311         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
1312                  sysconf->inputdev[sysconf->misc.default_inputdevId].name, events);
1313     }
1314     if (ico_apf_com_send(appsctl_handle, ICO_APF_RESOURCE_COMMAND_DELETE,
1315                          ICO_APF_RESID_INPUT_DEV, NULL, msg)
1316             != ICO_APF_RESOURCE_E_NONE) {
1317         apfw_error("ico_apf_resource_delete_input_event: Leave(commnad send error)");
1318         return ICO_APF_RESOURCE_E_COMMUNICATION;
1319     }
1320
1321     apfw_trace("ico_apf_resource_delete_input_event: Leave(OK)");
1322     return ICO_APF_RESOURCE_E_NONE;
1323 }
1324
1325 /*--------------------------------------------------------------------------*/
1326 /**
1327  *  @brief  Send responce form server(AppsController) to client application
1328  *
1329  *  @param[in]  appid       client application id
1330  *  @param[in]  event       event
1331  *  @param[in]  resource    target resource
1332  *  @param[in]  device      display device / sound zone
1333  *  @param[in]  id          application defined object id
1334  *  @return     result status
1335  *  @retval     ICO_APF_RESOURCE_E_NONE             success
1336  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED  not initialized
1337  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION    communication error
1338  *  @retval     ICO_APF_RESOURCE_E_INVAL            illegal appid or event code
1339  */
1340 /*--------------------------------------------------------------------------*/
1341 ICO_APF_API int
1342 ico_apf_resource_send_to_client(const char *appid, const int event,
1343                                 const int resource, const char *device, const int id)
1344 {
1345     remgr_com_handle_t  *p;
1346     char    msg[ICO_APF_RESOURCE_MSG_LEN];
1347
1348     apfw_trace("ico_apf_resource_send_to_client: Enter(%s,%d,%d,%s,%d)",
1349                appid, event, resource, device ? device : "(NULL)", id);
1350
1351     if ((! resmgr_initialized) || (! appsctl_handle))   {
1352         apfw_error("ico_apf_resource_send_to_client: Leave(not initialized)");
1353         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
1354     }
1355
1356     /* search client application    */
1357     p = handles;
1358     while (p)   {
1359         if (strcmp(p->appid, appid) == 0)   break;
1360         p = p->next;
1361     }
1362     if (! p)    {
1363         apfw_error("ico_apf_resource_send_to_client: Leave(appid not exist)");
1364         return ICO_APF_RESOURCE_E_INVAL;
1365     }
1366
1367     /* set send message parameter */
1368     if (device) {
1369         snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d", device, id);
1370     }
1371     else    {
1372         /* no display URI, default display  */
1373         if ((resource == ICO_APF_RESID_BASIC_SCREEN) ||
1374             (resource == ICO_APF_RESID_INT_SCREEN) ||
1375             (resource == ICO_APF_RESID_ON_SCREEN))  {
1376             snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
1377                      sysconf->display[sysconf->misc.default_displayId].
1378                          zone[sysconf->misc.default_dispzoneId].name, id);
1379         }
1380         else if (resource == ICO_APF_RESID_INPUT_DEV)   {
1381             snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
1382                      sysconf->inputdev[sysconf->misc.default_inputdevId].name, id);
1383         }
1384         else    {
1385             snprintf(msg, ICO_APF_RESOURCE_MSG_LEN-1, "%s %d",
1386                      sysconf->sound[sysconf->misc.default_soundId].
1387                          zone[sysconf->misc.default_soundzoneId].name, id);
1388         }
1389     }
1390     if (ico_apf_com_send(p->handle, event, resource, appid, msg)
1391             != ICO_APF_RESOURCE_E_NONE) {
1392         apfw_error("ico_apf_resource_send_to_client: Leave(commnad send error)");
1393         return ICO_APF_RESOURCE_E_COMMUNICATION;
1394     }
1395
1396     apfw_trace("ico_apf_resource_send_to_client: Leave(OK)");
1397     return ICO_APF_RESOURCE_E_NONE;
1398 }
1399
1400 /*--------------------------------------------------------------------------*/
1401 /**
1402  *  @brief  Send request to Multi Sound Manager
1403  *
1404  *  @param[in]  cmd         send command
1405  *  @param[in]  pid         target pid
1406  *  @return     result status
1407  *  @retval     ICO_APF_RESOURCE_E_NONE             success
1408  *  @retval     ICO_APF_RESOURCE_E_NOT_INITIALIZED  not initialized
1409  *  @retval     ICO_APF_RESOURCE_E_COMMUNICATION    communication error
1410  */
1411 /*--------------------------------------------------------------------------*/
1412 ICO_APF_API int
1413 ico_apf_resource_send_to_soundctl(const ico_apf_sound_state_e cmd, const int pid)
1414 {
1415     apfw_trace("ico_apf_resource_send_to_soundctl: Enter(%s[%d],%d)",
1416                cmd == ICO_APF_SOUND_COMMAND_MUTEON ? "Stop" :
1417                    (cmd == ICO_APF_SOUND_COMMAND_MUTEOFF ? "Start" : "\0"), (int)cmd, pid);
1418
1419     if ((! resmgr_initialized) || (! soundmgr_handle))   {
1420         apfw_error("ico_apf_resource_send_to_soundctl: Leave(not initialized)");
1421         return ICO_APF_RESOURCE_E_NOT_INITIALIZED;
1422     }
1423
1424     if (ico_apf_com_send(soundmgr_handle, cmd, pid, NULL, NULL)
1425             != ICO_APF_RESOURCE_E_NONE) {
1426         apfw_error("ico_apf_resource_send_to_soundctl: Leave(commnad send error)");
1427         return ICO_APF_RESOURCE_E_COMMUNICATION;
1428     }
1429     apfw_trace("ico_apf_resource_send_to_soundctl: Leave(OK)");
1430     return ICO_APF_RESOURCE_E_NONE;
1431 }
1432