The source component class implementation and the shared object plugin macros are in the same file, dust.c
:
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <babeltrace2/babeltrace.h>
struct dust_in {
};
static
const char *name)
{
msg_field_class);
return event_class;
}
static
struct dust_in *dust_in)
{
dust_in->send_msg_event_class = create_event_class(stream_class,
"send-msg");
dust_in->recv_msg_event_class = create_event_class(stream_class,
"recv-msg");
}
static
const bt_value *params,
void *initialize_method_data)
{
struct dust_in *dust_in = malloc(sizeof(*dust_in));
dust_in->path_value =
create_metadata_and_stream(self_component, dust_in);
"out", NULL, NULL);
}
static
{
free(dust_in);
}
enum dust_in_message_iterator_state {
DUST_IN_MESSAGE_ITERATOR_STATE_STREAM_BEGINNING,
DUST_IN_MESSAGE_ITERATOR_STATE_EVENT,
DUST_IN_MESSAGE_ITERATOR_STATE_ENDED,
};
struct dust_in_message_iterator {
struct dust_in *dust_in;
enum dust_in_message_iterator_state state;
FILE *file;
char name_buffer[32];
char msg_buffer[1024];
};
static
dust_in_message_iterator_initialize(
{
struct dust_in_message_iterator *dust_in_iter =
malloc(sizeof(*dust_in_iter));
dust_in_iter->dust_in = dust_in;
dust_in_iter->state = DUST_IN_MESSAGE_ITERATOR_STATE_STREAM_BEGINNING;
dust_in_iter->file = fopen(path, "r");
}
static
void dust_in_message_iterator_finalize(
{
struct dust_in_message_iterator *dust_in_iter =
fclose(dust_in_iter->file);
free(dust_in_iter);
}
static
struct dust_in_message_iterator *dust_in_iter,
{
uint64_t timestamp;
uint64_t extra_us;
int count = fscanf(dust_in_iter->file, "%" PRIu64 " %" PRIu64 " %s %[^\n]",
×tamp, &extra_us, &dust_in_iter->name_buffer[0],
&dust_in_iter->msg_buffer[0]);
if (count == EOF || feof(dust_in_iter->file)) {
dust_in_iter->dust_in->stream);
dust_in_iter->state = DUST_IN_MESSAGE_ITERATOR_STATE_ENDED;
goto end;
}
if (strcmp(dust_in_iter->name_buffer, "send-msg") == 0) {
event_class = dust_in_iter->dust_in->send_msg_event_class;
} else {
event_class = dust_in_iter->dust_in->recv_msg_event_class;
}
timestamp *= UINT64_C(1000000000);
timestamp += extra_us * UINT64_C(1000);
self_message_iterator, event_class, dust_in_iter->dust_in->stream,
timestamp);
payload_field, 0);
end:
return message;
}
static
uint64_t *count)
{
struct dust_in_message_iterator *dust_in_iter =
switch (dust_in_iter->state) {
case DUST_IN_MESSAGE_ITERATOR_STATE_STREAM_BEGINNING:
dust_in_iter->dust_in->stream);
dust_in_iter->state = DUST_IN_MESSAGE_ITERATOR_STATE_EVENT;
break;
case DUST_IN_MESSAGE_ITERATOR_STATE_EVENT:
message = create_message_from_line(dust_in_iter,
self_message_iterator);
break;
case DUST_IN_MESSAGE_ITERATOR_STATE_ENDED:
status =
goto end;
}
if (message) {
messages[0] = message;
*count = 1;
}
end:
return status;
}
dust_in_message_iterator_initialize);
dust_in_message_iterator_finalize);
bt_message const ** bt_message_array_const
Array of constant messages.
Definition types.h:182
bt_component_class_initialize_method_status
Status codes for bt_component_class_source_initialize_method, bt_component_class_filter_initialize_me...
Definition component-class-dev.h:891
@ BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
Success.
Definition component-class-dev.h:896
bt_message_iterator_class_initialize_method_status
Status codes for bt_message_iterator_class_initialize_method.
Definition message-iterator-class.h:661
bt_message_iterator_class_next_method_status
Status codes for bt_message_iterator_class_next_method.
Definition message-iterator-class.h:718
@ BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK
Success.
Definition message-iterator-class.h:666
@ BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
Success.
Definition message-iterator-class.h:723
@ BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END
End of iteration.
Definition message-iterator-class.h:729
struct bt_message bt_message
Message.
Definition types.h:58
bt_message * bt_message_stream_beginning_create(bt_self_message_iterator *self_message_iterator, const bt_stream *stream)
Creates a stream beginning message for the stream stream from the message iterator self_message_itera...
bt_message * bt_message_event_create_with_default_clock_snapshot(bt_self_message_iterator *self_message_iterator, const bt_event_class *event_class, const bt_stream *stream, uint64_t clock_snapshot_value)
Creates an event message, having an instance of the event class event_class and a default clock snaps...
bt_event * bt_message_event_borrow_event(bt_message *message)
Borrows the event of the event message message.
bt_message * bt_message_stream_end_create(bt_self_message_iterator *self_message_iterator, const bt_stream *stream)
Creates a stream end message for the stream stream from the message iterator self_message_iterator.
#define BT_PLUGIN_SOURCE_COMPONENT_CLASS(_name, _message_iterator_class_next_method)
Alias of BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID() with the _plugin_id parameter set to auto,...
Definition plugin-dev.h:773
#define BT_PLUGIN_MODULE()
Defines a plugin module.
Definition plugin-dev.h:335
#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_FINALIZE_METHOD(_name, _method)
Alias of BT_PLUGIN_SOURCE_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID() with the _plugin_id parameter set...
Definition plugin-dev.h:1242
#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD(_name, _method)
Alias of BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_WITH_ID() with the...
Definition plugin-dev.h:1425
#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_FINALIZE_METHOD(_name, _method)
Alias of BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_FINALIZE_METHOD_WITH_ID() with the _...
Definition plugin-dev.h:1379
#define BT_PLUGIN(_name)
Alias of BT_PLUGIN_WITH_ID() with the _id parameter set to auto.
Definition plugin-dev.h:423
#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_INITIALIZE_METHOD(_name, _method)
Alias of BT_PLUGIN_SOURCE_COMPONENT_CLASS_INITIALIZE_METHOD_WITH_ID() with the _plugin_id parameter s...
Definition plugin-dev.h:1333
struct bt_self_component_port_output bt_self_component_port_output
Self component output port.
Definition types.h:81
struct bt_self_component bt_self_component
Self component.
Definition types.h:71
bt_self_component_add_port_status bt_self_component_source_add_output_port(bt_self_component_source *self_component, const char *name, void *user_data, bt_self_component_port_output **self_component_port)
Adds an output port named name and having the user data user_data to the source component self_compon...
void * bt_self_component_get_data(const bt_self_component *self_component)
Returns the user data of the component self_component.
struct bt_self_component_source bt_self_component_source
Self source component.
Definition types.h:84
static bt_self_component * bt_self_component_source_as_self_component(bt_self_component_source *self_component)
Upcasts the self source component self_component to the common bt_self_component type.
Definition self-component.h:811
void bt_self_component_set_data(bt_self_component *self_component, void *user_data)
Sets the user data of the component self_component to data.
struct bt_self_component_source_configuration bt_self_component_source_configuration
Self source component configuration.
Definition types.h:85
struct bt_self_message_iterator_configuration bt_self_message_iterator_configuration
Self message iterator configuration.
Definition types.h:87
bt_self_component * bt_self_message_iterator_borrow_component(bt_self_message_iterator *self_message_iterator)
Borrows the component which provides the message iterator self_message_iterator.
void * bt_self_message_iterator_get_data(const bt_self_message_iterator *self_message_iterator)
Returns the user data of the message iterator self_message_iterator.
struct bt_self_message_iterator bt_self_message_iterator
Self message iterator.
Definition types.h:86
void bt_self_message_iterator_set_data(bt_self_message_iterator *self_message_iterator, void *user_data)
Sets the user data of the message iterator self_message_iterator to data.
struct bt_clock_class bt_clock_class
Clock class.
Definition types.h:22
void bt_clock_class_put_ref(const bt_clock_class *clock_class)
Decrements the reference count of the clock class clock_class.
bt_clock_class * bt_clock_class_create(bt_self_component *self_component)
Creates a default clock class from the self component self_component.
void bt_event_class_put_ref(const bt_event_class *event_class)
Decrements the reference count of the event class event_class.
bt_event_class * bt_event_class_create(bt_stream_class *stream_class)
Creates a default event class and adds it to the stream class stream_class.
bt_event_class_set_field_class_status bt_event_class_set_payload_field_class(bt_event_class *event_class, bt_field_class *field_class)
Sets the payload field class of the event class event_class to field_class.
bt_event_class_set_name_status bt_event_class_set_name(bt_event_class *event_class, const char *name)
Sets the name of the event class event_class to a copy of name.
struct bt_event_class bt_event_class
Event class.
Definition types.h:37
bt_field * bt_event_borrow_payload_field(bt_event *event)
Borrows the payload field of the event event.
struct bt_event bt_event
Event.
Definition types.h:36
void bt_field_class_put_ref(const bt_field_class *field_class)
Decrements the reference count of the field class field_class.
struct bt_field_class bt_field_class
Field class.
Definition types.h:39
bt_field_class * bt_field_class_structure_create(bt_trace_class *trace_class)
Creates a structure field class from the trace class trace_class.
bt_field_class * bt_field_class_string_create(bt_trace_class *trace_class)
Creates a string field class from the trace class trace_class.
bt_field_class_structure_append_member_status bt_field_class_structure_append_member(bt_field_class *field_class, const char *name, bt_field_class *member_field_class)
Appends a member to the structure field class field_class having the name name and the field class me...
bt_field_string_set_value_status bt_field_string_set_value(bt_field *field, const char *value)
Sets the value of the string field field to a copy of value.
bt_field * bt_field_structure_borrow_member_field_by_index(bt_field *field, uint64_t index)
Borrows the field of the member at index index from the structure field field.
struct bt_field bt_field
Field.
Definition types.h:38
bt_stream_class_set_default_clock_class_status bt_stream_class_set_default_clock_class(bt_stream_class *stream_class, bt_clock_class *clock_class)
Sets the default clock class of the stream class stream_class to clock_class.
struct bt_stream_class bt_stream_class
Stream class.
Definition types.h:90
bt_stream_class * bt_stream_class_create(bt_trace_class *trace_class)
Creates a default stream class and adds it to the trace class trace_class.
bt_trace_class * bt_stream_class_borrow_trace_class(bt_stream_class *stream_class)
Borrows the trace class which contains the stream class stream_class.
void bt_stream_class_put_ref(const bt_stream_class *stream_class)
Decrements the reference count of the stream class stream_class.
void bt_stream_put_ref(const bt_stream *stream)
Decrements the reference count of the stream stream.
bt_stream * bt_stream_create(bt_stream_class *stream_class, bt_trace *trace)
Creates a stream from the stream class stream_class and adds it to the trace trace.
struct bt_stream bt_stream
Stream.
Definition types.h:89
void bt_trace_class_put_ref(const bt_trace_class *trace_class)
Decrements the reference count of the trace class trace_class.
bt_trace_class * bt_trace_class_create(bt_self_component *self_component)
Creates a default trace class from the self component self_component.
struct bt_trace_class bt_trace_class
Trace class.
Definition types.h:92
bt_trace * bt_trace_create(bt_trace_class *trace_class)
Creates a default trace from the trace class trace_class.
void bt_trace_put_ref(const bt_trace *trace)
Decrements the reference count of the trace trace.
struct bt_trace bt_trace
Trace.
Definition types.h:91
struct bt_value bt_value
Value.
Definition types.h:93
void bt_value_get_ref(const bt_value *value)
Increments the reference count of the value value.
void bt_value_put_ref(const bt_value *value)
Decrements the reference count of the value value.
const char * bt_value_string_get(const bt_value *value)
Returns the raw value of the string value value.
const bt_value * bt_value_map_borrow_entry_value_const(const bt_value *value, const char *key)
Borrows the value of the entry with the key key in the map value value (const version).