]> git.sur5r.net Git - i3/i3/blob - include/ipc.h
ipc: implement events, cleanup the code a bit
[i3/i3] / include / ipc.h
1 /*
2  * vim:ts=8:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  *
6  * © 2009-2010 Michael Stapelberg and contributors
7  *
8  * See file LICENSE for license information.
9  *
10  */
11
12 #ifndef _IPC_H
13 #define _IPC_H
14
15 #include <ev.h>
16
17 #include "i3/ipc.h"
18
19 typedef struct ipc_client {
20         int fd;
21
22         /* The events which this client wants to receive */
23         int num_events;
24         char **events;
25
26         TAILQ_ENTRY(ipc_client) clients;
27 } ipc_client;
28
29 /*
30  * Callback type for the different message types.
31  *
32  * message is the raw packet, as received from the UNIX domain socket. size
33  * is the remaining size of bytes for this packet.
34  *
35  * message_size is the size of the message as the sender specified it.
36  * message_type is the type of the message as the sender specified it.
37  *
38  */
39 typedef void(*handler_t)(int, uint8_t*, int, uint32_t, uint32_t);
40
41 /* Macro to declare a callback */
42 #define IPC_HANDLER(name) \
43         static void handle_ ## name (int fd, uint8_t *message, \
44                                      int size, uint32_t message_size, \
45                                      uint32_t message_type)
46
47 /**
48  * Handler for activity on the listening socket, meaning that a new client
49  * has just connected and we should accept() him. Sets up the event handler
50  * for activity on the new connection and inserts the file descriptor into
51  * the list of clients.
52  *
53  */
54 void ipc_new_client(EV_P_ struct ev_io *w, int revents);
55
56 /**
57  * Creates the UNIX domain socket at the given path, sets it to non-blocking
58  * mode, bind()s and listen()s on it.
59  *
60  */
61 int ipc_create_socket(const char *filename);
62
63 /**
64  * Sends the specified event to all IPC clients which are currently connected
65  * and subscribed to this kind of event.
66  *
67  */
68 void ipc_send_event(const char *event, uint32_t message_type, const char *payload);
69
70
71 #endif