1 #ifndef ANVIL_CLIENT_H
2 #define ANVIL_CLIENT_H
3 
4 enum anvil_client_flags {
5 	/* if connect() fails with ENOENT, hide the error */
6 	ANVIL_CLIENT_FLAG_HIDE_ENOENT	= 0x01
7 };
8 
9 /* reply=NULL if query failed */
10 typedef void anvil_callback_t(const char *reply, void *context);
11 
12 /* If reconnect_callback is specified, it's called when connection is lost.
13    If the callback returns FALSE, reconnection isn't attempted. */
14 struct anvil_client *
15 anvil_client_init(const char *path, bool (*reconnect_callback)(void),
16 		  enum anvil_client_flags flags) ATTR_NULL(2);
17 void anvil_client_deinit(struct anvil_client **client);
18 
19 /* Connect to anvil. If retry=TRUE, try connecting for a while */
20 int anvil_client_connect(struct anvil_client *client, bool retry);
21 
22 /* Send a query to anvil, expect a one line reply. The returned pointer can be
23    used to abort the query later. It becomes invalid when callback is
24    called (= the callback must not call it). Returns NULL if the query couldn't
25    be sent. */
26 struct anvil_query *
27 anvil_client_query(struct anvil_client *client, const char *query,
28 		   anvil_callback_t *callback, void *context);
29 void anvil_client_query_abort(struct anvil_client *client,
30 			      struct anvil_query **query);
31 /* Send a command to anvil, don't expect any replies. */
32 void anvil_client_cmd(struct anvil_client *client, const char *cmd);
33 
34 /* Returns TRUE if anvil is connected to. */
35 bool anvil_client_is_connected(struct anvil_client *client);
36 
37 #endif
38