1 /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 /* 7 * A remote client to the server. 8 */ 9 #ifndef CRAS_RCLIENT_H_ 10 #define CRAS_RCLIENT_H_ 11 12 struct cras_client_message; 13 struct cras_message; 14 struct cras_rclient; 15 struct cras_server_message; 16 17 /* Creates an rclient structure. 18 * Args: 19 * fd - The file descriptor used for communication with the client. 20 * id - Unique identifier for this client. 21 * Returns: 22 * A pointer to the newly created rclient on success, NULL on failure. 23 */ 24 struct cras_rclient *cras_rclient_create(int fd, size_t id); 25 26 /* Destroys an rclient created with "cras_rclient_create". 27 * Args: 28 * client - The client to destroy. 29 */ 30 void cras_rclient_destroy(struct cras_rclient *client); 31 32 /* Handles a message from the client. 33 * Args: 34 * client - The client that received this message. 35 * msg - The message that was sent by the remote client. 36 * fd - The file descriptor that was sent by the remote client (or -1 if no 37 * file descriptor was sent). 38 * Returns: 39 * 0 on success, otherwise a negative error code. 40 */ 41 int cras_rclient_message_from_client(struct cras_rclient *client, 42 const struct cras_server_message *msg, 43 int fd); 44 45 /* Handles a received buffer from the client. 46 * Args: 47 * client - The client that received this message. 48 * buf - The raw byte buffer the client sent. It should contain a valid 49 * cras_server_message. 50 * buf_len - The length of |buf|. 51 * fd - The file descriptor that was sent by the remote client (or -1 if no 52 * file descriptor was sent). 53 * Returns: 54 * 0 on success, otherwise a negative error code. 55 */ 56 int cras_rclient_buffer_from_client(struct cras_rclient *client, 57 const uint8_t *buf, 58 size_t buf_len, 59 int fd); 60 61 /* Sends a message to the client. 62 * Args: 63 * client - The client to send the message to. 64 * msg - The message to send. 65 * fds - Array of file descriptors or null 66 * num_fds - Number of entries in the fds array. 67 * Returns: 68 * number of bytes written on success, otherwise a negative error code. 69 */ 70 int cras_rclient_send_message(const struct cras_rclient *client, 71 const struct cras_client_message *msg, 72 int *fds, 73 unsigned int num_fds); 74 75 #endif /* CRAS_RCLIENT_H_ */ 76