* SOFTWARE.
*/
-#include <babeltrace/ctf-ir/event.h>
-#include <babeltrace/ctf-ir/packet.h>
-#include <babeltrace/ctf-ir/event-class.h>
-#include <babeltrace/ctf-ir/stream.h>
-#include <babeltrace/ctf-ir/stream-class.h>
-#include <babeltrace/ctf-ir/clock-class.h>
-#include <babeltrace/ctf-ir/fields.h>
-#include <babeltrace/ctf-writer/stream.h>
-#include <babeltrace/ctf-ir/field-types.h>
+#define BT_LOG_TAG "PLUGIN-CTFCOPYTRACE-LIB-CLOCK-FIELDS"
+#include "logging.h"
+
+#include <babeltrace/babeltrace.h>
#include <assert.h>
#include <stdio.h>
ret = bt_ctf_field_type_integer_set_size(type, 64);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to set integer size to 64.");
goto end;
}
ret = bt_ctf_field_type_integer_set_mapped_clock_class(type,
writer_clock_class);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to map integer to clock_class.");
goto end;
}
ret = bt_ctf_field_type_variant_get_field(type,
&entry_name, &entry_type, i);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to get variant field.");
goto error;
}
+
ret = find_update_clock_fields(err, entry_type,
writer_clock_class);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to find clock fields.");
goto error;
}
BT_PUT(entry_type);
ret = bt_ctf_field_type_structure_get_field(type,
&entry_name, &entry_type, i);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to get struct field.");
goto error;
}
+
ret = find_update_clock_fields(err, entry_type,
writer_clock_class);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to find clock fields.");
goto error;
}
BT_PUT(entry_type);
struct bt_ctf_field_type *entry_type = NULL;
entry_type = bt_ctf_field_type_sequence_get_element_type(type);
- if (!entry_type) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
- goto error;
- }
+ assert(entry_type);
+
ret = find_update_clock_fields(err, entry_type, writer_clock_class);
BT_PUT(entry_type);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to find clock fields.");
goto error;
}
int find_update_array_clock_fields(FILE *err, struct bt_ctf_field_type *type,
struct bt_ctf_clock_class *writer_clock_class)
{
- int ret;
+ int ret = 0;
struct bt_ctf_field_type *entry_type = NULL;
entry_type = bt_ctf_field_type_array_get_element_type(type);
- if (!entry_type) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
- goto error;
- }
+ assert(entry_type);
+
ret = find_update_clock_fields(err, entry_type, writer_clock_class);
BT_PUT(entry_type);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to find clock fields.");
ret = -1;
goto end;
}
- ret = 0;
- goto end;
-
-error:
- ret = -1;
end:
return ret;
}
struct bt_ctf_field_type *entry_type = NULL;
entry_type = bt_ctf_field_type_enumeration_get_container_type(type);
- if (!entry_type) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
- goto error;
- }
+ assert(entry_type);
+
ret = find_update_clock_fields(err, entry_type, writer_clock_class);
BT_PUT(entry_type);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to find clock fields.");
goto error;
}
/* FIXME multi-clock? */
writer_clock_class = bt_ctf_trace_get_clock_class_by_index(writer_trace, 0);
- if (!writer_clock_class) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
- goto error;
- }
+ assert(writer_clock_class);
new_type = bt_ctf_field_type_copy(type);
if (!new_type) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to copy field type.");
goto error;
}
if (bt_ctf_field_type_get_type_id(new_type) != BT_CTF_FIELD_TYPE_ID_STRUCT) {
- fprintf(err, "[error] Unexpected header field type\n");
+ BT_LOGE("Expected header field type to be struct: type=%d",
+ bt_ctf_field_type_get_type_id(new_type));
goto error;
}
ret = find_update_struct_clock_fields(err, new_type, writer_clock_class);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to find clock fields in struct.");
goto error;
}
BT_PUT(writer_clock_class);
ret = bt_ctf_field_floating_point_get_value(field, &value);
if (ret) {
- ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__,
- __FILE__, __LINE__);
- goto end;
+ BT_LOGE_STR("Failed to get value.");
+ goto error;
}
+
ret = bt_ctf_field_floating_point_set_value(copy_field, value);
if (ret) {
ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__,
- __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to set floating point value.");
goto end;
}
ret = 0;
+ goto end;
+error:
+ ret = -1;
end:
return ret;
}
value = bt_ctf_field_string_get_value(field);
if (!value) {
- ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__,
- __FILE__, __LINE__);
- goto end;
+ BT_LOGE_STR("Failed to get value.");
+ goto error;
}
+
ret = bt_ctf_field_string_set_value(copy_field, value);
if (ret) {
ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__,
- __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to set string value.");
goto end;
}
ret = 0;
+ goto end;
+error:
+ ret = -1;
end:
return ret;
}
struct bt_ctf_field *copy_field)
{
struct bt_ctf_field_type *type = NULL;
- int ret;
+ int ret = 0;
type = bt_ctf_field_get_type(field);
- if (!type) {
- ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto end;
- }
+ assert(type);
switch (bt_ctf_field_type_get_type_id(type)) {
case BT_CTF_FIELD_TYPE_ID_INTEGER:
break;
}
- ret = 0;
BT_PUT(type);
-end:
return ret;
}
struct bt_ctf_field *container = NULL, *copy_container = NULL;
container = bt_ctf_field_enumeration_get_container(field);
- if (!container) {
- ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto end;
- }
+ assert(container);
copy_container = bt_ctf_field_enumeration_get_container(copy_field);
- if (!copy_container) {
- ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto error;
- }
+ assert(copy_container);
ret = copy_override_field(err, event, writer_event, container,
copy_container);
if (ret) {
ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to override enum field.");
goto error;
}
struct bt_ctf_field *variant_field = NULL, *copy_variant_field = NULL;
tag = bt_ctf_field_variant_get_tag(field);
- if (!tag) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto error;
- }
+ assert(tag);
variant_field = bt_ctf_field_variant_get_field(field, tag);
if (!variant_field) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to get variant field.");
goto error;
}
copy_variant_field = bt_ctf_field_variant_get_field(copy_field, tag);
- if (!copy_variant_field) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto error;
- }
+ assert(copy_variant_field);
ret = copy_override_field(err, event, writer_event, variant_field,
copy_variant_field);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to override variant field.");
goto error;
}
struct bt_ctf_field *entry_field = NULL, *entry_copy = NULL;
length_field = bt_ctf_field_sequence_get_length(field);
- if (!length_field) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto error;
- }
+ assert(length_field);
ret = bt_ctf_field_unsigned_integer_get_value(length_field, &count);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE("Failed to get value.");
goto error;
}
ret = bt_ctf_field_sequence_set_length(copy_field, length_field);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to set sequence length.");
goto error;
}
BT_PUT(length_field);
for (i = 0; i < count; i++) {
entry_field = bt_ctf_field_sequence_get_field(field, i);
if (!entry_field) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to get sequence field.");
goto error;
}
entry_copy = bt_ctf_field_sequence_get_field(copy_field, i);
- if (!entry_copy) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto error;
- }
+ assert(entry_copy);
ret = copy_override_field(err, event, writer_event, entry_field,
entry_copy);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Faield to override field in sequence.");
goto error;
}
BT_PUT(entry_field);
entry_field = bt_ctf_field_array_get_field(field, i);
if (!entry_field) {
ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to get array field.");
goto error;
}
entry_copy = bt_ctf_field_array_get_field(copy_field, i);
- if (!entry_copy) {
- ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto error;
- }
+ assert(entry_copy);
ret = copy_override_field(err, event, writer_event, entry_field,
entry_copy);
if (ret) {
ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to override field in array.");
goto error;
}
BT_PUT(entry_field);
entry_field = bt_ctf_field_structure_get_field_by_index(field, i);
if (!entry_field) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to get struct field.");
goto error;
}
ret = bt_ctf_field_type_structure_get_field(type, &entry_name,
&entry_type, i);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n",
- __func__, __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to get struct field.");
goto error;
}
entry_copy = bt_ctf_field_structure_get_field_by_index(copy_field, i);
- if (!entry_copy) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto error;
- }
+ assert(entry_copy);
ret = copy_override_field(err, event, writer_event, entry_field,
entry_copy);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to override field in struct.");
goto error;
}
BT_PUT(entry_copy);
if (bt_ctf_field_type_integer_get_signed(type)) {
ret = bt_ctf_field_signed_integer_get_value(field, &value);
if (ret) {
- ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__,
- __FILE__, __LINE__);
- goto end;
+ BT_LOGE("Failed to get value.");
+ goto error;
}
+
ret = bt_ctf_field_signed_integer_set_value(copy_field, value);
if (ret) {
ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__,
- __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to set signed integer value.");
goto end;
}
} else {
ret = bt_ctf_field_unsigned_integer_get_value(field,
&uvalue);
if (ret) {
- ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__,
- __FILE__, __LINE__);
- goto end;
+ BT_LOGE("Failed to get value.");
+ goto error;
}
+
ret = bt_ctf_field_unsigned_integer_set_value(copy_field, uvalue);
if (ret) {
ret = -1;
- fprintf(err, "[error] %s in %s:%d\n", __func__,
- __FILE__, __LINE__);
+ BT_LOGE_STR("Failed to set unsigned integer value.");
goto end;
}
}
ret = 0;
+ goto end;
+error:
+ ret = -1;
end:
return ret;
}
struct bt_ctf_clock_class *clock_class = NULL;
trace = bt_ctf_stream_class_get_trace(stream_class);
- if (!trace) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto end;
- }
+ assert(trace);
/* FIXME multi-clock? */
clock_class = bt_ctf_trace_get_clock_class_by_index(trace, 0);
bt_put(trace);
-end:
+
return clock_class;
}
struct bt_ctf_clock_class *clock_class = NULL;
event_class = bt_ctf_event_get_class(event);
- if (!event_class) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto end;
- }
+ assert(event_class);
stream_class = bt_ctf_event_class_get_stream_class(event_class);
BT_PUT(event_class);
- if (!stream_class) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto end;
- }
+ assert(stream_class);
clock_class = stream_class_get_clock_class(err, stream_class);
bt_put(stream_class);
-end:
return clock_class;
}
clock_value = bt_ctf_event_get_clock_value(event, clock_class);
BT_PUT(clock_class);
- if (!clock_value) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto error;
- }
+ assert(clock_value);
ret = bt_ctf_clock_value_get_value(clock_value, &value);
BT_PUT(clock_value);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE("Failed to get clock value.");
goto error;
}
ret = bt_ctf_field_unsigned_integer_set_value(copy_field, value);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to set unsigned integer value.");
goto error;
}
writer_clock_class = event_get_clock_class(err, writer_event);
- if (!writer_clock_class) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
- goto error;
- }
+ assert(writer_clock_class);
writer_clock_value = bt_ctf_clock_value_create(writer_clock_class, value);
BT_PUT(writer_clock_class);
if (!writer_clock_value) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to create clock value.");
goto error;
}
ret = bt_ctf_event_set_clock_value(writer_event, writer_clock_value);
BT_PUT(writer_clock_value);
if (ret) {
- fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
- __LINE__);
+ BT_LOGE_STR("Failed to set clock value.");
goto error;
}