X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=plugins%2Fctf%2Fcommon%2Fbtr%2Fbtr.h;h=c87eda014fc2af54a94cfcaabeeb0e5e4deef4ea;hb=56e18c4ce186892c36d7f2cb5078087425e60134;hp=4b5e7bc78b814f22f46d1527a590bb3f27bbf55c;hpb=9d408fcae74602e3591f66623ceb85f482d948ed;p=babeltrace.git diff --git a/plugins/ctf/common/btr/btr.h b/plugins/ctf/common/btr/btr.h index 4b5e7bc7..c87eda01 100644 --- a/plugins/ctf/common/btr/btr.h +++ b/plugins/ctf/common/btr/btr.h @@ -32,6 +32,8 @@ #include #include +#include "../metadata/ctf-meta.h" + /** * @file ctf-btr.h * @@ -51,37 +53,40 @@ /** * Binary type reader API status codes. */ -enum bt_ctf_btr_status { +enum bt_btr_status { /** Out of memory. */ - BT_CTF_BTR_STATUS_ENOMEM = -5, + BT_BTR_STATUS_ENOMEM = -5, /** * The binary stream reader reached the end of the user-provided * buffer, but data is still needed to finish decoding the * requested type. * - * The user needs to call bt_ctf_btr_continue() as long as - * #BT_CTF_BTR_STATUS_EOF is returned to complete the decoding + * The user needs to call bt_btr_continue() as long as + * #BT_BTR_STATUS_EOF is returned to complete the decoding * process of a given type. */ - BT_CTF_BTR_STATUS_EOF = 1, + BT_BTR_STATUS_EOF = 1, /** Invalid argument. */ - BT_CTF_BTR_STATUS_INVAL = -3, + BT_BTR_STATUS_INVAL = -3, /** General error. */ - BT_CTF_BTR_STATUS_ERROR = -1, + BT_BTR_STATUS_ERROR = -1, /** Everything okay. */ - BT_CTF_BTR_STATUS_OK = 0, + BT_BTR_STATUS_OK = 0, }; /** Type reader. */ -struct bt_ctf_btr; +struct bt_btr; + +typedef enum bt_btr_status (* bt_btr_unsigned_int_cb_func)(uint64_t, + struct ctf_field_type *, void *); /* * Type reader user callback functions. */ -struct bt_ctf_btr_cbs { +struct bt_btr_cbs { /** * Type callback functions. * @@ -90,22 +95,20 @@ struct bt_ctf_btr_cbs { * a compound type begins/ends, or when a basic type is * completely decoded (along with its value). * - * Each function also receives the CTF IR field type associated + * Each function also receives the CTF field type associated * with the call, and user data (registered to the type reader - * calling them). This field type is a weak reference; the - * callback function must use bt_ctf_field_type_get() to keep - * its own reference of it. + * calling them). * - * Actual CTF IR fields are \em not created here; this would be - * the responsibility of a type reader's user (the provider of - * those callback functions). + * Actual trace IR fields are \em not created here; this would + * be the responsibility of a type reader's user (the provider + * of those callback functions). * * All the type callback functions return one of the following * values: * - * - #BT_CTF_BTR_STATUS_OK: Everything is okay; + * - #BT_BTR_STATUS_OK: Everything is okay; * continue the decoding process. - * - #BT_CTF_BTR_STATUS_ERROR: General error (reported + * - #BT_BTR_STATUS_ERROR: General error (reported * to type reader's user). * * Any member of this structure may be set to \c NULL, should @@ -119,14 +122,13 @@ struct bt_ctf_btr_cbs { * indicate this). * * @param value Signed integer value - * @param type Integer or enumeration type (weak - * reference) + * @param type Integer or enumeration type * @param data User data - * @returns #BT_CTF_BTR_STATUS_OK or - * #BT_CTF_BTR_STATUS_ERROR + * @returns #BT_BTR_STATUS_OK or + * #BT_BTR_STATUS_ERROR */ - enum bt_ctf_btr_status (* signed_int)(int64_t value, - struct bt_ctf_field_type *type, void *data); + enum bt_btr_status (* signed_int)(int64_t value, + struct ctf_field_type *type, void *data); /** * Called when an unsigned integer type is completely @@ -135,71 +137,68 @@ struct bt_ctf_btr_cbs { * indicate this). * * @param value Unsigned integer value - * @param type Integer or enumeration type (weak - * reference) + * @param type Integer or enumeration type * @param data User data - * @returns #BT_CTF_BTR_STATUS_OK or - * #BT_CTF_BTR_STATUS_ERROR + * @returns #BT_BTR_STATUS_OK or + * #BT_BTR_STATUS_ERROR */ - enum bt_ctf_btr_status (* unsigned_int)(uint64_t value, - struct bt_ctf_field_type *type, void *data); + bt_btr_unsigned_int_cb_func unsigned_int; /** * Called when a floating point number type is * completely decoded. * * @param value Floating point number value - * @param type Floating point number type (weak - * reference) + * @param type Floating point number type * @param data User data - * @returns #BT_CTF_BTR_STATUS_OK or - * #BT_CTF_BTR_STATUS_ERROR + * @returns #BT_BTR_STATUS_OK or + * #BT_BTR_STATUS_ERROR */ - enum bt_ctf_btr_status (* floating_point)(double value, - struct bt_ctf_field_type *type, void *data); + enum bt_btr_status (* floating_point)(double value, + struct ctf_field_type *type, void *data); /** * Called when a string type begins. * * All the following user callback function calls will - * be made to bt_ctf_btr_cbs::types::string(), each of + * be made to bt_btr_cbs::types::string(), each of * them providing one substring of the complete string * type's value. * - * @param type Beginning string type (weak reference) + * @param type Beginning string type * @param data User data - * @returns #BT_CTF_BTR_STATUS_OK or - * #BT_CTF_BTR_STATUS_ERROR + * @returns #BT_BTR_STATUS_OK or + * #BT_BTR_STATUS_ERROR */ - enum bt_ctf_btr_status (* string_begin)( - struct bt_ctf_field_type *type, void *data); + enum bt_btr_status (* string_begin)( + struct ctf_field_type *type, void *data); /** * Called when a string type's substring is decoded - * (between a call to bt_ctf_btr_cbs::types::string_begin() - * and a call to bt_ctf_btr_cbs::types::string_end()). + * (between a call to bt_btr_cbs::types::string_begin() + * and a call to bt_btr_cbs::types::string_end()). * * @param value String value (\em not null-terminated) * @param len String value length - * @param type String type (weak reference) + * @param type String type * @param data User data - * @returns #BT_CTF_BTR_STATUS_OK or - * #BT_CTF_BTR_STATUS_ERROR + * @returns #BT_BTR_STATUS_OK or + * #BT_BTR_STATUS_ERROR */ - enum bt_ctf_btr_status (* string)(const char *value, - size_t len, struct bt_ctf_field_type *type, + enum bt_btr_status (* string)(const char *value, + size_t len, struct ctf_field_type *type, void *data); /** * Called when a string type ends. * - * @param type Ending string type (weak reference) + * @param type Ending string type * @param data User data - * @returns #BT_CTF_BTR_STATUS_OK or - * #BT_CTF_BTR_STATUS_ERROR + * @returns #BT_BTR_STATUS_OK or + * #BT_BTR_STATUS_ERROR */ - enum bt_ctf_btr_status (* string_end)( - struct bt_ctf_field_type *type, void *data); + enum bt_btr_status (* string_end)( + struct ctf_field_type *type, void *data); /** * Called when a compound type begins. @@ -207,32 +206,32 @@ struct bt_ctf_btr_cbs { * All the following type callback function calls will * signal sequential elements of this compound type, * until the next corresponding - * bt_ctf_btr_cbs::types::compound_end() is called. + * bt_btr_cbs::types::compound_end() is called. * * If \p type is a variant type, then only one type * callback function call will follow before the call to - * bt_ctf_btr_cbs::types::compound_end(). This single + * bt_btr_cbs::types::compound_end(). This single * call indicates the selected type of this variant * type. * - * @param type Beginning compound type (weak reference) + * @param type Beginning compound type * @param data User data - * @returns #BT_CTF_BTR_STATUS_OK or - * #BT_CTF_BTR_STATUS_ERROR + * @returns #BT_BTR_STATUS_OK or + * #BT_BTR_STATUS_ERROR */ - enum bt_ctf_btr_status (* compound_begin)( - struct bt_ctf_field_type *type, void *data); + enum bt_btr_status (* compound_begin)( + struct ctf_field_type *type, void *data); /** * Called when a compound type ends. * - * @param type Ending compound type (weak reference) + * @param type Ending compound type * @param data User data - * @returns #BT_CTF_BTR_STATUS_OK or - * #BT_CTF_BTR_STATUS_ERROR + * @returns #BT_BTR_STATUS_OK or + * #BT_BTR_STATUS_ERROR */ - enum bt_ctf_btr_status (* compound_end)( - struct bt_ctf_field_type *type, void *data); + enum bt_btr_status (* compound_end)( + struct ctf_field_type *type, void *data); } types; /** @@ -248,25 +247,25 @@ struct bt_ctf_btr_cbs { * Called to query the current length of a given sequence * type. * - * @param type Sequence type (weak reference) + * @param type Sequence type * @param data User data * @returns Sequence length or - * #BT_CTF_BTR_STATUS_ERROR on error + * #BT_BTR_STATUS_ERROR on error */ - int64_t (* get_sequence_length)(struct bt_ctf_field_type *type, + int64_t (* get_sequence_length)(struct ctf_field_type *type, void *data); /** * Called to query the current selected type of a given * variant type. * - * @param type Variant type (weak reference) + * @param type Variant type * @param data User data * @returns Current selected type (owned by * this) or \c NULL on error */ - struct bt_ctf_field_type * (* get_variant_type)( - struct bt_ctf_field_type *type, void *data); + struct ctf_field_type * (* borrow_variant_selected_field_type)( + struct ctf_field_type *type, void *data); } query; }; @@ -277,14 +276,16 @@ struct bt_ctf_btr_cbs { * @param data User data (passed to user callback functions) * @returns New binary type reader on success, or \c NULL on error */ -struct bt_ctf_btr *bt_ctf_btr_create(struct bt_ctf_btr_cbs cbs, void *data); +BT_HIDDEN +struct bt_btr *bt_btr_create(struct bt_btr_cbs cbs, void *data); /** * Destroys a CTF binary type reader, freeing all internal resources. * * @param btr Binary type reader */ -void bt_ctf_btr_destroy(struct bt_ctf_btr *btr); +BT_HIDDEN +void bt_btr_destroy(struct bt_btr *btr); /** * Decodes a given CTF type from a buffer of bytes. @@ -294,21 +295,21 @@ void bt_ctf_btr_destroy(struct bt_ctf_btr *btr); * The \p status output parameter is where a status is written, amongst * the following: * - * - #BT_CTF_BTR_STATUS_OK: Decoding is done. - * - #BT_CTF_BTR_STATUS_EOF: The end of the buffer was reached, + * - #BT_BTR_STATUS_OK: Decoding is done. + * - #BT_BTR_STATUS_EOF: The end of the buffer was reached, * but more data is needed to finish the decoding process of the - * requested type. The user needs to call bt_ctf_btr_continue() - * as long as #BT_CTF_BTR_STATUS_EOF is returned to complete the + * requested type. The user needs to call bt_btr_continue() + * as long as #BT_BTR_STATUS_EOF is returned to complete the * decoding process of the original type. - * - #BT_CTF_BTR_STATUS_INVAL: Invalid argument. - * - #BT_CTF_BTR_STATUS_ERROR: General error. + * - #BT_BTR_STATUS_INVAL: Invalid argument. + * - #BT_BTR_STATUS_ERROR: General error. * * Calling this function resets the type reader's internal state. If - * #BT_CTF_BTR_STATUS_EOF is returned, bt_ctf_btr_continue() needs to - * be called next, \em not bt_ctf_btr_decode(). + * #BT_BTR_STATUS_EOF is returned, bt_btr_continue() needs to + * be called next, \em not bt_btr_decode(). * * @param btr Binary type reader - * @param type Type to decode (weak reference) + * @param type Type to decode * @param buf Buffer * @param offset Offset of first bit from \p buf (bits) * @param packet_offset Offset of \p offset within the CTF @@ -317,10 +318,11 @@ void bt_ctf_btr_destroy(struct bt_ctf_btr *btr); * @param status Returned status (see description above) * @returns Number of consumed bits */ -size_t bt_ctf_btr_start(struct bt_ctf_btr *btr, - struct bt_ctf_field_type *type, const uint8_t *buf, +BT_HIDDEN +size_t bt_btr_start(struct bt_btr *btr, + struct ctf_field_type *type, const uint8_t *buf, size_t offset, size_t packet_offset, size_t sz, - enum bt_ctf_btr_status *status); + enum bt_btr_status *status); /** * Continues the decoding process a given CTF type. @@ -330,14 +332,14 @@ size_t bt_ctf_btr_start(struct bt_ctf_btr *btr, * The \p status output parameter is where a status is placed, amongst * the following: * - * - #BT_CTF_BTR_STATUS_OK: decoding is done. - * - #BT_CTF_BTR_STATUS_EOF: the end of the buffer was reached, + * - #BT_BTR_STATUS_OK: decoding is done. + * - #BT_BTR_STATUS_EOF: the end of the buffer was reached, * but more data is needed to finish the decoding process of the - * requested type. The user needs to call bt_ctf_btr_continue() - * as long as #BT_CTF_BTR_STATUS_EOF is returned to complete the + * requested type. The user needs to call bt_btr_continue() + * as long as #BT_BTR_STATUS_EOF is returned to complete the * decoding process of the original type. - * - #BT_CTF_BTR_STATUS_INVAL: invalid argument. - * - #BT_CTF_BTR_STATUS_ERROR: general error. + * - #BT_BTR_STATUS_INVAL: invalid argument. + * - #BT_BTR_STATUS_ERROR: general error. * * @param btr Binary type reader * @param buf Buffer @@ -345,24 +347,29 @@ size_t bt_ctf_btr_start(struct bt_ctf_btr *btr, * @param status Returned status (see description above) * @returns Number of consumed bits */ -size_t bt_ctf_btr_continue(struct bt_ctf_btr *btr, +BT_HIDDEN +size_t bt_btr_continue(struct bt_btr *btr, const uint8_t *buf, size_t sz, - enum bt_ctf_btr_status *status); + enum bt_btr_status *status); + +BT_HIDDEN +void bt_btr_set_unsigned_int_cb(struct bt_btr *btr, + bt_btr_unsigned_int_cb_func cb); static inline -const char *bt_ctf_btr_status_string(enum bt_ctf_btr_status status) +const char *bt_btr_status_string(enum bt_btr_status status) { switch (status) { - case BT_CTF_BTR_STATUS_ENOMEM: - return "BT_CTF_BTR_STATUS_ENOMEM"; - case BT_CTF_BTR_STATUS_EOF: - return "BT_CTF_BTR_STATUS_EOF"; - case BT_CTF_BTR_STATUS_INVAL: - return "BT_CTF_BTR_STATUS_INVAL"; - case BT_CTF_BTR_STATUS_ERROR: - return "BT_CTF_BTR_STATUS_ERROR"; - case BT_CTF_BTR_STATUS_OK: - return "BT_CTF_BTR_STATUS_OK"; + case BT_BTR_STATUS_ENOMEM: + return "BT_BTR_STATUS_ENOMEM"; + case BT_BTR_STATUS_EOF: + return "BT_BTR_STATUS_EOF"; + case BT_BTR_STATUS_INVAL: + return "BT_BTR_STATUS_INVAL"; + case BT_BTR_STATUS_ERROR: + return "BT_BTR_STATUS_ERROR"; + case BT_BTR_STATUS_OK: + return "BT_BTR_STATUS_OK"; default: return "(unknown)"; }