/* * Copyright (c) 2003 INRIA - All rights reserved * main authors: Christoph Neumann - christoph.neumann@inrialpes.fr * Vincent Roca - vincent.roca@inrialpes.fr * Julien Laboure - julien.laboure@inrialpes.fr * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ #include "flute.h" #include #include #include static struct termios initial_settings; static void reset_term(void) { tcsetattr(0, TCSANOW, &initial_settings); } static void sig_catcher (int sig) { reset_term(); } void *display(void * arg) { int interval; struct termios new_settings; struct timeval tv; fd_set readfds; unsigned char c; struct sigaction sa; unsigned int highlight=0; unsigned int toi; /* Default update rate is x seconds */ interval = 1; tcgetattr(0, &initial_settings); memcpy(&new_settings, &initial_settings, sizeof(struct termios)); new_settings.c_lflag &= ~(ISIG | ICANON); /* unbuffered input */ /* Turn off echoing */ new_settings.c_lflag &= ~(ECHO | ECHONL); signal (SIGTERM, sig_catcher); sigaction (SIGTERM, (struct sigaction *) 0, &sa); sa.sa_flags |= SA_RESTART; #if defined(FREEBSD) sa.sa_flags &= ~SA_NOCLDSTOP; #else sa.sa_flags &= ~SA_INTERRUPT; #endif sigaction (SIGTERM, &sa, (struct sigaction *) 0); sigaction (SIGINT, &sa, (struct sigaction *) 0); tcsetattr(0, TCSANOW, &new_settings); atexit(reset_term); while(1) { pthread_mutex_lock(&flutemutex); toi=displayFDT(highlight, myfiles); pthread_mutex_unlock(&flutemutex); tv.tv_sec = interval; tv.tv_usec = 0; FD_ZERO (&readfds); FD_SET (0, &readfds); select (1, &readfds, NULL, NULL, &tv); if (FD_ISSET (0, &readfds)) { if (read (0, &c, 1) <= 0) { /* signal */ EXIT(("Keyboard input error\n")); } switch(c) { case 113: EXIT(("Good Bye\n")); /**q**/ case 27: /**arrow pad**/ if (read (0, &c, 1) <= 0) { /* signal */ //pthread_exit((void *)EXIT_FAILURE) EXIT(("Keyboard input error\n")); } if (read (0, &c, 1) <= 0) { /* signal */ //pthread_exit((void *)EXIT_FAILURE) EXIT(("Keyboard input error\n")); } if (c==66) highlight++; if (c==65 && highlight!=0) highlight--; break; case 10: /**ENTER**/ if (mode==SEND || !interactive || toi==0) break; pthread_mutex_lock(&flutemutex); if (FFileFindTOI(toi,myfiles)==NULL) { unsigned int mcl_option = toi; if (mcl_ctl(id, MCL_OPT_FLUTE_DELIVER_THIS_ADU, (void*)&mcl_option, sizeof(mcl_option))) EXIT(("mcl_ctl: MCL_OPT_FLUTE_DELIVER_THIS_ADU failed\n")) myfiles=addTOItoFFile(myfiles,toi); } //else FFileRemoveTOI(toi,&myfiles); /deselection not supported yet pthread_mutex_unlock(&flutemutex); break; } } //sleep(interval); } }