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