2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
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
10 * @brief client library for Ecore(EFL) application
23 #include "ico_apf_private.h"
24 #include "ico_apf_ecore.h"
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);
30 /*--------------------------------------------------------------------------*/
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.
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)
41 /*--------------------------------------------------------------------------*/
43 ico_apf_ecore_init(const char *uri)
45 apfw_trace("ico_apf_ecore_init: Enter(uri=%s)", uri ? uri : "(NULL)");
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;
53 /* set file descriptor to Ecore main loop */
54 ico_apf_com_poll_fd_control(ico_apf_ecore_fdcontrol);
56 apfw_trace("ico_apf_ecore_init: Leave(OK)");
57 return ICO_APF_E_NONE;
60 /*--------------------------------------------------------------------------*/
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.
69 /*--------------------------------------------------------------------------*/
71 ico_apf_ecore_term(void)
73 apfw_trace("ico_apf_ecore_term: Enter");
75 /* terminate resource controller */
76 ico_apf_resource_term_client();
78 apfw_trace("ico_apf_ecore_term: Leave");
81 /*--------------------------------------------------------------------------*/
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.
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)
92 /*--------------------------------------------------------------------------*/
94 ico_apf_ecore_init_server(const char *uri)
96 apfw_trace("ico_apf_ecore_init_server: Enter(uri=%s)", uri ? uri : "(NULL)");
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;
104 /* set file descriptor to Ecore main loop */
105 ico_apf_com_poll_fd_control(ico_apf_ecore_fdcontrol);
107 apfw_trace("ico_apf_ecore_init_server: Leave(OK)");
108 return ICO_APF_E_NONE;
111 /*--------------------------------------------------------------------------*/
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.
120 /*--------------------------------------------------------------------------*/
122 ico_apf_ecore_term_server(void)
124 apfw_trace("ico_apf_ecore_term_server: Enter");
126 /* terminate resource controller */
127 ico_apf_resource_term_server();
129 apfw_trace("ico_apf_ecore_term_server: Leave");
132 /*--------------------------------------------------------------------------*/
134 * @brief ico_apf_comm_connect
135 * callback function called by Ecore when a file descriptor had a change
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
142 /*--------------------------------------------------------------------------*/
144 ico_apf_ecore_fdevent(void *data, Ecore_Fd_Handler *handler)
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;
155 ico_apf_com_poll_fd_event((ico_apf_com_poll_t *)data, flags);
157 return ECORE_CALLBACK_RENEW;
160 /*--------------------------------------------------------------------------*/
162 * @brief ico_apf_ecore_fdcontrol
163 * This function connects to AppsController.
165 * @param[in] fd_ctl file descriptors
166 * @param[in] num_fds number of file descriptors
169 /*--------------------------------------------------------------------------*/
171 ico_apf_ecore_fdcontrol(ico_apf_com_poll_t *fd_ctl[], const int num_fds)
173 Ecore_Fd_Handler_Flags flags;
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;
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);
191 ecore_main_fd_handler_active_set((Ecore_Fd_Handler *)fd_ctl[i]->user_data,
196 /* remove file descriptor */
197 ecore_main_fd_handler_del((Ecore_Fd_Handler *)fd_ctl[i]->user_data);