| 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 | |
| 18 | #ifndef USTCOMM_H |
| 19 | #define USTCOMM_H |
| 20 | |
| 21 | #include <sys/types.h> |
| 22 | #include <sys/un.h> |
| 23 | #include <urcu/list.h> |
| 24 | |
| 25 | #include <ust/kcompat/kcompat.h> |
| 26 | #include "multipoll.h" |
| 27 | |
| 28 | #define SOCK_DIR "/tmp/ust-app-socks" |
| 29 | #define UST_SIGNAL SIGIO |
| 30 | |
| 31 | struct ustcomm_connection { |
| 32 | struct list_head list; |
| 33 | int fd; |
| 34 | /* Data that has not yet been consumed: */ |
| 35 | char *recv_buf; |
| 36 | int recv_buf_size; |
| 37 | int recv_buf_alloc; |
| 38 | }; |
| 39 | |
| 40 | /* ustcomm_server must be shallow-copyable */ |
| 41 | struct ustcomm_server { |
| 42 | /* the "server" socket for serving the external requests */ |
| 43 | int listen_fd; |
| 44 | char *socketpath; |
| 45 | |
| 46 | struct list_head connections; |
| 47 | }; |
| 48 | |
| 49 | struct ustcomm_ustd { |
| 50 | struct ustcomm_server server; |
| 51 | }; |
| 52 | |
| 53 | struct ustcomm_app { |
| 54 | struct ustcomm_server server; |
| 55 | }; |
| 56 | |
| 57 | /* ustcomm_source must be shallow-copyable */ |
| 58 | struct ustcomm_source { |
| 59 | int fd; |
| 60 | void *priv; |
| 61 | }; |
| 62 | |
| 63 | struct ustcomm_multipoll_conn_info { |
| 64 | struct ustcomm_connection *conn; |
| 65 | int (*cb)(char *msg, struct ustcomm_source *src); |
| 66 | }; |
| 67 | |
| 68 | //int send_message_pid(pid_t pid, const char *msg, char **reply); |
| 69 | extern int ustcomm_request_consumer(pid_t pid, const char *channel); |
| 70 | |
| 71 | extern int ustcomm_ustd_recv_message(struct ustcomm_ustd *ustd, char **msg, struct ustcomm_source *src, int timeout); |
| 72 | extern int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg, struct ustcomm_source *src, int timeout); |
| 73 | |
| 74 | extern int ustcomm_init_app(pid_t pid, struct ustcomm_app *handle); |
| 75 | extern void ustcomm_fini_app(struct ustcomm_app *handle, int keep_socket_file); |
| 76 | extern void ustcomm_fini_ustd(struct ustcomm_ustd *handle); |
| 77 | |
| 78 | extern int ustcomm_init_ustd(struct ustcomm_ustd *handle, const char *sock_path); |
| 79 | |
| 80 | extern int ustcomm_connect_app(pid_t pid, struct ustcomm_connection *conn); |
| 81 | extern int ustcomm_close_app(struct ustcomm_connection *conn); |
| 82 | extern int ustcomm_connect_path(const char *path, struct ustcomm_connection *conn, pid_t signalpid); |
| 83 | extern int ustcomm_send_request(struct ustcomm_connection *conn, const char *req, char **reply); |
| 84 | extern int ustcomm_send_reply(struct ustcomm_server *server, char *msg, struct ustcomm_source *src); |
| 85 | extern int ustcomm_disconnect(struct ustcomm_connection *conn); |
| 86 | extern int ustcomm_close_all_connections(struct ustcomm_server *server); |
| 87 | extern void ustcomm_mp_add_app_clients(struct mpentries *ent, struct ustcomm_app *app, int (*cb)(char *recvbuf, struct ustcomm_source *src)); |
| 88 | |
| 89 | extern int nth_token_is(const char *str, const char *token, int tok_no); |
| 90 | |
| 91 | extern char *nth_token(const char *str, int tok_no); |
| 92 | |
| 93 | extern int pid_is_online(pid_t); |
| 94 | |
| 95 | #endif /* USTCOMM_H */ |