1 #ifndef IPC_GROUP_H
2 #define IPC_GROUP_H
3 
4 enum ipc_cmd_status {
5 	/* Command received a reply line */
6 	IPC_CMD_STATUS_REPLY,
7 	/* Command finished successfully */
8 	IPC_CMD_STATUS_OK,
9 	/* Command finished with errors */
10 	IPC_CMD_STATUS_ERROR
11 };
12 
13 struct ipc_group {
14 	int listen_fd;
15 	char *name;
16 
17 	/* connections list also acts as a refcount */
18 	struct ipc_connection *connections;
19 };
20 
21 /* line is non-NULL only with IPC_CMD_STATUS_REPLY.
22    Each line begins with the connection ID and TAB. */
23 typedef void ipc_cmd_callback_t(enum ipc_cmd_status status,
24 				const char *line, void *context);
25 
26 struct ipc_group *ipc_group_alloc(int listen_fd);
27 void ipc_group_free(struct ipc_group **group);
28 
29 struct ipc_group *ipc_group_lookup_listen_fd(int listen_fd);
30 struct ipc_group *ipc_group_lookup_name(const char *name);
31 
32 /* Returns 0 if name is ok, -1 if name doesn't match the existing one. */
33 int ipc_group_update_name(struct ipc_group *group, const char *name);
34 
35 /* Send a command to all connections in a group. All connections are expected
36    to answer something. If there are no connections, callback() is called
37    immediately and FALSE is returned. */
38 bool ipc_group_cmd(struct ipc_group *group, const char *cmd,
39 		   ipc_cmd_callback_t *callback, void *context);
40 
41 void ipc_groups_init(void);
42 void ipc_groups_deinit(void);
43 void ipc_groups_disconnect_all(void);
44 
45 #endif
46