X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=liblttkconsumerd%2Flttkconsumerd.h;fp=liblttkconsumerd%2Flttkconsumerd.h;h=10e4a5504e19148ac7fe69d10783342090019bc4;hp=cbdedd213ba0c614e3336d91378c780ac26af618;hb=cb040cc13fdbe2d5561c4ee10d94701436b9c8ae;hpb=c72c2927a2478c534b64593bb31507dc010daf34 diff --git a/liblttkconsumerd/lttkconsumerd.h b/liblttkconsumerd/lttkconsumerd.h index cbdedd213..10e4a5504 100644 --- a/liblttkconsumerd/lttkconsumerd.h +++ b/liblttkconsumerd/lttkconsumerd.h @@ -57,15 +57,59 @@ struct kconsumerd_fd { unsigned long max_sb_size; /* the subbuffer size for this channel */ }; +struct kconsumerd_local_data { + /* function to call when data is available on a buffer */ + int (*on_buffer_ready)(struct kconsumerd_fd *kconsumerd_fd); + /* socket to communicate errors with sessiond */ + int kconsumerd_error_socket; + /* socket to exchange commands with sessiond */ + char *kconsumerd_command_sock_path; + /* communication with splice */ + int kconsumerd_thread_pipe[2]; + /* pipe to wake the poll thread when necessary */ + int kconsumerd_poll_pipe[2]; + /* to let the signal handler wake up the fd receiver thread */ + int kconsumerd_should_quit[2]; +}; + /* - * kconsumerd_init(void) + * kconsumerd_create * initialise the necessary environnement : - * - inform the polling thread to update the polling array + * - create a new context * - create the poll_pipe * - create the should_quit pipe (for signal handler) - * returns the return code of pipe, 0 on success, -1 on error + * - create the thread pipe (for splice) + * Takes a function pointer as argument, this function is called when data is + * available on a buffer. This function is responsible to do the + * kernctl_get_next_subbuf, read the data with mmap or splice depending on the + * buffer configuration and then kernctl_put_next_subbuf at the end. + * Returns a pointer to the new context or NULL on error. + */ +struct kconsumerd_local_data *kconsumerd_create( + int (*buffer_ready)(struct kconsumerd_fd *kconsumerd_fd)); + +/* + * kconsumerd_destroy + * Close all fds associated with the instance and free the context + */ +void kconsumerd_destroy(struct kconsumerd_local_data *ctx); + +/* + * kconsumerd_on_read_subbuffer_mmap + * mmap the ring buffer, read it and write the data to the tracefile. + * Returns the number of bytes written + */ +int kconsumerd_on_read_subbuffer_mmap(struct kconsumerd_local_data *ctx, + struct kconsumerd_fd *kconsumerd_fd, unsigned long len); + +/* + * kconsumerd_on_read_subbuffer + * + * Splice the data from the ring buffer to the tracefile. + * Returns the number of bytes spliced */ -int kconsumerd_init(void); +int kconsumerd_on_read_subbuffer_splice(struct kconsumerd_local_data *ctx, + struct kconsumerd_fd *kconsumerd_fd, unsigned long len); /* * kconsumerd_send_error @@ -73,7 +117,8 @@ int kconsumerd_init(void); * returns the return code of sendmsg : the number of bytes transmitted * or -1 on error. */ -int kconsumerd_send_error(enum lttcomm_return_code cmd); +int kconsumerd_send_error(struct kconsumerd_local_data *ctx, + enum lttcomm_return_code cmd); /* * kconsumerd_poll_socket @@ -101,7 +146,7 @@ void *kconsumerd_thread_receive_fds(void *data); * kconsumerd_should_exit * Called from signal handler to ensure a clean exit */ -void kconsumerd_should_exit(void); +void kconsumerd_should_exit(struct kconsumerd_local_data *ctx); /* * kconsumerd_cleanup @@ -113,12 +158,12 @@ void kconsumerd_cleanup(void); * kconsumerd_set_error_socket * Set the error socket for communication with a session daemon */ -void kconsumerd_set_error_socket(int sock); +void kconsumerd_set_error_socket(struct kconsumerd_local_data *ctx, int sock); /* * kconsumerd_set_command_socket_path * Set the command socket path for communication with a session daemon */ -void kconsumerd_set_command_socket_path(char *sock); +void kconsumerd_set_command_socket_path(struct kconsumerd_local_data *ctx, char *sock); #endif /* _LIBLTTKCONSUMERD_H */