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 library to communicate with outer process
23 #include <sys/epoll.h>
26 #include <libwebsockets.h>
30 #include <Ecore_Evas.h>
34 #include "ico_uxf_conf_common.h"
36 #include "home_screen_parser.h"
37 #include "home_screen.h"
38 #include "home_screen_lib.h"
40 /*============================================================================*/
42 /*============================================================================*/
43 #define WEBSOCKET_MAX_BUFFER (4096)
44 #define HS_REQ_ANS_HELLO "REQ_ANS_HELLO"
45 typedef struct _hs_lib_poll hs_lib_poll_t;
46 typedef struct _hs_lib_handle hs_lib_handle_t;
47 typedef struct _hs_lib_msg hs_lib_msg_t;
49 /* management connection */
50 struct _hs_lib_handle {
51 hs_lib_handle_t *next; /* next handle */
52 int fd; /* Socket file descriptor */
55 struct libwebsocket_context *wsi_context;
56 /* Context of libwebsockets */
57 struct libwebsocket *wsi; /* WSI of libwebsockets */
59 char appid[ICO_UXF_MAX_PROCESS_NAME];
67 hs_lib_handle_t *handle;
75 hs_lib_handle_t *handle;
78 /*============================================================================*/
80 /*============================================================================*/
81 static struct libwebsocket_context *hs_wsicontext = NULL;
82 static hs_lib_msg_t *hs_send_msg = NULL;
83 static hs_lib_msg_t *hs_recv_msg = NULL;
84 static hs_lib_msg_t *hs_free_msg = NULL;
85 static hs_lib_handle_t *hs_handles = NULL;
86 static hs_lib_handle_t *hs_handles_free = NULL;
87 static hs_lib_poll_t *hs_polls = NULL;
88 static hs_lib_poll_t *hs_polls_free = NULL;
90 /*============================================================================*/
91 /* Function prototype for static(internal) functions */
92 /*============================================================================*/
93 static void hs_lib_handle_command(hs_lib_msg_t *msg);
94 static void hs_lib_handle_application(hs_lib_msg_t *msg);
95 static void hs_lib_handle_onscreen(hs_lib_msg_t *msg);
96 static hs_lib_msg_t *hs_lib_alloc_msg(char *data, int len);
97 static void hs_lib_free_msg(hs_lib_msg_t *msg);
98 static void hs_lib_free_handle(hs_lib_handle_t *handle);
99 static hs_lib_handle_t *hs_lib_alloc_handle(void);
100 static void hs_lib_realsend(hs_lib_msg_t *msg);
101 static hs_lib_msg_t *hs_lib_get_sendmsg(int type);
102 static int hs_lib_put_sendmsg(hs_lib_msg_t *send);
103 static hs_lib_msg_t *hs_lib_get_recvmsg(void);
104 static void hs_lib_put_recvmsg(hs_lib_msg_t *recv);
105 static void hs_lib_com_dispatch(hs_lib_handle_t *_handle, int timeoutms);
106 static void hs_lib_poll_fd_event(hs_lib_poll_t *poll, int flags);
107 static Eina_Bool hs_lib_ecore_fdevent(void *data, Ecore_Fd_Handler *handler);
108 static void hs_lib_control_fd(hs_lib_poll_t *fd_ctl[], const int num_fds);
109 static int hs_lib_add_poll_fd(int fd, int flags);
110 static void hs_lib_del_poll_fd(int fd);
111 static void hs_lib_set_mode_poll_fd(int fd, int flags);
112 static void hs_lib_clear_mode_poll_fd(int fd, int flags);
113 static char *get_parsed_str(char *in, char *out, int len, int arg_idx);
114 static char *getFileName(char *filepath, int len);
115 static int hs_lib_callback_http(struct libwebsocket_context *context,
116 struct libwebsocket *wsi,
117 enum libwebsocket_callback_reasons reason, void *user,
118 void *in, size_t len);
119 static int hs_lib_callback_command(struct libwebsocket_context *context,
120 struct libwebsocket *wsi,
121 enum libwebsocket_callback_reasons reason, void *user,
122 void *in, size_t len);
123 static int hs_lib_callback_statusbar(struct libwebsocket_context *context,
124 struct libwebsocket *wsi,
125 enum libwebsocket_callback_reasons reason,
126 void *user, void *in, size_t len);
127 static int hs_lib_callback_onscreen(struct libwebsocket_context *context,
128 struct libwebsocket *wsi,
129 enum libwebsocket_callback_reasons reason, void *user,
130 void *in, size_t len);
131 static int hs_lib_callback_app(struct libwebsocket_context *context,
132 struct libwebsocket *wsi,
133 enum libwebsocket_callback_reasons reason, void *user,
134 void *in, size_t len);
136 /*============================================================================*/
138 /*============================================================================*/
139 static struct libwebsocket_protocols protocols[] = {
142 hs_lib_callback_http,
145 { /* HomeScreen - command */
147 hs_lib_callback_command,
150 { /* HomeScreen - StatusBar */
152 hs_lib_callback_statusbar,
155 { /* HomeScreen - OnScreen */
157 hs_lib_callback_onscreen,
160 { /* HomeScreen - OtherNatiiveApps */
172 /*============================================================================*/
174 /*============================================================================*/
175 /*--------------------------------------------------------------------------*/
177 * @brief hs_lib_handle_command
178 * callback at received message from external command tools,
179 * and handle the message.
181 * @param[in] msg received message
184 /*--------------------------------------------------------------------------*/
186 hs_lib_handle_command(hs_lib_msg_t *msg)
190 char buff[ICO_HS_MSG_SIZE];
193 uifw_trace("hs_lib_handle_command: Enter");
195 if (strcmp(msg->data, HS_REQ_ANS_HELLO) == 0) {
196 memset(buff, 0, sizeof(buff));
198 send = hs_lib_alloc_msg("ANS HELLO", strlen("ANS HELLO"));
200 uifw_warn("hs_lib_handle_command: ERROR(allocate send msg)");
203 send->type = ICO_HS_PROTOCOL_TYPE_CM;
205 hs_lib_put_sendmsg(send);
207 uifw_trace("hs_lib_handle_command: Leave");
212 /* data sent by command is parsed and controlled for the window */
213 ret = hs_parse_form(msg->data, msg->len);
214 if (hs_req_touch == ICO_HS_TOUCH_TOBE_HIDE) {
215 hs_show_appscreen(NULL);
216 hs_control_app_screen();
218 else if (hs_req_touch == ICO_HS_TOUCH_TOBE_SHOW) {
219 hs_get_tilescreendata();
225 memset(buff, 0, sizeof(buff));
227 cnt = snprintf(buff, sizeof(buff), "ANS %s OK", msg->data);
230 cnt = snprintf(buff, sizeof(buff), "ERR %s FAILED", msg->data);
234 send = hs_lib_alloc_msg(buff, cnt);
236 uifw_warn("hs_lib_handle_command: ERROR(allocate send msg)");
239 send->type = ICO_HS_PROTOCOL_TYPE_CM;
241 hs_lib_put_sendmsg(send);
244 uifw_trace("hs_lib_handle_command: Leave");
247 /*--------------------------------------------------------------------------*/
249 * @brief hs_lib_handle_application
250 * callback at received message from a application, and handle the
253 * @param[in] msg received message
256 /*--------------------------------------------------------------------------*/
258 hs_lib_handle_application(hs_lib_msg_t *msg)
261 char msg_data[ICO_HS_MSG_SIZE];
262 char tmp_buf[ICO_HS_MSG_SIZE];
263 char *data = msg->data;
266 uifw_trace("hs_lib_handle_application: Enter");
268 if (strncmp("OPEN", data, 4) == 0) {
269 strncpy(msg_data, get_parsed_str(data, tmp_buf, sizeof(tmp_buf), 2),
272 uifw_trace("hs_lib_callback_app: app_id = %s, msg_data - %s, in - %s",
273 app_id, msg_data, data);
274 strncpy(hs_active_onscreen, app_id, sizeof(hs_active_onscreen));
275 strncpy(msg->handle->appid, app_id, sizeof(hs_active_onscreen));
277 send = hs_lib_alloc_msg(data, msg->len);
279 uifw_warn("hs_lib_callback_app: ERROR(allocate send msg)");
282 send->type = ICO_HS_PROTOCOL_TYPE_OS;
284 hs_lib_put_sendmsg(send);
286 else if (strncmp("CLOSE", data, 5) == 0) {
287 /* native apps only */
289 memset(hs_active_onscreen, 0, sizeof(hs_active_onscreen));
290 /* disconnect app-protocol */
291 if ((msg->handle != NULL) && (msg->handle->wsi != NULL)) {
292 libwebsocket_close_and_free_session(msg->handle->wsi_context,
294 LWS_CLOSE_STATUS_NORMAL);
297 uifw_trace("hs_lib_handle_application: Leave");
300 /*--------------------------------------------------------------------------*/
302 * @brief hs_lib_handle_onscreen
303 * callback at received message from onscreen, and handle the
306 * @param[in] msg received message
309 /*--------------------------------------------------------------------------*/
311 hs_lib_handle_onscreen(hs_lib_msg_t *msg)
313 char msg_buf[ICO_HS_MSG_SIZE];
314 char msg_data[ICO_HS_MSG_SIZE];
315 char tmp_buf[ICO_HS_MSG_SIZE];
319 const Ico_Uxf_conf_application *appConf = NULL;
320 char *data = msg->data;
321 hs_lib_handle_t *handle;
324 uifw_trace("hs_lib_handle_onscreen: Enter");
327 memset(msg_data, 0x00, sizeof(msg_data));
328 p_msg_data = &msg_data[0];
329 strncpy(p_msg_data, data, msg->len);
331 uifw_trace("hs_lib_handle_onscreen: hs_active_onscreen = %s",
333 /* parse message from OnScreen */
334 if (strncmp("RESULT", p_msg_data, 6) == 0) {
336 ptr = get_parsed_str(p_msg_data, tmp_buf, sizeof(tmp_buf), 1);
337 if (strncmp("SUCCESS", ptr, 7) == 0) {
338 /* loaded edje: success */
340 send = hs_lib_alloc_msg(data, msg->len);
342 uifw_warn("hs_lib_handle_onscreen: ERROR(allocate send msg)");
345 send->type = ICO_HS_PROTOCOL_TYPE_APP;
346 hs_lib_put_sendmsg(send);
348 else if (strncmp("FAILED", ptr, 6) == 0) {
349 /* not loaded edje: failed */
350 if (strcmp(hs_active_onscreen, ICO_UXF_PROC_DEFAULT_HOMESCREEN)
352 /* appli_list or appli_kill: raise touch layer */
356 /* native apps: raise own */
359 memset(hs_active_onscreen, 0, sizeof(hs_active_onscreen));
360 /* disconnect app-protocol */
363 if (handle->type == ICO_HS_PROTOCOL_TYPE_APP) {
364 libwebsocket_close_and_free_session(handle->wsi_context,
366 LWS_CLOSE_STATUS_NORMAL);
369 handle = handle->next;
373 else if (strncmp("TOUCH", data, 5) == 0) {
374 if (strlen(hs_active_onscreen) == 0) {
377 else if (strcmp(hs_active_onscreen, ICO_UXF_PROC_DEFAULT_HOMESCREEN)
380 ptr = get_parsed_str(p_msg_data, tmp_buf, sizeof(tmp_buf), 1);
381 if (strncmp(getFileName(ptr, strlen(ptr)),
382 ICO_HS_ONS_APPLI_LIST_NAME,
383 sizeof(ICO_HS_ONS_APPLI_LIST_NAME)) == 0) {
385 ptr = get_parsed_str(p_msg_data, tmp_buf, sizeof(tmp_buf), 2);
386 appConf = ico_uxf_getAppByAppid(ptr);
388 "hs_lib_handle_onscreen: hs_tile_get_index_app = %d(%s)",
390 if (appConf != NULL) {
391 sprintf(msg_buf, "FOCUS %s", ptr);
392 send = hs_lib_alloc_msg(msg_buf, strlen(msg_buf));
395 "hs_lib_handle_onscreen: ERROR(allocate send msg)");
398 send->type = ICO_HS_PROTOCOL_TYPE_CM;
399 ret = hs_lib_put_sendmsg(send);
401 ret = ico_uxf_process_execute(ptr);
403 if ((ret == ICO_UXF_EOK) || (ret == ICO_UXF_EBUSY)) {
404 idx = hs_tile_get_index_app(ptr);
406 idx = hs_tile_get_minchange();
408 hs_tile_set_app(idx, ptr);
410 hs_tile_show_screen();
416 memset(hs_active_onscreen, 0, sizeof(hs_active_onscreen));
419 if (strncmp(ptr, "next_bt", 7) == 0) {
420 hs_get_ons_edj_path(tmp_buf, sizeof(tmp_buf));
421 sprintf(msg_buf, "OPEN %s%s %s", tmp_buf,
422 ICO_HS_ONS_APPLI_LIST_NAME,
423 ICO_UXF_PROC_DEFAULT_HOMESCREEN);
424 uifw_trace("send '%s' to onscreen", msg_buf);
425 send = hs_lib_alloc_msg(msg_buf, strlen(msg_buf));
428 "hs_lib_handle_onscreen: ERROR(allocate send msg)");
431 send->type = ICO_HS_PROTOCOL_TYPE_OS;
432 (void)hs_lib_put_sendmsg(send);
434 else if (strncmp(ptr, "cancel_bt", 8) == 0) {
436 memset(hs_active_onscreen, 0,
437 sizeof(hs_active_onscreen));
441 memset(hs_active_onscreen, 0,
442 sizeof(hs_active_onscreen));
446 else if (strncmp(getFileName(ptr, strlen(ptr)),
447 ICO_HS_ONS_APPLI_KILL_NAME,
448 sizeof(ICO_HS_ONS_APPLI_KILL_NAME)) == 0) {
450 ptr = get_parsed_str(p_msg_data, tmp_buf, sizeof(tmp_buf), 2);
451 if (strncmp(ptr, "ok_bt", 5) == 0) {
452 uifw_trace("%s: ok_bt", ICO_HS_ONS_APPLI_KILL_NAME);
453 if (strlen(hs_kill_appid) == 0) {
455 memset(hs_active_onscreen, 0,
456 sizeof(hs_active_onscreen));
459 sprintf((char *)msg_buf, "FOCUS %s", hs_kill_appid);
460 uifw_trace("send '%s' to command", msg_buf);
461 send = hs_lib_alloc_msg(msg_buf, strlen(msg_buf));
464 "hs_lib_handle_onscreen: ERROR(allocate send msg)");
467 send->type = ICO_HS_PROTOCOL_TYPE_CM;
468 ret = hs_lib_put_sendmsg(send);
471 hs_tile_kill_app(hs_kill_appid);
472 hs_tile_show_screen();
478 else if (strncmp(ptr, "cancel_bt", 8) == 0) {
479 uifw_trace("%s: cancel_bt", ICO_HS_ONS_APPLI_KILL_NAME);
481 hs_tile_show_screen();
484 uifw_trace("%s: else %s", ICO_HS_ONS_APPLI_KILL_NAME, ptr);
487 memset(hs_active_onscreen, 0, sizeof(hs_active_onscreen));
488 memset(hs_kill_appid, 0, sizeof(hs_kill_appid));
492 uifw_trace("send %s to app", data);
493 send = hs_lib_alloc_msg(data, msg->len);
495 uifw_warn("hs_lib_handle_onscreen: ERROR(allocate send msg)");
498 send->type = ICO_HS_PROTOCOL_TYPE_APP;
499 hs_lib_put_sendmsg(send);
503 uifw_trace("hs_lib_handle_onscreen: Leave");
505 /*--------------------------------------------------------------------------*/
507 * @brief hs_lib_handle_statusbar
508 * callback at received message from statusbar, and handle the
511 * @param[in] msg received message
514 /*--------------------------------------------------------------------------*/
516 hs_lib_handle_statusbar(hs_lib_msg_t *msg)
519 char tmp_buf[ICO_HS_MSG_SIZE];
521 Ico_Uxf_ProcessWin wins[1];
522 Ico_Uxf_ProcessAttr attr;
527 uifw_trace("hs_lib_handle_statusbar: Enter(%s)", msg->data);
529 if (strncmp("CLICK ESCUTCHEON", msg->data, 16) == 0) {
530 /* clicked escutcheon button and send a command to outer commander */
531 hs_click_escutcheon();
532 /* send "Receive OK" message to statusbar */
533 send = hs_lib_alloc_msg("RECEIVE OK", strlen("RECEIVE OK"));
535 send->type = ICO_HS_PROTOCOL_TYPE_SB;
536 hs_lib_put_sendmsg(send);
539 else if (strncmp("OPEN", msg->data, 4) == 0) {
540 /* forward the message to onscreen */
541 if (hs_click_applist()) {
542 send = hs_lib_alloc_msg(msg->data, msg->len);
544 strncpy(hs_active_onscreen, ICO_UXF_PROC_DEFAULT_HOMESCREEN,
545 sizeof(hs_active_onscreen));
546 send->type = ICO_HS_PROTOCOL_TYPE_OS;
547 hs_lib_put_sendmsg(send);
550 /* send "Receive OK" message to statusbar */
551 send = hs_lib_alloc_msg("RECEIVE OK", strlen("RECEIVE OK"));
553 send->type = ICO_HS_PROTOCOL_TYPE_SB;
554 hs_lib_put_sendmsg(send);
557 else if (strncmp("SHOW", msg->data, 4) == 0) {
558 /* show the application on the application screen */
559 cmd = get_parsed_str(msg->data, tmp_buf, sizeof(tmp_buf), 1);
561 /* wait for creating the application's window */
562 memset(wins, 0, sizeof(wins));
563 while (wins[0].window <= 0) {
564 ret = ico_uxf_process_window_get(cmd, wins, 1);
566 ret = ico_uxf_process_attribute_get(cmd, &attr);
567 if (wins[0].window > 0) {
570 else if ((ret >= 0) && (attr.status != ICO_UXF_PROCSTATUS_RUN)) {
571 /* launch the application */
572 ret = ico_uxf_process_execute(cmd);
573 if ((ret == ICO_UXF_EOK) || (ret == ICO_UXF_EBUSY)) {
574 idx = hs_tile_get_index_app(cmd);
576 idx = hs_tile_get_minchange();
578 hs_tile_set_app(idx, cmd);
583 /* unknown application */
587 ecore_main_loop_iterate();
597 /* show the application screen*/
598 hs_show_appscreen(cmd);
600 /* send "Receive OK" message to statusbar */
601 send = hs_lib_alloc_msg("RECEIVE OK", strlen("RECEIVE OK"));
603 send->type = ICO_HS_PROTOCOL_TYPE_SB;
604 hs_lib_put_sendmsg(send);
607 uifw_trace("hs_lib_handle_statusbar: Leave");
610 /*--------------------------------------------------------------------------*/
612 * @brief hs_lib_alloc_msg
613 * Allocate a msg structure
615 * @param[in] data data
616 * @param[in] len data length
618 * @retval > 0 success
621 /*--------------------------------------------------------------------------*/
622 static hs_lib_msg_t *
623 hs_lib_alloc_msg(char *data, int len)
628 msg = malloc(sizeof(hs_lib_msg_t));
635 hs_free_msg = hs_free_msg->next;
637 memset(msg, 0, sizeof(hs_lib_msg_t));
640 msg->data = strdup(data);
649 /*--------------------------------------------------------------------------*/
651 * @brief hs_lib_free_msg
654 * @param[in] data data
655 * @param[in] free data lenght
658 /*--------------------------------------------------------------------------*/
660 hs_lib_free_msg(hs_lib_msg_t *msg)
670 memset(msg, 0, sizeof(hs_lib_msg_t));
672 msg->next = hs_free_msg;
678 /*--------------------------------------------------------------------------*/
680 * @brief hs_lib_free_handle
681 * free the indecated handle.
683 * @param handle handle to free
686 /*--------------------------------------------------------------------------*/
688 hs_lib_free_handle(hs_lib_handle_t *handle)
690 hs_lib_handle_t *free;
691 hs_lib_handle_t *bfree;
703 bfree->next = free->next;
706 hs_handles = free->next;
708 free->next = hs_handles_free;
709 hs_handles_free = free;
713 /*--------------------------------------------------------------------------*/
715 * @brief hs_lib_alloc_handle
720 * @retval > 0 success
723 /*--------------------------------------------------------------------------*/
724 static hs_lib_handle_t *
725 hs_lib_alloc_handle(void)
727 hs_lib_handle_t *handle;
729 if (!hs_handles_free) {
730 handle = malloc(sizeof(hs_lib_handle_t));
736 handle = hs_handles_free;
737 hs_handles_free = hs_handles_free->next;
739 memset(handle, 0, sizeof(hs_lib_handle_t));
742 handle->next = hs_handles;
749 /*--------------------------------------------------------------------------*/
751 * @brief hs_lib_realsend
752 * write send message to websocket actually.
754 * @param[in] msg write message
757 /*--------------------------------------------------------------------------*/
759 hs_lib_realsend(hs_lib_msg_t *msg)
761 unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512
762 + LWS_SEND_BUFFER_POST_PADDING];
763 unsigned char *pt = &buf[LWS_SEND_BUFFER_PRE_PADDING];
766 strcpy((char*)pt, msg->data);
768 uifw_trace("hs_lib_realsend: send(wsi=%x, type=h:%d(m:%d), len=%d, msg=%s)",
769 msg->handle->wsi, msg->handle->type, msg->type, msg->len, msg->data);
770 n = libwebsocket_write(msg->handle->wsi, pt, strlen((char *)pt),
774 uifw_warn("hs_lib_realsend: ERROR(fail to write ws)");
777 hs_lib_free_msg(msg);
779 uifw_warn("hs_lib_realsend: Leave(send len = %d)", n);
784 /*--------------------------------------------------------------------------*/
786 * @brief hs_lib_get_sendmsg
787 * get the send message from the send queue.
789 * @param[in] type receiver
790 * @return send message address
791 * @retval > 0 success
794 /*--------------------------------------------------------------------------*/
795 static hs_lib_msg_t *
796 hs_lib_get_sendmsg(int type)
804 if (msg->type == type) {
813 hs_send_msg = msg->next;
817 bmsg->next = msg->next;
825 /*--------------------------------------------------------------------------*/
827 * @brief hs_lib_put_sendmsg
828 * put the send message to the send queue end.
830 * @param[in] data send message
832 * @retval ICO_HS_OK success
833 * @retval ICO_HS_ERR error
835 /*--------------------------------------------------------------------------*/
837 hs_lib_put_sendmsg(hs_lib_msg_t *send)
840 hs_lib_handle_t *handle;
842 uifw_trace("hs_lib_put_sendmsg: Enter");
846 if (handle->type == send->type) {
849 handle = handle->next;
852 uifw_trace("hs_lib_put_sendmsg: Leave(target(type:%d) does not exist", send->type);
853 hs_lib_free_msg(send);
872 send->handle = handle;
873 uifw_trace("hs_lib_put_sendmsg: libwebsocket_callback_on_writable"
874 "(wsi_ctx=%x, wsi=%x", handle->wsi_context, handle->wsi);
875 libwebsocket_callback_on_writable(handle->wsi_context, handle->wsi);
877 hs_lib_com_dispatch(handle, 0);
880 uifw_trace("hs_lib_put_sendmsg: Leave");
885 /*--------------------------------------------------------------------------*/
887 * @brief hs_lib_get_recvmsg
888 * get the receive message from the receive queue end.
891 * @return recv message address
892 * @retval > 0 success
895 /*--------------------------------------------------------------------------*/
896 static hs_lib_msg_t *
897 hs_lib_get_recvmsg(void)
903 hs_recv_msg = msg->next;
910 /*--------------------------------------------------------------------------*/
912 * @brief hs_lib_put_recvmsg
913 * put the receive message to the receive queue end.
915 * @param[in] data receive message
918 /*--------------------------------------------------------------------------*/
920 hs_lib_put_recvmsg(hs_lib_msg_t *recv)
939 /*--------------------------------------------------------------------------*/
941 * @brief hs_lib_com_dispatch
942 * The accumulated data that transmitted or received is procecssed
944 * @param[in] _handle connect handle,
945 * if NULL target is all connection
946 * @param[in] timeoutms maximum wait time on miri-sec.
947 * 0 is no wait, -1 is wait forever.
950 /*--------------------------------------------------------------------------*/
952 hs_lib_com_dispatch(hs_lib_handle_t *_handle, int timeoutms)
954 hs_lib_handle_t *handle;
965 uifw_warn("hs_lib_com_dispatch: wsi=%x", handle->wsi_context);
966 if (libwebsocket_service(handle->wsi_context, timeoutms) < 0) {
967 uifw_warn("hs_lib_com_dispatch: fd=%d is done", handle->fd);
970 /* treate received buffer */
971 msg = hs_lib_get_recvmsg();
974 case ICO_HS_PROTOCOL_TYPE_CM:
975 hs_lib_handle_command(msg);
978 case ICO_HS_PROTOCOL_TYPE_SB:
979 hs_lib_handle_statusbar(msg);
982 case ICO_HS_PROTOCOL_TYPE_OS:
983 hs_lib_handle_onscreen(msg);
986 case ICO_HS_PROTOCOL_TYPE_APP:
987 hs_lib_handle_application(msg);
993 hs_lib_free_msg(msg);
994 msg = hs_lib_get_recvmsg();
999 handle = handle->next;
1003 /*--------------------------------------------------------------------------*/
1005 * @brief hs_lib_poll_fd_event
1006 * Notify the changes of file descriptor's state
1008 * @param[in] fd_ctl The structure of file descriptor's controller
1009 * @param[in] flags Flags
1012 /*--------------------------------------------------------------------------*/
1014 hs_lib_poll_fd_event(hs_lib_poll_t *poll, int flags)
1016 hs_lib_handle_t *handle = poll->handle;
1018 uifw_trace("hs_lib_ecore_fdevent: Enter(flags=%08x)", flags);
1020 /* try to ws service */
1021 hs_lib_com_dispatch(handle, 0);
1023 /* control polling fd's event? */
1028 /*--------------------------------------------------------------------------*/
1030 * @brief hs_lib_ecore_fdevent
1031 * callback function called by Ecore when the websocket's file
1032 * descriptor had change
1034 * @param[in] data user data(ico_apf_com_poll_t)
1035 * @param[in] handler Ecore file descriptor handler
1036 * @return call back setting
1037 * @retval ECORE_CALLBACK_RENEW set callback
1039 /*--------------------------------------------------------------------------*/
1041 hs_lib_ecore_fdevent(void *data, Ecore_Fd_Handler *handler)
1045 uifw_trace("hs_lib_ecore_fdevent: Enter");
1048 = (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
1051 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_WRITE)) {
1052 flags |= ECORE_FD_WRITE;
1054 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR)) {
1058 hs_lib_poll_fd_event((hs_lib_poll_t *)data, flags);
1060 return ECORE_CALLBACK_RENEW;
1063 /*--------------------------------------------------------------------------*/
1065 * @brief hs_lib_control_fd
1066 * control file descriptors to add or delete ecore event handler
1068 * @param[in] fd_ctl file descriptors
1069 * @param[in] num_fds number of file descriptors
1072 /*--------------------------------------------------------------------------*/
1074 hs_lib_control_fd(hs_lib_poll_t *fd_ctl[], const int num_fds)
1077 Ecore_Fd_Handler_Flags flags;
1079 for (ii = 0; ii < num_fds; ii++) {
1080 if (fd_ctl[ii]->flags) {
1081 flags = (fd_ctl[ii]->flags & EPOLLIN) ? ECORE_FD_READ : 0;
1082 if (fd_ctl[ii]->flags & EPOLLOUT) {
1083 flags |= ECORE_FD_WRITE;
1085 if (fd_ctl[ii]->flags & (EPOLLERR | EPOLLPRI)) {
1086 flags |= ECORE_FD_ERROR;
1088 if (!fd_ctl[ii]->user_data) {
1090 "hs_lib_control_fd: ADD(fd=%d, flg=%08x, eflg=%08x)",
1091 fd_ctl[ii]->fd, fd_ctl[ii]->flags, flags);
1092 fd_ctl[ii]->user_data
1093 = (void *)ecore_main_fd_handler_add(
1096 hs_lib_ecore_fdevent,
1102 "hs_lib_control_fd: CHANGE(fd=%d, flg=%08x, eflg=%08x)",
1103 fd_ctl[ii]->fd, fd_ctl[ii]->flags, flags);
1104 ecore_main_fd_handler_active_set(
1105 (Ecore_Fd_Handler *)fd_ctl[ii]->user_data,
1110 /* remove file descriptor */
1111 uifw_trace("hs_lib_control_fd: DELL(fd=%d)", fd_ctl[ii]->fd);
1112 ecore_main_fd_handler_del((Ecore_Fd_Handler *)fd_ctl[ii]->user_data);
1117 /*--------------------------------------------------------------------------*/
1119 * @brief hs_lib_add_poll_fd
1120 * add file descriptor of websocket for poll
1122 * @param[in] fd file descriptor
1123 * @param[in] flags event flag
1125 * @retval ICO_HS_OK success
1126 * @retval ICO_HS_ERR error
1128 /*--------------------------------------------------------------------------*/
1130 hs_lib_add_poll_fd(int fd, int flags)
1132 hs_lib_poll_t *poll;
1133 hs_lib_poll_t *fds[0];
1134 hs_lib_handle_t *handle;
1136 /* get management table */
1139 if (poll->fd == fd) {
1145 if (hs_polls_free) {
1146 poll = hs_polls_free;
1147 hs_polls_free = poll->next;
1148 poll->user_data = NULL;
1151 poll = calloc(sizeof(hs_lib_poll_t), 1);
1153 uifw_warn("hs_lib_add_poll_fd: ERR(allocate poll table failed)");
1158 poll->next = hs_polls;
1161 poll->flags = flags;
1163 /* if the fd is same as wsi_context, set the handle */
1164 handle = hs_handles;
1166 if (handle->fd == fd)
1168 handle = handle->next;
1171 poll->handle = handle;
1172 handle->poll = poll;
1175 poll->handle = NULL;
1180 hs_lib_control_fd(fds, 1);
1185 /*--------------------------------------------------------------------------*/
1187 * @brief hs_lib_del_poll_fd
1188 * delete file descriptor of websocket for poll
1190 * @param[in] fd file descriptor
1193 /*--------------------------------------------------------------------------*/
1195 hs_lib_del_poll_fd(int fd)
1197 hs_lib_poll_t *poll;
1198 hs_lib_poll_t *fds[0];
1200 /* get management table */
1203 if (poll->fd == fd) {
1204 hs_polls = poll->next;
1209 hs_lib_control_fd(fds, 1);
1211 /* add free polls */
1212 poll->next = hs_polls_free;
1213 hs_polls_free = poll;
1222 /*--------------------------------------------------------------------------*/
1224 * @brief hs_lib_set_mode_poll_fd
1225 * set event to file descriptor of websocket for poll
1227 * @param[in] fd file descriptor
1228 * @param[in] flags event flag
1231 /*--------------------------------------------------------------------------*/
1233 hs_lib_set_mode_poll_fd(int fd, int flags)
1235 hs_lib_poll_t *poll;
1236 hs_lib_poll_t *fds[0];
1238 /* get management table */
1241 if (poll->fd == fd) {
1243 poll->flags |= flags;
1245 hs_lib_control_fd(fds, 1);
1253 /*--------------------------------------------------------------------------*/
1255 * @brief hs_lib_clear_mode_poll_fd
1256 * clear event to file descriptor of websocket for poll
1258 * @param[in] fd file descriptor
1259 * @param[in] flags event flag
1262 /*--------------------------------------------------------------------------*/
1264 hs_lib_clear_mode_poll_fd(int fd, int flags)
1266 hs_lib_poll_t *poll;
1267 hs_lib_poll_t *fds[0];
1269 /* get management table */
1272 if (poll->fd == fd) {
1274 poll->flags &= ~flags;
1276 hs_lib_control_fd(fds, 1);
1284 /*--------------------------------------------------------------------------*/
1286 * @brief get_parsed_str
1287 * extract word by the given arg_idx.
1289 * @param[in] in source char array
1290 * @param[in] out char array store word
1291 * @param[in] len char array length
1292 * @param[in] arg_idx index
1294 * @retval >=0 pointer to extract word
1296 /*--------------------------------------------------------------------------*/
1298 get_parsed_str(char *in, char *out, int len, int arg_idx)
1303 uifw_trace("get_parsed_str: %s arg = %d", in, arg_idx);
1305 memset(out, 0, len);
1306 strncpy(out, in, len);
1307 data = strtok(out, " ");
1308 for (ii = 0; ii < arg_idx; ii++) {
1309 data = strtok(NULL, " ");
1312 uifw_trace("get_parsed_str data: %s", data);
1317 /* get filename from the full path */
1319 getFileName(char *filepath, int len)
1322 char *name = filepath;
1324 for (ii = 0; ii < len - 1; ii++) {
1325 if (filepath[ii] == 0)
1327 if (filepath[ii] == '/')
1328 name = &filepath[ii + 1];
1331 uifw_trace("getFileName name: %s", name);
1336 /*--------------------------------------------------------------------------*/
1338 * @brief hs_lib_event_message
1341 * @param[in] type receiver
1342 * @param[in] fromat message to send
1344 * @retval ICO_HS_OK success
1345 * @retval ICO_HS_ERR error
1347 /*--------------------------------------------------------------------------*/
1349 hs_lib_event_message(int type, char *format, ...)
1352 char message[ICO_HS_MSG_SIZE];
1355 memset(message, 0, sizeof(message));
1357 va_start(list, format);
1358 vsnprintf(message, sizeof(message), format, list);
1361 uifw_trace("hs_lib_event_message: message to %d, %s", type, message);
1362 send = hs_lib_alloc_msg(message, strlen(message));
1364 uifw_warn("hs_lib_event_message: ERROR(allocate send msg)");
1369 return hs_lib_put_sendmsg(send);
1372 /*--------------------------------------------------------------------------*/
1374 * @brief hs_lib_callback_http
1375 * Connection status is notified from libwebsockets.
1377 * @param[in] context libwebsockets context
1378 * @param[in] wsi libwebsockets management table
1379 * @param[in] reason event type
1380 * @param[in] user intact
1381 * @param[in] in receive message
1382 * @param[in] len message size[BYTE]
1384 * @retval =0 success
1387 /*--------------------------------------------------------------------------*/
1389 hs_lib_callback_http(struct libwebsocket_context *context,
1390 struct libwebsocket *wsi,
1391 enum libwebsocket_callback_reasons reason, void *user,
1392 void *in, size_t len)
1396 uifw_trace("hs_lib_callback_http: context=%p", context);
1397 uifw_trace("HS-REASON %d", reason);
1399 fd = libwebsocket_get_socket_fd(wsi);
1401 case LWS_CALLBACK_ADD_POLL_FD:
1402 uifw_trace("LWS_CALLBACK_ADD_POLL_FD: wsi_fd=%d fd=%d flg=%08x", fd,
1403 (int)(long)user, (int)len);
1404 (void)hs_lib_add_poll_fd(fd, (int)len);
1407 case LWS_CALLBACK_DEL_POLL_FD:
1408 uifw_trace("LWS_CALLBACK_DEL_POLL_FD: wsi_fd=%d fd=%d flg=%08x", fd,
1409 (int)(long)user, (int)len);
1410 hs_lib_del_poll_fd(fd);
1413 case LWS_CALLBACK_SET_MODE_POLL_FD:
1414 uifw_trace("LWS_CALLBACK_SET_MODE_POLL_FD: wsi_fd=%d fd=%d flg=%08x",
1415 fd, (int)(long)user, (int)len);
1416 hs_lib_set_mode_poll_fd(fd, (int)len);
1419 case LWS_CALLBACK_CLEAR_MODE_POLL_FD:
1420 uifw_trace("LWS_CALLBACK_CLEAR_MODE_POLL_FD: wsi_fd=%d fd=%d flg=%08x",
1421 fd, (int)(long)user, (int)len);
1422 hs_lib_clear_mode_poll_fd(fd, (int)len);
1432 /*--------------------------------------------------------------------------*/
1434 * @brief hs_lib_callback_command
1435 * this callback function is notified from libwebsockets
1438 * @param[in] context libwebsockets context
1439 * @param[in] wsi libwebsockets management table
1440 * @param[in] reason event type
1441 * @param[in] user intact
1442 * @param[in] in receive message
1443 * @param[in] len message size[BYTE]
1445 * @retval =0 success
1448 /*--------------------------------------------------------------------------*/
1450 hs_lib_callback_command(struct libwebsocket_context *context,
1451 struct libwebsocket *wsi,
1452 enum libwebsocket_callback_reasons reason, void *user,
1453 void *in, size_t len)
1456 hs_lib_handle_t *handle;
1457 hs_lib_poll_t *poll;
1460 uifw_trace("hs_lib_callback_command: Enter(ctx=%p, wsi_fd=%d, reason=%d",
1461 context, libwebsocket_get_socket_fd(wsi), reason);
1463 fd = libwebsocket_get_socket_fd(wsi);
1464 if (reason == LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION) {
1465 /* connect from client. the client must exist only one */
1466 uifw_trace("hs_lib_callback_command: "
1467 "LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION(fd=%d)", fd);
1468 handle = hs_handles;
1470 if (handle->fd == fd)
1472 handle = handle->next;
1475 handle = hs_lib_alloc_handle();
1477 uifw_warn("hs_lib_callback_command: ERROR(allocate handle)");
1480 handle->wsi_context = hs_wsicontext;
1483 handle->type = ICO_HS_PROTOCOL_TYPE_CM;
1487 if (poll->fd == handle->fd) {
1488 poll->handle = handle;
1489 handle->poll = poll;
1496 handle = hs_handles;
1498 if (handle->wsi == wsi)
1500 handle = handle->next;
1504 case LWS_CALLBACK_ESTABLISHED:
1505 uifw_trace("hs_lib_callback_command: "
1506 "LWS_CALLBACK_ESTABLISHED(wsi=%x)", wsi);
1507 handle->service_on = 1;
1509 msg = hs_lib_alloc_msg(HS_REQ_ANS_HELLO, strlen(HS_REQ_ANS_HELLO));
1511 uifw_warn("hs_lib_callback_command: ERROR(allocate recv msg)");
1514 msg->type = ICO_HS_PROTOCOL_TYPE_CM;
1515 msg->handle = handle;
1517 hs_lib_put_recvmsg(msg);
1518 uifw_trace("hs_lib_callback_command: "
1519 "LWS_CALLBACK_ESTABLISHED: Leave");
1522 case LWS_CALLBACK_RECEIVE:
1523 uifw_trace("hs_lib_callback_command: "
1524 "LWS_CALLBACK_RECEIVE:(len=%d \"%s\")", len, in);
1525 if (strlen(in) == 0)
1528 msg = hs_lib_alloc_msg((char *)in, len);
1530 uifw_warn("hs_lib_callback_command: ERROR(allocate recv msg)");
1533 msg->type = ICO_HS_PROTOCOL_TYPE_CM;
1534 msg->handle = handle;
1536 hs_lib_put_recvmsg(msg);
1537 uifw_trace("hs_lib_callback_command: "
1538 "LWS_CALLBACK_RECEIVE: Leave");
1541 case LWS_CALLBACK_CLOSED:
1542 uifw_trace("hs_lib_callback_command: "
1543 "LWS_CALLBACK_CLOSED:(wsi=%x)", wsi);
1544 hs_lib_free_handle(handle);
1547 case LWS_CALLBACK_SERVER_WRITEABLE:
1548 uifw_trace("hs_lib_callback_command: "
1549 "LWS_CALLBACK_SERVER_WRITEABLE:(wsi=%x)", wsi);
1550 hs_lib_realsend(hs_lib_get_sendmsg(ICO_HS_PROTOCOL_TYPE_CM));
1553 uifw_trace("HS-REASON %d", reason);
1560 /*--------------------------------------------------------------------------*/
1562 * @brief hs_lib_callback_statusbar
1563 * this callback function is notified from libwebsockets
1564 * statusbar protocol
1566 * @param[in] context libwebsockets context
1567 * @param[in] wsi libwebsockets management table
1568 * @param[in] reason event type
1569 * @param[in] user intact
1570 * @param[in] in receive message
1571 * @param[in] len message size[BYTE]
1573 * @retval =0 success
1576 /*--------------------------------------------------------------------------*/
1578 hs_lib_callback_statusbar(struct libwebsocket_context *context,
1579 struct libwebsocket *wsi,
1580 enum libwebsocket_callback_reasons reason,
1581 void *user, void *in, size_t len)
1584 hs_lib_handle_t *handle;
1585 hs_lib_poll_t *poll;
1588 uifw_trace("hs_lib_callback_statusbar: Enter(ctx=%p, wsi_fd=%d, reason=%d",
1589 context, libwebsocket_get_socket_fd(wsi), reason);
1591 fd = libwebsocket_get_socket_fd(wsi);
1592 if (reason == LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION) {
1593 /* connect from client. the client must exist only one */
1594 uifw_trace("hs_lib_callback_statusbar: "
1595 "LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION(fd=%d)", fd);
1596 handle = hs_handles;
1598 if (handle->fd == fd)
1600 handle = handle->next;
1603 handle = hs_lib_alloc_handle();
1605 uifw_warn("hs_lib_callback_statusbar: ERROR(allocate handle)");
1608 handle->wsi_context = hs_wsicontext;
1611 handle->type = ICO_HS_PROTOCOL_TYPE_SB;
1615 if (poll->fd == handle->fd) {
1616 poll->handle = handle;
1617 handle->poll = poll;
1624 handle = hs_handles;
1626 if (handle->wsi == wsi)
1628 handle = handle->next;
1632 case LWS_CALLBACK_ESTABLISHED:
1633 uifw_trace("hs_lib_callback_statusbar: "
1634 "LWS_CALLBACK_ESTABLISHED(wsi=%x)", wsi);
1635 handle->service_on = 1;
1638 case LWS_CALLBACK_RECEIVE:
1639 uifw_trace("hs_lib_callback_statusbar: "
1640 "LWS_CALLBACK_RECEIVE:(len=%d \"%s\")", len, in);
1642 if (strlen(in) == 0)
1645 msg = hs_lib_alloc_msg((char *)in, len);
1647 uifw_warn("hs_lib_callback_statusbar: ERROR(allocate recv msg)");
1650 msg->type = ICO_HS_PROTOCOL_TYPE_SB;
1651 msg->handle = handle;
1653 hs_lib_put_recvmsg(msg);
1654 uifw_trace("hs_lib_callback_statusbar: "
1655 "LWS_CALLBACK_RECEIVE: Leave");
1658 case LWS_CALLBACK_CLOSED:
1659 uifw_trace("hs_lib_callback_statusbar: "
1660 "LWS_CALLBACK_CLOSED:(wsi=%x)", wsi);
1661 hs_lib_free_handle(handle);
1664 case LWS_CALLBACK_SERVER_WRITEABLE:
1665 uifw_trace("hs_lib_callback_statusbar: "
1666 "LWS_CALLBACK_SERVER_WRITEABLE:(wsi=%x)", wsi);
1667 hs_lib_realsend(hs_lib_get_sendmsg(ICO_HS_PROTOCOL_TYPE_SB));
1670 uifw_trace("HS-REASON %d", reason);
1677 /*--------------------------------------------------------------------------*/
1679 * @brief hs_lib_callback_onscreen
1680 * this callback function is notified from libwebsockets
1681 * statusbar protocol
1683 * @param[in] context libwebsockets context
1684 * @param[in] wsi libwebsockets management table
1685 * @param[in] reason event type
1686 * @param[in] user intact
1687 * @param[in] in receive message
1688 * @param[in] len message size[BYTE]
1690 * @retval =0 success
1693 /*--------------------------------------------------------------------------*/
1695 hs_lib_callback_onscreen(struct libwebsocket_context *context,
1696 struct libwebsocket *wsi,
1697 enum libwebsocket_callback_reasons reason, void *user,
1698 void *in, size_t len)
1701 hs_lib_handle_t *handle;
1702 hs_lib_poll_t *poll;
1705 uifw_trace("hs_lib_callback_onscreen: Enter(ctx=%p, wsi_fd=%d, reason=%d",
1706 context, libwebsocket_get_socket_fd(wsi), reason);
1708 fd = libwebsocket_get_socket_fd(wsi);
1709 if (reason == LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION) {
1710 /* connect from client. the client must exist only one */
1711 uifw_trace("hs_lib_callback_onscreen: "
1712 "LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION(fd=%d)", fd);
1713 handle = hs_handles;
1715 if (handle->fd == fd)
1717 handle = handle->next;
1720 handle = hs_lib_alloc_handle();
1722 uifw_warn("hs_lib_callback_onscreen: ERROR(allocate handle)");
1725 handle->wsi_context = hs_wsicontext;
1728 handle->type = ICO_HS_PROTOCOL_TYPE_OS;
1732 if (poll->fd == handle->fd) {
1733 poll->handle = handle;
1734 handle->poll = poll;
1741 handle = hs_handles;
1743 if (handle->wsi == wsi)
1745 handle = handle->next;
1749 case LWS_CALLBACK_ESTABLISHED:
1750 uifw_trace("hs_lib_callback_onscreen: "
1751 "LWS_CALLBACK_ESTABLISHED(wsi=%x)", wsi);
1752 handle->service_on = 1;
1755 case LWS_CALLBACK_RECEIVE:
1756 uifw_trace("hs_lib_callback_onscreen: "
1757 "LWS_CALLBACK_RECEIVE:(len=%d \"%s\")", len, in);
1759 if (strlen(in) == 0)
1762 msg = hs_lib_alloc_msg((char *)in, len);
1764 uifw_warn("hs_lib_callback_onscreen: ERROR(allocate recv msg)");
1767 msg->type = ICO_HS_PROTOCOL_TYPE_OS;
1768 msg->handle = handle;
1770 hs_lib_put_recvmsg(msg);
1771 uifw_trace("hs_lib_callback_onscreen: "
1772 "LWS_CALLBACK_RECEIVE: Leave");
1775 case LWS_CALLBACK_CLOSED:
1776 uifw_trace("hs_lib_callback_onscreen: "
1777 "LWS_CALLBACK_CLOSED:(wsi=%x)", wsi);
1778 hs_lib_free_handle(handle);
1781 case LWS_CALLBACK_SERVER_WRITEABLE:
1782 uifw_trace("hs_lib_callback_onscreen: "
1783 "LWS_CALLBACK_SERVER_WRITEABLE:(wsi=%x)", wsi);
1784 hs_lib_realsend(hs_lib_get_sendmsg(ICO_HS_PROTOCOL_TYPE_OS));
1789 uifw_trace("hs_lib_callback_onscreen: HS-REASON %d", reason);
1796 /*--------------------------------------------------------------------------*/
1798 * @brief hs_lib_callback_app
1799 * this callback function is notified from libwebsockets
1800 * application protocol
1802 * @param[in] context libwebsockets context
1803 * @param[in] wsi libwebsockets management table
1804 * @param[in] reason event type
1805 * @param[in] user intact
1806 * @param[in] in receive message
1807 * @param[in] len message size[BYTE]
1809 * @retval =0 success
1812 /*--------------------------------------------------------------------------*/
1814 hs_lib_callback_app(struct libwebsocket_context *context,
1815 struct libwebsocket *wsi,
1816 enum libwebsocket_callback_reasons reason, void *user,
1817 void *in, size_t len)
1820 hs_lib_handle_t *handle;
1821 hs_lib_poll_t *poll;
1824 uifw_trace("hs_lib_callback_app: Enter(ctx=%p, wsi_fd=%d, reason=%d",
1825 context, libwebsocket_get_socket_fd(wsi), reason);
1827 fd = libwebsocket_get_socket_fd(wsi);
1828 if (reason == LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION) {
1829 /* connect from client.*/
1830 uifw_trace("hs_lib_callback_app: "
1831 "LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION(fd=%d)", fd);
1832 handle = hs_handles;
1834 if (handle->fd == fd)
1836 handle = handle->next;
1839 handle = hs_lib_alloc_handle();
1841 uifw_warn("hs_lib_callback_app: ERROR(allocate handle)");
1844 handle->wsi_context = hs_wsicontext;
1847 handle->type = ICO_HS_PROTOCOL_TYPE_APP;
1851 if (poll->fd == handle->fd) {
1852 poll->handle = handle;
1853 handle->poll = poll;
1860 handle = hs_handles;
1862 if (handle->wsi == wsi)
1864 handle = handle->next;
1868 case LWS_CALLBACK_ESTABLISHED:
1869 uifw_trace("hs_lib_callback_app: "
1870 "LWS_CALLBACK_ESTABLISHED(wsi=%x)", wsi);
1871 handle->service_on = 1;
1874 case LWS_CALLBACK_RECEIVE:
1875 uifw_trace("hs_lib_callback_app: "
1876 "LWS_CALLBACK_RECEIVE:(len=%d \"%s\")", len, in);
1878 if (strlen(in) == 0)
1881 msg = hs_lib_alloc_msg((char *)in, len);
1883 uifw_warn("hs_lib_callback_app: ERROR(allocate recv msg)");
1886 msg->type = ICO_HS_PROTOCOL_TYPE_APP;
1887 msg->handle = handle;
1889 hs_lib_put_recvmsg(msg);
1890 uifw_trace("hs_lib_callback_app: "
1891 "LWS_CALLBACK_RECEIVE: Leave");
1894 case LWS_CALLBACK_CLOSED:
1895 uifw_trace("hs_lib_callback_app: "
1896 "LWS_CALLBACK_CLOSED:(wsi=%x)", wsi);
1897 hs_lib_free_handle(handle);
1900 case LWS_CALLBACK_SERVER_WRITEABLE:
1901 uifw_trace("hs_lib_callback_app: "
1902 "LWS_CALLBACK_SERVER_WRITEABLE:(wsi=%x)", wsi);
1903 hs_lib_realsend(hs_lib_get_sendmsg(ICO_HS_PROTOCOL_TYPE_APP));
1906 uifw_trace("hs_lib_callback_app: HS-REASON %d", reason);
1913 /*--------------------------------------------------------------------------*/
1915 * @brief hs_lib_main
1916 * initialize homescreen lib to connect statusbar and onscreen,
1917 * external command tools.
1919 * @param[in] port websocket port
1921 * @retval ICO_HS_OK success
1922 * @retval ICO_HS_ERR error
1924 /*--------------------------------------------------------------------------*/
1926 hs_lib_main(int port)
1929 hs_lib_handle_t *handle;
1931 handle = hs_lib_alloc_handle();
1933 = libwebsocket_create_context(ICO_HS_WS_PORT, NULL, protocols,
1934 libwebsocket_internal_extensions,
1935 NULL, NULL, -1, -1, opts);
1936 if (handle->wsi_context == NULL) {
1938 "home_screen_lib_main: ERROR(libwebsocket_create_context failed.)");
1941 hs_wsicontext = handle->wsi_context;