From 24570659e607b7e40bd21cd23e9563c2bd65ba30 Mon Sep 17 00:00:00 2001 From: hackbard Date: Tue, 17 May 2005 14:08:56 +0000 Subject: [PATCH 1/1] remoted initial checkin --- remoted.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 remoted.c diff --git a/remoted.c b/remoted.c new file mode 100644 index 0000000..834527b --- /dev/null +++ b/remoted.c @@ -0,0 +1,76 @@ +/* small remote daemon + + reads input from /dev/lircd and will hopefully do something usefull + in the future ... + + author: hackbard@hackdaworld.org + + hint: you will need event.{c,h} from my-code repos! + +*/ + + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "event.h" + +#define LIRCD "/dev/lircd" + +typedef struct s_priv { + int fd; + t_event event; +} t_priv; + +int nop(t_event *event,void *ptr) { + return 1; +} + +int act(t_event *event,void *ptr) { + + t_priv *priv=(t_priv *)ptr; + char message[1024]; + int count; + char *button; + + count=read(priv->fd,message,1024); + strtok(message," "); + strtok(NULL," "); + button=strtok(NULL," "); + // strtok(NULL," "); + dprintf(2,"pressed button: %s (received %d bytes)\n",button,count); + + return 1; +} + +int main() { + + t_priv priv; + struct sockaddr_un addr; + int retval; + + addr.sun_family=AF_UNIX; + strcpy(addr.sun_path,LIRCD); + priv.fd=socket(AF_UNIX,SOCK_STREAM,0); + retval=connect(priv.fd,(struct sockaddr *)&addr,sizeof(addr)); + printf("connecting to lircd ... %d\n",retval); + + printf("fd = %d\n",priv.fd); + event_init(&(priv.event),2); + event_math(priv.fd,&(priv.event),READ,ADD); + event_set_timeout(&(priv.event),0,0); + + // event_start(&priv.event,&priv,act,nop); + event_start(&priv.event,&priv,act,nop); + + close(priv.fd); + return 1; +} -- 2.39.2