| 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 |
| 6 | * it under the terms of the GNU General Public License, version 2 only, |
| 7 | * as 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 |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef LTTNG_VIEWER_H |
| 20 | #define LTTNG_VIEWER_H |
| 21 | |
| 22 | #include <limits.h> |
| 23 | |
| 24 | #define LTTNG_VIEWER_PATH_MAX 4096 |
| 25 | #define LTTNG_VIEWER_NAME_MAX 255 |
| 26 | #define LTTNG_VIEWER_HOST_NAME_MAX 64 |
| 27 | |
| 28 | /* Flags in reply to get_next_index and get_packet. */ |
| 29 | /* New metadata is required to read this packet. */ |
| 30 | #define LTTNG_VIEWER_FLAG_NEW_METADATA (1 << 0) |
| 31 | /* New stream got added to the trace */ |
| 32 | #define LTTNG_VIEWER_FLAG_NEW_STREAM (1 << 1) |
| 33 | |
| 34 | enum lttng_viewer_command { |
| 35 | VIEWER_CONNECT = 1, |
| 36 | VIEWER_LIST_SESSIONS = 2, |
| 37 | VIEWER_ATTACH_SESSION = 3, |
| 38 | VIEWER_GET_NEXT_INDEX = 4, |
| 39 | VIEWER_GET_PACKET = 5, |
| 40 | VIEWER_GET_METADATA = 6, |
| 41 | }; |
| 42 | |
| 43 | enum lttng_viewer_attach_return_code { |
| 44 | VIEWER_ATTACH_OK = 1, /* If the attach command succeeded. */ |
| 45 | VIEWER_ATTACH_ALREADY = 2, /* If a viewer is already attached. */ |
| 46 | VIEWER_ATTACH_UNK = 3, /* If the session ID is unknown. */ |
| 47 | VIEWER_ATTACH_NOT_LIVE = 4, /* If the session is not live. */ |
| 48 | VIEWER_ATTACH_SEEK_ERR = 5, /* Seek error. */ |
| 49 | }; |
| 50 | |
| 51 | enum lttng_viewer_next_index_return_code { |
| 52 | VIEWER_INDEX_OK = 1, /* Index is available. */ |
| 53 | VIEWER_INDEX_RETRY = 2, /* Index not yet available. */ |
| 54 | VIEWER_INDEX_HUP = 3, /* Index closed (trace destroyed). */ |
| 55 | VIEWER_INDEX_ERR = 4, /* Unknow error. */ |
| 56 | VIEWER_INDEX_INACTIVE = 5, /* Inactive stream beacon. */ |
| 57 | }; |
| 58 | |
| 59 | enum lttng_viewer_get_packet_return_code { |
| 60 | VIEWER_GET_PACKET_OK = 1, |
| 61 | VIEWER_GET_PACKET_RETRY = 2, |
| 62 | VIEWER_GET_PACKET_ERR = 3, |
| 63 | }; |
| 64 | |
| 65 | enum lttng_viewer_get_metadata_return_code { |
| 66 | VIEWER_METADATA_OK = 1, |
| 67 | VIEWER_NO_NEW_METADATA = 2, |
| 68 | VIEWER_METADATA_ERR = 3, |
| 69 | }; |
| 70 | |
| 71 | enum lttng_viewer_connection_type { |
| 72 | VIEWER_CLIENT_COMMAND = 1, |
| 73 | VIEWER_CLIENT_NOTIFICATION = 2, |
| 74 | }; |
| 75 | |
| 76 | enum lttng_viewer_seek { |
| 77 | VIEWER_SEEK_BEGINNING = 1, /* Receive the trace packets from the beginning. */ |
| 78 | VIEWER_SEEK_LAST = 2, /* Receive the trace packets from now. */ |
| 79 | }; |
| 80 | |
| 81 | struct lttng_viewer_session { |
| 82 | uint64_t id; |
| 83 | char hostname[LTTNG_VIEWER_HOST_NAME_MAX]; |
| 84 | char session_name[LTTNG_VIEWER_NAME_MAX]; |
| 85 | uint32_t live_timer; |
| 86 | uint32_t clients; |
| 87 | } __attribute__((__packed__)); |
| 88 | |
| 89 | struct lttng_viewer_stream { |
| 90 | uint64_t id; |
| 91 | uint64_t ctf_trace_id; |
| 92 | char path_name[LTTNG_VIEWER_PATH_MAX]; |
| 93 | char channel_name[LTTNG_VIEWER_NAME_MAX]; |
| 94 | int metadata_flag; |
| 95 | } __attribute__((__packed__)); |
| 96 | |
| 97 | struct lttng_viewer_cmd { |
| 98 | uint64_t data_size; /* data size following this header */ |
| 99 | uint32_t cmd; /* enum lttcomm_relayd_command */ |
| 100 | uint32_t cmd_version; /* command version */ |
| 101 | } __attribute__((__packed__)); |
| 102 | |
| 103 | /* |
| 104 | * CONNECT payload. |
| 105 | */ |
| 106 | struct lttng_viewer_connect { |
| 107 | uint32_t major; |
| 108 | uint32_t minor; |
| 109 | uint32_t type; /* enum lttng_viewer_connection_type */ |
| 110 | uint64_t viewer_session_id; /* session ID assigned by the relay for command connections */ |
| 111 | } __attribute__((__packed__)); |
| 112 | |
| 113 | /* |
| 114 | * VIEWER_LIST_SESSIONS payload. |
| 115 | */ |
| 116 | struct lttng_viewer_list_sessions { |
| 117 | uint32_t sessions_count; |
| 118 | char session_list[]; /* struct lttng_viewer_session */ |
| 119 | } __attribute__((__packed__)); |
| 120 | |
| 121 | /* |
| 122 | * VIEWER_ATTACH_SESSION payload. |
| 123 | */ |
| 124 | struct lttng_viewer_attach_session_request { |
| 125 | uint64_t session_id; |
| 126 | uint32_t seek; /* enum lttng_viewer_seek */ |
| 127 | uint64_t offset; /* unused for now */ |
| 128 | } __attribute__((__packed__)); |
| 129 | |
| 130 | struct lttng_viewer_attach_session_response { |
| 131 | uint32_t status; /* enum lttng_viewer_attach_return_code */ |
| 132 | uint32_t streams_count; |
| 133 | char stream_list[]; /* struct lttng_viewer_stream */ |
| 134 | } __attribute__((__packed__)); |
| 135 | |
| 136 | /* |
| 137 | * VIEWER_GET_NEXT_INDEX payload. |
| 138 | */ |
| 139 | struct lttng_viewer_get_next_index { |
| 140 | uint64_t stream_id; |
| 141 | } __attribute__ ((__packed__)); |
| 142 | |
| 143 | struct lttng_viewer_index { |
| 144 | uint32_t status; /* enum lttng_viewer_next_index_return_code */ |
| 145 | uint64_t offset; |
| 146 | uint64_t packet_size; |
| 147 | uint64_t content_size; |
| 148 | uint64_t timestamp_begin; |
| 149 | uint64_t timestamp_end; |
| 150 | uint64_t events_discarded; |
| 151 | uint64_t stream_id; |
| 152 | uint32_t flags; /* LTTNG_VIEWER_FLAG_* */ |
| 153 | } __attribute__ ((__packed__)); |
| 154 | |
| 155 | /* |
| 156 | * VIEWER_GET_PACKET payload. |
| 157 | */ |
| 158 | struct lttng_viewer_get_packet { |
| 159 | uint64_t stream_id; |
| 160 | uint64_t offset; |
| 161 | uint32_t len; |
| 162 | } __attribute__((__packed__)); |
| 163 | |
| 164 | struct lttng_viewer_trace_packet { |
| 165 | uint32_t status; /* enum lttng_viewer_get_packet_return_code */ |
| 166 | uint32_t len; |
| 167 | uint32_t flags; /* LTTNG_VIEWER_FLAG_* */ |
| 168 | char data[]; |
| 169 | } __attribute__((__packed__)); |
| 170 | |
| 171 | /* |
| 172 | * VIEWER_GET_METADATA payload. |
| 173 | */ |
| 174 | struct lttng_viewer_get_metadata { |
| 175 | uint64_t stream_id; |
| 176 | } __attribute__((__packed__)); |
| 177 | |
| 178 | struct lttng_viewer_metadata_packet { |
| 179 | uint32_t status; /* enum lttng_viewer_get_metadata_return_code */ |
| 180 | uint64_t len; |
| 181 | char data[]; |
| 182 | } __attribute__((__packed__)); |
| 183 | |
| 184 | #endif /* LTTNG_VIEWER_H */ |