#include <babeltrace/ctf-ir/field-types-internal.h>
#include <babeltrace/ctf-ir/attributes-internal.h>
#include <babeltrace/ctf-ir/validation-internal.h>
+#include <babeltrace/ctf-ir/visitor-internal.h>
#include <babeltrace/ctf-ir/utils.h>
+#include <babeltrace/plugin/notification/schema.h>
#include <babeltrace/compiler.h>
#include <babeltrace/values.h>
#include <babeltrace/ref.h>
#define DEFAULT_IDENTIFIER_SIZE 128
#define DEFAULT_METADATA_STRING_SIZE 4096
+struct notification_handler {
+ bt_ctf_notification_cb func;
+ void *data;
+};
+
static
void bt_ctf_trace_destroy(struct bt_object *obj);
static
return ret;
}
+static
+int get_stream_class_count(void *element)
+{
+ return bt_ctf_trace_get_stream_class_count(
+ (struct bt_ctf_trace *) element);
+}
+
+static
+void *get_stream_class(void *element, int i)
+{
+ return bt_ctf_trace_get_stream_class(
+ (struct bt_ctf_trace *) element, i);
+}
+
+static
+int visit_stream_class(void *element, bt_ctf_ir_visitor visitor,void *data)
+{
+ return bt_ctf_stream_class_visit(element, visitor, data);
+}
+
+int bt_ctf_trace_visit(struct bt_ctf_trace *trace,
+ bt_ctf_ir_visitor visitor, void *data)
+{
+ int ret;
+ struct bt_ctf_ir_element element =
+ { .element = trace, .type = BT_CTF_IR_TYPE_TRACE };
+
+ if (!trace || !visitor) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = visitor_helper(&element, get_stream_class_count,
+ get_stream_class, visit_stream_class, visitor, data);
+end:
+ return ret;
+}
+
+static
+int ir_visitor(struct bt_ctf_ir_element *element, void *data)
+{
+ int ret = 0;
+
+ switch (element->type) {
+ case BT_CTF_IR_TYPE_TRACE:
+ {
+ break;
+ }
+ case BT_CTF_IR_TYPE_STREAM_CLASS:
+ {
+ break;
+ }
+ case BT_CTF_IR_TYPE_EVENT_CLASS:
+ {
+ break;
+ }
+ default:
+ assert(0);
+ ret = -1;
+ goto end;
+ }
+end:
+ return ret;
+}
+
+int bt_ctf_trace_add_notification_handler_cb(struct bt_ctf_trace *trace,
+ bt_ctf_notification_cb handler, void *handler_data)
+{
+ int ret = 0;
+ struct notification_handler *handler_wrapper =
+ g_new0(struct notification_handler, 1);
+
+ if (!trace || !handler || !handler_wrapper) {
+ ret = -1;
+ goto error;
+ }
+
+ handler_wrapper->func = handler;
+ handler_wrapper->data = handler_data;
+
+ /* Emit notifications describing the current schema. */
+ ret = bt_ctf_trace_visit(trace, ir_visitor, handler_wrapper);
+ if (ret) {
+ goto error;
+ }
+
+ g_ptr_array_add(trace->notification_handlers, handler_wrapper);
+ return ret;
+error:
+ g_free(handler_wrapper);
+ return ret;
+}
+
BT_HIDDEN
struct bt_ctf_field_type *get_field_type(enum field_type_alias alias)
{
+ int ret;
unsigned int alignment, size;
struct bt_ctf_field_type *field_type = NULL;
alignment = field_type_aliases_alignments[alias];
size = field_type_aliases_sizes[alias];
field_type = bt_ctf_field_type_integer_create(size);
- bt_ctf_field_type_set_alignment(field_type, alignment);
+ ret = bt_ctf_field_type_set_alignment(field_type, alignment);
+ if (ret) {
+ BT_PUT(field_type);
+ }
end:
return field_type;
}