diff options
| author | phintuka <phintuka> | 2009-10-31 20:26:00 +0000 |
|---|---|---|
| committer | phintuka <phintuka> | 2009-10-31 20:26:00 +0000 |
| commit | a36815251ee39b044e5e09826b70866e4d24ac02 (patch) | |
| tree | cf3cbd6cd984f6ef070d86982cb96311fcd44839 | |
| parent | 75977419bf46beff6a89361aafa434f4363fd57f (diff) | |
| download | xineliboutput-a36815251ee39b044e5e09826b70866e4d24ac02.tar.gz xineliboutput-a36815251ee39b044e5e09826b70866e4d24ac02.tar.bz2 | |
Cosmetics
| -rw-r--r-- | xine_frontend_lirc.c | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/xine_frontend_lirc.c b/xine_frontend_lirc.c index 9b08da83..93b0fa06 100644 --- a/xine_frontend_lirc.c +++ b/xine_frontend_lirc.c @@ -4,12 +4,12 @@ * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * - * $Id: xine_frontend_lirc.c,v 1.21 2008-11-19 18:55:20 rofafor Exp $ + * $Id: xine_frontend_lirc.c,v 1.22 2009-10-31 20:26:00 phintuka Exp $ * */ /* * - * Almost directly copied from vdr-1.4.3-2 (lirc.c : cLircRemote) + * Almost directly copied from vdr-1.4.3-2 (lirc.c : cLircRemote) * */ /* @@ -45,7 +45,7 @@ #define RECONNECTDELAY 3000 /* ms */ #define LIRC_KEY_BUF 30 -#define LIRC_BUFFER_SIZE 128 +#define LIRC_BUFFER_SIZE 128 #define MIN_LIRCD_CMD_LEN 5 /* static data */ @@ -74,12 +74,12 @@ static void lircd_connect(void) { struct sockaddr_un addr; - if(fd_lirc >= 0) { + if (fd_lirc >= 0) { close(fd_lirc); fd_lirc = -1; } - if(!lirc_device_name) { + if (!lirc_device_name) { LOGDBG("no lirc device given"); return; } @@ -104,23 +104,23 @@ static void lircd_connect(void) static void *lirc_receiver_thread(void *fe_gen) { frontend_t *fe = (frontend_t*)fe_gen; - int timeout = -1; + const int priority = -1; + int timeout = -1; + int repeat = 0; uint64_t FirstTime = time_ms(); uint64_t LastTime = time_ms(); - char buf[LIRC_BUFFER_SIZE]; - char LastKeyName[LIRC_KEY_BUF] = ""; - int repeat = 0; + char buf[LIRC_BUFFER_SIZE]; + char LastKeyName[LIRC_KEY_BUF] = ""; LOGMSG("lirc forwarding started"); - const int priority = -1; errno = 0; - if((nice(priority) == -1) && errno) + if ((nice(priority) == -1) && errno) LOGDBG("LIRC: Can't nice to value: %d", priority); lircd_connect(); - while(lirc_device_name && fd_lirc >= 0) { + while (lirc_device_name && fd_lirc >= 0) { fd_set set; int ready, ret = -1; FD_ZERO(&set); @@ -137,114 +137,114 @@ static void *lirc_receiver_thread(void *fe_gen) } pthread_testcancel(); - if(ready < 0) { + if (ready < 0) { LOGMSG("LIRC connection lost ?"); break; } - - if(ready) { - do { - errno = 0; - ret = read(fd_lirc, buf, sizeof(buf)); - pthread_testcancel(); - } while(ret < 0 && errno == EINTR); + if (ready) { + + do { + errno = 0; + ret = read(fd_lirc, buf, sizeof(buf)); + pthread_testcancel(); + } while (ret < 0 && errno == EINTR); if (ret <= 0 ) { - /* try reconnecting */ - LOGERR("LIRC connection lost"); - lircd_connect(); - while(lirc_device_name && fd_lirc < 0) { - pthread_testcancel(); - sleep(RECONNECTDELAY/1000); - lircd_connect(); - } - if(fd_lirc >= 0) - LOGMSG("LIRC reconnected"); + /* try reconnecting */ + LOGERR("LIRC connection lost"); + lircd_connect(); + while (lirc_device_name && fd_lirc < 0) { + pthread_testcancel(); + sleep(RECONNECTDELAY/1000); + lircd_connect(); + } + if (fd_lirc >= 0) + LOGMSG("LIRC reconnected"); continue; } if (ret >= MIN_LIRCD_CMD_LEN) { unsigned int count; - char KeyName[LIRC_KEY_BUF]; - LOGDBG("LIRC: %s", buf); + char KeyName[LIRC_KEY_BUF]; + LOGDBG("LIRC: %s", buf); - if (sscanf(buf, "%*x %x %29s", &count, KeyName) != 2) { - /* '29' in '%29s' is LIRC_KEY_BUF-1! */ - LOGMSG("unparseable lirc command: %s", buf); - continue; - } + if (sscanf(buf, "%*x %x %29s", &count, KeyName) != 2) { + /* '29' in '%29s' is LIRC_KEY_BUF-1! */ + LOGMSG("unparseable lirc command: %s", buf); + continue; + } - if(lirc_repeat_emu) + if (lirc_repeat_emu) if (strcmp(KeyName, LastKeyName) == 0 && elapsed(LastTime) < REPEATDELAY) - count = repeat + 1; + count = repeat + 1; if (count == 0) { - if (strcmp(KeyName, LastKeyName) == 0 && elapsed(FirstTime) < REPEATDELAY) - continue; /* skip keys coming in too fast */ - if (repeat) { - alarm(3); - fe->send_input_event(fe, "LIRC", LastKeyName, 0, 1); - alarm(0); - } - - strcpy(LastKeyName, KeyName); - repeat = 0; - FirstTime = time_ms(); - timeout = -1; - } - else { - if (elapsed(LastTime) < REPEATFREQ) - continue; /* repeat function kicks in after a short delay */ - - if (elapsed(FirstTime) < REPEATDELAY) { - if(lirc_repeat_emu) - LastTime = time_ms(); - continue; /* skip keys coming in too fast */ - } - repeat = 1; - timeout = REPEATDELAY; - } - LastTime = time_ms(); - - if (gui_hotkeys) { - if(!strcmp(KeyName, "Quit")) { - fe->send_event(fe, "QUIT"); - break; - } - if(!strcmp(KeyName, "Fullscreen")) { - if(!repeat) - fe->send_event(fe, "TOGGLE_FULLSCREEN"); - continue; - } - if(!strcmp(KeyName, "Deinterlace")) { - if(!repeat) - fe->send_event(fe, "TOGGLE_DEINTERLACE"); - continue; - } + if (strcmp(KeyName, LastKeyName) == 0 && elapsed(FirstTime) < REPEATDELAY) + continue; /* skip keys coming in too fast */ + if (repeat) { + alarm(3); + fe->send_input_event(fe, "LIRC", LastKeyName, 0, 1); + alarm(0); + } + + strcpy(LastKeyName, KeyName); + repeat = 0; + FirstTime = time_ms(); + timeout = -1; + } + else { + if (elapsed(LastTime) < REPEATFREQ) + continue; /* repeat function kicks in after a short delay */ + + if (elapsed(FirstTime) < REPEATDELAY) { + if (lirc_repeat_emu) + LastTime = time_ms(); + continue; /* skip keys coming in too fast */ + } + repeat = 1; + timeout = REPEATDELAY; + } + LastTime = time_ms(); + + if (gui_hotkeys) { + if (!strcmp(KeyName, "Quit")) { + fe->send_event(fe, "QUIT"); + break; + } + if (!strcmp(KeyName, "Fullscreen")) { + if (!repeat) + fe->send_event(fe, "TOGGLE_FULLSCREEN"); + continue; + } + if (!strcmp(KeyName, "Deinterlace")) { + if (!repeat) + fe->send_event(fe, "TOGGLE_DEINTERLACE"); + continue; + } } - alarm(3); - fe->send_input_event(fe, "LIRC", KeyName, repeat, 0); - alarm(0); + alarm(3); + fe->send_input_event(fe, "LIRC", KeyName, repeat, 0); + alarm(0); } else if (repeat) { /* the last one was a repeat, so let's generate a release */ - if (elapsed(LastTime) >= REPEATTIMEOUT) { - alarm(3); - fe->send_input_event(fe, "LIRC", LastKeyName, 0, 1); - alarm(0); - repeat = 0; - *LastKeyName = 0; - timeout = -1; - } + if (elapsed(LastTime) >= REPEATTIMEOUT) { + alarm(3); + fe->send_input_event(fe, "LIRC", LastKeyName, 0, 1); + alarm(0); + repeat = 0; + *LastKeyName = 0; + timeout = -1; + } } } } - if(fd_lirc >= 0) + if (fd_lirc >= 0) close(fd_lirc); fd_lirc = -1; pthread_exit(NULL); @@ -253,26 +253,26 @@ static void *lirc_receiver_thread(void *fe_gen) void lirc_start(struct frontend_s *fe, char *lirc_dev, int repeat_emu) { - if(lirc_dev) { + if (lirc_dev) { int err; lirc_device_name = lirc_dev; lirc_repeat_emu = repeat_emu; if ((err = pthread_create (&lirc_thread, - NULL, lirc_receiver_thread, - (void*)fe)) != 0) { - fprintf(stderr, "can't create new thread for lirc (%s)\n", - strerror(err)); + NULL, lirc_receiver_thread, + (void*)fe)) != 0) { + fprintf(stderr, "can't create new thread for lirc (%s)\n", + strerror(err)); } } } void lirc_stop(void) { - if(lirc_device_name) { + if (lirc_device_name) { void *p; - /*free(lirc_device_name);*/ + /*free(lirc_device_name);*/ lirc_device_name = NULL; - if(fd_lirc >= 0) + if (fd_lirc >= 0) close(fd_lirc); fd_lirc = -1; pthread_cancel (lirc_thread); |
