Commit | Line | Data |
---|---|---|
c39c72ee PMF |
1 | /* Copyright (C) 2009 Pierre-Marc Fournier |
2 | * | |
3 | * This library is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the GNU Lesser General Public | |
5 | * License as published by the Free Software Foundation; either | |
6 | * version 2.1 of the License, or (at your option) any later version. | |
7 | * | |
8 | * This library is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 | * Lesser General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU Lesser General Public | |
14 | * License along with this library; if not, write to the Free Software | |
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
16 | */ | |
17 | ||
f9e5ce61 PMF |
18 | #ifndef USTCOMM_H |
19 | #define USTCOMM_H | |
20 | ||
21 | #include <sys/types.h> | |
b02e31e5 | 22 | #include <sys/un.h> |
f9e5ce61 | 23 | |
aca1ad90 | 24 | #include "kcompat.h" |
0e4b45ac | 25 | #include "multipoll.h" |
aca1ad90 | 26 | |
397d8454 | 27 | #define SOCK_DIR "/tmp/ust-app-socks" |
ab33e65c PP |
28 | #define UST_SIGNAL SIGIO |
29 | ||
aca1ad90 PMF |
30 | struct ustcomm_connection { |
31 | struct list_head list; | |
32 | int fd; | |
5932431b PMF |
33 | /* Data that has not yet been consumed: */ |
34 | char *recv_buf; | |
35 | int recv_buf_size; | |
36 | int recv_buf_alloc; | |
aca1ad90 PMF |
37 | }; |
38 | ||
3a7b90de | 39 | /* ustcomm_server must be shallow-copyable */ |
811e4b93 | 40 | struct ustcomm_server { |
b0540e11 | 41 | /* the "server" socket for serving the external requests */ |
aca1ad90 | 42 | int listen_fd; |
d0b5f2b9 | 43 | char *socketpath; |
aca1ad90 PMF |
44 | |
45 | struct list_head connections; | |
d0b5f2b9 PMF |
46 | }; |
47 | ||
48 | struct ustcomm_ustd { | |
811e4b93 PMF |
49 | struct ustcomm_server server; |
50 | }; | |
aca1ad90 | 51 | |
811e4b93 PMF |
52 | struct ustcomm_app { |
53 | struct ustcomm_server server; | |
d0b5f2b9 PMF |
54 | }; |
55 | ||
3a7b90de | 56 | /* ustcomm_source must be shallow-copyable */ |
b02e31e5 | 57 | struct ustcomm_source { |
811e4b93 PMF |
58 | int fd; |
59 | void *priv; | |
b02e31e5 PMF |
60 | }; |
61 | ||
0e4b45ac PMF |
62 | struct ustcomm_multipoll_conn_info { |
63 | struct ustcomm_connection *conn; | |
64 | int (*cb)(char *msg, struct ustcomm_source *src); | |
65 | }; | |
66 | ||
08230db7 | 67 | extern char *strdup_malloc(const char *s); |
688760ef | 68 | |
3bb56863 | 69 | //int send_message_pid(pid_t pid, const char *msg, char **reply); |
08230db7 | 70 | extern int ustcomm_request_consumer(pid_t pid, const char *channel); |
d0b5f2b9 | 71 | |
08230db7 PMF |
72 | extern int ustcomm_ustd_recv_message(struct ustcomm_ustd *ustd, char **msg, struct ustcomm_source *src, int timeout); |
73 | extern int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg, struct ustcomm_source *src, int timeout); | |
3847c3ba | 74 | |
08230db7 | 75 | extern int ustcomm_init_app(pid_t pid, struct ustcomm_app *handle); |
2a79ceeb | 76 | extern void ustcomm_fini_app(struct ustcomm_app *handle, int keep_socket_file); |
f3b9955d | 77 | extern void ustcomm_fini_ustd(struct ustcomm_ustd *handle); |
d0b5f2b9 | 78 | |
c97d4437 | 79 | extern int ustcomm_init_ustd(struct ustcomm_ustd *handle, const char *sock_path); |
f9e5ce61 | 80 | |
08230db7 | 81 | extern int ustcomm_connect_app(pid_t pid, struct ustcomm_connection *conn); |
2a79ceeb | 82 | extern int ustcomm_close_app(struct ustcomm_connection *conn); |
08230db7 PMF |
83 | extern int ustcomm_connect_path(const char *path, struct ustcomm_connection *conn, pid_t signalpid); |
84 | extern int ustcomm_send_request(struct ustcomm_connection *conn, const char *req, char **reply); | |
85 | extern int ustcomm_send_reply(struct ustcomm_server *server, char *msg, struct ustcomm_source *src); | |
86 | extern int ustcomm_disconnect(struct ustcomm_connection *conn); | |
99b72dc0 | 87 | extern int ustcomm_close_all_connections(struct ustcomm_server *server); |
0e4b45ac | 88 | extern void ustcomm_mp_add_app_clients(struct mpentries *ent, struct ustcomm_app *app, int (*cb)(struct ustcomm_connection *conn, char *msg)); |
3bb56863 | 89 | |
7e92827d | 90 | extern int nth_token_is(const char *str, const char *token, int tok_no); |
b02e31e5 | 91 | |
7e92827d | 92 | extern char *nth_token(const char *str, int tok_no); |
b02e31e5 | 93 | |
08230db7 | 94 | extern int pid_is_online(pid_t); |
ab33e65c | 95 | |
f9e5ce61 | 96 | #endif /* USTCOMM_H */ |