X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Fcommon%2Fmsg-iter%2Fmsg-iter.h;h=8b662ee38084757e6fac9b4e7e9dd7a11206a9f1;hp=1aeeafe5e91969c33bd38981d8cde57ddda7b5eb;hb=0235b0db7de5bcacdb3650c92461f2ce5eb2143d;hpb=ea14c7dd641ec094a4c63e2f6de59aab8cbb8603 diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.h b/src/plugins/ctf/common/msg-iter/msg-iter.h index 1aeeafe5..8b662ee3 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.h +++ b/src/plugins/ctf/common/msg-iter/msg-iter.h @@ -1,31 +1,16 @@ -#ifndef CTF_MSG_ITER_H -#define CTF_MSG_ITER_H - /* - * Babeltrace - CTF message iterator + * SPDX-License-Identifier: MIT * * Copyright (c) 2015-2016 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015-2016 Philippe Proulx * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Babeltrace - CTF message iterator */ +#ifndef CTF_MSG_ITER_H +#define CTF_MSG_ITER_H + +#include #include #include #include @@ -44,80 +29,64 @@ */ /** - * Medium operations status codes. + * Medium operations status codes. These use the same values as + * libbabeltrace2. */ -enum bt_msg_iter_medium_status { +enum ctf_msg_iter_medium_status { /** * End of file. * * The medium function called by the message iterator * function reached the end of the file. */ - BT_MSG_ITER_MEDIUM_STATUS_EOF = 1, + CTF_MSG_ITER_MEDIUM_STATUS_EOF = 1, /** * There is no data available right now, try again later. */ - BT_MSG_ITER_MEDIUM_STATUS_AGAIN = 11, - - /** Unsupported operation. */ - BT_MSG_ITER_MEDIUM_STATUS_UNSUPPORTED = -3, - - /** Invalid argument. */ - BT_MSG_ITER_MEDIUM_STATUS_INVAL = -2, + CTF_MSG_ITER_MEDIUM_STATUS_AGAIN = 11, /** General error. */ - BT_MSG_ITER_MEDIUM_STATUS_ERROR = -1, + CTF_MSG_ITER_MEDIUM_STATUS_ERROR = -1, + + /** Memory error. */ + CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR = -12, /** Everything okay. */ - BT_MSG_ITER_MEDIUM_STATUS_OK = 0, + CTF_MSG_ITER_MEDIUM_STATUS_OK = 0, }; /** * CTF message iterator API status code. */ -enum bt_msg_iter_status { +enum ctf_msg_iter_status { /** * End of file. * * The medium function called by the message iterator * function reached the end of the file. */ - BT_MSG_ITER_STATUS_EOF = BT_MSG_ITER_MEDIUM_STATUS_EOF, + CTF_MSG_ITER_STATUS_EOF = CTF_MSG_ITER_MEDIUM_STATUS_EOF, /** * There is no data available right now, try again later. * * Some condition resulted in the - * bt_msg_iter_medium_ops::request_bytes() user function not + * ctf_msg_iter_medium_ops::request_bytes() user function not * having access to any data now. You should retry calling the * last called message iterator function once the situation * is resolved. */ - BT_MSG_ITER_STATUS_AGAIN = BT_MSG_ITER_MEDIUM_STATUS_AGAIN, - - /** Invalid argument. */ - BT_MSG_ITER_STATUS_INVAL = BT_MSG_ITER_MEDIUM_STATUS_INVAL, - - /** Unsupported operation. */ - BT_MSG_ITER_STATUS_UNSUPPORTED = BT_MSG_ITER_MEDIUM_STATUS_UNSUPPORTED, + CTF_MSG_ITER_STATUS_AGAIN = CTF_MSG_ITER_MEDIUM_STATUS_AGAIN, /** General error. */ - BT_MSG_ITER_STATUS_ERROR = BT_MSG_ITER_MEDIUM_STATUS_ERROR, + CTF_MSG_ITER_STATUS_ERROR = CTF_MSG_ITER_MEDIUM_STATUS_ERROR, - /** Everything okay. */ - BT_MSG_ITER_STATUS_OK = 0, -}; + /** Memory error. */ + CTF_MSG_ITER_STATUS_MEMORY_ERROR = CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR, -/** - * CTF message iterator seek operation directives. - */ -enum bt_msg_iter_seek_whence { - /** - * Set the iterator's position to an absolute offset in the underlying - * medium. - */ - BT_MSG_ITER_SEEK_WHENCE_SET, + /** Everything okay. */ + CTF_MSG_ITER_STATUS_OK = CTF_MSG_ITER_MEDIUM_STATUS_OK, }; /** @@ -126,7 +95,7 @@ enum bt_msg_iter_seek_whence { * Those user functions are called by the message iterator * functions to request medium actions. */ -struct bt_msg_iter_medium_ops { +struct ctf_msg_iter_medium_ops { /** * Returns the next byte buffer to be used by the binary file * reader to deserialize binary data. @@ -154,36 +123,36 @@ struct bt_msg_iter_medium_ops { * * This function must return one of the following statuses: * - * - #BT_MSG_ITER_MEDIUM_STATUS_OK: Everything + * - #CTF_MSG_ITER_MEDIUM_STATUS_OK: Everything * is okay, i.e. \p buffer_sz is set to a positive value * reflecting the number of available bytes in the buffer * starting at the address written in \p buffer_addr. - * - #BT_MSG_ITER_MEDIUM_STATUS_AGAIN: No data is + * - #CTF_MSG_ITER_MEDIUM_STATUS_AGAIN: No data is * available right now. In this case, the message * iterator function called by the user returns - * #BT_MSG_ITER_STATUS_AGAIN, and it is the user's + * #CTF_MSG_ITER_STATUS_AGAIN, and it is the user's * responsibility to make sure enough data becomes available * before calling the \em same message iterator * function again to continue the decoding process. - * - #BT_MSG_ITER_MEDIUM_STATUS_EOF: The end of + * - #CTF_MSG_ITER_MEDIUM_STATUS_EOF: The end of * the file was reached, and no more data will ever be * available for this file. In this case, the message * iterator function called by the user returns - * #BT_MSG_ITER_STATUS_EOF. This must \em not be + * #CTF_MSG_ITER_STATUS_EOF. This must \em not be * returned when returning at least one byte of data to the * caller, i.e. this must be returned when there's * absolutely nothing left; should the request size be * larger than what's left in the file, this function must * return what's left, setting \p buffer_sz to the number of * remaining bytes, and return - * #BT_MSG_ITER_MEDIUM_STATUS_EOF on the \em following + * #CTF_MSG_ITER_MEDIUM_STATUS_EOF on the \em following * call. - * - #BT_MSG_ITER_MEDIUM_STATUS_ERROR: A fatal - * error occured during this operation. In this case, the + * - #CTF_MSG_ITER_MEDIUM_STATUS_ERROR: A fatal + * error occurred during this operation. In this case, the * message iterator function called by the user returns - * #BT_MSG_ITER_STATUS_ERROR. + * #CTF_MSG_ITER_STATUS_ERROR. * - * If #BT_MSG_ITER_MEDIUM_STATUS_OK is not returned, the + * If #CTF_MSG_ITER_MEDIUM_STATUS_OK is not returned, the * values of \p buffer_sz and \p buffer_addr are \em ignored by * the caller. * @@ -193,24 +162,29 @@ struct bt_msg_iter_medium_ops { * @param data User data * @returns Status code (see description above) */ - enum bt_msg_iter_medium_status (* request_bytes)(size_t request_sz, + enum ctf_msg_iter_medium_status (* request_bytes)(size_t request_sz, uint8_t **buffer_addr, size_t *buffer_sz, void *data); /** * Repositions the underlying stream's position. * * This *optional* method repositions the underlying stream - * to a given absolute or relative position, as indicated by - * the whence directive. + * to a given absolute position in the medium. * - * @param whence One of #bt_msg_iter_seek_whence values * @param offset Offset to use for the given directive * @param data User data - * @returns One of #bt_msg_iter_medium_status values + * @returns One of #ctf_msg_iter_medium_status values */ - enum bt_msg_iter_medium_status (* seek)( - enum bt_msg_iter_seek_whence whence, - off_t offset, void *data); + enum ctf_msg_iter_medium_status (* seek)(off_t offset, void *data); + + /** + * Called when the message iterator wishes to inform the medium that it + * is about to start a new packet. + * + * After the iterator has called switch_packet, the following call to + * request_bytes must return the content at the start of the next + * packet. */ + enum ctf_msg_iter_medium_status (* switch_packet)(void *data); /** * Returns a stream instance (weak reference) for the given @@ -232,7 +206,7 @@ struct bt_msg_iter_medium_ops { }; /** CTF message iterator. */ -struct bt_msg_iter; +struct ctf_msg_iter; /** * Creates a CTF message iterator. @@ -243,7 +217,7 @@ struct bt_msg_iter; * @param trace Trace to read * @param max_request_sz Maximum buffer size, in bytes, to * request to - * bt_msg_iter_medium_ops::request_bytes() + * ctf_msg_iter_medium_ops::request_bytes() * at a time * @param medops Medium operations * @param medops_data User data (passed to medium operations) @@ -251,9 +225,14 @@ struct bt_msg_iter; * success, or \c NULL on error */ BT_HIDDEN -struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc, - size_t max_request_sz, struct bt_msg_iter_medium_ops medops, - void *medops_data, bt_logging_level log_level); +struct ctf_msg_iter *ctf_msg_iter_create( + struct ctf_trace_class *tc, + size_t max_request_sz, + struct ctf_msg_iter_medium_ops medops, + void *medops_data, + bt_logging_level log_level, + bt_self_component *self_comp, + bt_self_message_iterator *self_msg_iter); /** * Destroys a CTF message iterator, freeing all internal resources. @@ -263,32 +242,31 @@ struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc, * @param msg_iter CTF message iterator */ BT_HIDDEN -void bt_msg_iter_destroy(struct bt_msg_iter *msg_iter); +void ctf_msg_iter_destroy(struct ctf_msg_iter *msg_iter); /** * Returns the next message from a CTF message iterator. * - * Upon successful completion, #BT_MSG_ITER_STATUS_OK is + * Upon successful completion, #CTF_MSG_ITER_STATUS_OK is * returned, and the next message is written to \p msg. * In this case, the caller is responsible for calling * bt_message_put() on the returned message. * - * If this function returns #BT_MSG_ITER_STATUS_AGAIN, the caller + * If this function returns #CTF_MSG_ITER_STATUS_AGAIN, the caller * should make sure that data becomes available to its medium, and * call this function again, until another status is returned. * * @param msg_iter CTF message iterator * @param message Returned message if the function's - * return value is #BT_MSG_ITER_STATUS_OK - * @returns One of #bt_msg_iter_status values + * return value is #CTF_MSG_ITER_STATUS_OK + * @returns One of #ctf_msg_iter_status values */ BT_HIDDEN -enum bt_msg_iter_status bt_msg_iter_get_next_message( - struct bt_msg_iter *notit, - bt_self_message_iterator *msg_iter, - bt_message **message); +enum ctf_msg_iter_status ctf_msg_iter_get_next_message( + struct ctf_msg_iter *msg_it, + const bt_message **message); -struct bt_msg_iter_packet_properties { +struct ctf_msg_iter_packet_properties { int64_t exp_packet_total_size; int64_t exp_packet_content_size; uint64_t stream_class_id; @@ -303,77 +281,73 @@ struct bt_msg_iter_packet_properties { }; BT_HIDDEN -enum bt_msg_iter_status bt_msg_iter_get_packet_properties( - struct bt_msg_iter *notit, - struct bt_msg_iter_packet_properties *props); +enum ctf_msg_iter_status ctf_msg_iter_get_packet_properties( + struct ctf_msg_iter *msg_it, + struct ctf_msg_iter_packet_properties *props); + +BT_HIDDEN +enum ctf_msg_iter_status ctf_msg_iter_curr_packet_first_event_clock_snapshot( + struct ctf_msg_iter *msg_it, uint64_t *first_event_cs); BT_HIDDEN -void bt_msg_iter_set_medops_data(struct bt_msg_iter *notit, - void *medops_data); +enum ctf_msg_iter_status ctf_msg_iter_curr_packet_last_event_clock_snapshot( + struct ctf_msg_iter *msg_it, uint64_t *last_event_cs); BT_HIDDEN -enum bt_msg_iter_status bt_msg_iter_seek( - struct bt_msg_iter *notit, off_t offset); +enum ctf_msg_iter_status ctf_msg_iter_seek( + struct ctf_msg_iter *msg_it, off_t offset); /* * Resets the iterator so that the next requested medium bytes are * assumed to be the first bytes of a new stream. Depending on - * bt_msg_iter_set_emit_stream_beginning_message(), the first message - * which this iterator emits after calling bt_msg_iter_reset() is of - * type `BT_MESSAGE_TYPE_STREAM_BEGINNING`. + * ctf_msg_iter_set_emit_stream_beginning_message(), the first message + * which this iterator emits after calling ctf_msg_iter_reset() is of + * type `CTF_MESSAGE_TYPE_STREAM_BEGINNING`. */ BT_HIDDEN -void bt_msg_iter_reset(struct bt_msg_iter *notit); +void ctf_msg_iter_reset(struct ctf_msg_iter *msg_it); /* - * Like bt_msg_iter_reset(), but preserves stream-dependent state. + * Like ctf_msg_iter_reset(), but preserves stream-dependent state. */ BT_HIDDEN -void bt_msg_iter_reset_for_next_stream_file(struct bt_msg_iter *notit); - -BT_HIDDEN -void bt_msg_iter_set_emit_stream_beginning_message(struct bt_msg_iter *notit, - bool val); +void ctf_msg_iter_reset_for_next_stream_file(struct ctf_msg_iter *msg_it); BT_HIDDEN -void bt_msg_iter_set_emit_stream_end_message(struct bt_msg_iter *notit, +void ctf_msg_iter_set_dry_run(struct ctf_msg_iter *msg_it, bool val); static inline -const char *bt_msg_iter_medium_status_string( - enum bt_msg_iter_medium_status status) +const char *ctf_msg_iter_medium_status_string( + enum ctf_msg_iter_medium_status status) { switch (status) { - case BT_MSG_ITER_MEDIUM_STATUS_EOF: - return "BT_MSG_ITER_MEDIUM_STATUS_EOF"; - case BT_MSG_ITER_MEDIUM_STATUS_AGAIN: - return "BT_MSG_ITER_MEDIUM_STATUS_AGAIN"; - case BT_MSG_ITER_MEDIUM_STATUS_INVAL: - return "BT_MSG_ITER_MEDIUM_STATUS_INVAL"; - case BT_MSG_ITER_MEDIUM_STATUS_ERROR: - return "BT_MSG_ITER_MEDIUM_STATUS_ERROR"; - case BT_MSG_ITER_MEDIUM_STATUS_OK: - return "BT_MSG_ITER_MEDIUM_STATUS_OK"; + case CTF_MSG_ITER_MEDIUM_STATUS_EOF: + return "EOF"; + case CTF_MSG_ITER_MEDIUM_STATUS_AGAIN: + return "AGAIN"; + case CTF_MSG_ITER_MEDIUM_STATUS_ERROR: + return "ERROR"; + case CTF_MSG_ITER_MEDIUM_STATUS_OK: + return "OK"; default: return "(unknown)"; } } static inline -const char *bt_msg_iter_status_string( - enum bt_msg_iter_status status) +const char *ctf_msg_iter_status_string( + enum ctf_msg_iter_status status) { switch (status) { - case BT_MSG_ITER_STATUS_EOF: - return "BT_MSG_ITER_STATUS_EOF"; - case BT_MSG_ITER_STATUS_AGAIN: - return "BT_MSG_ITER_STATUS_AGAIN"; - case BT_MSG_ITER_STATUS_INVAL: - return "BT_MSG_ITER_STATUS_INVAL"; - case BT_MSG_ITER_STATUS_ERROR: - return "BT_MSG_ITER_STATUS_ERROR"; - case BT_MSG_ITER_STATUS_OK: - return "BT_MSG_ITER_STATUS_OK"; + case CTF_MSG_ITER_STATUS_EOF: + return "EOF"; + case CTF_MSG_ITER_STATUS_AGAIN: + return "AGAIN"; + case CTF_MSG_ITER_STATUS_ERROR: + return "ERROR"; + case CTF_MSG_ITER_STATUS_OK: + return "OK"; default: return "(unknown)"; }