4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
8 * Jaewon Lim <jaewon81.lim@samsung.com>
9 * Woojin Jung <woojin2.jung@samsung.com>
10 * Juyoung Kim <j0.kim@samsung.com>
11 * Cherepanov Vitaliy <v.cherepanov@samsung.com>
12 * Nikita Kalyazin <n.kalyazin@samsung.com>
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
18 * http://www.apache.org/licenses/LICENSE-2.0
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
28 * - Samsung RnD Institute Russia
31 #define __STDC_FORMAT_MACROS
33 #include <stdlib.h> // for realpath
34 #include <string.h> // for strtok, strcpy, strncpy
35 #include <limits.h> // for realpath
38 #include <errno.h> // for errno
39 #include <sys/types.h> // for accept, mkdir, opendir, readdir
40 #include <sys/socket.h> // for accept
41 #include <sys/stat.h> // for mkdir
42 #include <sys/eventfd.h> // for eventfd
43 #include <sys/epoll.h> // for epoll apis
44 #include <sys/timerfd.h> // for timerfd
45 #include <unistd.h> // for access, sleep
51 #include <attr/xattr.h> // for fsetxattr
52 #include <sys/smack.h>
55 #include <linux/input.h>
61 #include "da_protocol.h"
64 #include "process_info.h"
66 #define DA_WORK_DIR "/home/developer/sdk_tools/da/"
67 #define DA_READELF_PATH "/home/developer/sdk_tools/da/readelf"
68 #define SCREENSHOT_DIR "/tmp/da"
71 #define MAX_APP_LAUNCH_TIME 60
72 #define MAX_CONNECT_TIMEOUT_TIME 5*60
75 #define MAX_FILENAME 128
77 #define ARRAY_END (-11)
79 input_dev g_key_dev[MAX_DEVICE];
80 input_dev g_touch_dev[MAX_DEVICE];
82 // return bytes size of readed data
83 // return 0 if no data readed or error occurred
84 static int _file_read(FILE* fp, char *buffer, int size)
88 if(fp != NULL && size > 0)
90 ret = fread((void*)buffer, sizeof(char), size, fp);
98 ret = 0; // error case
104 // get input id of given input device
105 static int get_input_id(char* inputname)
107 static int query_cmd_type = 0; // 1 if /lib/udev/input_id, 2 if udevadm
109 char buffer[BUF_SIZE];
110 char command[MAX_FILENAME];
113 // determine input_id query command
114 if(unlikely(query_cmd_type == 0))
116 if(access("/lib/udev/input_id", F_OK) == 0) // there is /lib/udev/input_id
120 else // there is not /lib/udev/input_id
126 // make command string
127 if(query_cmd_type == 1)
129 sprintf(command, "/lib/udev/input_id /class/input/%s", inputname);
133 sprintf(command, "udevadm info --name=input/%s --query=property", inputname);
137 cmd_fp = popen(command, "r");
138 _file_read(cmd_fp, buffer, BUF_SIZE);
140 // determine input id
141 if(strstr(buffer, INPUT_ID_STR_KEY)) // key
145 else if(strstr(buffer, INPUT_ID_STR_TOUCH)) // touch
147 ret = INPUT_ID_TOUCH;
149 else if(strstr(buffer, INPUT_ID_STR_KEYBOARD)) // keyboard
153 else if(strstr(buffer, INPUT_ID_STR_TABLET)) // touch (emulator)
155 ret = INPUT_ID_TOUCH;
163 // get filename and fd of given input type devices
164 static void _get_fds(input_dev *dev, int input_id)
170 dp = opendir("/sys/class/input");
174 while((d = readdir(dp)) != NULL)
176 if(!strncmp(d->d_name, "event", 5)) // start with "event"
179 if(input_id == get_input_id(d->d_name))
181 sprintf(dev[count].fileName, "/dev/input/%s", d->d_name);
182 dev[count].fd = open(dev[count].fileName, O_RDWR | O_NONBLOCK);
190 dev[count].fd = ARRAY_END; // end of input_dev array
194 void _device_write(input_dev *dev, struct input_event* in_ev)
197 for(i = 0; dev[i].fd != ARRAY_END; i++)
201 write(dev[i].fd, in_ev, sizeof(struct input_event));
202 LOGI("write(%d, %d, %d)\n",
203 dev[i].fd, (int)in_ev, sizeof(struct input_event));
208 long long get_total_alloc_size()
211 long long allocsize = 0;
213 for(i = 0; i < MAX_TARGET_COUNT; i++)
215 if(manager.target[i].socket != -1 && manager.target[i].allocmem > 0)
216 allocsize += manager.target[i].allocmem;
221 static int getEmptyTargetSlot()
224 for(i = 0; i < MAX_TARGET_COUNT; i++)
226 if(manager.target[i].socket == -1)
233 static void setEmptyTargetSlot(int index)
235 if(index >= 0 && index < MAX_TARGET_COUNT)
237 manager.target[index].pid = -1;
238 manager.target[index].recv_thread = -1;
239 manager.target[index].allocmem = 0;
240 manager.target[index].starttime = 0;
241 manager.target[index].initial_log = 0;
242 if(manager.target[index].event_fd != -1)
243 close(manager.target[index].event_fd);
244 manager.target[index].event_fd = -1;
245 if(manager.target[index].socket != -1)
246 close(manager.target[index].socket);
247 manager.target[index].socket = -1;
251 // =============================================================================
252 // start and terminate control functions
253 // =============================================================================
255 static int exec_app(const struct app_info_t *app_info)
258 static struct epoll_event ev;
261 switch (app_info->app_type) {
263 kill_app(app_info->exe_path);
264 if (exec_app_tizen(app_info->app_id, app_info->exe_path)) {
265 LOGE("Cannot exec tizen app %s\n", app_info->app_id);
269 case APP_TYPE_RUNNING:
270 // TODO: nothing, it's running
271 LOGI("already started\n");
272 write_process_info(atoi(app_info->app_id), 0);
274 case APP_TYPE_COMMON:
275 kill_app(app_info->exe_path);
276 if (exec_app_common(app_info->exe_path)) {
277 LOGE("Cannot exec common app %s\n", app_info->exe_path);
282 LOGE("Unknown app type %d\n", app_info->app_type);
287 if (res == 0 && app_info->app_type != APP_TYPE_RUNNING) {
288 manager.app_launch_timerfd = timerfd_create(CLOCK_REALTIME, TFD_CLOEXEC);
289 if(manager.app_launch_timerfd > 0)
291 struct itimerspec ctime;
292 ctime.it_value.tv_sec = MAX_APP_LAUNCH_TIME;
293 ctime.it_value.tv_nsec = 0;
294 ctime.it_interval.tv_sec = 0;
295 ctime.it_interval.tv_nsec = 0;
296 if (timerfd_settime(manager.app_launch_timerfd, 0, &ctime, NULL) < 0)
298 LOGE("fail to set app launch timer\n");
299 close(manager.app_launch_timerfd);
300 manager.app_launch_timerfd = -1;
304 // add event fd to epoll list
306 ev.data.fd = manager.app_launch_timerfd;
307 if (epoll_ctl(manager.efd, EPOLL_CTL_ADD,
308 manager.app_launch_timerfd, &ev) < 0)
310 // fail to add event fd
311 LOGE("fail to add app launch timer fd to epoll list\n");
312 close(manager.app_launch_timerfd);
313 manager.app_launch_timerfd = -1;
315 LOGI("application launch time started\n");
319 LOGE("cannot create launch timer\n");
323 LOGI("ret=%d\n", res);
327 int launch_timer_start()
329 static struct epoll_event ev;
332 manager.connect_timeout_timerfd = timerfd_create(CLOCK_REALTIME, TFD_CLOEXEC);
333 if(manager.connect_timeout_timerfd > 0)
335 struct itimerspec ctime;
336 ctime.it_value.tv_sec = MAX_CONNECT_TIMEOUT_TIME;
337 ctime.it_value.tv_nsec = 0;
338 ctime.it_interval.tv_sec = 0;
339 ctime.it_interval.tv_nsec = 0;
340 if (timerfd_settime(manager.connect_timeout_timerfd, 0, &ctime, NULL) < 0)
342 LOGE("fail to set connect timeout timer\n");
343 close(manager.connect_timeout_timerfd);
344 manager.connect_timeout_timerfd = -1;
348 // add event fd to epoll list
350 ev.data.fd = manager.connect_timeout_timerfd;
351 if (epoll_ctl(manager.efd, EPOLL_CTL_ADD,
352 manager.connect_timeout_timerfd, &ev) < 0)
354 // fail to add event fd
355 LOGE("fail to add app connection timeout timer fd to epoll list\n");
356 close(manager.connect_timeout_timerfd);
357 manager.connect_timeout_timerfd = -1;
359 LOGI("connection timeout timer started\n");
363 LOGE("cannot create connection timeout timer\n");
366 LOGI("ret=%d\n", res);
370 static void epoll_add_input_events();
371 static void epoll_del_input_events();
373 int start_profiling()
375 const struct app_info_t *app_info = &prof_session.app_info;
378 // remove previous screen capture files
379 remove_indir(SCREENSHOT_DIR);
380 mkdir(SCREENSHOT_DIR, 0777);
382 smack_lsetlabel(SCREENSHOT_DIR, "*", SMACK_LABEL_ACCESS);
385 if (IS_OPT_SET(FL_CPU | FL_MEMORY)) {
386 if (samplingStart() < 0) {
387 LOGE("Cannot start sampling\n");
393 if (IS_OPT_SET(FL_RECORDING))
394 epoll_add_input_events();
396 if (exec_app(app_info)) {
397 LOGE("Cannot exec app\n");
405 if (IS_OPT_SET(FL_RECORDING))
406 epoll_del_input_events();
407 if (IS_OPT_SET(FL_CPU | FL_MEMORY))
411 LOGI("return %d\n", res);
415 void stop_profiling(void)
417 if (IS_OPT_SET(FL_RECORDING))
418 epoll_del_input_events();
419 if (IS_OPT_SET(FL_CPU | FL_MEMORY))
423 static void reconfigure_recording(struct conf_t conf)
425 uint64_t old_features = prof_session.conf.use_features0;
426 uint64_t new_features = conf.use_features0;
427 uint64_t to_enable = (new_features ^ old_features) & new_features;
428 uint64_t to_disable = (new_features ^ old_features) & old_features;
430 if (IS_OPT_SET_IN(FL_RECORDING, to_disable)) {
431 epoll_del_input_events();
432 prof_session.conf.use_features0 &= ~FL_RECORDING;
435 if (IS_OPT_SET_IN(FL_RECORDING, to_enable)) {
436 epoll_add_input_events();
437 prof_session.conf.use_features0 |= FL_RECORDING;
442 static int reconfigure_cpu_and_memory(struct conf_t conf)
444 uint64_t old_features = prof_session.conf.use_features0;
445 uint64_t new_features = conf.use_features0;
446 uint64_t to_enable = (new_features ^ old_features) & new_features;
447 uint64_t to_disable = (new_features ^ old_features) & old_features;
449 prof_session.conf.system_trace_period = conf.system_trace_period;
451 if (IS_OPT_SET(FL_CPU | FL_MEMORY))
454 if (IS_OPT_SET_IN(FL_CPU | FL_MEMORY, to_disable)) {
455 prof_session.conf.use_features0 &= ~(FL_CPU | FL_MEMORY);
459 if (IS_OPT_SET_IN(FL_CPU | FL_MEMORY, to_enable)) {
460 if (samplingStart() < 0) {
461 LOGE("Cannot start sampling\n");
464 prof_session.conf.use_features0 |= (FL_CPU | FL_MEMORY);
470 int reconfigure(struct conf_t conf)
472 reconfigure_recording(conf);
473 if (reconfigure_cpu_and_memory(conf)) {
474 LOGE("Cannot reconf cpu and memory\n");
481 // just send stop message to all target process
482 static void terminate_all_target()
486 msg_target_t sendlog;
488 sendlog.type = MSG_STOP;
491 for (i = 0; i < MAX_TARGET_COUNT; i++)
493 if(manager.target[i].socket != -1)
495 sendlen = send(manager.target[i].socket, &sendlog,
496 sizeof(sendlog.type) + sizeof(sendlog.length),
500 LOGI("TERMINATE send exit msg (socket %d) "
501 "by terminate_all_target()\n", manager.target[i].socket);
507 // terminate all target and wait for threads
511 terminate_all_target();
513 // wait for all other thread exit
514 for(i = 0; i < MAX_TARGET_COUNT; i++)
516 if(manager.target[i].recv_thread != -1)
518 pthread_join(manager.target[i].recv_thread, NULL);
523 // terminate all profiling by critical error
524 // TODO: don't send data to host
525 static void terminate_error(char* errstr, int send_to_host)
527 LOGE("termination all with err '%s'\n", errstr);
528 struct msg_data_t *msg = NULL;
529 if (send_to_host != 0){
530 msg = gen_message_error(errstr);
535 LOGI("cannot generate error message\n");
541 #define MAX_EVENTS_NUM 10
542 static int deviceEventHandler(input_dev* dev, int input_type)
547 struct input_event in_ev[MAX_EVENTS_NUM];
548 struct msg_data_t *log;
550 if(input_type == INPUT_ID_TOUCH || input_type == INPUT_ID_KEY)
553 size = read(dev->fd, &in_ev[count], sizeof(*in_ev) );
556 } while (count < MAX_EVENTS_NUM && size > 0);
559 LOGI("read %d %s events\n",
561 input_type == INPUT_ID_KEY ? STR_KEY : STR_TOUCH);
562 log = gen_message_event(in_ev, count, input_type);
563 printBuf((char *)log, MSG_DATA_HDR_LEN + log->len);
570 LOGW("unknown input_type\n");
571 ret = 1; // it is not error
576 // return 0 if normal case
577 // return plus value if non critical error occur
578 // return minus value if critical error occur
579 // return -11 if all target process closed
580 static int targetEventHandler(int epollfd, int index, uint64_t msg)
584 if (index == 0) { // main application
586 if ( is_same_app_process(prof_session.app_info.exe_path,
587 manager.target[index].pid) == 0 ) {
588 LOGE("is same error: '%s' is not %d\n",
589 prof_session.app_info.exe_path,
590 manager.target[index].pid);
594 if (start_replay() != 0) {
595 LOGE("Cannot start replay thread\n");
599 manager.target[index].initial_log = 1;
602 if(msg & EVENT_STOP || msg & EVENT_ERROR)
604 LOGI("target close, socket(%d), pid(%d) : (remaining %d target)\n",
605 manager.target[index].socket,
606 manager.target[index].pid,
607 manager.target_count - 1);
608 if (index == 0) { // main application
611 epoll_ctl(epollfd, EPOLL_CTL_DEL, manager.target[index].event_fd, NULL);
612 setEmptyTargetSlot(index);
613 // all target client are closed
614 if (0 == __sync_sub_and_fetch(&manager.target_count, 1))
621 // return 0 if normal case
622 // return plus value if non critical error occur
623 // return minus value if critical error occur
624 static int targetServerHandler(int efd)
627 struct epoll_event ev;
629 int index = getEmptyTargetSlot();
630 if(index == MAX_TARGET_COUNT)
632 LOGW("Max target number(8) reached, no more target can connected\n");
636 manager.target[index].socket =
637 accept(manager.target_server_socket, NULL, NULL);
639 if(manager.target[index].socket >= 0) // accept succeed
642 // set smack attribute for certification
643 fsetxattr(manager.target[index].socket, "security.SMACK64IPIN", "*", 1, 0);
644 fsetxattr(manager.target[index].socket, "security.SMACK64IPOUT", "*", 1, 0);
645 #endif /* LOCALTEST */
647 // send config message to target process
648 log.type = MSG_OPTION;
649 log.length = sprintf(log.data, "%lu",
650 (unsigned long int) prof_session.conf.use_features0);
651 send(manager.target[index].socket, &log,
652 sizeof(log.type) + sizeof(log.length) + log.length,
656 manager.target[index].event_fd = eventfd(0, EFD_NONBLOCK);
657 if(manager.target[index].event_fd == -1)
659 // fail to make event fd
660 LOGE("fail to make event fd for socket (%d)\n",
661 manager.target[index].socket);
662 goto TARGET_CONNECT_FAIL;
665 // add event fd to epoll list
667 ev.data.fd = manager.target[index].event_fd;
668 if(epoll_ctl(efd, EPOLL_CTL_ADD, manager.target[index].event_fd, &ev) < 0)
670 // fail to add event fd
671 LOGE("fail to add event fd to epoll list for socket (%d)\n",
672 manager.target[index].socket);
673 goto TARGET_CONNECT_FAIL;
676 // make recv thread for target
677 if(makeRecvThread(index) != 0)
679 // fail to make recv thread
680 LOGE("fail to make recv thread for socket (%d)\n",
681 manager.target[index].socket);
682 epoll_ctl(efd, EPOLL_CTL_DEL, manager.target[index].event_fd, NULL);
683 goto TARGET_CONNECT_FAIL;
686 if(manager.app_launch_timerfd >= 0)
688 LOGI("release launch timer\n");
689 epoll_ctl(efd, EPOLL_CTL_DEL, manager.app_launch_timerfd, NULL);
690 close(manager.app_launch_timerfd);
691 manager.app_launch_timerfd = -1;
694 LOGI("target connected = %d(running %d target)\n",
695 manager.target[index].socket, manager.target_count + 1);
697 manager.target_count++;
702 LOGE("Failed to accept at target server socket\n");
706 if(manager.target_count == 0) // if this connection is main connection
712 // if this connection is not main connection then ignore process by error
713 setEmptyTargetSlot(index);
718 // return 0 if normal case
719 // return plus value if non critical error occur
720 // return minus value if critical error occur
721 static int hostServerHandler(int efd)
723 static int hostserverorder = 0;
725 struct epoll_event ev;
727 if(hostserverorder > 1) // control and data socket connected already
730 csocket = accept(manager.host_server_socket, NULL, NULL);
732 if(csocket >= 0) // accept succeed
735 ev.data.fd = csocket;
736 if(epoll_ctl(efd, EPOLL_CTL_ADD, csocket, &ev) < 0)
738 // consider as accept fail
739 LOGE("Failed to add socket fd to epoll list\n");
744 if(hostserverorder == 0)
746 manager.host.control_socket = csocket;
748 LOGI("host control socket connected = %d\n", csocket);
752 manager.host.data_socket = csocket;
753 LOGI("host data socket connected = %d\n", csocket);
761 LOGE("Failed to accept from host server socket\n");
767 // return 0 if normal case
768 // return plus value if non critical error occur
769 // return minus value if critical error occur
770 // return -11 if socket closed
772 static int controlSocketHandler(int efd)
775 struct msg_t msg_head;
779 if(manager.connect_timeout_timerfd >= 0)
781 LOGI("release connect timeout timer\n");
782 epoll_ctl(efd, EPOLL_CTL_DEL, manager.connect_timeout_timerfd, NULL);
783 close(manager.connect_timeout_timerfd);
784 manager.connect_timeout_timerfd = -1;
788 recv_len = recv(manager.host.control_socket,
791 // error or close request from host
792 if (recv_len == -1 || recv_len == 0)
795 msg = malloc(MSG_CMD_HDR_LEN + msg_head.len);
797 LOGE("Cannot alloc msg\n");
798 sendACKToHost(msg_head.id, ERR_WRONG_MESSAGE_FORMAT, 0, 0);
801 msg->id = msg_head.id;
802 msg->len = msg_head.len;
804 // Receive payload (if exists)
805 recv_len = recv(manager.host.control_socket,
807 msg->len, MSG_WAITALL);
811 res = host_message_handler(msg);
818 static void epoll_add_input_events()
820 struct epoll_event ev;
823 // add device fds to epoll event pool
825 for (i = 0; g_key_dev[i].fd != ARRAY_END; i++) {
826 if (g_key_dev[i].fd >= 0) {
827 ev.data.fd = g_key_dev[i].fd;
828 if (epoll_ctl(manager.efd,
830 g_key_dev[i].fd, &ev) < 0)
831 LOGE("keyboard device file epoll_ctl error\n");
836 for (i = 0; g_touch_dev[i].fd != ARRAY_END; i++) {
837 if (g_touch_dev[i].fd >= 0) {
838 ev.data.fd = g_touch_dev[i].fd;
839 if (epoll_ctl(manager.efd,
841 g_touch_dev[i].fd, &ev) < 0)
842 LOGE("touch device file epoll_ctl error\n");
847 static void epoll_del_input_events()
851 // remove device fds from epoll event pool
852 for (i = 0; g_key_dev[i].fd != ARRAY_END; i++)
853 if (g_key_dev[i].fd >= 0)
854 if (epoll_ctl(manager.efd,
856 g_key_dev[i].fd, NULL) < 0)
857 LOGE("keyboard device file epoll_ctl error\n");
859 for (i = 0; g_touch_dev[i].fd != ARRAY_END; i++)
860 if (g_touch_dev[i].fd >= 0)
861 if (epoll_ctl(manager.efd,
863 g_touch_dev[i].fd, NULL) < 0)
864 LOGE("touch device file epoll_ctl error\n");
866 static bool initialize_epoll_events(void)
868 struct epoll_event ev;
870 if ((manager.efd = epoll_create1(0)) < 0) {
871 LOGE("epoll creation error\n");
875 // add server sockets to epoll event pool
877 ev.data.fd = manager.host_server_socket;
878 if (epoll_ctl(manager.efd, EPOLL_CTL_ADD,
879 manager.host_server_socket, &ev) < 0)
881 LOGE("Host server socket epoll_ctl error\n");
885 ev.data.fd = manager.target_server_socket;
886 if (epoll_ctl(manager.efd, EPOLL_CTL_ADD,
887 manager.target_server_socket, &ev) < 0)
889 LOGE("Target server socket epoll_ctl error\n");
895 // return 0 for normal case
898 int return_value = 0;
899 struct epoll_event *events = malloc(EPOLL_SIZE * sizeof(*events));
901 _get_fds(g_key_dev, INPUT_ID_KEY);
902 _get_fds(g_touch_dev, INPUT_ID_TOUCH);
905 LOGE("Out of memory when allocate epoll event pool\n");
909 if (!initialize_epoll_events()) {
914 if (launch_timer_start() < 0) {
915 LOGE("Launch timer start failed\n");
923 // number of occured events
924 int numevent = epoll_wait(manager.efd, events, EPOLL_SIZE, -1);
926 LOGE("Failed to epoll_wait : num of event(%d), errno(%d)\n", numevent, errno);
930 for(i = 0; i < numevent; i++)
932 // check for request from event fd
933 for(k = 0; k < MAX_TARGET_COUNT; k++)
935 if(manager.target[k].socket != -1 &&
936 events[i].data.fd == manager.target[k].event_fd)
939 recvLen = read(manager.target[k].event_fd, &u, sizeof(uint64_t));
940 if(recvLen != sizeof(uint64_t))
942 // maybe closed, but ignoring is more safe then
943 // removing fd from epoll list
947 if(-11 == targetEventHandler(manager.efd, k, u))
949 LOGI("all target process is closed\n");
957 if(k != MAX_TARGET_COUNT)
960 // check for request from device fd
961 for(k = 0; g_touch_dev[k].fd != ARRAY_END; k++)
963 if(g_touch_dev[k].fd >= 0 &&
964 events[i].data.fd == g_touch_dev[k].fd)
966 if(deviceEventHandler(&g_touch_dev[k], INPUT_ID_TOUCH) < 0)
968 LOGE("Internal DA framework error, "
969 "Please re-run the profiling (touch dev)\n");
976 if(g_touch_dev[k].fd != ARRAY_END)
979 for(k = 0; g_key_dev[k].fd != ARRAY_END; k++)
981 if(g_key_dev[k].fd >= 0 &&
982 events[i].data.fd == g_key_dev[k].fd)
984 if(deviceEventHandler(&g_key_dev[k], INPUT_ID_KEY) < 0)
986 LOGE("Internal DA framework error, "
987 "Please re-run the profiling (key dev)\n");
994 if(g_key_dev[k].fd != ARRAY_END)
997 // connect request from target
998 if (events[i].data.fd == manager.target_server_socket)
1000 if (targetServerHandler(manager.efd) < 0) // critical error
1002 terminate_error("Internal DA framework error, "
1003 "Please re-run the profiling (targetServerHandler)\n", 1);
1007 // connect request from host
1008 else if (events[i].data.fd == manager.host_server_socket)
1010 int result = hostServerHandler(manager.efd);
1013 LOGE("Internal DA framework error (hostServerHandler)\n");
1017 // control message from host
1018 else if (events[i].data.fd == manager.host.control_socket)
1020 int result = controlSocketHandler(manager.efd);
1021 if (result == -11) // socket close
1023 //if the host disconnected.
1024 //In all other cases daemon must report an error and continue the loop
1025 //close connect_timeoutt and host socket and quit
1026 LOGI("Connection closed. Termination. (%d)\n",
1027 manager.host.control_socket);
1031 else if (result < 0)
1033 terminate_error("Internal DA framework error, "
1034 "Please re-run the profiling.", 1);
1039 else if (events[i].data.fd == manager.host.data_socket)
1042 recvLen = recv(manager.host.data_socket, recvBuf, 32, MSG_DONTWAIT);
1044 { // close data socket
1045 epoll_ctl(manager.efd, EPOLL_CTL_DEL,
1046 manager.host.data_socket,
1048 close(manager.host.data_socket);
1049 manager.host.data_socket = -1;
1050 // TODO: finish transfer thread
1053 LOGI("host message from data socket %d\n", recvLen);
1055 // check for application launch timerfd
1056 else if (events[i].data.fd == manager.app_launch_timerfd)
1058 // send to host timeout error message for launching application
1059 epoll_ctl(manager.efd, EPOLL_CTL_DEL,
1060 manager.app_launch_timerfd, NULL);
1061 close(manager.app_launch_timerfd);
1062 manager.app_launch_timerfd = -1;
1063 LOGE("Failed to launch application\n");
1066 // check for connection timeout timerfd
1067 else if (events[i].data.fd == manager.connect_timeout_timerfd)
1069 // send to host timeout error message for launching application
1070 terminate_error("no incoming connections", 1);
1071 epoll_ctl(manager.efd, EPOLL_CTL_DEL,
1072 manager.connect_timeout_timerfd, NULL);
1073 close(manager.connect_timeout_timerfd);
1074 manager.connect_timeout_timerfd = -1;
1075 LOGE("No connection in %d sec. shutdown.\n",MAX_CONNECT_TIMEOUT_TIME);
1082 LOGW("Unknown socket fd (%d)\n", events[i].data.fd);
1088 LOGI("close efd\n");
1092 return return_value;