]> git.sur5r.net Git - i3/i3/blob - include/ipc.h
Merge branch 'master' into next
[i3/i3] / include / ipc.h
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * ipc.c: UNIX domain socket IPC (initialization, client handling, protocol).
8  *
9  */
10 #pragma once
11
12 #include <ev.h>
13 #include <stdbool.h>
14 #include <yajl/yajl_gen.h>
15 #include <yajl/yajl_parse.h>
16
17 #include "data.h"
18 #include "tree.h"
19
20 #include "i3/ipc.h"
21
22 extern char *current_socketpath;
23
24 typedef struct ipc_client {
25         int fd;
26
27         /* The events which this client wants to receive */
28         int num_events;
29         char **events;
30
31         TAILQ_ENTRY(ipc_client) clients;
32 } ipc_client;
33
34 /*
35  * Callback type for the different message types.
36  *
37  * message is the raw packet, as received from the UNIX domain socket. size
38  * is the remaining size of bytes for this packet.
39  *
40  * message_size is the size of the message as the sender specified it.
41  * message_type is the type of the message as the sender specified it.
42  *
43  */
44 typedef void(*handler_t)(int, uint8_t*, int, uint32_t, uint32_t);
45
46 /* Macro to declare a callback */
47 #define IPC_HANDLER(name) \
48         static void handle_ ## name (int fd, uint8_t *message, \
49                                      int size, uint32_t message_size, \
50                                      uint32_t message_type)
51
52 /**
53  * Handler for activity on the listening socket, meaning that a new client
54  * has just connected and we should accept() him. Sets up the event handler
55  * for activity on the new connection and inserts the file descriptor into
56  * the list of clients.
57  *
58  */
59 void ipc_new_client(EV_P_ struct ev_io *w, int revents);
60
61 /**
62  * Creates the UNIX domain socket at the given path, sets it to non-blocking
63  * mode, bind()s and listen()s on it.
64  *
65  */
66 int ipc_create_socket(const char *filename);
67
68 /**
69  * Sends the specified event to all IPC clients which are currently connected
70  * and subscribed to this kind of event.
71  *
72  */
73 void ipc_send_event(const char *event, uint32_t message_type, const char *payload);
74
75 /**
76  * Calls shutdown() on each socket and closes it. This function to be called
77  * when exiting or restarting only!
78  *
79  */
80 void ipc_shutdown(void);
81
82 void dump_node(yajl_gen gen, Con *con, bool inplace_restart);