| 1 | /* |
| 2 | * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com> |
| 3 | * David Goulet <dgoulet@efficios.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License, version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
| 16 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef _VIEWER_STREAM_H |
| 20 | #define _VIEWER_STREAM_H |
| 21 | |
| 22 | #include <limits.h> |
| 23 | #include <inttypes.h> |
| 24 | #include <pthread.h> |
| 25 | |
| 26 | #include <common/hashtable/hashtable.h> |
| 27 | |
| 28 | #include "ctf-trace.h" |
| 29 | #include "lttng-viewer-abi.h" |
| 30 | #include "stream.h" |
| 31 | |
| 32 | /* Stub */ |
| 33 | struct relay_stream; |
| 34 | |
| 35 | /* |
| 36 | * Shadow copy of the relay_stream structure for the viewer side. The only |
| 37 | * fields updated by the writer (streaming side) after allocation are : |
| 38 | * total_index_received and close_flag. Everything else is updated by the |
| 39 | * reader (viewer side). |
| 40 | */ |
| 41 | struct relay_viewer_stream { |
| 42 | uint64_t stream_handle; |
| 43 | uint64_t session_id; |
| 44 | int read_fd; |
| 45 | int index_read_fd; |
| 46 | char *path_name; |
| 47 | char *channel_name; |
| 48 | uint64_t last_sent_index; |
| 49 | uint64_t total_index_received; |
| 50 | uint64_t tracefile_count; |
| 51 | uint64_t tracefile_count_current; |
| 52 | /* Stop after reading this tracefile. */ |
| 53 | uint64_t tracefile_count_last; |
| 54 | struct lttng_ht_node_u64 stream_n; |
| 55 | struct rcu_head rcu_node; |
| 56 | struct ctf_trace *ctf_trace; |
| 57 | /* |
| 58 | * This lock blocks only when the writer is about to start overwriting |
| 59 | * a file currently read by the reader. |
| 60 | * |
| 61 | * This is nested INSIDE the viewer_stream_rotation_lock. |
| 62 | */ |
| 63 | pthread_mutex_t overwrite_lock; |
| 64 | /* Information telling us if the stream is a metadata stream. */ |
| 65 | unsigned int metadata_flag:1; |
| 66 | /* |
| 67 | * Information telling us that the stream is closed in write, so |
| 68 | * we don't expect new indexes and we can read up to EOF. |
| 69 | */ |
| 70 | unsigned int close_write_flag:1; |
| 71 | /* |
| 72 | * If the streaming side closes a FD in use in the viewer side, |
| 73 | * it sets this flag to inform that it is a normal error. |
| 74 | */ |
| 75 | unsigned int abort_flag:1; |
| 76 | /* Indicates if this stream has been sent to a viewer client. */ |
| 77 | unsigned int sent_flag:1; |
| 78 | }; |
| 79 | |
| 80 | struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, |
| 81 | enum lttng_viewer_seek seek_t, struct ctf_trace *ctf_trace); |
| 82 | struct relay_viewer_stream *viewer_stream_find_by_id(uint64_t id); |
| 83 | void viewer_stream_destroy(struct ctf_trace *ctf_trace, |
| 84 | struct relay_viewer_stream *stream); |
| 85 | void viewer_stream_delete(struct relay_viewer_stream *stream); |
| 86 | int viewer_stream_rotate(struct relay_viewer_stream *vstream, |
| 87 | struct relay_stream *stream); |
| 88 | |
| 89 | #endif /* _VIEWER_STREAM_H */ |