Fixed some RPMlint errors - group name, duplicate files, etc.
[profile/ivi/ico-uxf-homescreen.git] / ico-app-framework / ico_apf_ecore.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   client library for Ecore(EFL) application
11  *
12  * @date    Feb-28-2013
13  */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <getopt.h>
19 #include <string.h>
20 #include <sys/time.h>
21 #include <Ecore.h>
22
23 #include "ico_apf_private.h"
24 #include "ico_apf_ecore.h"
25
26 /* define static function prototype         */
27 static Eina_Bool ico_apf_ecore_fdevent(void *data, Ecore_Fd_Handler *handler);
28 static void ico_apf_ecore_fdcontrol(ico_apf_com_poll_t *fd_ctl[], const int num_fds);
29
30 /*--------------------------------------------------------------------------*/
31 /**
32  *  @brief  ico_apf_ecore_init
33  *          This function connects to AppsController for Ecore application.
34  *          If you use AppsController's function, you must call this function.
35  *
36  *  @param[in]  uri             server URI
37  *  @return     result status
38  *  @retval     ICO_APF_E_NONE      success
39  *  @retval     ICO_APF_E_IO_ERROR  error(failed)
40  */
41 /*--------------------------------------------------------------------------*/
42 ICO_APF_API int
43 ico_apf_ecore_init(const char *uri)
44 {
45     apfw_trace("ico_apf_ecore_init: Enter(uri=%s)", uri ? uri : "(NULL)");
46
47     /* initialize resource controller           */
48     if (ico_apf_resource_init_client(uri) !=  ICO_APF_RESOURCE_E_NONE)  {
49         apfw_error("ico_apf_ecore_init: Leave(Resource initialize Error)");
50         return ICO_APF_E_IO_ERROR;
51     }
52
53     /* set file descriptor to Ecore main loop   */
54     ico_apf_com_poll_fd_control(ico_apf_ecore_fdcontrol);
55
56     apfw_trace("ico_apf_ecore_init: Leave(OK)");
57     return ICO_APF_E_NONE;
58 }
59
60 /*--------------------------------------------------------------------------*/
61 /**
62  *  @brief  ico_apf_ecore_term
63  *          This function connects to AppsController for Ecore application.
64  *          If you use AppsController's function, you must call this function.
65  *
66  *  @param      none
67  *  @return     none
68  */
69 /*--------------------------------------------------------------------------*/
70 ICO_APF_API void
71 ico_apf_ecore_term(void)
72 {
73     apfw_trace("ico_apf_ecore_term: Enter");
74
75     /* terminate resource controller            */
76     ico_apf_resource_term_client();
77
78     apfw_trace("ico_apf_ecore_term: Leave");
79 }
80
81 /*--------------------------------------------------------------------------*/
82 /**
83  *  @brief  ico_apf_ecore_init_server
84  *          This function connects to AppsController for Ecore application.
85  *          If you use AppsController's function, you must call this function.
86  *
87  *  @param[in]  appid           id of application
88  *  @return     result status
89  *  @retval     ICO_APF_E_NONE      success
90  *  @retval     ICO_APF_E_IO_ERROR  error(failed)
91  */
92 /*--------------------------------------------------------------------------*/
93 ICO_APF_API int
94 ico_apf_ecore_init_server(const char *uri)
95 {
96     apfw_trace("ico_apf_ecore_init_server: Enter(uri=%s)", uri ? uri : "(NULL)");
97
98     /* initialize resource controller           */
99     if (ico_apf_resource_init_server(uri) !=  ICO_APF_RESOURCE_E_NONE)  {
100         apfw_error("ico_apf_ecore_init_server: Leave(Resource initialize Error)");
101         return ICO_APF_E_IO_ERROR;
102     }
103
104     /* set file descriptor to Ecore main loop   */
105     ico_apf_com_poll_fd_control(ico_apf_ecore_fdcontrol);
106
107     apfw_trace("ico_apf_ecore_init_server: Leave(OK)");
108     return ICO_APF_E_NONE;
109 }
110
111 /*--------------------------------------------------------------------------*/
112 /**
113  *  @brief  ico_apf_ecore_term_server
114  *          This function connects to AppsController for Ecore application.
115  *          If you use AppsController's function, you must call this function.
116  *
117  *  @param      none
118  *  @return     none
119  */
120 /*--------------------------------------------------------------------------*/
121 ICO_APF_API void
122 ico_apf_ecore_term_server(void)
123 {
124     apfw_trace("ico_apf_ecore_term_server: Enter");
125
126     /* terminate resource controller            */
127     ico_apf_resource_term_server();
128
129     apfw_trace("ico_apf_ecore_term_server: Leave");
130 }
131
132 /*--------------------------------------------------------------------------*/
133 /**
134  * @brief   ico_apf_comm_connect
135  *          callback function called by Ecore when a file descriptor had a change
136  *
137  * @param[in]   data            user data(ico_apf_com_poll_t)
138  * @param[in]   handler         Ecore file descriptor handler
139  * @return      call back setting
140  * @retval      ECORE_CALLBACK_RENEW    set callback
141  */
142 /*--------------------------------------------------------------------------*/
143 static Eina_Bool
144 ico_apf_ecore_fdevent(void *data, Ecore_Fd_Handler *handler)
145 {
146     int     flags;
147
148     flags = (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
149                     ? ICO_APF_COM_POLL_READ : 0;
150     if (ecore_main_fd_handler_active_get(handler, ECORE_FD_WRITE))
151         flags |= ICO_APF_COM_POLL_WRITE;
152     if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
153         flags |= ICO_APF_COM_POLL_ERROR;
154
155     ico_apf_com_poll_fd_event((ico_apf_com_poll_t *)data, flags);
156
157     return ECORE_CALLBACK_RENEW;
158 }
159
160 /*--------------------------------------------------------------------------*/
161 /**
162  * @brief   ico_apf_ecore_fdcontrol
163  *          This function connects to AppsController.
164  *
165  * @param[in]   fd_ctl      file descriptors
166  * @param[in]   num_fds     number of file descriptors
167  * @return      none
168  */
169 /*--------------------------------------------------------------------------*/
170 static void
171 ico_apf_ecore_fdcontrol(ico_apf_com_poll_t *fd_ctl[], const int num_fds)
172 {
173     Ecore_Fd_Handler_Flags flags;
174     int     i;
175
176     for (i = 0; i < num_fds; i++) {
177         if (fd_ctl[i]->flags) {
178             flags = (fd_ctl[i]->flags & ICO_APF_COM_POLL_READ) ? ECORE_FD_READ : 0;
179
180             if (fd_ctl[i]->flags & ICO_APF_COM_POLL_WRITE)   flags |= ECORE_FD_WRITE;
181             if (fd_ctl[i]->flags & ICO_APF_COM_POLL_ERROR)   flags |= ECORE_FD_ERROR;
182             if (! fd_ctl[i]->user_data) {
183                 /* add file descriptor  */
184                 fd_ctl[i]->user_data = (void *)
185                     ecore_main_fd_handler_add(fd_ctl[i]->fd, flags,
186                                               ico_apf_ecore_fdevent,
187                                               (void *)fd_ctl[i], NULL, NULL);
188             }
189             else {
190                 /* change event         */
191                 ecore_main_fd_handler_active_set((Ecore_Fd_Handler *)fd_ctl[i]->user_data,
192                                                  flags);
193             }
194         }
195         else {
196             /* remove file descriptor   */
197             ecore_main_fd_handler_del((Ecore_Fd_Handler *)fd_ctl[i]->user_data);
198         }
199     }
200 }
201