13 #include <netinet/in.h> 14 #include <sys/socket.h> 16 #define RECONNECTDELAY 3000 // ms 22 addr.sun_family = AF_UNIX;
23 strcpy(
addr.sun_path, DeviceName);
40 if ((
f = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0) {
41 if (connect(
f, (
struct sockaddr *)&
addr,
sizeof(
addr)) >= 0)
71 int ret = ready ?
safe_read(
f, buf,
sizeof(buf)) : -1;
73 if (
f < 0 || ready && ret <= 0) {
74 esyslog(
"ERROR: lircd connection broken, trying to reconnect every %.1f seconds",
float(
RECONNECTDELAY) / 1000);
81 isyslog(
"reconnected to lircd");
87 if (ready && ret > 0) {
91 if (sscanf(buf,
"%*x %x %29s", &count, KeyName) != 2) {
92 esyslog(
"ERROR: unparseable lirc command: %s", buf);
101 Put(LastKeyName,
false,
true);
102 strcpy(LastKeyName, KeyName);
115 timeout = Delta * 10 / 9;
119 Put(KeyName, repeat);
122 else if (pressed && repeat) {
123 Put(LastKeyName,
false,
true);
static bool FileReady(int FileDes, int TimeoutMs=1000)
cLircRemote(const char *DeviceName)
virtual void Action(void)
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
static void SleepMs(int TimeoutMs)
Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the...
void bool Start(void)
Sets the description of this thread, which will be used when logging starting or stopping of the thre...
bool Put(uint64_t Code, bool Repeat=false, bool Release=false)
bool Running(void)
Returns false if a derived cThread object shall leave its Action() function.
void Cancel(int WaitSeconds=0)
Cancels the thread by first setting 'running' to false, so that the Action() loop can finish in an or...
uint64_t Elapsed(void) const