#include <babeltrace/ctf-writer/trace-internal.h>
#include <babeltrace/ctf-writer/trace.h>
#include <babeltrace/ctf-writer/writer-internal.h>
-#include <babeltrace/ref.h>
+#include <babeltrace/ctf-writer/object.h>
#include <inttypes.h>
#include <stdint.h>
#include <unistd.h>
int bt_ctf_stream_common_initialize(
struct bt_ctf_stream_common *stream,
struct bt_ctf_stream_class_common *stream_class, const char *name,
- uint64_t id, bt_object_release_func release_func)
+ uint64_t id, bt_ctf_object_release_func release_func)
{
int ret = 0;
struct bt_ctf_trace_common *trace = NULL;
- bt_object_init_shared_with_parent(&stream->base, release_func);
+ bt_ctf_object_init_shared_with_parent(&stream->base, release_func);
if (!stream_class) {
BT_LOGW_STR("Invalid parameter: stream class is NULL.");
* Acquire reference to parent since stream will become publicly
* reachable; it needs its parent to remain valid.
*/
- bt_object_set_parent(&stream->base, &trace->base);
+ bt_ctf_object_set_parent(&stream->base, &trace->base);
stream->stream_class = stream_class;
stream->id = (int64_t) id;
}
static
-void bt_ctf_stream_destroy(struct bt_object *obj);
+void bt_ctf_stream_destroy(struct bt_ctf_object *obj);
static
int try_set_structure_field_integer(struct bt_ctf_field *, char *, uint64_t);
}
}
end:
- bt_put(field_type);
+ bt_ctf_object_put_ref(field_type);
return ret;
}
magic_field, (uint64_t) magic_value);
}
end:
- bt_put(magic_field);
+ bt_ctf_object_put_ref(magic_field);
return ret;
}
}
trace = (struct bt_ctf_trace *)
- bt_object_get_parent(&stream->common.base);
+ bt_ctf_object_get_parent(&stream->common.base);
for (i = 0; i < 16; i++) {
struct bt_ctf_field *uuid_element =
ret = bt_ctf_field_integer_unsigned_set_value(
uuid_element, (uint64_t) trace->common.uuid[i]);
- bt_put(uuid_element);
+ bt_ctf_object_put_ref(uuid_element);
if (ret) {
BT_LOGW("Cannot set integer field's value (for `uuid` packet header field): "
"stream-addr=%p, stream-name=\"%s\", field-addr=%p, "
stream, bt_ctf_stream_get_name(stream), uuid_field);
end:
- bt_put(uuid_field);
- BT_PUT(trace);
+ bt_ctf_object_put_ref(uuid_field);
+ BT_CTF_OBJECT_PUT_REF_AND_RESET(trace);
return ret;
}
static
}
end:
- bt_put(stream_id_field);
+ bt_ctf_object_put_ref(stream_id_field);
return ret;
}
}
end:
- bt_put(field);
+ bt_ctf_object_put_ref(field);
return ret;
}
}
end:
- bt_put(field);
+ bt_ctf_object_put_ref(field);
return ret;
}
}
end:
- bt_put(field);
+ bt_ctf_object_put_ref(field);
return ret;
}
goto end;
}
- bt_put(cc);
+ bt_ctf_object_put_ref(cc);
val_size = bt_ctf_field_type_integer_get_size(
(void *) field_common->type);
BT_ASSERT(val_size >= 1);
BT_ASSERT(int_field);
ret = visit_field_update_clock_value(int_field, val);
- bt_put(int_field);
+ bt_ctf_object_put_ref(int_field);
break;
}
case BT_CTF_FIELD_TYPE_ID_ARRAY:
BT_ASSERT(elem_field);
ret = visit_field_update_clock_value(elem_field, val);
- bt_put(elem_field);
+ bt_ctf_object_put_ref(elem_field);
if (ret) {
goto end;
}
BT_ASSERT(elem_field);
ret = visit_field_update_clock_value(elem_field, val);
- bt_put(elem_field);
+ bt_ctf_object_put_ref(elem_field);
if (ret) {
goto end;
}
BT_ASSERT(member_field);
ret = visit_field_update_clock_value(member_field, val);
- bt_put(member_field);
+ bt_ctf_object_put_ref(member_field);
if (ret) {
goto end;
}
}
ret = visit_field_update_clock_value(cur_field, val);
- bt_put(cur_field);
+ bt_ctf_object_put_ref(cur_field);
break;
}
default:
field = bt_ctf_event_get_header(event);
ret = visit_field_update_clock_value(field, val);
- bt_put(field);
+ bt_ctf_object_put_ref(field);
if (ret) {
BT_LOGW_STR("Cannot automatically update clock value in "
"event's header.");
field = bt_ctf_event_get_stream_event_context(event);
ret = visit_field_update_clock_value(field, val);
- bt_put(field);
+ bt_ctf_object_put_ref(field);
if (ret) {
BT_LOGW_STR("Cannot automatically update clock value in "
"event's stream event context.");
field = bt_ctf_event_get_context(event);
ret = visit_field_update_clock_value(field, val);
- bt_put(field);
+ bt_ctf_object_put_ref(field);
if (ret) {
BT_LOGW_STR("Cannot automatically update clock value in "
"event's context.");
field = bt_ctf_event_get_payload_field(event);
ret = visit_field_update_clock_value(field, val);
- bt_put(field);
+ bt_ctf_object_put_ref(field);
if (ret) {
BT_LOGW_STR("Cannot automatically update clock value in "
"event's payload.");
if (strcmp(member_name, "packet_size") == 0 &&
!bt_ctf_field_is_set_recursive(member_field)) {
- bt_put(member_field);
+ bt_ctf_object_put_ref(member_field);
continue;
}
if (strcmp(member_name, "content_size") == 0 &&
!bt_ctf_field_is_set_recursive(member_field)) {
- bt_put(member_field);
+ bt_ctf_object_put_ref(member_field);
continue;
}
if (strcmp(member_name, "events_discarded") == 0 &&
!bt_ctf_field_is_set_recursive(member_field)) {
- bt_put(member_field);
+ bt_ctf_object_put_ref(member_field);
continue;
}
if (strcmp(member_name, "packet_seq_num") == 0 &&
!bt_ctf_field_is_set_recursive(member_field)) {
- bt_put(member_field);
+ bt_ctf_object_put_ref(member_field);
continue;
}
ret = visit_field_update_clock_value(member_field,
&cur_clock_value);
- bt_put(member_field);
+ bt_ctf_object_put_ref(member_field);
if (ret) {
BT_LOGW("Cannot automatically update clock value "
"in stream's packet context: "
}
end:
- bt_put(ts_begin_field);
- bt_put(ts_end_field);
+ bt_ctf_object_put_ref(ts_begin_field);
+ bt_ctf_object_put_ref(ts_end_field);
return ret;
}
static
void release_event(struct bt_ctf_event *event)
{
- if (bt_object_get_ref_count(&event->common.base)) {
+ if (bt_ctf_object_get_ref_count(&event->common.base)) {
/*
* The event is being orphaned, but it must guarantee the
* existence of its event class for the duration of its
* lifetime.
*/
- bt_get(event->common.class);
- BT_PUT(event->common.base.parent);
+ bt_ctf_object_get_ref(event->common.class);
+ BT_CTF_OBJECT_PUT_REF_AND_RESET(event->common.base.parent);
} else {
- bt_object_try_spec_release(&event->common.base);
+ bt_ctf_object_try_spec_release(&event->common.base);
}
}
stream->pos.fd = -1;
writer = (struct bt_ctf_writer *)
- bt_object_get_parent(&trace->common.base);
+ bt_ctf_object_get_parent(&trace->common.base);
stream->last_ts_end = -1ULL;
BT_LOGD("CTF writer stream object belongs writer's trace: "
"writer-addr=%p", writer);
goto end;
error:
- BT_PUT(stream);
+ BT_CTF_OBJECT_PUT_REF_AND_RESET(stream);
end:
- bt_put(writer);
+ bt_ctf_object_put_ref(writer);
return stream;
}
}
end:
- bt_put(events_discarded_field);
+ bt_ctf_object_put_ref(events_discarded_field);
return ret;
}
stream, bt_ctf_stream_get_name(stream), event_count);
end:
- bt_put(events_discarded_field);
+ bt_ctf_object_put_ref(events_discarded_field);
}
static int auto_populate_event_header(struct bt_ctf_stream *stream,
stream, bt_ctf_stream_get_name(stream), event);
end:
- bt_put(id_field);
- bt_put(timestamp_field);
- bt_put(mapped_clock_class);
+ bt_ctf_object_put_ref(id_field);
+ bt_ctf_object_put_ref(timestamp_field);
+ bt_ctf_object_put_ref(mapped_clock_class);
return ret;
}
goto end;
}
- bt_object_set_parent(&event->common.base, &stream->common.base);
+ bt_ctf_object_set_parent(&event->common.base, &stream->common.base);
BT_LOGV_STR("Automatically populating the header of the event to append.");
ret = auto_populate_event_header(stream, event);
if (ret) {
* longer needed.
*/
BT_LOGV_STR("Putting the event's class.");
- bt_put(event->common.class);
+ bt_ctf_object_put_ref(event->common.class);
BT_LOGV("Appended event to stream: "
"stream-addr=%p, stream-name=\"%s\", event-addr=%p, "
"event-class-name=\"%s\", event-class-id=%" PRId64,
* Orphan the event; we were not successful in associating it to
* a stream.
*/
- bt_object_set_parent(&event->common.base, NULL);
+ bt_ctf_object_set_parent(&event->common.base, NULL);
return ret;
}
packet_context = stream->packet_context;
if (packet_context) {
- bt_get(packet_context);
+ bt_ctf_object_get_ref(packet_context);
}
end:
return packet_context;
goto end;
}
- bt_put(field_type);
- bt_put(stream->packet_context);
- stream->packet_context = bt_get(field);
+ bt_ctf_object_put_ref(field_type);
+ bt_ctf_object_put_ref(stream->packet_context);
+ stream->packet_context = bt_ctf_object_get_ref(field);
BT_LOGV("Set stream's packet context field: "
"stream-addr=%p, stream-name=\"%s\", "
"packet-context-field-addr=%p",
packet_header = stream->packet_header;
if (packet_header) {
- bt_get(packet_header);
+ bt_ctf_object_get_ref(packet_header);
}
end:
return packet_header;
}
trace = (struct bt_ctf_trace *)
- bt_object_get_parent(&stream->common.base);
+ bt_ctf_object_get_parent(&stream->common.base);
if (!field) {
if (trace->common.packet_header_field_type) {
}
skip_validation:
- bt_put(stream->packet_header);
- stream->packet_header = bt_get(field);
+ bt_ctf_object_put_ref(stream->packet_header);
+ stream->packet_header = bt_ctf_object_get_ref(field);
BT_LOGV("Set stream's packet header field: "
"stream-addr=%p, stream-name=\"%s\", "
"packet-header-field-addr=%p",
stream, bt_ctf_stream_get_name(stream), field);
end:
- BT_PUT(trace);
- bt_put(field_type);
+ BT_CTF_OBJECT_PUT_REF_AND_RESET(trace);
+ bt_ctf_object_put_ref(field_type);
return ret;
}
member = bt_ctf_field_structure_get_field_by_name(structure, name);
if (member) {
bt_ctf_field_common_reset_recursive((void *) member);
- bt_put(member);
+ bt_ctf_object_put_ref(member);
}
}
packet_size_field = bt_ctf_field_structure_get_field_by_name(
stream->packet_context, "packet_size");
has_packet_size = (packet_size_field != NULL);
- bt_put(packet_size_field);
+ bt_ctf_object_put_ref(packet_size_field);
}
if (stream->flushed_packet_count == 1) {
struct bt_ctf_field *field = bt_ctf_field_structure_get_field_by_name(
stream->packet_context, "content_size");
- bt_put(field);
+ bt_ctf_object_put_ref(field);
if (!field) {
if (stream->pos.offset != stream->pos.packet_size) {
BT_LOGW("Stream's packet context's `content_size` field is missing, "
}
static
-void bt_ctf_stream_destroy(struct bt_object *obj)
+void bt_ctf_stream_destroy(struct bt_ctf_object *obj)
{
struct bt_ctf_stream *stream = (void *) obj;
}
BT_LOGD_STR("Putting packet header field.");
- bt_put(stream->packet_header);
+ bt_ctf_object_put_ref(stream->packet_header);
BT_LOGD_STR("Putting packet context field.");
- bt_put(stream->packet_context);
+ bt_ctf_object_put_ref(stream->packet_context);
g_free(stream);
}
}
ret = !ret ? 1 : ret;
end:
- bt_put(integer);
- bt_put(field_type);
+ bt_ctf_object_put_ref(integer);
+ bt_ctf_object_put_ref(field_type);
return ret;
}
struct bt_ctf_stream_class *bt_ctf_stream_get_class(
struct bt_ctf_stream *stream)
{
- return bt_get(bt_ctf_stream_common_borrow_class(BT_CTF_TO_COMMON(stream)));
+ return bt_ctf_object_get_ref(bt_ctf_stream_common_borrow_class(BT_CTF_TO_COMMON(stream)));
}
const char *bt_ctf_stream_get_name(struct bt_ctf_stream *stream)