remoted initial checkin master origin
authorhackbard <hackbard>
Tue, 17 May 2005 14:08:56 +0000 (14:08 +0000)
committerhackbard <hackbard>
Tue, 17 May 2005 14:08:56 +0000 (14:08 +0000)
remoted.c [new file with mode: 0644]

diff --git a/remoted.c b/remoted.c
new file mode 100644 (file)
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 <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <string.h>
+#include <fcntl.h>
+
+#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;
+}