remoted initial checkin
[my-code/remoted.git] / remoted.c
1 /* small remote daemon
2
3    reads input from /dev/lircd and will hopefully do something usefull
4    in the future ...
5
6    author: hackbard@hackdaworld.org
7
8    hint: you will need event.{c,h} from my-code repos!
9
10 */
11
12
13 #define _GNU_SOURCE
14 #include <stdio.h>
15 #include <unistd.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <sys/select.h>
19 #include <sys/socket.h>
20 #include <sys/un.h>
21 #include <string.h>
22 #include <fcntl.h>
23
24 #include "event.h"
25
26 #define LIRCD "/dev/lircd"
27
28 typedef struct s_priv {
29         int fd;
30         t_event event;
31 } t_priv;
32
33 int nop(t_event *event,void *ptr) {
34         return 1;
35 }
36
37 int act(t_event *event,void *ptr) {
38
39         t_priv *priv=(t_priv *)ptr;
40         char message[1024];
41         int count;
42         char *button;
43
44         count=read(priv->fd,message,1024);
45         strtok(message," ");
46         strtok(NULL," ");
47         button=strtok(NULL," ");
48         // strtok(NULL," ");
49         dprintf(2,"pressed button: %s (received %d bytes)\n",button,count);
50
51         return 1;
52 }
53
54 int main() {
55
56         t_priv priv;
57         struct sockaddr_un addr;
58         int retval;
59         
60         addr.sun_family=AF_UNIX;
61         strcpy(addr.sun_path,LIRCD);
62         priv.fd=socket(AF_UNIX,SOCK_STREAM,0);
63         retval=connect(priv.fd,(struct sockaddr *)&addr,sizeof(addr));
64         printf("connecting to lircd ... %d\n",retval);
65
66         printf("fd = %d\n",priv.fd);
67         event_init(&(priv.event),2);
68         event_math(priv.fd,&(priv.event),READ,ADD);
69         event_set_timeout(&(priv.event),0,0);
70
71         // event_start(&priv.event,&priv,act,nop);
72         event_start(&priv.event,&priv,act,nop);
73
74         close(priv.fd);
75         return 1;
76 }