Add field value is_set and reset functions to the public API
[babeltrace.git] / lib / ctf-ir / stream.c
index f13c024a3f230628853a5730c826c113b2bc6834..5741a7a520f6fbc4126f50ec031b5be12f269174 100644 (file)
@@ -360,7 +360,7 @@ int set_packet_context_events_discarded(struct bt_ctf_stream *stream)
         * discarded events. We do not allow wrapping here. If it's
         * valid, update the stream's current count.
         */
-       if (bt_ctf_field_is_set(field)) {
+       if (bt_ctf_field_value_is_set(field)) {
                uint64_t user_val;
 
                ret = bt_ctf_field_unsigned_integer_get_value(field,
@@ -1156,7 +1156,7 @@ static int auto_populate_event_header(struct bt_ctf_stream *stream,
        int ret = 0;
        struct bt_ctf_field *id_field = NULL, *timestamp_field = NULL;
        struct bt_ctf_clock_class *mapped_clock_class = NULL;
-       uint64_t event_class_id;
+       int64_t event_class_id;
 
        assert(event);
 
@@ -1175,8 +1175,12 @@ static int auto_populate_event_header(struct bt_ctf_stream *stream,
                stream, bt_ctf_stream_get_name(stream), event);
 
        id_field = bt_ctf_field_structure_get_field(event->event_header, "id");
-       event_class_id = (uint64_t) bt_ctf_event_class_get_id(event->event_class);
-       assert(event_class_id >= 0);
+       event_class_id = bt_ctf_event_class_get_id(event->event_class);
+       if (event_class_id < 0) {
+               BT_LOGE("Event class ID cannot be found");
+               ret = -1;
+               goto end;
+       }
        if (id_field && bt_ctf_field_type_is_integer(id_field->type)) {
                ret = set_integer_field_value(id_field, event_class_id);
                if (ret) {
@@ -1490,7 +1494,7 @@ void reset_structure_field(struct bt_ctf_field *structure, const char *name)
 
        member = bt_ctf_field_structure_get_field(structure, name);
        if (member) {
-               (void) bt_ctf_field_reset(member);
+               (void) bt_ctf_field_reset_value(member);
                bt_put(member);
        }
 }
@@ -1507,7 +1511,7 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
        if (!stream) {
                BT_LOGW_STR("Invalid parameter: stream is NULL.");
                ret = -1;
-               goto end;
+               goto end_no_stream;
        }
 
        if (stream->pos.fd < 0) {
@@ -1711,17 +1715,6 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
        stream->flushed_packet_count++;
        stream->size += stream->pos.packet_size / CHAR_BIT;
 
-       do {
-               ret = ftruncate(stream->pos.fd, stream->size);
-       } while (ret == -1 && errno == EINTR);
-       if (ret == -1) {
-               BT_LOGE_ERRNO("Cannot truncate stream file to new size",
-                               ": size=%" PRIu64 ", stream-addr=%p, "
-                               "stream-name=\"%s\"",
-                               stream->size, stream,
-                               bt_ctf_stream_get_name(stream));
-       }
-
 end:
        /* Reset automatically-set fields. */
        if (stream->packet_context) {
@@ -1745,6 +1738,8 @@ end:
                        "packet-size=%" PRIu64,
                        stream->pos.offset, stream->pos.packet_size);
        }
+
+end_no_stream:
        return ret;
 }
 
@@ -1867,7 +1862,7 @@ int _set_structure_field_integer(struct bt_ctf_field *structure, char *name,
        }
 
        /* Make sure the payload has not already been set. */
-       if (!force && bt_ctf_field_is_set(integer)) {
+       if (!force && bt_ctf_field_value_is_set(integer)) {
                /* Payload already set, not an error */
                BT_LOGV("Field's payload is already set: struct-field-addr=%p, "
                        "name=\"%s\", force=%d", structure, name, force);
This page took 0.025016 seconds and 4 git commands to generate.