From: Julien Desfossez Date: Sun, 12 Oct 2014 01:28:59 +0000 (-0400) Subject: babeltrace headers sync X-Git-Tag: v0.3~18 X-Git-Url: http://git.lttng.org/?p=lttngtop.git;a=commitdiff_plain;h=4a325d7e67f172698cbe7dbdcc05d4d59342e72b babeltrace headers sync Signed-off-by: Julien Desfossez --- diff --git a/lib/babeltrace/align.h b/lib/babeltrace/align.h index f6a1966..4f6a301 100644 --- a/lib/babeltrace/align.h +++ b/lib/babeltrace/align.h @@ -27,7 +27,7 @@ #include #include -#include +#include #ifndef PAGE_SIZE /* Cygwin limits.h defines its own PAGE_SIZE */ #define PAGE_SIZE sysconf(_SC_PAGE_SIZE) diff --git a/lib/babeltrace/bitfield.h b/lib/babeltrace/bitfield.h index b7fce09..6cf804e 100644 --- a/lib/babeltrace/bitfield.h +++ b/lib/babeltrace/bitfield.h @@ -28,7 +28,7 @@ */ #include /* C99 5.2.4.2 Numerical limits */ -#include /* C99 5.2.4.2 Numerical limits */ +#include /* C99 5.2.4.2 Numerical limits */ #include #include /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */ diff --git a/lib/babeltrace/compat/limits.h b/lib/babeltrace/compat/limits.h new file mode 100644 index 0000000..b276183 --- /dev/null +++ b/lib/babeltrace/compat/limits.h @@ -0,0 +1,46 @@ +#ifndef _BABELTRACE_LIMITS_H +#define _BABELTRACE_LIMITS_H + +/* + * Copyright (C) 2014 Jérémie Galarneau + * + * 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. + */ + +#include + +#ifdef __linux__ + +#define BABELTRACE_HOST_NAME_MAX HOST_NAME_MAX + +#elif defined(__FreeBSD__) + +#define BABELTRACE_HOST_NAME_MAX MAXHOSTNAMELEN + +#elif defined(_POSIX_HOST_NAME_MAX) + +#define BABELTRACE_HOST_NAME_MAX _POSIX_HOST_NAME_MAX + +#else + +#define BABELTRACE_HOST_NAME_MAX 256 + +#endif /* __linux__, __FreeBSD__, _POSIX_HOST_NAME_MAX */ + +#endif /* _BABELTRACE_LIMITS_H */ diff --git a/lib/babeltrace/ctf-ir/clock-internal.h b/lib/babeltrace/ctf-ir/clock-internal.h new file mode 100644 index 0000000..dc4d02e --- /dev/null +++ b/lib/babeltrace/ctf-ir/clock-internal.h @@ -0,0 +1,62 @@ +#ifndef BABELTRACE_CTF_IR_CLOCK_INTERNAL_H +#define BABELTRACE_CTF_IR_CLOCK_INTERNAL_H + +/* + * BabelTrace - CTF IR: Clock internal + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + */ + +#include +#include +#include +#include +#include +#include + +struct bt_ctf_clock { + struct bt_ctf_ref ref_count; + GString *name; + GString *description; + uint64_t frequency; + uint64_t precision; + uint64_t offset_s; /* Offset in seconds */ + uint64_t offset; /* Offset in ticks */ + uint64_t time; /* Current clock value */ + uuid_t uuid; + int absolute; + /* + * A clock's properties can't be modified once it is added to a stream + * class. + */ + int frozen; +}; + +BT_HIDDEN +void bt_ctf_clock_freeze(struct bt_ctf_clock *clock); + +BT_HIDDEN +void bt_ctf_clock_serialize(struct bt_ctf_clock *clock, + struct metadata_context *context); + +#endif /* BABELTRACE_CTF_IR_CLOCK_INTERNAL_H */ diff --git a/lib/babeltrace/ctf-ir/clock.h b/lib/babeltrace/ctf-ir/clock.h new file mode 100644 index 0000000..c1ae948 --- /dev/null +++ b/lib/babeltrace/ctf-ir/clock.h @@ -0,0 +1,253 @@ +#ifndef BABELTRACE_CTF_IR_CLOCK_H +#define BABELTRACE_CTF_IR_CLOCK_H + +/* + * BabelTrace - CTF IR: Clock + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + * + * The Common Trace Format (CTF) Specification is available at + * http://www.efficios.com/ctf + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_ctf_clock; + +/* + * bt_ctf_clock_create: create a clock. + * + * Allocate a new clock setting its reference count to 1. + * + * @param name Name of the clock (will be copied). + * + * Returns an allocated clock on success, NULL on error. + */ +extern struct bt_ctf_clock *bt_ctf_clock_create(const char *name); + +/* + * bt_ctf_clock_get_name: get a clock's name. + * + * Get the clock's name. + * + * @param clock Clock instance. + * + * Returns the clock's name, NULL on error. + */ +extern const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock); + +/* + * bt_ctf_clock_get_description: get a clock's description. + * + * Get the clock's description. + * + * @param clock Clock instance. + * + * Returns the clock's description, NULL if unset. + */ +extern const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock); + +/* + * bt_ctf_clock_set_description: set a clock's description. + * + * Set the clock's description. The description appears in the clock's TSDL + * meta-data. + * + * @param clock Clock instance. + * @param desc Description of the clock. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, + const char *desc); + +/* + * bt_ctf_clock_get_frequency: get a clock's frequency. + * + * Get the clock's frequency (Hz). + * + * @param clock Clock instance. + * + * Returns the clock's frequency, -1ULL on error. + */ +extern uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock); + +/* + * bt_ctf_clock_set_frequency: set a clock's frequency. + * + * Set the clock's frequency (Hz). + * + * @param clock Clock instance. + * @param freq Clock's frequency in Hz, defaults to 1 000 000 000 Hz (1ns). + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, + uint64_t freq); + +/* + * bt_ctf_clock_get_precision: get a clock's precision. + * + * Get the clock's precision (in clock ticks). + * + * @param clock Clock instance. + * + * Returns the clock's precision, -1ULL on error. + */ +extern uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock); + +/* + * bt_ctf_clock_set_precision: set a clock's precision. + * + * Set the clock's precision. + * + * @param clock Clock instance. + * @param precision Clock's precision in clock ticks, defaults to 1. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, + uint64_t precision); + +/* + * bt_ctf_clock_get_offset_s: get a clock's offset in seconds. + * + * Get the clock's offset in seconds from POSIX.1 Epoch, 1970-01-01. + * + * @param clock Clock instance. + * + * Returns the clock's offset in seconds, -1ULL on error. + */ +extern uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock); + +/* + * bt_ctf_clock_set_offset_s: set a clock's offset in seconds. + * + * Set the clock's offset in seconds from POSIX.1 Epoch, 1970-01-01, + * defaults to 0. + * + * @param clock Clock instance. + * @param offset_s Clock's offset in seconds, defaults to 0. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, + uint64_t offset_s); + +/* + * bt_ctf_clock_get_offset_s: get a clock's offset in ticks. + * + * Get the clock's offset in ticks from Epoch + offset_t. + * + * @param clock Clock instance. + * + * Returns the clock's offset in ticks from Epoch + offset_s, -1ULL on error. + */ +extern uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock); + +/* + * bt_ctf_clock_set_offset: set a clock's offset in ticks. + * + * Set the clock's offset in ticks from Epoch + offset_s. + * + * @param clock Clock instance. + * @param offset Clock's offset in ticks from Epoch + offset_s, defaults to 0. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, + uint64_t offset); + +/* + * bt_ctf_clock_get_is_absolute: get a clock's absolute attribute. + * + * Get the clock's absolute attribute. A clock is absolute if the clock is a + * global reference across the trace's other clocks. + * + * @param clock Clock instance. + * + * Returns the clock's absolute attribute, a negative value on error. + */ +extern int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock); + +/* + * bt_ctf_clock_set_is_absolute: set a clock's absolute attribute. + * + * Set the clock's absolute attribute. A clock is absolute if the clock is a + * global reference across the trace's other clocks. + * + * @param clock Clock instance. + * @param is_absolute Clock's absolute attribute, defaults to FALSE. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, + int is_absolute); + +/* + * bt_ctf_clock_get_time: get a clock's current time value. + * + * Get the current time in nanoseconds since the clock's origin (offset and + * offset_s attributes). + * + * Returns the clock's current time value, -1ULL on error. + */ +extern uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock); + +/* + * bt_ctf_clock_set_time: set a clock's current time value. + * + * Set the current time in nanoseconds since the clock's origin (offset and + * offset_s attributes). Defaults to 0. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, + uint64_t time); + +/* + * bt_ctf_clock_get and bt_ctf_clock_put: increment and decrement the + * refcount of the clock + * + * These functions ensure that the clock won't be destroyed when it + * is in use. The same number of get and put (plus one extra put to + * release the initial reference done at creation) has to be done to + * destroy a clock. + * + * When the clock refcount is decremented to 0 by a bt_ctf_clock_put, + * the clock is freed. + * + * @param clock Clock instance. + */ +extern void bt_ctf_clock_get(struct bt_ctf_clock *clock); +extern void bt_ctf_clock_put(struct bt_ctf_clock *clock); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_CTF_IR_CLOCK_H */ diff --git a/lib/babeltrace/ctf-ir/event-fields-internal.h b/lib/babeltrace/ctf-ir/event-fields-internal.h new file mode 100644 index 0000000..89b9496 --- /dev/null +++ b/lib/babeltrace/ctf-ir/event-fields-internal.h @@ -0,0 +1,105 @@ +#ifndef BABELTRACE_CTF_WRITER_EVENT_FIELDS_INTERNAL_H +#define BABELTRACE_CTF_WRITER_EVENT_FIELDS_INTERNAL_H + +/* + * BabelTrace - CTF Writer: Event Fields internal + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + */ + +#include +#include +#include +#include +#include + +struct bt_ctf_field { + struct bt_ctf_ref ref_count; + struct bt_ctf_field_type *type; + int payload_set; +}; + +struct bt_ctf_field_integer { + struct bt_ctf_field parent; + struct definition_integer definition; +}; + +struct bt_ctf_field_enumeration { + struct bt_ctf_field parent; + struct bt_ctf_field *payload; +}; + +struct bt_ctf_field_floating_point { + struct bt_ctf_field parent; + struct definition_float definition; + struct definition_integer sign, mantissa, exp; +}; + +struct bt_ctf_field_structure { + struct bt_ctf_field parent; + GHashTable *field_name_to_index; + GPtrArray *fields; /* Array of pointers to struct bt_ctf_field */ +}; + +struct bt_ctf_field_variant { + struct bt_ctf_field parent; + struct bt_ctf_field *tag; + struct bt_ctf_field *payload; +}; + +struct bt_ctf_field_array { + struct bt_ctf_field parent; + GPtrArray *elements; /* Array of pointers to struct bt_ctf_field */ +}; + +struct bt_ctf_field_sequence { + struct bt_ctf_field parent; + struct bt_ctf_field *length; + GPtrArray *elements; /* Array of pointers to struct bt_ctf_field */ +}; + +struct bt_ctf_field_string { + struct bt_ctf_field parent; + GString *payload; +}; + +/* + * Set a field's value with an already allocated field instance. + */ +BT_HIDDEN +int bt_ctf_field_structure_set_field(struct bt_ctf_field *structure, + const char *name, struct bt_ctf_field *value); + +/* Validate that the field's payload is set. */ +BT_HIDDEN +int bt_ctf_field_validate(struct bt_ctf_field *field); + +/* Mark field payload as unset. */ +BT_HIDDEN +int bt_ctf_field_reset(struct bt_ctf_field *field); + +BT_HIDDEN +int bt_ctf_field_serialize(struct bt_ctf_field *field, + struct ctf_stream_pos *pos); + +#endif /* BABELTRACE_CTF_WRITER_EVENT_FIELDS_INTERNAL_H */ diff --git a/lib/babeltrace/ctf-ir/event-fields.h b/lib/babeltrace/ctf-ir/event-fields.h new file mode 100644 index 0000000..e08e36b --- /dev/null +++ b/lib/babeltrace/ctf-ir/event-fields.h @@ -0,0 +1,322 @@ +#ifndef BABELTRACE_CTF_IR_EVENT_FIELDS_H +#define BABELTRACE_CTF_IR_EVENT_FIELDS_H + +/* + * BabelTrace - CTF IR: Event Fields + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + * + * The Common Trace Format (CTF) Specification is available at + * http://www.efficios.com/ctf + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_ctf_event_class; +struct bt_ctf_event; +struct bt_ctf_field; +struct bt_ctf_field_type; + +/* + * bt_ctf_field_create: create an instance of a field. + * + * Allocate a new field of the type described by the bt_ctf_field_type + * structure.The creation of a field sets its reference count to 1. + * + * @param type Field type to be instanciated. + * + * Returns an allocated field on success, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_field_create( + struct bt_ctf_field_type *type); + +/* + * bt_ctf_field_structure_get_field: get a structure's field. + * + * Get the structure's field corresponding to the provided field name. + * bt_ctf_field_put() must be called on the returned value. + * + * @param structure Structure field instance. + * @param name Name of the field in the provided structure. + * + * Returns a field instance on success, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_field_structure_get_field( + struct bt_ctf_field *structure, const char *name); + +/* + * bt_ctf_field_structure_get_field_by_index: get a structure's field by index. + * + * Get the structure's field corresponding to the provided field name. + * bt_ctf_field_put() must be called on the returned value. + * The indexes are the same as those provided for bt_ctf_field_type_structure. + * + * @param structure Structure field instance. + * @param index Index of the field in the provided structure. + * + * Returns a field instance on success, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index( + struct bt_ctf_field *structure, size_t index); + +/* + * bt_ctf_field_array_get_field: get an array's field at position "index". + * + * Return the array's field at position "index". bt_ctf_field_put() must be + * called on the returned value. + * + * @param array Array field instance. + * @param index Position of the array's desired element. + * + * Returns a field instance on success, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_field_array_get_field( + struct bt_ctf_field *array, uint64_t index); + +/* + * bt_ctf_field_sequence_get_length: get a sequence's length. + * + * Get the sequence's length field. + * + * @param sequence Sequence field instance. + * + * Returns a field instance on success, NULL if a length was never set. + */ +extern struct bt_ctf_field *bt_ctf_field_sequence_get_length( + struct bt_ctf_field *sequence); + +/* + * bt_ctf_field_sequence_set_length: set a sequence's length. + * + * Set the sequence's length field. + * + * @param sequence Sequence field instance. + * @param length_field Unsigned integer field instance indicating the + * sequence's length. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, + struct bt_ctf_field *length_field); + +/* + * bt_ctf_field_sequence_get_field: get a sequence's field at position "index". + * + * Return the sequence's field at position "index". The sequence's length must + * have been set prior to calling this function using + * bt_ctf_field_sequence_set_length(). + * bt_ctf_field_put() must be called on the returned value. + * + * @param array Sequence field instance. + * @param index Position of the sequence's desired element. + * + * Returns a field instance on success, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_field_sequence_get_field( + struct bt_ctf_field *sequence, uint64_t index); + +/* + * bt_ctf_field_variant_get_field: get a variant's selected field. + * + * Return the variant's selected field. The "tag" field is the selector enum + * field. bt_ctf_field_put() must be called on the returned value. + * + * @param variant Variant field instance. + * @param tag Selector enumeration field. + * + * Returns a field instance on success, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_field_variant_get_field( + struct bt_ctf_field *variant, struct bt_ctf_field *tag); + +/* + * bt_ctf_field_enumeration_get_container: get an enumeration field's container. + * + * Return the enumeration's underlying container field (an integer). + * bt_ctf_field_put() must be called on the returned value. + * + * @param enumeration Enumeration field instance. + * + * Returns a field instance on success, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_field_enumeration_get_container( + struct bt_ctf_field *enumeration); + +/* + * bt_ctf_field_enumeration_get_mapping_name: get an enumeration field's mapping + * name. + * + * Return the enumeration's underlying container field (an integer). + * bt_ctf_field_put() must be called on the returned value. + * + * @param enumeration Enumeration field instance. + * + * Returns a field instance on success, NULL on error. + */ +extern const char *bt_ctf_field_enumeration_get_mapping_name( + struct bt_ctf_field *enumeration); + +/* + * bt_ctf_field_signed_integer_get_value: get a signed integer field's value + * + * Get a signed integer field's value. + * + * @param integer Signed integer field instance. + * @param value Pointer to a signed integer where the value will be stored. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, + int64_t *value); + +/* + * bt_ctf_field_signed_integer_set_value: set a signed integer field's value + * + * Set a signed integer field's value. The value is checked to make sure it + * can be stored in the underlying field. + * + * @param integer Signed integer field instance. + * @param value Signed integer field value. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, + int64_t value); + +/* + * bt_ctf_field_unsigned_integer_get_value: get unsigned integer field's value + * + * Get an unsigned integer field's value. + * + * @param integer Unsigned integer field instance. + * @param value Pointer to an unsigned integer where the value will be stored. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, + uint64_t *value); + +/* + * bt_ctf_field_unsigned_integer_set_value: set unsigned integer field's value + * + * Set an unsigned integer field's value. The value is checked to make sure it + * can be stored in the underlying field. + * + * @param integer Unsigned integer field instance. + * @param value Unsigned integer field value. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, + uint64_t value); + +/* + * bt_ctf_field_floating_point_get_value: get a floating point field's value + * + * Get a floating point field's value. + * + * @param floating_point Floating point field instance. + * @param value Pointer to a double where the value will be stored. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_floating_point_get_value( + struct bt_ctf_field *floating_point, double *value); + +/* + * bt_ctf_field_floating_point_set_value: set a floating point field's value + * + * Set a floating point field's value. The underlying type may not support the + * double's full precision. + * + * @param floating_point Floating point field instance. + * @param value Floating point field value. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_floating_point_set_value( + struct bt_ctf_field *floating_point, + double value); + +/* + * bt_ctf_field_string_get_value: get a string field's value + * + * Get a string field's value. + * + * @param string_field String field instance. + * + * Returns the string's value, NULL if unset. + */ +extern const char *bt_ctf_field_string_get_value( + struct bt_ctf_field *string_field); + +/* + * bt_ctf_field_string_set_value: set a string field's value + * + * Set a string field's value. + * + * @param string_field String field instance. + * @param value String field value (will be copied). + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, + const char *value); + +/* + * bt_ctf_field_get_type: get a field's type + * + * @param field Field intance. + * + * Returns a field type instance on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_get_type( + struct bt_ctf_field *field); + +/* + * bt_ctf_field_get and bt_ctf_field_put: increment and decrement the + * field's reference count. + * + * These functions ensure that the field won't be destroyed when it + * is in use. The same number of get and put (plus one extra put to + * release the initial reference done at creation) have to be done to + * destroy a field. + * + * When the field's reference count is decremented to 0 by a bt_ctf_field_put, + * the field is freed. + * + * @param field Field instance. + */ +extern void bt_ctf_field_get(struct bt_ctf_field *field); +extern void bt_ctf_field_put(struct bt_ctf_field *field); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_CTF_IR_EVENT_FIELDS_H */ diff --git a/lib/babeltrace/ctf-ir/event-internal.h b/lib/babeltrace/ctf-ir/event-internal.h new file mode 100644 index 0000000..ac4cd6d --- /dev/null +++ b/lib/babeltrace/ctf-ir/event-internal.h @@ -0,0 +1,82 @@ +#ifndef BABELTRACE_CTF_IR_EVENT_INTERNAL_H +#define BABELTRACE_CTF_IR_EVENT_INTERNAL_H + +/* + * BabelTrace - CTF IR: Event internal + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + */ + +#include +#include +#include +#include +#include +#include + +struct bt_ctf_event_class { + struct bt_ctf_ref ref_count; + GQuark name; + int id_set; + uint32_t id; + struct bt_ctf_stream_class *stream_class; + /* Structure type containing the event's context */ + struct bt_ctf_field_type *context; + /* Structure type containing the event's fields */ + struct bt_ctf_field_type *fields; + int frozen; +}; + +struct bt_ctf_event { + struct bt_ctf_ref ref_count; + uint64_t timestamp; + struct bt_ctf_event_class *event_class; + struct bt_ctf_field *context_payload; + struct bt_ctf_field *fields_payload; +}; + +BT_HIDDEN +void bt_ctf_event_class_freeze(struct bt_ctf_event_class *event_class); + +BT_HIDDEN +int bt_ctf_event_class_set_stream_class(struct bt_ctf_event_class *event_class, + struct bt_ctf_stream_class *stream_class); + +BT_HIDDEN +int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class, + struct metadata_context *context); + +BT_HIDDEN +int bt_ctf_event_validate(struct bt_ctf_event *event); + +BT_HIDDEN +int bt_ctf_event_serialize(struct bt_ctf_event *event, + struct ctf_stream_pos *pos); + +BT_HIDDEN +int bt_ctf_event_set_timestamp(struct bt_ctf_event *event, uint64_t timestamp); + +BT_HIDDEN +uint64_t bt_ctf_event_get_timestamp(struct bt_ctf_event *event); + +#endif /* BABELTRACE_CTF_IR_EVENT_INTERNAL_H */ diff --git a/lib/babeltrace/ctf-ir/event-types-internal.h b/lib/babeltrace/ctf-ir/event-types-internal.h new file mode 100644 index 0000000..8d0477b --- /dev/null +++ b/lib/babeltrace/ctf-ir/event-types-internal.h @@ -0,0 +1,157 @@ +#ifndef BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H +#define BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H + +/* + * BabelTrace - CTF IR: Event types internal + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef void(*type_freeze_func)(struct bt_ctf_field_type *); +typedef int(*type_serialize_func)(struct bt_ctf_field_type *, + struct metadata_context *); + +struct bt_ctf_field_type { + struct bt_ctf_ref ref_count; + struct bt_declaration *declaration; + type_freeze_func freeze; + type_serialize_func serialize; + /* + * A type can't be modified once it is added to an event or after a + * a field has been instanciated from it. + */ + int frozen; +}; + +struct bt_ctf_field_type_integer { + struct bt_ctf_field_type parent; + struct declaration_integer declaration; +}; + +struct enumeration_mapping { + union { + uint64_t _unsigned; + int64_t _signed; + } range_start; + + union { + uint64_t _unsigned; + int64_t _signed; + } range_end; + GQuark string; +}; + +struct bt_ctf_field_type_enumeration { + struct bt_ctf_field_type parent; + struct bt_ctf_field_type *container; + GPtrArray *entries; /* Array of pointers to struct enum_mapping */ + struct declaration_enum declaration; +}; + +struct bt_ctf_field_type_floating_point { + struct bt_ctf_field_type parent; + struct declaration_float declaration; + struct declaration_integer sign; + struct declaration_integer mantissa; + struct declaration_integer exp; +}; + +struct structure_field { + GQuark name; + struct bt_ctf_field_type *type; +}; + +struct bt_ctf_field_type_structure { + struct bt_ctf_field_type parent; + GHashTable *field_name_to_index; + GPtrArray *fields; /* Array of pointers to struct structure_field */ + struct declaration_enum declaration; +}; + +struct bt_ctf_field_type_variant { + struct bt_ctf_field_type parent; + GString *tag_name; + struct bt_ctf_field_type_enumeration *tag; + GHashTable *field_name_to_index; + GPtrArray *fields; /* Array of pointers to struct structure_field */ + struct declaration_variant declaration; +}; + +struct bt_ctf_field_type_array { + struct bt_ctf_field_type parent; + struct bt_ctf_field_type *element_type; + unsigned int length; /* Number of elements */ + struct declaration_array declaration; +}; + +struct bt_ctf_field_type_sequence { + struct bt_ctf_field_type parent; + struct bt_ctf_field_type *element_type; + GString *length_field_name; + struct declaration_sequence declaration; +}; + +struct bt_ctf_field_type_string { + struct bt_ctf_field_type parent; + struct declaration_string declaration; +}; + +BT_HIDDEN +void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type); + +BT_HIDDEN +struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed( + struct bt_ctf_field_type_variant *variant, int64_t tag_value); + +BT_HIDDEN +struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned( + struct bt_ctf_field_type_variant *variant, uint64_t tag_value); + +BT_HIDDEN +int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type, + struct metadata_context *context); + +BT_HIDDEN +int bt_ctf_field_type_validate(struct bt_ctf_field_type *type); + +BT_HIDDEN +const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned( + struct bt_ctf_field_type_enumeration *enumeration_type, + uint64_t value); + +BT_HIDDEN +const char *bt_ctf_field_type_enumeration_get_mapping_name_signed( + struct bt_ctf_field_type_enumeration *enumeration_type, + int64_t value); + +#endif /* BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H */ diff --git a/lib/babeltrace/ctf-ir/event-types.h b/lib/babeltrace/ctf-ir/event-types.h new file mode 100644 index 0000000..96200ce --- /dev/null +++ b/lib/babeltrace/ctf-ir/event-types.h @@ -0,0 +1,742 @@ +#ifndef BABELTRACE_CTF_IR_EVENT_TYPES_H +#define BABELTRACE_CTF_IR_EVENT_TYPES_H + +/* + * BabelTrace - CTF IR: Event Types + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + * + * The Common Trace Format (CTF) Specification is available at + * http://www.efficios.com/ctf + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_ctf_event_class; +struct bt_ctf_event; +struct bt_ctf_field_type; +struct bt_ctf_field; + +enum bt_ctf_integer_base { + BT_CTF_INTEGER_BASE_UNKNOWN = -1, + BT_CTF_INTEGER_BASE_BINARY = 2, + BT_CTF_INTEGER_BASE_OCTAL = 8, + BT_CTF_INTEGER_BASE_DECIMAL = 10, + BT_CTF_INTEGER_BASE_HEXADECIMAL = 16, +}; + +enum bt_ctf_byte_order { + BT_CTF_BYTE_ORDER_UNKNOWN = -1, + BT_CTF_BYTE_ORDER_NATIVE = 0, + BT_CTF_BYTE_ORDER_LITTLE_ENDIAN, + BT_CTF_BYTE_ORDER_BIG_ENDIAN, + BT_CTF_BYTE_ORDER_NETWORK, +}; + +/* + * bt_ctf_field_type_integer_create: create an integer field type. + * + * Allocate a new integer field type of the given size. The creation of a field + * type sets its reference countto 1. + * + * @param size Integer field type size/length in bits. + * + * Returns an allocated field type on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_type_integer_create( + unsigned int size); + +/* + * bt_ctf_field_type_integer_get_size: get an integer type's size. + * + * Get an integer type's size. + * + * @param integer Integer type. + * + * Returns the integer type's size, a negative value on error. + */ +extern int bt_ctf_field_type_integer_get_size( + struct bt_ctf_field_type *integer); + +/* + * bt_ctf_field_type_integer_get_signed: get an integer type's signedness. + * + * Get an integer type's signedness attribute. + * + * @param integer Integer type. + * + * Returns the integer's signedness, a negative value on error. + */ +extern int bt_ctf_field_type_integer_get_signed( + struct bt_ctf_field_type *integer); + +/* + * bt_ctf_field_type_integer_set_signed: set an integer type's signedness. + * + * Set an integer type's signedness attribute. + * + * @param integer Integer type. + * @param is_signed Integer's signedness, defaults to FALSE. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_integer_set_signed( + struct bt_ctf_field_type *integer, int is_signed); + +/* + * bt_ctf_field_type_integer_get_base: get an integer type's base. + * + * Get an integer type's base used to pretty-print the resulting trace. + * + * @param integer Integer type. + * + * Returns the integer type's base on success, BT_CTF_INTEGER_BASE_UNKNOWN on + * error. + */ +extern enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base( + struct bt_ctf_field_type *integer); + +/* + * bt_ctf_field_type_integer_set_base: set an integer type's base. + * + * Set an integer type's base used to pretty-print the resulting trace. + * + * @param integer Integer type. + * @param base Integer base, defaults to BT_CTF_INTEGER_BASE_DECIMAL. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, + enum bt_ctf_integer_base base); + +/* + * bt_ctf_field_type_integer_get_encoding: get an integer type's encoding. + * + * @param integer Integer type. + * + * Returns the string field's encoding on success, CTF_STRING_UNKNOWN on error. + */ +extern enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding( + struct bt_ctf_field_type *integer); + +/* + * bt_ctf_field_type_integer_set_encoding: set an integer type's encoding. + * + * An integer encoding may be set to signal that the integer must be printed as + * a text character. + * + * @param integer Integer type. + * @param encoding Integer output encoding, defaults to CTF_STRING_ENCODING_NONE + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_integer_set_encoding( + struct bt_ctf_field_type *integer, + enum ctf_string_encoding encoding); + +/* + * bt_ctf_field_type_enumeration_create: create an enumeration field type. + * + * Allocate a new enumeration field type with the given underlying type. The + * creation of a field type sets its reference count to 1. + * The resulting enumeration will share the integer_container_type's ownership + * by increasing its reference count. + * + * @param integer_container_type Underlying integer type of the enumeration + * type. + * + * Returns an allocated field type on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create( + struct bt_ctf_field_type *integer_container_type); + +/* + * bt_ctf_field_type_enumeration_get_container_type: get underlying container. + * + * Get the enumeration type's underlying integer container type. + * + * @param enumeration Enumeration type. + * + * Returns an allocated field type on success, NULL on error. + */ +extern +struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type( + struct bt_ctf_field_type *enumeration); + +/* + * bt_ctf_field_type_enumeration_add_mapping: add an enumeration mapping. + * + * Add a mapping to the enumeration. The range's values are inclusive. + * + * @param enumeration Enumeration type. + * @param name Enumeration mapping name (will be copied). + * @param range_start Enumeration mapping range start. + * @param range_end Enumeration mapping range end. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_enumeration_add_mapping( + struct bt_ctf_field_type *enumeration, const char *name, + int64_t range_start, int64_t range_end); + +/* + * bt_ctf_field_type_enumeration_add_mapping_unsigned: add an enumeration + * mapping. + * + * Add a mapping to the enumeration. The range's values are inclusive. + * + * @param enumeration Enumeration type. + * @param name Enumeration mapping name (will be copied). + * @param range_start Enumeration mapping range start. + * @param range_end Enumeration mapping range end. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_enumeration_add_mapping_unsigned( + struct bt_ctf_field_type *enumeration, const char *name, + uint64_t range_start, uint64_t range_end); + +/* + * bt_ctf_field_type_enumeration_get_mapping_count: Get the number of mappings + * defined in the enumeration. + * + * @param enumeration Enumeration type. + * + * Returns the mapping count on success, a negative value on error. + */ +extern int64_t bt_ctf_field_type_enumeration_get_mapping_count( + struct bt_ctf_field_type *enumeration); + +/* + * bt_ctf_field_type_enumeration_get_mapping: get an enumeration mapping. + * + * @param enumeration Enumeration type. + * @param index Index of mapping. + * @param name Pointer where the mapping's name will be returned (valid for + * the lifetime of the enumeration). + * @param range_start Pointer where the enumeration mapping's range start will + * be returned. + * @param range_end Pointer where the enumeration mapping's range end will + * be returned. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_enumeration_get_mapping( + struct bt_ctf_field_type *enumeration, size_t index, + const char **name, int64_t *range_start, int64_t *range_end); + +/* + * bt_ctf_field_type_enumeration_get_mapping_unsigned: get a mapping. + * + * @param enumeration Enumeration type. + * @param index Index of mapping. + * @param name Pointer where the mapping's name will be returned (valid for + * the lifetime of the enumeration). + * @param range_start Pointer where the enumeration mapping's range start will + * be returned. + * @param range_end Pointer where the enumeration mapping's range end will + * be returned. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_enumeration_get_mapping_unsigned( + struct bt_ctf_field_type *enumeration, size_t index, + const char **name, uint64_t *range_start, + uint64_t *range_end); + +/* + * bt_ctf_field_type_enumeration_get_mapping_index_by_name: get an enumerations' + * mapping index by name. + * + * @param enumeration Enumeration type. + * @param name Mapping name. + * @param index Pointer where the enumeration's mapping index will be returned. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_enumeration_get_mapping_index_by_name( + struct bt_ctf_field_type *enumeration, const char *name, + size_t *index); + +/* + * bt_ctf_field_type_enumeration_get_mapping_index_by_value: get an + * enumerations' mapping index by value. + * + * @param enumeration Enumeration type. + * @param value Value. + * @param index Pointer where the enumeration's mapping index will be returned. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_enumeration_get_mapping_index_by_value( + struct bt_ctf_field_type *enumeration, int64_t value, + size_t *index); + +/* + * bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value: get an + * enumerations' mapping index by value. + * + * @param enumeration Enumeration type. + * @param value Value. + * @param index Pointer where the enumeration's mapping index will be returned. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value( + struct bt_ctf_field_type *enumeration, uint64_t value, + size_t *index); + +/* + * bt_ctf_field_type_floating_point_create: create a floating point field type. + * + * Allocate a new floating point field type. The creation of a field type sets + * its reference count to 1. + * + * Returns an allocated field type on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void); + +/* + * bt_ctf_field_type_floating_point_get_exponent_digits: get exponent digit + * count. + * + * @param floating_point Floating point type. + * + * Returns the exponent digit count on success, a negative value on error. + */ +extern int bt_ctf_field_type_floating_point_get_exponent_digits( + struct bt_ctf_field_type *floating_point); + +/* + * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit + * count. + * + * Set the number of exponent digits to use to store the floating point field. + * The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG. + * + * @param floating_point Floating point type. + * @param exponent_digits Number of digits to allocate to the exponent (defaults + * to FLT_EXP_DIG). + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_floating_point_set_exponent_digits( + struct bt_ctf_field_type *floating_point, + unsigned int exponent_digits); + +/* + * bt_ctf_field_type_floating_point_get_mantissa_digits: get mantissa digit + * count. + * + * @param floating_point Floating point type. + * + * Returns the mantissa digit count on success, a negative value on error. + */ +extern int bt_ctf_field_type_floating_point_get_mantissa_digits( + struct bt_ctf_field_type *floating_point); + +/* + * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit + * count. + * + * Set the number of mantissa digits to use to store the floating point field. + * The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG. + * + * @param floating_point Floating point type. + * @param mantissa_digits Number of digits to allocate to the mantissa (defaults + * to FLT_MANT_DIG). + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_floating_point_set_mantissa_digits( + struct bt_ctf_field_type *floating_point, + unsigned int mantissa_digits); + +/* + * bt_ctf_field_type_structure_create: create a structure field type. + * + * Allocate a new structure field type. The creation of a field type sets + * its reference count to 1. + * + * Returns an allocated field type on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void); + +/* + * bt_ctf_field_type_structure_add_field: add a field to a structure. + * + * Add a field of type "field_type" to the structure. The structure will share + * field_type's ownership by increasing its reference count. + * + * @param structure Structure type. + * @param field_type Type of the field to add to the structure type. + * @param field_name Name of the structure's new field (will be copied). + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_structure_add_field( + struct bt_ctf_field_type *structure, + struct bt_ctf_field_type *field_type, + const char *field_name); + +/* + * bt_ctf_field_type_structure_get_field_count: Get the number of fields defined + * in the structure. + * + * @param structure Structure type. + * + * Returns the field count on success, a negative value on error. + */ +extern int64_t bt_ctf_field_type_structure_get_field_count( + struct bt_ctf_field_type *structure); + +/* + * bt_ctf_field_type_structure_get_field: get a structure's field type and name. + * + * @param structure Structure type. + * @param field_type Pointer to a const char* where the field's name will + * be returned. + * @param field_type Pointer to a bt_ctf_field_type* where the field's type will + * be returned. + * @param index Index of field. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_structure_get_field( + struct bt_ctf_field_type *structure, + const char **field_name, struct bt_ctf_field_type **field_type, + size_t index); + +/* + * bt_ctf_field_type_structure_get_field_type_by_name: get a structure field's + * type by name. + * + * @param structure Structure type. + * @param field_name Name of the structure's field. + * + * Returns a field type instance on success, NULL on error. + */ +extern +struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name( + struct bt_ctf_field_type *structure, const char *field_name); + +/* + * bt_ctf_field_type_variant_create: create a variant field type. + * + * Allocate a new variant field type. The creation of a field type sets + * its reference count to 1. tag_name must be the name of an enumeration + * field declared in the same scope as this variant. + * + * @param enum_tag Type of the variant's tag/selector (must be an enumeration). + * @param tag_name Name of the variant's tag/selector field (will be copied). + * + * Returns an allocated field type on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_type_variant_create( + struct bt_ctf_field_type *enum_tag, const char *tag_name); + +/* + * bt_ctf_field_type_variant_get_tag_type: get a variant's tag type. + * + * @param variant Variant type. + * + * Returns a field type instance on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type( + struct bt_ctf_field_type *variant); + +/* + * bt_ctf_field_type_variant_get_tag_name: get a variant's tag name. + * + * @param variant Variant type. + * + * Returns the tag field's name, NULL on error. + */ +extern const char *bt_ctf_field_type_variant_get_tag_name( + struct bt_ctf_field_type *variant); + +/* + * bt_ctf_field_type_variant_add_field: add a field to a variant. + * + * Add a field of type "field_type" to the variant. The variant will share + * field_type's ownership by increasing its reference count. The "field_name" + * will be copied. field_name must match a mapping in the tag/selector + * enumeration. + * + * @param variant Variant type. + * @param field_type Type of the variant type's new field. + * @param field_name Name of the variant type's new field (will be copied). + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_variant_add_field( + struct bt_ctf_field_type *variant, + struct bt_ctf_field_type *field_type, + const char *field_name); + +/* + * bt_ctf_field_type_variant_get_field_type_by_name: get variant field's type. + * + * @param structure Variant type. + * @param field_name Name of the variant's field. + * + * Returns a field type instance on success, NULL on error. + */ +extern +struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name( + struct bt_ctf_field_type *variant, const char *field_name); + +/* + * bt_ctf_field_type_variant_get_field_type_from_tag: get variant field's type. + * + * @param variant Variant type. + * @param tag Type tag (enum). + * + * Returns a field type instance on success, NULL on error. + */ +extern +struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag( + struct bt_ctf_field_type *variant, struct bt_ctf_field *tag); + +/* + * bt_ctf_field_type_variant_get_field_count: Get the number of fields defined + * in the variant. + * + * @param variant Variant type. + * + * Returns the field count on success, a negative value on error. + */ +extern int64_t bt_ctf_field_type_variant_get_field_count( + struct bt_ctf_field_type *variant); + +/* + * bt_ctf_field_type_variant_get_field: get a variant's field name and type. + * + * @param variant Variant type. + * @param field_type Pointer to a const char* where the field's name will + * be returned. + * @param field_type Pointer to a bt_ctf_field_type* where the field's type will + * be returned. + * @param index Index of field. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_variant_get_field( + struct bt_ctf_field_type *variant, const char **field_name, + struct bt_ctf_field_type **field_type, size_t index); + +/* + * bt_ctf_field_type_array_create: create an array field type. + * + * Allocate a new array field type. The creation of a field type sets + * its reference count to 1. + * + * @param element_type Array's element type. + * @oaram length Array type's length. + * + * Returns an allocated field type on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_type_array_create( + struct bt_ctf_field_type *element_type, unsigned int length); + +/* + * bt_ctf_field_type_array_get_element_type: get an array's element type. + * + * @param array Array type. + * + * Returns a field type instance on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type( + struct bt_ctf_field_type *array); + +/* + * bt_ctf_field_type_array_get_length: get an array's length. + * + * @param array Array type. + * + * Returns the array's length on success, a negative value on error. + */ +extern int64_t bt_ctf_field_type_array_get_length( + struct bt_ctf_field_type *array); + +/* + * bt_ctf_field_type_sequence_create: create a sequence field type. + * + * Allocate a new sequence field type. The creation of a field type sets + * its reference count to 1. "length_field_name" must match an integer field + * declared in the same scope. + * + * @param element_type Sequence's element type. + * @param length_field_name Name of the sequence's length field (will be + * copied). + * + * Returns an allocated field type on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_create( + struct bt_ctf_field_type *element_type, + const char *length_field_name); + +/* + * bt_ctf_field_type_sequence_get_element_type: get a sequence's element type. + * + * @param sequence Sequence type. + * + * Returns a field type instance on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type( + struct bt_ctf_field_type *sequence); + +/* + * bt_ctf_field_type_sequence_get_length_field_name: get length field name. + * + * @param sequence Sequence type. + * + * Returns the sequence's length field on success, NULL on error. + */ +extern const char *bt_ctf_field_type_sequence_get_length_field_name( + struct bt_ctf_field_type *sequence); + +/* + * bt_ctf_field_type_string_create: create a string field type. + * + * Allocate a new string field type. The creation of a field type sets + * its reference count to 1. + * + * Returns an allocated field type on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_field_type_string_create(void); + +/* + * bt_ctf_field_type_string_get_encoding: get a string type's encoding. + * + * Get the string type's encoding. + * + * @param string_type String type. + * + * Returns the string's encoding on success, a CTF_STRING_UNKNOWN on error. + */ +extern enum ctf_string_encoding bt_ctf_field_type_string_get_encoding( + struct bt_ctf_field_type *string_type); + +/* + * bt_ctf_field_type_string_set_encoding: set a string type's encoding. + * + * Set the string type's encoding. + * + * @param string_type String type. + * @param encoding String field encoding, default CTF_STRING_ENCODING_ASCII. + * Valid values are CTF_STRING_ENCODING_ASCII and CTF_STRING_ENCODING_UTF8. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_string_set_encoding( + struct bt_ctf_field_type *string_type, + enum ctf_string_encoding encoding); + +/* + * bt_ctf_field_type_get_alignment: get a field type's alignment. + * + * Get the field type's alignment. + * + * @param type Field type. + * + * Returns the field type's alignment on success, a negative value on error. + */ +extern int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type); + +/* + * bt_ctf_field_type_set_alignment: set a field type's alignment. + * + * Set the field type's alignment. + * + * @param type Field type. + * @param alignment Type's alignment. Defaults to 1 (bit-aligned). However, + * some types, such as structures and string, may impose other alignment + * constraints. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, + unsigned int alignment); + +/* + * bt_ctf_field_type_get_byte_order: get a field type's byte order. + * + * @param type Field type. + * + * Returns the field type's byte order on success, a negative value on error. + */ +extern enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order( + struct bt_ctf_field_type *type); + +/* + * bt_ctf_field_type_set_byte_order: set a field type's byte order. + * + * Set the field type's byte order. + * + * @param type Field type. + * @param byte_order Field type's byte order. Defaults to + * BT_CTF_BYTE_ORDER_NATIVE, the host machine's endianness. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, + enum bt_ctf_byte_order byte_order); + +/* + * bt_ctf_field_type_get_type_id: get a field type's ctf_type_id. + * + * @param type Field type. + * + * Returns the field type's ctf_type_id, CTF_TYPE_UNKNOWN on error. + */ +extern enum ctf_type_id bt_ctf_field_type_get_type_id( + struct bt_ctf_field_type *type); + +/* + * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement + * the field type's reference count. + * + * These functions ensure that the field type won't be destroyed while it + * is in use. The same number of get and put (plus one extra put to + * release the initial reference done at creation) have to be done to + * destroy a field type. + * + * When the field type's reference count is decremented to 0 by a + * bt_ctf_field_type_put, the field type is freed. + * + * @param type Field type. + */ +extern void bt_ctf_field_type_get(struct bt_ctf_field_type *type); +extern void bt_ctf_field_type_put(struct bt_ctf_field_type *type); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_CTF_IR_EVENT_TYPES_H */ diff --git a/lib/babeltrace/ctf-ir/event.h b/lib/babeltrace/ctf-ir/event.h new file mode 100644 index 0000000..7daab39 --- /dev/null +++ b/lib/babeltrace/ctf-ir/event.h @@ -0,0 +1,277 @@ +#ifndef BABELTRACE_CTF_IR_EVENT_H +#define BABELTRACE_CTF_IR_EVENT_H + +/* + * BabelTrace - CTF IR: Event + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + * + * The Common Trace Format (CTF) Specification is available at + * http://www.efficios.com/ctf + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_ctf_event_class; +struct bt_ctf_event; +struct bt_ctf_field; +struct bt_ctf_field_type; +struct bt_ctf_stream_class; + +/* + * bt_ctf_event_class_create: create an event class. + * + * Allocate a new event class of the given name. The creation of an event class + * sets its reference count to 1. A unique event id is automatically assigned + * to the event class. + * + * @param name Event class name (will be copied). + * + * Returns an allocated event class on success, NULL on error. + */ +extern struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name); + +/* + * bt_ctf_event_class_get_name: Get an event class' name. + * + * @param event_class Event class. + * + * Returns the event class' name, NULL on error. + */ +extern const char *bt_ctf_event_class_get_name( + struct bt_ctf_event_class *event_class); + +/* + * bt_ctf_event_class_get_id: Get an event class' id. + * + * @param event_class Event class. + * + * Returns the event class' id, a negative value on error. + */ +extern int64_t bt_ctf_event_class_get_id( + struct bt_ctf_event_class *event_class); + +/* + * bt_ctf_event_class_set_id: Set an event class' id. + * + * Set an event class' id. Must be unique stream-wise. + * Note that event classes are already assigned a unique id when added to a + * stream class if none was set explicitly. + * + * @param event_class Event class. + * @param id Event class id. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_event_class_set_id( + struct bt_ctf_event_class *event_class, uint32_t id); + +/* + * bt_ctf_event_class_get_stream_class: Get an event class' stream class. + * + * @param event_class Event class. + * + * Returns the event class' stream class, NULL on error or if the event class + * is not associated with a stream class. + */ +extern struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class( + struct bt_ctf_event_class *event_class); + +/* + * bt_ctf_event_class_add_field: add a field to an event class. + * + * Add a field of type "type" to the event class. The event class will share + * type's ownership by increasing its reference count. The "name" will be + * copied. + * + * @param event_class Event class. + * @param type Field type to add to the event class. + * @param name Name of the new field. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, + struct bt_ctf_field_type *type, + const char *name); + +/* + * bt_ctf_event_class_get_field_count: Get an event class' field count. + * + * @param event_class Event class. + * + * Returns the event class' field count, a negative value on error. + */ +extern int64_t bt_ctf_event_class_get_field_count( + struct bt_ctf_event_class *event_class); + +/* + * bt_ctf_event_class_get_field: Get event class' field type and name by index. + * + * @param event_class Event class. + * @param field_name Pointer to a const char* where the field's name will + * be returned. + * @param field_type Pointer to a bt_ctf_field_type* where the field's type will + * be returned. + * @param index Index of field. + * + * Returns 0 on success, a negative error on value. + */ +extern int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, + const char **field_name, struct bt_ctf_field_type **field_type, + size_t index); + +/* + * bt_ctf_event_class_get_field_type_by_name: Get an event class's field by name + * + * @param event_class Event class. + * @param name Name of the field. + * + * Returns a field type on success, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name( + struct bt_ctf_event_class *event_class, const char *name); + +/* + * bt_ctf_event_class__get and bt_ctf_event_class_put: increment and decrement + * the event class' reference count. + * + * These functions ensure that the event class won't be destroyed while it + * is in use. The same number of get and put (plus one extra put to + * release the initial reference done at creation) have to be done to + * destroy an event class. + * + * When the event class' reference count is decremented to 0 by a + * bt_ctf_event_class_put, the event class is freed. + * + * @param event_class Event class. + */ +extern void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class); +extern void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class); + +/* + * bt_ctf_event_create: instanciate an event. + * + * Allocate a new event of the given event class. The creation of an event + * sets its reference count to 1. Each instance shares the ownership of the + * event class using its reference count. + * + * @param event_class Event class. + * + * Returns an allocated field type on success, NULL on error. + */ +extern struct bt_ctf_event *bt_ctf_event_create( + struct bt_ctf_event_class *event_class); + +/* + * bt_ctf_event_get_class: get an event's class. + * + * @param event Event. + * + * Returns the event's class, NULL on error. + */ +extern struct bt_ctf_event_class *bt_ctf_event_get_class( + struct bt_ctf_event *event); + +/* + * bt_ctf_event_get_clock: get an event's associated clock. + * + * @param event Event. + * + * Returns the event's clock, NULL on error. + */ +extern struct bt_ctf_clock *bt_ctf_event_get_clock( + struct bt_ctf_event *event); + +/* + * bt_ctf_event_get_payload: get an event's field. + * + * Returns the field matching "name". bt_ctf_field_put() must be called on the + * returned value. + * + * @param event Event instance. + * @param name Event field name. + * + * Returns a field instance on success, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, + const char *name); + +/* + * bt_ctf_event_set_payload: set an event's field. + * + * Set a manually allocated field as an event's payload. The event will share + * the field's ownership by using its reference count. + * bt_ctf_field_put() must be called on the returned value. + * + * @param event Event instance. + * @param name Event field name. + * @param value Instance of a field whose type corresponds to the event's field. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_event_set_payload(struct bt_ctf_event *event, + const char *name, + struct bt_ctf_field *value); + +/* + * bt_ctf_event_get_payload_by_index: Get event's field by index. + * + * Returns the field associated with the provided index. bt_ctf_field_put() + * must be called on the returned value. The indexes to be provided are + * the same as can be retrieved from the event class. + * + * @param event Event. + * @param index Index of field. + * + * Returns the event's field, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_event_get_payload_by_index( + struct bt_ctf_event *event, size_t index); + +/* + * bt_ctf_event_get and bt_ctf_event_put: increment and decrement + * the event's reference count. + * + * These functions ensure that the event won't be destroyed while it + * is in use. The same number of get and put (plus one extra put to + * release the initial reference done at creation) have to be done to + * destroy an event. + * + * When the event's reference count is decremented to 0 by a + * bt_ctf_event_put, the event is freed. + * + * @param event Event instance. + */ +extern void bt_ctf_event_get(struct bt_ctf_event *event); +extern void bt_ctf_event_put(struct bt_ctf_event *event); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_CTF_IR_EVENT_H */ diff --git a/lib/babeltrace/ctf-ir/stream-class-internal.h b/lib/babeltrace/ctf-ir/stream-class-internal.h new file mode 100644 index 0000000..67a9d17 --- /dev/null +++ b/lib/babeltrace/ctf-ir/stream-class-internal.h @@ -0,0 +1,66 @@ +#ifndef BABELTRACE_CTF_IR_STREAM_CLASS_INTERNAL_H +#define BABELTRACE_CTF_IR_STREAM_CLASS_INTERNAL_H + +/* + * BabelTrace - CTF IR: Stream class internal + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +struct bt_ctf_stream_class { + struct bt_ctf_ref ref_count; + GString *name; + struct bt_ctf_clock *clock; + GPtrArray *event_classes; /* Array of pointers to bt_ctf_event_class */ + int id_set; + uint32_t id; + uint32_t next_event_id; + uint32_t next_stream_id; + struct bt_ctf_field_type *event_header_type; + struct bt_ctf_field *event_header; + struct bt_ctf_field_type *packet_context_type; + struct bt_ctf_field_type *event_context_type; + struct bt_ctf_field *event_context; + int frozen; +}; + +BT_HIDDEN +void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class); + +BT_HIDDEN +int bt_ctf_stream_class_serialize(struct bt_ctf_stream_class *stream_class, + struct metadata_context *context); + +BT_HIDDEN +int bt_ctf_stream_class_set_byte_order(struct bt_ctf_stream_class *stream_class, + enum bt_ctf_byte_order byte_order); + +#endif /* BABELTRACE_CTF_IR_STREAM_CLASS_INTERNAL_H */ diff --git a/lib/babeltrace/ctf-ir/stream-class.h b/lib/babeltrace/ctf-ir/stream-class.h new file mode 100644 index 0000000..5c5918d --- /dev/null +++ b/lib/babeltrace/ctf-ir/stream-class.h @@ -0,0 +1,217 @@ +#ifndef BABELTRACE_CTF_IR_STREAM_CLASS_H +#define BABELTRACE_CTF_IR_STREAM_CLASS_H + +/* + * BabelTrace - CTF IR: Stream Class + * + * Copyright 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + * + * The Common Trace Format (CTF) Specification is available at + * http://www.efficios.com/ctf + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_ctf_event_class; +struct bt_ctf_stream_class; +struct bt_ctf_clock; + +/* + * bt_ctf_stream_class_create: create a stream class. + * + * Allocate a new stream class of the given name. The creation of an event class + * sets its reference count to 1. + * + * A stream class' packet context is a structure initialized with the following + * fields: + * - uint64_t timestamp_begin + * - uint64_t timestamp_end + * - uint64_t content_size + * - uint64_t packet_size + * - uint64_t events_discarded + * + * @param name Stream name. + * + * Returns an allocated stream class on success, NULL on error. + */ +extern struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name); + +/* + * bt_ctf_stream_class_get_name: Get a stream class' name. + * + * @param stream_class Stream class. + * + * Returns the stream class' name, NULL on error. + */ +extern const char *bt_ctf_stream_class_get_name( + struct bt_ctf_stream_class *stream_class); + +/* + * bt_ctf_stream_class_get_clock: get the clock associated with a stream class. + * + * @param stream_class Stream class. + * + * Returns a clock instance, NULL on error. + */ +extern struct bt_ctf_clock *bt_ctf_stream_class_get_clock( + struct bt_ctf_stream_class *stream_class); + +/* + * bt_ctf_stream_class_set_clock: assign a clock to a stream class. + * + * Assign a clock to a stream class. This clock will be sampled each time an + * event is appended to an instance of this stream class. + * + * @param stream_class Stream class. + * @param clock Clock to assign to the provided stream class. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_stream_class_set_clock( + struct bt_ctf_stream_class *stream_class, + struct bt_ctf_clock *clock); + +/* + * bt_ctf_stream_class_get_id: Get a stream class' id. + * + * @param stream_class Stream class. + * + * Returns the stream class' id, a negative value on error. + */ +extern int64_t bt_ctf_stream_class_get_id( + struct bt_ctf_stream_class *stream_class); + +/* + * bt_ctf_stream_class_set_id: Set a stream class' id. + * + * Set a stream class' id. Must be unique trace-wise. + * Note that stream classes are assigned a unique id when a stream instance + * is created for the first time from a trace or writer. + * + * @param stream_class Stream class. + * @param id Stream class id. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_stream_class_set_id( + struct bt_ctf_stream_class *stream_class, uint32_t id); + +/* + * bt_ctf_stream_class_set_clock: assign a clock to a stream class. + * + * Add an event class to a stream class. New events can be added even after a + * stream has beem instanciated and events have been appended. However, a stream + * will not accept events of a class that has not been registered beforehand. + * The stream class will share the ownership of "event_class" by incrementing + * its reference count. + * + * @param stream_class Stream class. + * @param event_class Event class to add to the provided stream class. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_stream_class_add_event_class( + struct bt_ctf_stream_class *stream_class, + struct bt_ctf_event_class *event_class); + +/* + * bt_ctf_stream_class_get_event_class_count: Get a stream class' event class + * count. + * + * @param stream_class Stream class. + * + * Returns the stream class' event count, a negative value on error. + */ +extern int64_t bt_ctf_stream_class_get_event_class_count( + struct bt_ctf_stream_class *stream_class); + +/* + * bt_ctf_stream_class_get_event_class: Get stream class event class by index. + * + * @param stream_class Stream class. + * @param index Index of field. + * + * Returns event class, NULL on error. + */ +extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class( + struct bt_ctf_stream_class *stream_class, size_t index); + +/* + * bt_ctf_stream_class_get_event_class_by_name: Get stream class event class by + * name. + * + * @param stream_class Stream class. + * @param name Event name. + * + * Returns event class, NULL on error. + */ +extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name( + struct bt_ctf_stream_class *stream_class, const char *name); + +/* + * bt_ctf_stream_class_get_packet_context_type: get the stream class' packet + * context type. + * + * @param stream_class Stream class. + * + * Returns the packet context's type, NULL on error. + */ +extern struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type( + struct bt_ctf_stream_class *stream_class); + +/* + * bt_ctf_stream_class_set_packet_context_type: set the stream class' packet + * context type. + * + * @param stream_class Stream class. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_stream_class_set_packet_context_type( + struct bt_ctf_stream_class *stream_class, + struct bt_ctf_field_type *packet_context_type); + +/* + * bt_ctf_stream_class_get and bt_ctf_stream_class_put: increment and + * decrement the stream class' reference count. + * + * These functions ensure that the stream class won't be destroyed while it + * is in use. The same number of get and put (plus one extra put to + * release the initial reference done at creation) have to be done to + * destroy a stream class. + * + * When the stream class' reference count is decremented to 0 by a + * bt_ctf_stream_class_put, the stream class is freed. + * + * @param stream_class Stream class. + */ +extern void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class); +extern void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_CTF_IR_STREAM_CLASS_H */ diff --git a/lib/babeltrace/ctf-ir/stream-internal.h b/lib/babeltrace/ctf-ir/stream-internal.h new file mode 100644 index 0000000..9214abb --- /dev/null +++ b/lib/babeltrace/ctf-ir/stream-internal.h @@ -0,0 +1,68 @@ +#ifndef BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H +#define BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H + +/* + * BabelTrace - CTF Writer: Stream internal + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +typedef void(*flush_func)(struct bt_ctf_stream *, void *); + +struct flush_callback { + flush_func func; + void *data; +}; + +struct bt_ctf_stream { + struct bt_ctf_ref ref_count; + uint32_t id; + struct bt_ctf_stream_class *stream_class; + struct flush_callback flush; + /* Array of pointers to bt_ctf_event for the current packet */ + GPtrArray *events; + struct ctf_stream_pos pos; + unsigned int flushed_packet_count; + struct bt_ctf_field *packet_context; +}; + +BT_HIDDEN +struct bt_ctf_stream *bt_ctf_stream_create( + struct bt_ctf_stream_class *stream_class); + +BT_HIDDEN +int bt_ctf_stream_set_flush_callback(struct bt_ctf_stream *stream, + flush_func callback, void *data); + +BT_HIDDEN +int bt_ctf_stream_set_fd(struct bt_ctf_stream *stream, int fd); + +#endif /* BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H */ diff --git a/lib/babeltrace/ctf-ir/stream.h b/lib/babeltrace/ctf-ir/stream.h new file mode 100644 index 0000000..d9e2bc2 --- /dev/null +++ b/lib/babeltrace/ctf-ir/stream.h @@ -0,0 +1,150 @@ +#ifndef BABELTRACE_CTF_IR_STREAM_H +#define BABELTRACE_CTF_IR_STREAM_H + +/* + * BabelTrace - CTF IR: Stream + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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. + * + * The Common Trace Format (CTF) Specification is available at + * http://www.efficios.com/ctf + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_ctf_event; +struct bt_ctf_stream; + +/* + * bt_ctf_stream_get_discarded_events_count: get the number of discarded + * events associated with this stream. + * + * Note that discarded events are not stored if the stream's packet + * context has no "events_discarded" field. An error will be returned + * in that case. + * + * @param stream Stream instance. + * + * Returns the number of discarded events, a negative value on error. + */ +extern int bt_ctf_stream_get_discarded_events_count( + struct bt_ctf_stream *stream, uint64_t *count); + +/* + * bt_ctf_stream_append_discarded_events: increment discarded events count. + * + * Increase the current packet's discarded event count. Has no effect if the + * stream class' packet context has no "events_discarded" field. + * + * @param stream Stream instance. + * @param event_count Number of discarded events to add to the stream's current + * packet. + */ +extern void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, + uint64_t event_count); + +/* + * bt_ctf_stream_append_event: append an event to the stream. + * + * Append "event" to the stream's current packet. The stream's associated clock + * will be sampled during this call. The event shall not be modified after + * being appended to a stream. The stream will share the event's ownership by + * incrementing its reference count. The current packet is not flushed to disk + * until the next call to bt_ctf_stream_flush. + * + * @param stream Stream instance. + * @param event Event instance to append to the stream's current packet. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, + struct bt_ctf_event *event); + +/* + * bt_ctf_stream_get_packet_context: get a stream's packet context. + * + * @param stream Stream instance. + * + * Returns a field instance on success, NULL on error. + */ +extern struct bt_ctf_field *bt_ctf_stream_get_packet_context( + struct bt_ctf_stream *stream); + +/* + * bt_ctf_stream_set_packet_context: set a stream's packet context. + * + * The packet context's type must match the stream class' packet + * context type. + * + * @param stream Stream instance. + * @param packet_context Packet context field instance. + * + * Returns a field instance on success, NULL on error. + */ +extern int bt_ctf_stream_set_packet_context( + struct bt_ctf_stream *stream, + struct bt_ctf_field *packet_context); + +/* + * bt_ctf_stream_flush: flush a stream. + * + * The stream's current packet's events will be flushed, thus closing the + * current packet. Events subsequently appended to the stream will be + * added to a new packet. + * + * Flushing will also set the packet context's default attributes if + * they remained unset while populating the current packet. These default + * attributes, along with their expected types, are detailed in stream-class.h. + * + * @param stream Stream instance. + * + * Returns 0 on success, a negative value on error. + */ +extern int bt_ctf_stream_flush(struct bt_ctf_stream *stream); + +/* + * bt_ctf_stream_get and bt_ctf_stream_put: increment and decrement the + * stream's reference count. + * + * These functions ensure that the stream won't be destroyed while it + * is in use. The same number of get and put (plus one extra put to + * release the initial reference done at creation) have to be done to + * destroy a stream. + * + * When the stream's reference count is decremented to 0 by a + * bt_ctf_stream_put, the stream is freed. + * + * @param stream Stream instance. + */ +extern void bt_ctf_stream_get(struct bt_ctf_stream *stream); +extern void bt_ctf_stream_put(struct bt_ctf_stream *stream); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_CTF_IR_STREAM_H */ diff --git a/lib/babeltrace/ctf-writer/clock.h b/lib/babeltrace/ctf-writer/clock.h index 7cfc073..507739b 100644 --- a/lib/babeltrace/ctf-writer/clock.h +++ b/lib/babeltrace/ctf-writer/clock.h @@ -1,10 +1,7 @@ -#ifndef BABELTRACE_CTF_WRITER_CLOCK_H -#define BABELTRACE_CTF_WRITER_CLOCK_H - /* * BabelTrace - CTF Writer: Clock * - * Copyright 2013 EfficiOS Inc. + * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau * @@ -30,137 +27,4 @@ * http://www.efficios.com/ctf */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_ctf_clock; - -/* - * bt_ctf_clock_create: create a clock. - * - * Allocate a new clock setting its reference count to 1. - * - * @param name Name of the clock (will be copied). - * - * Returns an allocated clock on success, NULL on error. - */ -extern struct bt_ctf_clock *bt_ctf_clock_create(const char *name); - -/* - * bt_ctf_clock_set_description: set a clock's description. - * - * Set the clock's description. The description appears in the clock's TSDL - * meta-data. - * - * @param clock Clock instance. - * @param desc Description of the clock. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, - const char *desc); - -/* - * bt_ctf_clock_set_frequency: set a clock's frequency. - * - * Set the clock's frequency (Hz). - * - * @param clock Clock instance. - * @param freq Clock's frequency in Hz, defaults to 1 000 000 000 Hz (1ns). - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, - uint64_t freq); - -/* - * bt_ctf_clock_set_precision: set a clock's precision. - * - * Set the clock's precision. - * - * @param clock Clock instance. - * @param precision Clock's precision in clock ticks, defaults to 1. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, - uint64_t precision); - -/* - * bt_ctf_clock_set_offset_s: set a clock's offset in seconds. - * - * Set the clock's offset in seconds from POSIX.1 Epoch, 1970-01-01, - * defaults to 0. - * - * @param clock Clock instance. - * @param offset_s Clock's offset in seconds, defaults to 0. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, - uint64_t offset_s); - - -/* - * bt_ctf_clock_set_offset: set a clock's offset in ticks. - * - * Set the clock's offset in ticks from Epoch + offset_s. - * - * @param clock Clock instance. - * @param offset Clock's offset in ticks from Epoch + offset_s, defaults to 0. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, - uint64_t offset); - -/* - * bt_ctf_clock_set_is_absolute: set a clock's absolute attribute. - * - * A clock is absolute if the clock is a global reference across the trace's - * other clocks. - * - * @param clock Clock instance. - * @param is_absolute Clock's absolute attribute, defaults to FALSE. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, - int is_absolute); - -/* - * bt_ctf_clock_set_time: set a clock's current time value. - * - * Set the current time in nanoseconds since the clock's origin (offset and - * offset_s attributes). The clock's value will be sampled as events are - * appended to a stream. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time); - -/* - * bt_ctf_clock_get and bt_ctf_clock_put: increment and decrement the - * refcount of the clock - * - * These functions ensure that the clock won't be destroyed when it - * is in use. The same number of get and put (plus one extra put to - * release the initial reference done at creation) has to be done to - * destroy a clock. - * - * When the clock refcount is decremented to 0 by a bt_ctf_clock_put, - * the clock is freed. - * - * @param clock Clock instance. - */ -extern void bt_ctf_clock_get(struct bt_ctf_clock *clock); -extern void bt_ctf_clock_put(struct bt_ctf_clock *clock); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_CTF_WRITER_CLOCK_H */ +#include diff --git a/lib/babeltrace/ctf-writer/event-fields.h b/lib/babeltrace/ctf-writer/event-fields.h index 8d3190b..b5d8ccb 100644 --- a/lib/babeltrace/ctf-writer/event-fields.h +++ b/lib/babeltrace/ctf-writer/event-fields.h @@ -1,10 +1,7 @@ -#ifndef BABELTRACE_CTF_WRITER_EVENT_FIELDS_H -#define BABELTRACE_CTF_WRITER_EVENT_FIELDS_H - /* * BabelTrace - CTF Writer: Event Fields * - * Copyright 2013 EfficiOS Inc. + * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau * @@ -30,189 +27,4 @@ * http://www.efficios.com/ctf */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_ctf_event_class; -struct bt_ctf_event; -struct bt_ctf_field; -struct bt_ctf_field_type; - -/* - * bt_ctf_field_create: create an instance of a field. - * - * Allocate a new field of the type described by the bt_ctf_field_type - * structure.The creation of a field sets its reference count to 1. - * - * @param type Field type to be instanciated. - * - * Returns an allocated field on success, NULL on error. - */ -extern struct bt_ctf_field *bt_ctf_field_create( - struct bt_ctf_field_type *type); - -/* - * bt_ctf_field_structure_get_field: get a structure's field. - * - * Get the structure's field corresponding to the provided field name. - * bt_ctf_field_put() must be called on the returned value. - * - * @param structure Structure field instance. - * @param name Name of the field in the provided structure. - * - * Returns a field instance on success, NULL on error. - */ -extern struct bt_ctf_field *bt_ctf_field_structure_get_field( - struct bt_ctf_field *structure, const char *name); - -/* - * bt_ctf_field_array_get_field: get an array's field at position "index". - * - * Return the array's field at position "index". bt_ctf_field_put() must be - * called on the returned value. - * - * @param array Array field instance. - * @param index Position of the array's desired element. - * - * Returns a field instance on success, NULL on error. - */ -extern struct bt_ctf_field *bt_ctf_field_array_get_field( - struct bt_ctf_field *array, uint64_t index); - -/* - * bt_ctf_field_sequence_set_length: set a sequence's length. - * - * Set the sequence's length field. - * - * @param sequence Sequence field instance. - * @param length_field Integer field instance indicating the sequence's length. - * - * Returns a field instance on success, NULL on error. - */ -extern int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, - struct bt_ctf_field *length_field); - -/* - * bt_ctf_field_sequence_get_field: get a sequence's field at position "index". - * - * Return the sequence's field at position "index". The sequence's length must - * have been set prior to calling this function using - * bt_ctf_field_sequence_set_length(). - * bt_ctf_field_put() must be called on the returned value. - * - * @param array Sequence field instance. - * @param index Position of the sequence's desired element. - * - * Returns a field instance on success, NULL on error. - */ -extern struct bt_ctf_field *bt_ctf_field_sequence_get_field( - struct bt_ctf_field *sequence, uint64_t index); - -/* - * bt_ctf_field_variant_get_field: get a variant's selected field. - * - * Return the variant's selected field. The "tag" field is the selector enum - * field. bt_ctf_field_put() must be called on the returned value. - * - * @param variant Variant field instance. - * @param tag Selector enumeration field. - * - * Returns a field instance on success, NULL on error. - */ -extern struct bt_ctf_field *bt_ctf_field_variant_get_field( - struct bt_ctf_field *variant, struct bt_ctf_field *tag); - -/* - * bt_ctf_field_enumeration_get_container: get an enumeration field's container. - * - * Return the enumeration's underlying container field (an integer). - * bt_ctf_field_put() must be called on the returned value. - * - * @param enumeration Enumeration field instance. - * - * Returns a field instance on success, NULL on error. - */ -extern struct bt_ctf_field *bt_ctf_field_enumeration_get_container( - struct bt_ctf_field *enumeration); - -/* - * bt_ctf_field_signed_integer_set_value: set a signed integer field's value - * - * Set a signed integer field's value. The value is checked to make sure it - * can be stored in the underlying field. - * - * @param integer Signed integer field instance. - * @param value Signed integer field value. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, - int64_t value); - -/* - * bt_ctf_field_unsigned_integer_set_value: set unsigned integer field's value - * - * Set an unsigned integer field's value. The value is checked to make sure it - * can be stored in the underlying field. - * - * @param integer Unsigned integer field instance. - * @param value Unsigned integer field value. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, - uint64_t value); - -/* - * bt_ctf_field_floating_point_set_value: set a floating point field's value - * - * Set a floating point field's value. The underlying type may not support the - * double's full precision. - * - * @param floating_point Floating point field instance. - * @param value Floating point field value. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_floating_point_set_value( - struct bt_ctf_field *floating_point, - double value); - -/* - * bt_ctf_field_string_set_value: set a string field's value - * - * Set a string field's value. - * - * @param string String field instance. - * @param value String field value (will be copied). - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_string_set_value(struct bt_ctf_field *string, - const char *value); - -/* - * bt_ctf_field_get and bt_ctf_field_put: increment and decrement the - * field's reference count. - * - * These functions ensure that the field won't be destroyed when it - * is in use. The same number of get and put (plus one extra put to - * release the initial reference done at creation) have to be done to - * destroy a field. - * - * When the field's reference count is decremented to 0 by a bt_ctf_field_put, - * the field is freed. - * - * @param field Field instance. - */ -extern void bt_ctf_field_get(struct bt_ctf_field *field); -extern void bt_ctf_field_put(struct bt_ctf_field *field); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_CTF_WRITER_EVENT_FIELDS_H */ +#include diff --git a/lib/babeltrace/ctf-writer/event-types.h b/lib/babeltrace/ctf-writer/event-types.h index cf43ed6..b1f4b21 100644 --- a/lib/babeltrace/ctf-writer/event-types.h +++ b/lib/babeltrace/ctf-writer/event-types.h @@ -1,10 +1,7 @@ -#ifndef BABELTRACE_CTF_WRITER_EVENT_TYPES_H -#define BABELTRACE_CTF_WRITER_EVENT_TYPES_H - /* * BabelTrace - CTF Writer: Event Types * - * Copyright 2013 EfficiOS Inc. + * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau * @@ -30,324 +27,4 @@ * http://www.efficios.com/ctf */ -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_ctf_event_class; -struct bt_ctf_event; -struct bt_ctf_field_type; - -enum bt_ctf_integer_base { - BT_CTF_INTEGER_BASE_UNKNOWN = -1, - BT_CTF_INTEGER_BASE_BINARY = 2, - BT_CTF_INTEGER_BASE_OCTAL = 8, - BT_CTF_INTEGER_BASE_DECIMAL = 10, - BT_CTF_INTEGER_BASE_HEXADECIMAL = 16, -}; - -/* - * bt_ctf_field_type_integer_create: create an integer field type. - * - * Allocate a new integer field type of the given size. The creation of a field - * type sets its reference count to 1. - * - * @param size Integer field type size/length in bits. - * - * Returns an allocated field type on success, NULL on error. - */ -extern struct bt_ctf_field_type *bt_ctf_field_type_integer_create( - unsigned int size); - -/* - * bt_ctf_field_type_integer_set_signed: set an integer type's signedness. - * - * Set an integer type's signedness attribute. - * - * @param integer Integer type. - * @param is_signed Integer's signedness, defaults to FALSE. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_type_integer_set_signed( - struct bt_ctf_field_type *integer, int is_signed); - -/* - * bt_ctf_field_type_integer_set_base: set an integer type's base. - * - * Set an integer type's base used to pretty-print the resulting trace. - * - * @param integer Integer type. - * @param base Integer base, defaults to BT_CTF_INTEGER_BASE_DECIMAL. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_type_integer_set_base( - struct bt_ctf_field_type *integer, - enum bt_ctf_integer_base base); - -/* - * bt_ctf_field_type_integer_set_encoding: set an integer type's encoding. - * - * An integer encoding may be set to signal that the integer must be printed as - * a text character. - * - * @param integer Integer type. - * @param encoding Integer output encoding, defaults to CTF_STRING_ENCODING_NONE - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_type_integer_set_encoding( - struct bt_ctf_field_type *integer, - enum ctf_string_encoding encoding); - -/* - * bt_ctf_field_type_enumeration_create: create an enumeration field type. - * - * Allocate a new enumeration field type with the given underlying type. The - * creation of a field type sets its reference count to 1. - * The resulting enumeration will share the integer_container_type's ownership - * by increasing its reference count. - * - * @param integer_container_type Underlying integer type of the enumeration - * type. - * - * Returns an allocated field type on success, NULL on error. - */ -extern struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create( - struct bt_ctf_field_type *integer_container_type); - -/* - * bt_ctf_field_type_enumeration_add_mapping: add an enumeration mapping. - * - * Add a mapping to the enumeration. The range's values are inclusive. - * - * @param enumeration Enumeration type. - * @param string Enumeration mapping name (will be copied). - * @param range_start Enumeration mapping range start. - * @param range_end Enumeration mapping range end. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_type_enumeration_add_mapping( - struct bt_ctf_field_type *enumeration, const char *string, - int64_t range_start, int64_t range_end); - -/* - * bt_ctf_field_type_floating_point_create: create a floating point field type. - * - * Allocate a new floating point field type. The creation of a field type sets - * its reference count to 1. - * - * Returns an allocated field type on success, NULL on error. - */ -extern struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void); - -/* - * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit - * count. - * - * Set the number of exponent digits to use to store the floating point field. - * The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG. - * - * @param floating_point Floating point type. - * @param exponent_digits Number of digits to allocate to the exponent (defaults - * to FLT_EXP_DIG). - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_type_floating_point_set_exponent_digits( - struct bt_ctf_field_type *floating_point, - unsigned int exponent_digits); - -/* - * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit - * count. - * - * Set the number of mantissa digits to use to store the floating point field. - * The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG. - * - * @param floating_point Floating point type. - * @param mantissa_digits Number of digits to allocate to the mantissa (defaults - * to FLT_MANT_DIG). - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_type_floating_point_set_mantissa_digits( - struct bt_ctf_field_type *floating_point, - unsigned int mantissa_digits); - -/* - * bt_ctf_field_type_structure_create: create a structure field type. - * - * Allocate a new structure field type. The creation of a field type sets - * its reference count to 1. - * - * Returns an allocated field type on success, NULL on error. - */ -extern struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void); - -/* - * bt_ctf_field_type_structure_add_field: add a field to a structure. - * - * Add a field of type "field_type" to the structure. The structure will share - * field_type's ownership by increasing its reference count. - * - * @param structure Structure type. - * @param field_type Type of the field to add to the structure type. - * @param field_name Name of the structure's new field (will be copied). - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_type_structure_add_field( - struct bt_ctf_field_type *structure, - struct bt_ctf_field_type *field_type, - const char *field_name); - -/* - * bt_ctf_field_type_variant_create: create a variant field type. - * - * Allocate a new variant field type. The creation of a field type sets - * its reference count to 1. tag_name must be the name of an enumeration - * field declared in the same scope as this variant. - * - * @param enum_tag Type of the variant's tag/selector (must be an enumeration). - * @param tag_name Name of the variant's tag/selector field (will be copied). - * - * Returns an allocated field type on success, NULL on error. - */ -extern struct bt_ctf_field_type *bt_ctf_field_type_variant_create( - struct bt_ctf_field_type *enum_tag, - const char *tag_name); - -/* - * bt_ctf_field_type_variant_add_field: add a field to a variant. - * - * Add a field of type "field_type" to the variant.The variant will share - * field_type's ownership by increasing its reference count. The "field_name" - * will be copied. field_name must match a mapping in the tag/selector - * enumeration. - * - * @param variant Variant type. - * @param field_type Type of the variant type's new field. - * @param field_name Name of the variant type's new field (will be copied). - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_type_variant_add_field( - struct bt_ctf_field_type *variant, - struct bt_ctf_field_type *field_type, - const char *field_name); - -/* - * bt_ctf_field_type_array_create: create an array field type. - * - * Allocate a new array field type. The creation of a field type sets - * its reference count to 1. - * - * @param element_type Array's element type. - * @oaram length Array type's length. - * - * Returns an allocated field type on success, NULL on error. - */ -extern struct bt_ctf_field_type *bt_ctf_field_type_array_create( - struct bt_ctf_field_type *element_type, - unsigned int length); - -/* - * bt_ctf_field_type_sequence_create: create a sequence field type. - * - * Allocate a new sequence field type. The creation of a field type sets - * its reference count to 1. "length_field_name" must match an integer field - * declared in the same scope. - * - * @param element_type Sequence's element type. - * @param length_field_name Name of the sequence's length field (will be - * copied). - * - * Returns an allocated field type on success, NULL on error. - */ -extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_create( - struct bt_ctf_field_type *element_type, - const char *length_field_name); - -/* - * bt_ctf_field_type_string_create: create a string field type. - * - * Allocate a new string field type. The creation of a field type sets - * its reference count to 1. - * - * Returns an allocated field type on success, NULL on error. - */ -extern struct bt_ctf_field_type *bt_ctf_field_type_string_create(void); - -/* - * bt_ctf_field_type_string_set_encoding: set a string type's encoding. - * - * Set the string type's encoding. - * - * @param string String type. - * @param encoding String field encoding, default CTF_STRING_ENCODING_ASCII. - * Valid values are CTF_STRING_ENCODING_ASCII and CTF_STRING_ENCODING_UTF8. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_type_string_set_encoding( - struct bt_ctf_field_type *string, - enum ctf_string_encoding encoding); - -/* - * bt_ctf_field_type_set_alignment: set a field type's alignment. - * - * Set the field type's alignment. - * - * @param type Field type. - * @param alignment Type's alignment. Defaults to 1 (bit-aligned). However, - * some types, such as structures and string, may impose other alignment - * constraints. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, - unsigned int alignment); - -/* - * bt_ctf_field_type_set_byte_order: set a field type's byte order. - * - * Set the field type's byte order. - * - * @param type Field type. - * @param byte_order Field type's byte order. Defaults to - * BT_CTF_BYTE_ORDER_NATIVE, the host machine's endianness. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, - enum bt_ctf_byte_order byte_order); - -/* - * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement - * the field type's reference count. - * - * These functions ensure that the field type won't be destroyed while it - * is in use. The same number of get and put (plus one extra put to - * release the initial reference done at creation) have to be done to - * destroy a field type. - * - * When the field type's reference count is decremented to 0 by a - * bt_ctf_field_type_put, the field type is freed. - * - * @param type Field type. - */ -extern void bt_ctf_field_type_get(struct bt_ctf_field_type *type); -extern void bt_ctf_field_type_put(struct bt_ctf_field_type *type); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_CTF_WRITER_EVENT_TYPES_H */ +#include diff --git a/lib/babeltrace/ctf-writer/event.h b/lib/babeltrace/ctf-writer/event.h index d8ef9d9..050bced 100644 --- a/lib/babeltrace/ctf-writer/event.h +++ b/lib/babeltrace/ctf-writer/event.h @@ -1,10 +1,7 @@ -#ifndef BABELTRACE_CTF_WRITER_EVENT_H -#define BABELTRACE_CTF_WRITER_EVENT_H - /* * BabelTrace - CTF Writer: Event * - * Copyright 2013 EfficiOS Inc. + * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau * @@ -30,125 +27,4 @@ * http://www.efficios.com/ctf */ -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_ctf_event_class; -struct bt_ctf_event; -struct bt_ctf_field; -struct bt_ctf_field_type; - -/* - * bt_ctf_event_class_create: create an event class. - * - * Allocate a new event class of the given name. The creation of an event class - * sets its reference count to 1. - * - * @param name Event class name (will be copied). - * - * Returns an allocated event class on success, NULL on error. - */ -extern struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name); - -/* - * bt_ctf_event_class_add_field: add a field to an event class. - * - * Add a field of type "type" to the event class. The event class will share - * type's ownership by increasing its reference count. The "name" will be - * copied. - * - * @param event_class Event class. - * @param type Field type to add to the event class. - * @param name Name of the new field. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, - struct bt_ctf_field_type *type, - const char *name); - -/* - * bt_ctf_event_class__get and bt_ctf_event_class_put: increment and decrement - * the event class' reference count. - * - * These functions ensure that the event class won't be destroyed while it - * is in use. The same number of get and put (plus one extra put to - * release the initial reference done at creation) have to be done to - * destroy an event class. - * - * When the event class' reference count is decremented to 0 by a - * bt_ctf_event_class_put, the event class is freed. - * - * @param event_class Event class. - */ -extern void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class); -extern void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class); - -/* - * bt_ctf_event_create: instanciate an event. - * - * Allocate a new event of the given event class. The creation of an event - * sets its reference count to 1. Each instance shares the ownership of the - * event class using its reference count. - * - * @param event_class Event class. - * - * Returns an allocated field type on success, NULL on error. - */ -extern struct bt_ctf_event *bt_ctf_event_create( - struct bt_ctf_event_class *event_class); - -/* - * bt_ctf_event_set_payload: set an event's field. - * - * Set a manually allocated field as an event's payload. The event will share - * the field's ownership by using its reference count. - * bt_ctf_field_put() must be called on the returned value. - * - * @param event Event instance. - * @param name Event field name. - * @param value Instance of a field whose type corresponds to the event's field. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_event_set_payload(struct bt_ctf_event *event, - const char *name, - struct bt_ctf_field *value); - -/* - * bt_ctf_event_get_payload: get an event's field. - * - * Returns the field matching "name". bt_ctf_field_put() must be called on the - * returned value. - * - * @param event Event instance. - * @param name Event field name. - * - * Returns a field instance on success, NULL on error. - */ -extern struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, - const char *name); - -/* - * bt_ctf_event_get and bt_ctf_event_put: increment and decrement - * the event's reference count. - * - * These functions ensure that the event won't be destroyed while it - * is in use. The same number of get and put (plus one extra put to - * release the initial reference done at creation) have to be done to - * destroy an event. - * - * When the event's reference count is decremented to 0 by a - * bt_ctf_event_put, the event is freed. - * - * @param event Event instance. - */ -extern void bt_ctf_event_get(struct bt_ctf_event *event); -extern void bt_ctf_event_put(struct bt_ctf_event *event); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_CTF_WRITER_EVENT_H */ +#include diff --git a/lib/babeltrace/ctf-writer/functor-internal.h b/lib/babeltrace/ctf-writer/functor-internal.h index 66d3fcf..1db2d29 100644 --- a/lib/babeltrace/ctf-writer/functor-internal.h +++ b/lib/babeltrace/ctf-writer/functor-internal.h @@ -4,7 +4,7 @@ /* * BabelTrace - CTF Writer: Functors for use with glib data structures * - * Copyright 2013 EfficiOS Inc. + * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau * diff --git a/lib/babeltrace/ctf-writer/ref-internal.h b/lib/babeltrace/ctf-writer/ref-internal.h index 486e243..1db4974 100644 --- a/lib/babeltrace/ctf-writer/ref-internal.h +++ b/lib/babeltrace/ctf-writer/ref-internal.h @@ -4,7 +4,7 @@ /* * BabelTrace - CTF Writer: Reference count * - * Copyright 2013 EfficiOS Inc. + * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau * diff --git a/lib/babeltrace/ctf-writer/stream-class.h b/lib/babeltrace/ctf-writer/stream-class.h new file mode 100644 index 0000000..2f6c8bd --- /dev/null +++ b/lib/babeltrace/ctf-writer/stream-class.h @@ -0,0 +1,30 @@ +/* + * BabelTrace - CTF Writer: Stream Class + * + * Copyright 2014 EfficiOS Inc. + * + * Author: Jérémie Galarneau + * + * 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. + * + * The Common Trace Format (CTF) Specification is available at + * http://www.efficios.com/ctf + */ + +#include diff --git a/lib/babeltrace/ctf-writer/stream.h b/lib/babeltrace/ctf-writer/stream.h index 9229f77..a878cae 100644 --- a/lib/babeltrace/ctf-writer/stream.h +++ b/lib/babeltrace/ctf-writer/stream.h @@ -1,10 +1,7 @@ -#ifndef BABELTRACE_CTF_WRITER_STREAM_H -#define BABELTRACE_CTF_WRITER_STREAM_H - /* * BabelTrace - CTF Writer: Stream * - * Copyright 2013 EfficiOS Inc. + * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau * @@ -30,140 +27,4 @@ * http://www.efficios.com/ctf */ -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_ctf_event; -struct bt_ctf_event_class; -struct bt_ctf_stream_class; -struct bt_ctf_stream; -struct bt_ctf_clock; - -/* - * bt_ctf_stream_class_create: create a stream class. - * - * Allocate a new stream class of the given name. The creation of an event class - * sets its reference count to 1. - * - * @param name Stream name. - * - * Returns an allocated stream class on success, NULL on error. - */ -extern struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name); - -/* - * bt_ctf_stream_class_set_clock: assign a clock to a stream class. - * - * Assign a clock to a stream class. This clock will be sampled each time an - * event is appended to an instance of this stream class. - * - * @param stream_class Stream class. - * @param clock Clock to assign to the provided stream class. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_stream_class_set_clock( - struct bt_ctf_stream_class *stream_class, - struct bt_ctf_clock *clock); - -/* - * bt_ctf_stream_class_set_clock: assign a clock to a stream class. - * - * Add an event class to a stream class. New events can be added even after a - * stream has beem instanciated and events have been appended. However, a stream - * will not accept events of a class that has not been registered beforehand. - * The stream class will share the ownership of "event_class" by incrementing - * its reference count. - * - * @param stream_class Stream class. - * @param event_class Event class to add to the provided stream class. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_stream_class_add_event_class( - struct bt_ctf_stream_class *stream_class, - struct bt_ctf_event_class *event_class); - -/* - * bt_ctf_stream_class_get and bt_ctf_stream_class_put: increment and - * decrement the stream class' reference count. - * - * These functions ensure that the stream class won't be destroyed while it - * is in use. The same number of get and put (plus one extra put to - * release the initial reference done at creation) have to be done to - * destroy a stream class. - * - * When the stream class' reference count is decremented to 0 by a - * bt_ctf_stream_class_put, the stream class is freed. - * - * @param stream_class Stream class. - */ -extern void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class); -extern void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class); - -/* - * bt_ctf_stream_append_discarded_events: increment discarded events count. - * - * Increase the current packet's discarded event count. - * - * @param stream Stream instance. - * @param event_count Number of discarded events to add to the stream's current - * packet. - * - * Returns 0 on success, a negative value on error. - */ -extern void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, - uint64_t event_count); - -/* - * bt_ctf_stream_append_event: append an event to the stream. - * - * Append "event" to the stream's current packet. The stream's associated clock - * will be sampled during this call. The event shall not be modified after - * being appended to a stream. The stream will share the event's ownership by - * incrementing its reference count. The current packet is not flushed to disk - * until the next call to bt_ctf_stream_flush. - * - * @param stream Stream instance. - * @param event Event instance to append to the stream's current packet. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, - struct bt_ctf_event *event); - -/* - * bt_ctf_stream_flush: flush a stream. - * - * The stream's current packet's events will be flushed to disk. Events - * subsequently appended to the stream will be added to a new packet. - * - * @param stream Stream instance. - * - * Returns 0 on success, a negative value on error. - */ -extern int bt_ctf_stream_flush(struct bt_ctf_stream *stream); - -/* - * bt_ctf_stream_get and bt_ctf_stream_put: increment and decrement the - * stream's reference count. - * - * These functions ensure that the stream won't be destroyed while it - * is in use. The same number of get and put (plus one extra put to - * release the initial reference done at creation) have to be done to - * destroy a stream. - * - * When the stream's reference count is decremented to 0 by a - * bt_ctf_stream_put, the stream is freed. - * - * @param stream Stream instance. - */ -extern void bt_ctf_stream_get(struct bt_ctf_stream *stream); -extern void bt_ctf_stream_put(struct bt_ctf_stream *stream); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_CTF_WRITER_STREAM_H */ +#include diff --git a/lib/babeltrace/ctf-writer/writer-internal.h b/lib/babeltrace/ctf-writer/writer-internal.h index 5c682dd..cf7e399 100644 --- a/lib/babeltrace/ctf-writer/writer-internal.h +++ b/lib/babeltrace/ctf-writer/writer-internal.h @@ -4,7 +4,7 @@ /* * BabelTrace - CTF Writer: Writer internal * - * Copyright 2013 EfficiOS Inc. + * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau * @@ -61,7 +61,7 @@ struct bt_ctf_writer { GPtrArray *streams; /* Array of pointers to bt_ctf_stream */ struct bt_ctf_field_type *trace_packet_header_type; struct bt_ctf_field *trace_packet_header; - uint32_t next_stream_id; + uint64_t next_stream_id; }; struct environment_variable { diff --git a/lib/babeltrace/ctf-writer/writer.h b/lib/babeltrace/ctf-writer/writer.h index 68031ac..60b660f 100644 --- a/lib/babeltrace/ctf-writer/writer.h +++ b/lib/babeltrace/ctf-writer/writer.h @@ -4,7 +4,7 @@ /* * BabelTrace - CTF Writer: Writer * - * Copyright 2013 EfficiOS Inc. + * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau * @@ -30,6 +30,8 @@ * http://www.efficios.com/ctf */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -39,13 +41,6 @@ struct bt_ctf_stream; struct bt_ctf_stream_class; struct bt_ctf_clock; -enum bt_ctf_byte_order { - BT_CTF_BYTE_ORDER_NATIVE = 0, - BT_CTF_BYTE_ORDER_LITTLE_ENDIAN, - BT_CTF_BYTE_ORDER_BIG_ENDIAN, - BT_CTF_BYTE_ORDER_NETWORK, -}; - /* * bt_ctf_writer_create: create a writer instance. * diff --git a/lib/babeltrace/ctf/ctf-index.h b/lib/babeltrace/ctf/ctf-index.h index 0efa888..b39b523 100644 --- a/lib/babeltrace/ctf/ctf-index.h +++ b/lib/babeltrace/ctf/ctf-index.h @@ -25,7 +25,7 @@ #ifndef LTTNG_INDEX_H #define LTTNG_INDEX_H -#include +#include #define CTF_INDEX_MAGIC 0xC1F1DCC1 #define CTF_INDEX_MAJOR 1 diff --git a/lib/babeltrace/ctf/events.h b/lib/babeltrace/ctf/events.h index c81d885..9f06801 100644 --- a/lib/babeltrace/ctf/events.h +++ b/lib/babeltrace/ctf/events.h @@ -270,6 +270,11 @@ int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx, */ const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event); +/* + * bt_ctf_get_decl_event_id: return the event-ID of the event or -1ULL on error + */ +uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event); + /* * bt_ctf_get_decl_fields: get all field declarations in a scope of an event * diff --git a/lib/babeltrace/ctf/types.h b/lib/babeltrace/ctf/types.h index 67b24ee..c336632 100644 --- a/lib/babeltrace/ctf/types.h +++ b/lib/babeltrace/ctf/types.h @@ -132,6 +132,28 @@ int ctf_init_pos(struct ctf_stream_pos *pos, struct bt_trace_descriptor *trace, int fd, int open_flags); int ctf_fini_pos(struct ctf_stream_pos *pos); +static inline +int ctf_pos_access_ok(struct ctf_stream_pos *pos, uint64_t bit_len) +{ + uint64_t max_len; + + if (unlikely(pos->offset == EOF)) + return 0; + if (pos->prot == PROT_READ) { + /* + * Reads may only reach up to the "content_size", + * regardless of the packet_size. + */ + max_len = pos->content_size; + } else { + /* Writes may take place up to the end of the packet. */ + max_len = pos->packet_size; + } + if (unlikely(pos->offset + bit_len > max_len)) + return 0; + return 1; +} + /* * move_pos - move position of a relative bit offset * @@ -142,21 +164,17 @@ int ctf_fini_pos(struct ctf_stream_pos *pos); static inline int ctf_move_pos(struct ctf_stream_pos *pos, uint64_t bit_offset) { - uint64_t max_len; + int ret = 0; printf_debug("ctf_move_pos test EOF: %" PRId64 "\n", pos->offset); - if (unlikely(pos->offset == EOF)) - return 0; - if (pos->prot == PROT_READ) - max_len = pos->content_size; - else - max_len = pos->packet_size; - if (unlikely(pos->offset + bit_offset > max_len)) - return 0; - + ret = ctf_pos_access_ok(pos, bit_offset); + if (!ret) { + goto end; + } pos->offset += bit_offset; printf_debug("ctf_move_pos after increment: %" PRId64 "\n", pos->offset); - return 1; +end: + return ret; } /* @@ -207,22 +225,6 @@ void ctf_pos_pad_packet(struct ctf_stream_pos *pos) ctf_packet_seek(&pos->parent, 0, SEEK_CUR); } -static inline -int ctf_pos_access_ok(struct ctf_stream_pos *pos, uint64_t bit_len) -{ - uint64_t max_len; - - if (unlikely(pos->offset == EOF)) - return 0; - if (pos->prot == PROT_READ) - max_len = pos->content_size; - else - max_len = pos->packet_size; - if (unlikely(pos->offset + bit_len > max_len)) - return 0; - return 1; -} - /* * Update the stream position to the current event. This moves to * the next packet if we are located at the end of the current packet. diff --git a/lib/babeltrace/endian.h b/lib/babeltrace/endian.h index f15a44f..001a471 100644 --- a/lib/babeltrace/endian.h +++ b/lib/babeltrace/endian.h @@ -47,7 +47,98 @@ #define BYTE_ORDER __BYTE_ORDER #else #include -#endif + +/* + * htobe/betoh are not defined for glibc < 2.9, so add them explicitly + * if they are missing. + */ +# ifdef __USE_BSD +/* Conversion interfaces. */ +# include + +# if __BYTE_ORDER == __LITTLE_ENDIAN +# ifndef htobe16 +# define htobe16(x) __bswap_16(x) +# endif +# ifndef htole16 +# define htole16(x) (x) +# endif +# ifndef be16toh +# define be16toh(x) __bswap_16(x) +# endif +# ifndef le16toh +# define le16toh(x) (x) +# endif + +# ifndef htobe32 +# define htobe32(x) __bswap_32(x) +# endif +# ifndef htole32 +# define htole32(x) (x) +# endif +# ifndef be32toh +# define be32toh(x) __bswap_32(x) +# endif +# ifndef le32toh +# define le32toh(x) (x) +# endif + +# ifndef htobe64 +# define htobe64(x) __bswap_64(x) +# endif +# ifndef htole64 +# define htole64(x) (x) +# endif +# ifndef be64toh +# define be64toh(x) __bswap_64(x) +# endif +# ifndef le64toh +# define le64toh(x) (x) +# endif + +# else /* __BYTE_ORDER == __LITTLE_ENDIAN */ +# ifndef htobe16 +# define htobe16(x) (x) +# endif +# ifndef htole16 +# define htole16(x) __bswap_16(x) +# endif +# ifndef be16toh +# define be16toh(x) (x) +# endif +# ifndef le16toh +# define le16toh(x) __bswap_16(x) +# endif + +# ifndef htobe32 +# define htobe32(x) (x) +# endif +# ifndef htole32 +# define htole32(x) __bswap_32(x) +# endif +# ifndef be32toh +# define be32toh(x) (x) +# endif +# ifndef le32toh +# define le32toh(x) __bswap_32(x) +# endif + +# ifndef htobe64 +# define htobe64(x) (x) +# endif +# ifndef htole64 +# define htole64(x) __bswap_64(x) +# endif +# ifndef be64toh +# define be64toh(x) (x) +# endif +# ifndef le64toh +# define le64toh(x) __bswap_64(x) +# endif + +# endif /* __BYTE_ORDER == __LITTLE_ENDIAN */ +# endif /* __USE_BSD */ +#endif /* else -- __FreeBSD__ */ #ifndef FLOAT_WORD_ORDER #ifdef __FLOAT_WORD_ORDER diff --git a/lib/babeltrace/format-internal.h b/lib/babeltrace/format-internal.h index 7f3eb5e..e0359ea 100644 --- a/lib/babeltrace/format-internal.h +++ b/lib/babeltrace/format-internal.h @@ -29,7 +29,7 @@ * SOFTWARE. */ -#include +#include #include #include diff --git a/lib/babeltrace/types.h b/lib/babeltrace/types.h index 677818b..b32d2a4 100644 --- a/lib/babeltrace/types.h +++ b/lib/babeltrace/types.h @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include #include