1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Now trying to reestablish the connection to the LIRC daemon in case it breaks

This commit is contained in:
Klaus Schmidinger 2006-01-27 16:03:32 +01:00
parent 7398125f31
commit b0678c91ab
4 changed files with 35 additions and 15 deletions

View File

@ -1485,6 +1485,8 @@ Ville Skytt
for adding a missing #include <linux/unistd.h> to thread.c for adding a missing #include <linux/unistd.h> to thread.c
for adding missing i18n entry for the "Timer" button for adding missing i18n entry for the "Timer" button
for removing the obsolete "ca.conf" section from vdr.1 for removing the obsolete "ca.conf" section from vdr.1
for making the cLircRemote try to reestablish the connection to the LIRC daemon
in case it breaks
Steffen Beyer <cpunk@reactor.de> Steffen Beyer <cpunk@reactor.de>
for fixing setting the colored button help after deleting a recording in case the next for fixing setting the colored button help after deleting a recording in case the next

View File

@ -4243,3 +4243,5 @@ Video Disk Recorder Revision History
Mair). Mair).
- Now checking whether the channel exists before setting the PMT filter in - Now checking whether the channel exists before setting the PMT filter in
cPatFilter::Process() (thanks to Thomas Bergwinkl). cPatFilter::Process() (thanks to Thomas Bergwinkl).
- Now trying to reestablish the connection to the LIRC daemon in case it breaks
(thanks to Ville Skyttä).

41
lirc.c
View File

@ -6,35 +6,28 @@
* *
* LIRC support added by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16. * LIRC support added by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16.
* *
* $Id: lirc.c 1.13 2005/09/02 12:51:35 kls Exp $ * $Id: lirc.c 1.14 2006/01/27 15:59:47 kls Exp $
*/ */
#include "lirc.h" #include "lirc.h"
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h>
#define REPEATLIMIT 20 // ms #define REPEATLIMIT 20 // ms
#define REPEATDELAY 350 // ms #define REPEATDELAY 350 // ms
#define KEYPRESSDELAY 150 // ms #define KEYPRESSDELAY 150 // ms
#define RECONNECTDELAY 3000 // ms
cLircRemote::cLircRemote(const char *DeviceName) cLircRemote::cLircRemote(const char *DeviceName)
:cRemote("LIRC") :cRemote("LIRC")
,cThread("LIRC remote control") ,cThread("LIRC remote control")
{ {
struct sockaddr_un addr;
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, DeviceName); strcpy(addr.sun_path, DeviceName);
if ((f = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0) { if (Connect()) {
if (connect(f, (struct sockaddr *)&addr, sizeof(addr)) >= 0) { Start();
Start(); return;
return;
}
LOG_ERROR_STR(DeviceName);
close(f);
} }
else
LOG_ERROR_STR(DeviceName);
f = -1; f = -1;
} }
@ -47,6 +40,20 @@ cLircRemote::~cLircRemote()
close(fh); close(fh);
} }
bool cLircRemote::Connect(void)
{
if ((f = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0) {
if (connect(f, (struct sockaddr *)&addr, sizeof(addr)) >= 0)
return true;
LOG_ERROR_STR(addr.sun_path);
close(f);
f = -1;
}
else
LOG_ERROR_STR(addr.sun_path);
return false;
}
bool cLircRemote::Ready(void) bool cLircRemote::Ready(void)
{ {
return f >= 0; return f >= 0;
@ -67,10 +74,16 @@ void cLircRemote::Action(void)
int ret = ready ? safe_read(f, buf, sizeof(buf)) : -1; int ret = ready ? safe_read(f, buf, sizeof(buf)) : -1;
if (ready && ret <= 0 ) { if (ready && ret <= 0 ) {
esyslog("ERROR: lircd connection lost"); esyslog("ERROR: lircd connection broken, trying to reconnect every %.1f seconds", float(RECONNECTDELAY) / 1000);
close(f); close(f);
f = -1; f = -1;
break; while (Running() && f < 0) {
cCondWait::SleepMs(RECONNECTDELAY);
if (Connect()) {
isyslog("reconnected to lircd");
break;
}
}
} }
if (ready && ret > 21) { if (ready && ret > 21) {

5
lirc.h
View File

@ -4,12 +4,13 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: lirc.h 1.3 2005/07/31 10:18:15 kls Exp $ * $Id: lirc.h 1.4 2006/01/27 16:00:19 kls Exp $
*/ */
#ifndef __LIRC_H #ifndef __LIRC_H
#define __LIRC_H #define __LIRC_H
#include <sys/un.h>
#include "remote.h" #include "remote.h"
#include "thread.h" #include "thread.h"
@ -17,7 +18,9 @@ class cLircRemote : public cRemote, private cThread {
private: private:
enum { LIRC_KEY_BUF = 30, LIRC_BUFFER_SIZE = 128 }; enum { LIRC_KEY_BUF = 30, LIRC_BUFFER_SIZE = 128 };
int f; int f;
struct sockaddr_un addr;
virtual void Action(void); virtual void Action(void);
bool Connect(void);
public: public:
cLircRemote(const char *DeviceName); cLircRemote(const char *DeviceName);
virtual ~cLircRemote(); virtual ~cLircRemote();