From: Philippe Proulx Date: Wed, 13 Feb 2019 17:13:26 +0000 (-0500) Subject: Make parent parameters const for some object creation functions X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=3b97c4201bef9b602b854c29e17a5c41018e1314;p=deliverable%2Fbabeltrace.git Make parent parameters const for some object creation functions The goal of this patch is for a filter message iterator to be able to create new messages with existing streams, packets, or clock classes (not created by itself). This can be used to replace an original message by a similar one, but slightly different. One use case is `flt.utils.trimmer` which potentially needs to remove original stream activity beginning/end messages and insert its own ones to represent the trimming time range. `flt.utils.trimmer` also needs to change the beginning and end times of discarded events/packets messages, which it can do now by creating new messages using the original stream. We cannot apply this to something like bt_stream_create() (making the stream class and trace parameters const) because a stream has a parent (trace object), therefore clashes could exist if any filter can add a new stream to a trace which it did not create. Events, packets, and messages have no parent. Signed-off-by: Philippe Proulx --- diff --git a/include/babeltrace/graph/message-discarded-events.h b/include/babeltrace/graph/message-discarded-events.h index 787691d0c..436ddcf62 100644 --- a/include/babeltrace/graph/message-discarded-events.h +++ b/include/babeltrace/graph/message-discarded-events.h @@ -34,11 +34,11 @@ extern "C" { extern bt_message *bt_message_discarded_events_create( bt_self_message_iterator *message_iterator, - bt_stream *stream); + const bt_stream *stream); extern bt_message *bt_message_discarded_events_create_with_default_clock_snapshots( bt_self_message_iterator *message_iterator, - bt_stream *stream, uint64_t beginning_raw_value, + const bt_stream *stream, uint64_t beginning_raw_value, uint64_t end_raw_value); extern bt_stream *bt_message_discarded_events_borrow_stream( diff --git a/include/babeltrace/graph/message-discarded-packets.h b/include/babeltrace/graph/message-discarded-packets.h index cb8dc7382..d12768cae 100644 --- a/include/babeltrace/graph/message-discarded-packets.h +++ b/include/babeltrace/graph/message-discarded-packets.h @@ -34,11 +34,11 @@ extern "C" { extern bt_message *bt_message_discarded_packets_create( bt_self_message_iterator *message_iterator, - bt_stream *stream); + const bt_stream *stream); extern bt_message *bt_message_discarded_packets_create_with_default_clock_snapshots( bt_self_message_iterator *message_iterator, - bt_stream *stream, uint64_t beginning_raw_value, + const bt_stream *stream, uint64_t beginning_raw_value, uint64_t end_raw_value); extern bt_stream *bt_message_discarded_packets_borrow_stream( diff --git a/include/babeltrace/graph/message-event.h b/include/babeltrace/graph/message-event.h index 9a7274751..733d91ad5 100644 --- a/include/babeltrace/graph/message-event.h +++ b/include/babeltrace/graph/message-event.h @@ -37,8 +37,8 @@ extern "C" { extern bt_message *bt_message_event_create( bt_self_message_iterator *message_iterator, - bt_event_class *event_class, - bt_packet *packet); + const bt_event_class *event_class, + const bt_packet *packet); extern bt_event *bt_message_event_borrow_event( bt_message *message); diff --git a/include/babeltrace/graph/message-inactivity.h b/include/babeltrace/graph/message-inactivity.h index 2549815d2..d2d43d011 100644 --- a/include/babeltrace/graph/message-inactivity.h +++ b/include/babeltrace/graph/message-inactivity.h @@ -35,7 +35,7 @@ extern "C" { extern bt_message *bt_message_inactivity_create( bt_self_message_iterator *message_iterator, - bt_clock_class *default_clock_class); + const bt_clock_class *default_clock_class); extern void bt_message_inactivity_set_default_clock_snapshot( bt_message *msg, uint64_t raw_value); diff --git a/include/babeltrace/graph/message-packet-beginning.h b/include/babeltrace/graph/message-packet-beginning.h index e7d425467..0b60cc961 100644 --- a/include/babeltrace/graph/message-packet-beginning.h +++ b/include/babeltrace/graph/message-packet-beginning.h @@ -34,7 +34,7 @@ extern "C" { extern bt_message *bt_message_packet_beginning_create( bt_self_message_iterator *message_iterator, - bt_packet *packet); + const bt_packet *packet); extern bt_packet *bt_message_packet_beginning_borrow_packet( bt_message *message); diff --git a/include/babeltrace/graph/message-packet-end.h b/include/babeltrace/graph/message-packet-end.h index 12cf0fc71..1d049ca1b 100644 --- a/include/babeltrace/graph/message-packet-end.h +++ b/include/babeltrace/graph/message-packet-end.h @@ -34,7 +34,7 @@ extern "C" { extern bt_message *bt_message_packet_end_create( bt_self_message_iterator *message_iterator, - bt_packet *packet); + const bt_packet *packet); extern bt_packet *bt_message_packet_end_borrow_packet( bt_message *message); diff --git a/include/babeltrace/graph/message-stream-activity-beginning.h b/include/babeltrace/graph/message-stream-activity-beginning.h index 2449a7286..d8ad11475 100644 --- a/include/babeltrace/graph/message-stream-activity-beginning.h +++ b/include/babeltrace/graph/message-stream-activity-beginning.h @@ -35,7 +35,7 @@ extern "C" { extern bt_message *bt_message_stream_activity_beginning_create( bt_self_message_iterator *message_iterator, - bt_stream *stream); + const bt_stream *stream); extern bt_stream *bt_message_stream_activity_beginning_borrow_stream( bt_message *message); diff --git a/include/babeltrace/graph/message-stream-activity-end.h b/include/babeltrace/graph/message-stream-activity-end.h index 7836745e3..cb4f26eaf 100644 --- a/include/babeltrace/graph/message-stream-activity-end.h +++ b/include/babeltrace/graph/message-stream-activity-end.h @@ -35,7 +35,7 @@ extern "C" { extern bt_message *bt_message_stream_activity_end_create( bt_self_message_iterator *message_iterator, - bt_stream *stream); + const bt_stream *stream); extern void bt_message_stream_activity_end_set_default_clock_snapshot_state( bt_message *msg, diff --git a/include/babeltrace/graph/message-stream-beginning.h b/include/babeltrace/graph/message-stream-beginning.h index 339c819e0..a93dd595b 100644 --- a/include/babeltrace/graph/message-stream-beginning.h +++ b/include/babeltrace/graph/message-stream-beginning.h @@ -34,7 +34,7 @@ extern "C" { extern bt_message *bt_message_stream_beginning_create( bt_self_message_iterator *message_iterator, - bt_stream *stream); + const bt_stream *stream); extern bt_stream *bt_message_stream_beginning_borrow_stream( bt_message *message); diff --git a/include/babeltrace/graph/message-stream-end.h b/include/babeltrace/graph/message-stream-end.h index a9865d42d..f78f6f59c 100644 --- a/include/babeltrace/graph/message-stream-end.h +++ b/include/babeltrace/graph/message-stream-end.h @@ -34,7 +34,7 @@ extern "C" { extern bt_message *bt_message_stream_end_create( bt_self_message_iterator *message_iterator, - bt_stream *stream); + const bt_stream *stream); extern bt_stream *bt_message_stream_end_borrow_stream( bt_message *message); diff --git a/include/babeltrace/trace-ir/packet.h b/include/babeltrace/trace-ir/packet.h index 54c35a05b..2db26decb 100644 --- a/include/babeltrace/trace-ir/packet.h +++ b/include/babeltrace/trace-ir/packet.h @@ -38,7 +38,7 @@ extern "C" { #endif -extern bt_packet *bt_packet_create(bt_stream *stream); +extern bt_packet *bt_packet_create(const bt_stream *stream); extern bt_stream *bt_packet_borrow_stream(bt_packet *packet); diff --git a/lib/graph/message/discarded-items.c b/lib/graph/message/discarded-items.c index 9393f6caa..78b30e45b 100644 --- a/lib/graph/message/discarded-items.c +++ b/lib/graph/message/discarded-items.c @@ -193,20 +193,20 @@ borrow_discarded_items_message_default_end_clock_snapshot_const( struct bt_message *bt_message_discarded_events_create( struct bt_self_message_iterator *message_iterator, - struct bt_stream *stream) + const struct bt_stream *stream) { return create_discarded_items_message(message_iterator, - BT_MESSAGE_TYPE_DISCARDED_EVENTS, stream, + BT_MESSAGE_TYPE_DISCARDED_EVENTS, (void *) stream, false, 0, 0); } struct bt_message *bt_message_discarded_events_create_with_default_clock_snapshots( struct bt_self_message_iterator *message_iterator, - struct bt_stream *stream, uint64_t beginning_raw_value, + const struct bt_stream *stream, uint64_t beginning_raw_value, uint64_t end_raw_value) { return create_discarded_items_message(message_iterator, - BT_MESSAGE_TYPE_DISCARDED_EVENTS, stream, + BT_MESSAGE_TYPE_DISCARDED_EVENTS, (void *) stream, true, beginning_raw_value, end_raw_value); } @@ -265,20 +265,20 @@ enum bt_property_availability bt_message_discarded_events_get_count( struct bt_message *bt_message_discarded_packets_create( struct bt_self_message_iterator *message_iterator, - struct bt_stream *stream) + const struct bt_stream *stream) { return create_discarded_items_message(message_iterator, - BT_MESSAGE_TYPE_DISCARDED_PACKETS, stream, + BT_MESSAGE_TYPE_DISCARDED_PACKETS, (void *) stream, false, 0, 0); } struct bt_message *bt_message_discarded_packets_create_with_default_clock_snapshots( struct bt_self_message_iterator *message_iterator, - struct bt_stream *stream, uint64_t beginning_raw_value, + const struct bt_stream *stream, uint64_t beginning_raw_value, uint64_t end_raw_value) { return create_discarded_items_message(message_iterator, - BT_MESSAGE_TYPE_DISCARDED_PACKETS, stream, + BT_MESSAGE_TYPE_DISCARDED_PACKETS, (void *) stream, true, beginning_raw_value, end_raw_value); } diff --git a/lib/graph/message/event.c b/lib/graph/message/event.c index b6517f82c..2b4b4ba8d 100644 --- a/lib/graph/message/event.c +++ b/lib/graph/message/event.c @@ -76,12 +76,14 @@ end: struct bt_message *bt_message_event_create( struct bt_self_message_iterator *self_msg_iter, - struct bt_event_class *event_class, - struct bt_packet *packet) + const struct bt_event_class *c_event_class, + const struct bt_packet *c_packet) { struct bt_self_component_port_input_message_iterator *msg_iter = (void *) self_msg_iter; struct bt_message_event *message = NULL; + struct bt_event_class *event_class = (void *) c_event_class; + struct bt_packet *packet = (void *) c_packet; struct bt_event *event; BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator"); diff --git a/lib/graph/message/inactivity.c b/lib/graph/message/inactivity.c index f2828d1cf..ada6dc67f 100644 --- a/lib/graph/message/inactivity.c +++ b/lib/graph/message/inactivity.c @@ -51,7 +51,7 @@ void bt_message_inactivity_destroy(struct bt_object *obj) struct bt_message *bt_message_inactivity_create( struct bt_self_message_iterator *self_msg_iter, - struct bt_clock_class *default_clock_class) + const struct bt_clock_class *default_clock_class) { struct bt_self_component_port_input_message_iterator *msg_iter = (void *) self_msg_iter; @@ -72,7 +72,8 @@ struct bt_message *bt_message_inactivity_create( BT_MESSAGE_TYPE_INACTIVITY, bt_message_inactivity_destroy, NULL); ret_msg = &message->parent; - message->default_cs = bt_clock_snapshot_create(default_clock_class); + message->default_cs = bt_clock_snapshot_create( + (void *) default_clock_class); if (!message->default_cs) { goto error; } diff --git a/lib/graph/message/packet.c b/lib/graph/message/packet.c index 32ce56980..adf64950a 100644 --- a/lib/graph/message/packet.c +++ b/lib/graph/message/packet.c @@ -117,25 +117,25 @@ end: struct bt_message *bt_message_packet_beginning_create( struct bt_self_message_iterator *self_msg_iter, - struct bt_packet *packet) + const struct bt_packet *packet) { struct bt_self_component_port_input_message_iterator *msg_iter = (void *) self_msg_iter; BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator"); - return bt_message_packet_create(msg_iter, packet, + return bt_message_packet_create(msg_iter, (void *) packet, &msg_iter->graph->packet_begin_msg_pool); } struct bt_message *bt_message_packet_end_create( struct bt_self_message_iterator *self_msg_iter, - struct bt_packet *packet) + const struct bt_packet *packet) { struct bt_self_component_port_input_message_iterator *msg_iter = (void *) self_msg_iter; BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator"); - return bt_message_packet_create(msg_iter, packet, + return bt_message_packet_create(msg_iter, (void *) packet, &msg_iter->graph->packet_end_msg_pool); } diff --git a/lib/graph/message/stream-activity.c b/lib/graph/message/stream-activity.c index fcee3dd1d..ccbe240a8 100644 --- a/lib/graph/message/stream-activity.c +++ b/lib/graph/message/stream-activity.c @@ -102,17 +102,17 @@ error: struct bt_message *bt_message_stream_activity_beginning_create( struct bt_self_message_iterator *self_msg_iter, - struct bt_stream *stream) + const struct bt_stream *stream) { - return create_stream_activity_message(self_msg_iter, stream, + return create_stream_activity_message(self_msg_iter, (void *) stream, BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING); } struct bt_message *bt_message_stream_activity_end_create( struct bt_self_message_iterator *self_msg_iter, - struct bt_stream *stream) + const struct bt_stream *stream) { - return create_stream_activity_message(self_msg_iter, stream, + return create_stream_activity_message(self_msg_iter, (void *) stream, BT_MESSAGE_TYPE_STREAM_ACTIVITY_END); } diff --git a/lib/graph/message/stream.c b/lib/graph/message/stream.c index 212e6482f..ec6cd8cb2 100644 --- a/lib/graph/message/stream.c +++ b/lib/graph/message/stream.c @@ -86,17 +86,17 @@ error: struct bt_message *bt_message_stream_beginning_create( struct bt_self_message_iterator *self_msg_iter, - struct bt_stream *stream) + const struct bt_stream *stream) { - return create_stream_message(self_msg_iter, stream, + return create_stream_message(self_msg_iter, (void *) stream, BT_MESSAGE_TYPE_STREAM_BEGINNING); } struct bt_message *bt_message_stream_end_create( struct bt_self_message_iterator *self_msg_iter, - struct bt_stream *stream) + const struct bt_stream *stream) { - return create_stream_message(self_msg_iter, stream, + return create_stream_message(self_msg_iter, (void *) stream, BT_MESSAGE_TYPE_STREAM_END); } diff --git a/lib/trace-ir/clock-snapshot.c b/lib/trace-ir/clock-snapshot.c index 792b3fc08..def5e7bcc 100644 --- a/lib/trace-ir/clock-snapshot.c +++ b/lib/trace-ir/clock-snapshot.c @@ -44,7 +44,8 @@ void bt_clock_snapshot_destroy(struct bt_clock_snapshot *clock_snapshot) } BT_HIDDEN -struct bt_clock_snapshot *bt_clock_snapshot_new(struct bt_clock_class *clock_class) +struct bt_clock_snapshot *bt_clock_snapshot_new( + struct bt_clock_class *clock_class) { struct bt_clock_snapshot *ret = NULL; @@ -68,7 +69,8 @@ end: } BT_HIDDEN -struct bt_clock_snapshot *bt_clock_snapshot_create(struct bt_clock_class *clock_class) +struct bt_clock_snapshot *bt_clock_snapshot_create( + struct bt_clock_class *clock_class) { struct bt_clock_snapshot *clock_snapshot = NULL; @@ -135,7 +137,8 @@ void bt_clock_snapshot_recycle(struct bt_clock_snapshot *clock_snapshot) bt_object_put_ref(clock_class); } -uint64_t bt_clock_snapshot_get_value(const struct bt_clock_snapshot *clock_snapshot) +uint64_t bt_clock_snapshot_get_value( + const struct bt_clock_snapshot *clock_snapshot) { BT_ASSERT_PRE_NON_NULL(clock_snapshot, "Clock snapshot"); BT_ASSERT_PRE(clock_snapshot->is_set, diff --git a/lib/trace-ir/packet.c b/lib/trace-ir/packet.c index f3e27dd2a..cab9f89ce 100644 --- a/lib/trace-ir/packet.c +++ b/lib/trace-ir/packet.c @@ -265,9 +265,10 @@ end: return packet; } -struct bt_packet *bt_packet_create(struct bt_stream *stream) +struct bt_packet *bt_packet_create(const struct bt_stream *c_stream) { struct bt_packet *packet = NULL; + struct bt_stream *stream = (void *) c_stream; BT_ASSERT_PRE_NON_NULL(stream, "Stream"); packet = bt_object_pool_create_object(&stream->packet_pool);