/* * Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn . * * Project: IDFetch. * Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine). * Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead). * Mentoring organization: Gentoo Linux. * Sponsored by GSOC 2010. * * This file is part of Segget. * * Segget is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * Segget is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with Segget; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include "tuiclient.h" #include "str.h" Twindow * next_window(){ cur_window_num++; if (cur_window_num>3) cur_window_num=0; switch (cur_window_num){ case 0: mainwindow.log_win.visible=false; mainwindow.error_log_win.visible=false; mainwindow.distfiles_win.visible=false; return &mainwindow; case 1: mainwindow.log_win.visible=true; mainwindow.error_log_win.visible=false; mainwindow.distfiles_win.visible=false; return &mainwindow.log_win; case 2: mainwindow.log_win.visible=false; mainwindow.error_log_win.visible=true; mainwindow.distfiles_win.visible=false; return &mainwindow.error_log_win; case 3: mainwindow.log_win.visible=false; mainwindow.error_log_win.visible=false; mainwindow.distfiles_win.visible=true; return &mainwindow.distfiles_win; } return &mainwindow; } /* void * watch_keyboard_thread_function(void *){ Twindow * cur_window=&mainwindow.distfiles_win; while (not exit_flag){ int key=getch(); if (key==ERR){ mainwindow.refresh(); struct timeval delay; delay.tv_sec=0; delay.tv_usec=300000; select(FD_SETSIZE, (fd_set *)0, (fd_set *)0,(fd_set *)0, (struct timeval *) &delay);//&timeout }else{ switch (key){ //tab - move between windows case (char)9:cur_window=next_window(); //KEY_DOWN case (char)2:cur_window->down(1);mainwindow.set_line(25,toString((int)key));break; //KEY_RIGHT case (char)5:cur_window->down(1);mainwindow.set_line(25,toString((int)key));break; //KEY_UP case (char)3:cur_window->up(1);mainwindow.set_line(25,toString((int)key));break; //KEY_LEFT case (char)4:cur_window->up(1);mainwindow.set_line(25,toString((int)key));break; //KEY_PG_DOWN case (char)82:cur_window->down(mainwindow.bottom_screenline_num);break; //KEY_PG_UP case (char)83:cur_window->up(mainwindow.bottom_screenline_num);break; case 'd': case 'D':mainwindow.distfiles_win.toggle(); mainwindow.log_win.visible=false; mainwindow.error_log_win.visible=false; cur_window=&mainwindow.distfiles_win; mainwindow.show(); break; case 'q': case 'Q':quit(0,"Interrupted by user");break; case 'h': case 'H':mainwindow.help_win.toggle(); mainwindow.show();break; case 'l': case 'L':mainwindow.log_win.toggle(); mainwindow.show();break; case 'e': case 'E':mainwindow.error_log_win.toggle(); mainwindow.show();break; default: mainwindow.set_line(25,toString((int)key)); } } } // pthread_exit((void*)watch_keyboard_thread_status); exit_curses_and_show_msg(); return (void*)0; //watch_keyboard_thread_status; } void * refresh_screen_thread_function(void *){ return (void*)0; } */ void * watch_keyboard_thread_function(void *){ Twindow * cur_window=&mainwindow.distfiles_win; while (not exit_flag){ char key=getch(); switch (key){ //tab - move between windows case (char)9:cur_window=next_window(); //KEY_DOWN case (char)2:cur_window->down(1);break; //KEY_RIGHT case (char)5:cur_window->down(1);break; //KEY_UP case (char)3:cur_window->up(1);break; //KEY_LEFT case (char)4:cur_window->up(1);break; //KEY_PG_DOWN case (char)82:cur_window->down(mainwindow.bottom_screenline_num);break; //KEY_PG_UP case (char)83:cur_window->up(mainwindow.bottom_screenline_num);break; case 'd': case 'D':mainwindow.distfiles_win.toggle(); mainwindow.log_win.visible=false; mainwindow.error_log_win.visible=false; cur_window=&mainwindow.distfiles_win; mainwindow.show(); break; case 'q': case 'Q':quit(0,"Interrupted by user");break; case 'h': case 'H':mainwindow.help_win.toggle(); mainwindow.show();break; case 'l': case 'L':mainwindow.log_win.toggle(); mainwindow.show();break; case 'e': case 'E':mainwindow.error_log_win.toggle(); mainwindow.show();break; // default: mainwindow.set_line(25,toString((int)key)); } } // pthread_exit((void*)watch_keyboard_thread_status); return (void*)watch_keyboard_thread_status; } void * refresh_screen_thread_function(void *){ while (! exit_flag){ mainwindow.refresh(); mainwindow.refresh(); // sleep(1); struct timeval delay; delay.tv_sec=0; delay.tv_usec=300000; select(FD_SETSIZE, (fd_set *)0, (fd_set *)0,(fd_set *)0, (struct timeval *) &delay);//&timeout } exit_curses_and_show_msg(); return 0; } void decode_connection_msg(string msg_body){ Tparts parts=split("",msg_body); int line_num=atoi(parts.before.c_str()); if (line_num<200){ mainwindow.set_line(line_num, parts.after); // set_line(line_num, "||"+toString(line_num)+"||("+first_part.substr(0,first_part.find("")+3)+")"+msg_text); // set_line(line_num, "||"+toString(line_num)+"||("+original_msg); }else{ mainwindow.screen_info_lines[line_num-200]=parts.after; } } /* void decode_downloaded_distfile_msg(string msg_body){ vector parts; parts=split_to_vector(" ", msg_body); if (parts.size()>4){ // if (settings.arg_wait_distfile!=""){ // if (parts[0]==settings.arg_wait_distfile){ // cant_find_distfile_exit_flag==false; // if // } // } for (ulong cur_distfile=0;cur_distfile1){ // debug("cur_wait_distfile"+settings.wait_distfiles_vector[cur_tuiwaited_distfile]); // debug("wait distfiles num="+toString(settings.wait_distfiles_vector.size())); // debug("d0"+settings.wait_distfiles_vector[0]); // debug("d1"+settings.wait_distfiles_vector[1]); settings.wait_distfiles_vector.erase(settings.wait_distfiles_vector.begin()+cur_tuiwaited_distfile,settings.wait_distfiles_vector.begin()+cur_tuiwaited_distfile+1); // debug("wait distfiles num="+toString(settings.wait_distfiles_vector.size())); // debug("d0"+settings.wait_distfiles_vector[0]); }else{ quit(0,"All distfiles have been downloaded"); } } } } } void decode_downloaded_distfile_msg(string msg_body){ vector parts; parts=split_to_vector("<>", msg_body); if (parts.size()>5){ for (ulong cur_distfile=0;cur_distfile9999){ quit(1,"Error in argument --wait-distfile="+settings.arg_wait_distfiles+" : Distfile name is too long"); }; char send_buffer[10000]; string send_msg=""+settings.arg_wait_distfiles+"<.>"; strcpy(send_buffer,send_msg.c_str()); if (write(sockfd, send_buffer, strlen(send_buffer))!=(int)send_msg.length()){ perror("Error in request.cpp: request(): request msg size and sent data size are different."); } fd_set readfds, testfds; FD_ZERO(&readfds); FD_SET(sockfd, &readfds); testfds = readfds; bool run_flag=true; while (run_flag){ //init each time ! // timeout.tv_sec=1; // timeout.tv_usec=0; result = select(FD_SETSIZE, &testfds, (fd_set *)0, (fd_set *)0, (struct timeval *) 0);//&timeout // if fd is set - it's not because of timeout - read data if (FD_ISSET(sockfd, &testfds)){ int nread; ioctl(sockfd, FIONREAD, &nread); if(nread == 0) { close(sockfd); // FD_CLR(sockfd, &readfds); // printf("removing client on fd %d\n", sockfd); run_flag=false; }else { char recv_buffer[BUFFER_SIZE+1]=" "; if (nread!=read(sockfd, recv_buffer, BUFFER_SIZE)){ error_log("Error in tuiclient.cpp : main() read bytes count does NOT match declared count."); }; //recv_msg=recv_msg+recv_buffer; // rest_of_the_msg=rest_of_the_msg+recv_buffer; rest_of_the_msg=recv_buffer; debug("RECEIVED:"+rest_of_the_msg); debug("END============================"); Tparts msg_parts; vector submsgs=split_to_vector("<.>", rest_of_the_msg); for (ulong submsg_num=0; submsg_num before_msg_and_msg=split_to_vector("",submsgs[submsg_num]); debug("Size:"+toString(submsgs.size())); if (before_msg_and_msg.size()>1){ vector msg_type_and_body=split_to_vector("",before_msg_and_msg[1]); if (msg_type_and_body.size()>1){ debug("msg_body="+msg_type_and_body[1]); }else{ debug("No msg_body found"); } if (msg_type_and_body.size()>0){ debug("msg_type="+msg_type_and_body[0]); char msg_type=msg_type_and_body[0][0]; // debug("msg_type="+msg_type_str); switch (msg_type){ case 'c': decode_connection_msg(msg_type_and_body[1]); break; case 'l': decode_log_msg(msg_type_and_body[1]);break; case 'e': decode_error_log_msg(msg_type_and_body[1]);break; case 'd': decode_downloaded_distfile_msg(msg_type_and_body[1]);break; // yes-distfile present in the queue case 'y': break; // continue waiting for catchup info // no distfile in the queue case 'n': quit(1,"Distfile(s): "+settings.arg_wait_distfiles+" is(are) not in the queue - quit"); break; //shouldn't get to this point - but just in case case 'N': quit(0,"Distfile(s): "+settings.arg_wait_distfiles+" is(are) already downloaded - quit"); break; //shouldn't get to this point - but just in case } } } } }; } } close(sockfd); } }catch(...){ // error_log_no_msg("Error in segget.cpp launch_tui_theread() failed"); } }catch(...){ perror("error during init and downloading process"); } while (1){ sleep(10); } quit(0,""); }