trace.c \
utils.c \
resolve.c \
- validation.c
+ validation.c \
+ visitor.c
libctf_ir_la_LIBADD = \
$(top_builddir)/lib/libbabeltrace.la
#include <babeltrace/ctf-writer/stream.h>
#include <babeltrace/ctf-ir/stream-class-internal.h>
#include <babeltrace/ctf-ir/validation-internal.h>
+#include <babeltrace/ctf-ir/visitor-internal.h>
#include <babeltrace/ctf-writer/functor-internal.h>
#include <babeltrace/ctf-ir/utils.h>
#include <babeltrace/ref.h>
bt_put(stream_class);
}
+static
+int get_event_class_count(void *element)
+{
+ return bt_ctf_stream_class_get_event_class_count(
+ (struct bt_ctf_stream_class *) element);
+}
+
+static
+void *get_event_class(void *element, int i)
+{
+ return bt_ctf_stream_class_get_event_class(
+ (struct bt_ctf_stream_class *) element, i);
+}
+
+static
+int visit_event_class(void *element, bt_ctf_ir_visitor visitor,void *data)
+{
+ struct bt_ctf_ir_element ir_element =
+ { .element = element,
+ .type = BT_CTF_IR_TYPE_EVENT_CLASS };
+
+ return visitor(&ir_element, data);
+}
+
+int bt_ctf_stream_class_visit(struct bt_ctf_stream_class *stream_class,
+ bt_ctf_ir_visitor visitor, void *data)
+{
+ int ret;
+ struct bt_ctf_ir_element element =
+ { .element = stream_class,
+ .type = BT_CTF_IR_TYPE_STREAM_CLASS };
+
+ if (!stream_class || !visitor) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = visitor_helper(&element, get_event_class_count,
+ get_event_class,
+ visit_event_class, visitor, data);
+end:
+ return ret;
+}
+
BT_HIDDEN
void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class)
{
#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>
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)
{
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:
--- /dev/null
+/*
+ * visitor.c
+ *
+ * Babeltrace CTF IR - Visitor
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/ctf-ir/visitor-internal.h>
+#include <babeltrace/ref.h>
+
+BT_HIDDEN
+int visitor_helper(struct bt_ctf_ir_element *root,
+ bt_child_count_accessor child_counter,
+ bt_child_accessor child_accessor,
+ bt_child_visitor child_visitor,
+ bt_ctf_ir_visitor visitor,
+ void *data)
+{
+ int ret, child_count, i;
+
+ ret = visitor(root, data);
+ if (ret) {
+ goto end;
+ }
+
+ child_count = child_counter(root->element);
+ if (child_count < 0) {
+ ret = child_count;
+ goto end;
+ }
+
+ for (i = 0; i < child_count; i++) {
+ void *child;
+
+ child = child_accessor(root->element, i);
+ if (!child) {
+ ret = -1;
+ goto end;
+ }
+ ret = child_visitor(child, visitor, data);
+ BT_PUT(child);
+ if (ret) {
+ goto end;
+ }
+ }
+end:
+ return ret;
+}
+
+enum bt_ctf_ir_type bt_ctf_ir_element_get_type(
+ struct bt_ctf_ir_element *element)
+{
+ enum bt_ctf_ir_type ret = BT_CTF_IR_TYPE_UNKNOWN;
+
+ if (!element) {
+ goto end;
+ }
+
+ ret = element->type;
+end:
+ return ret;
+}
+
+void *bt_ctf_ir_element_get_element(struct bt_ctf_ir_element *element)
+{
+ void *ret = NULL;
+
+ if (!element) {
+ goto end;
+ }
+
+ ret = element->element;
+end:
+ return ret;
+}
babeltrace/ctf-ir/packet.h \
babeltrace/ctf-ir/stream-class.h \
babeltrace/ctf-ir/trace.h \
- babeltrace/ctf-ir/utils.h
+ babeltrace/ctf-ir/utils.h \
+ babeltrace/ctf-ir/visitor.h
babeltraceplugininclude_HEADERS = \
babeltrace/plugin/plugin.h \
babeltrace/plugin/notification/notification.h \
babeltrace/plugin/notification/event.h \
babeltrace/plugin/notification/iterator.h \
- babeltrace/plugin/notification/packet.h
+ babeltrace/plugin/notification/packet.h \
+ babeltrace/plugin/notification/schema.h
noinst_HEADERS = \
babeltrace/align.h \
babeltrace/ctf-ir/packet-internal.h \
babeltrace/ctf-ir/trace-internal.h \
babeltrace/ctf-ir/validation-internal.h \
+ babeltrace/ctf-ir/visitor-internal.h \
babeltrace/ctf-writer/functor-internal.h \
babeltrace/trace-handle-internal.h \
babeltrace/compat/uuid.h \
*/
#include <stdint.h>
+#include <babeltrace/ctf-ir/visitor.h>
#ifdef __cplusplus
extern "C" {
struct bt_ctf_stream_class *stream_class,
struct bt_ctf_field_type *event_context_type);
+/*
+ * bt_ctf_stream_class_visit: visit a stream class' event classes.
+ *
+ * Call visitor on each of a stream class' event classes.
+ *
+ * @param stream_class Stream class instance.
+ * @param visitor visitor function to invoke for each stream class.
+ * @param data user data passed to the visitor.
+ *
+ * Returns 0 on success, a negative value on error.
+ */
+extern int bt_ctf_stream_class_visit(struct bt_ctf_stream_class *stream_class,
+ bt_ctf_ir_visitor visitor, void *data);
+
#ifdef __cplusplus
}
#endif
*/
#include <babeltrace/ctf-ir/field-types.h>
+#include <babeltrace/ctf-ir/visitor.h>
#include <babeltrace/values.h>
+#include <babeltrace/plugin/notification/notification.h>
#include <stdint.h>
#ifdef __cplusplus
extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace,
struct bt_ctf_field_type *packet_header_type);
+/*
+ * bt_ctf_trace_visit: visit a trace's hierarchy.
+ *
+ * Recursively walk a trace's hierarchy and call visitor on each of its
+ * elements.
+ *
+ * @param trace Trace instance.
+ * @param visitor visitor function to invoke for each element.
+ * @param data user data passed to the visitor.
+ *
+ * Returns 0 on success, a negative value on error.
+ */
+extern int bt_ctf_trace_visit(struct bt_ctf_trace *trace,
+ bt_ctf_ir_visitor visitor, void *data);
+
/*
* bt_ctf_trace_add_notification_handler_cb: set a notification callback
* which will be invoked whenever a trace's schema is modified.
--- /dev/null
+#ifndef BABELTRACE_CTF_IR_VISITOR_INTERNAL_H
+#define BABELTRACE_CTF_IR_VISITOR_INTERNAL_H
+
+/*
+ * BabelTrace - CTF IR: Visitor internal
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/ctf-ir/visitor.h>
+#include <babeltrace/babeltrace-internal.h>
+
+typedef void *(*bt_child_accessor)(void *element, int index);
+typedef int (*bt_child_count_accessor)(void *element);
+typedef int (*bt_child_visitor)(void *element, bt_ctf_ir_visitor visitor,
+ void *data);
+
+struct bt_ctf_ir_element {
+ enum bt_ctf_ir_type type;
+ void *element;
+};
+
+BT_HIDDEN
+int visitor_helper(struct bt_ctf_ir_element *root,
+ bt_child_count_accessor child_counter,
+ bt_child_accessor child_accessor,
+ bt_child_visitor child_visitor,
+ bt_ctf_ir_visitor visitor,
+ void *data);
+
+#endif /* BABELTRACE_CTF_IR_VISITOR_INTERNAL_H */
--- /dev/null
+#ifndef BABELTRACE_CTF_IR_VISITOR_H
+#define BABELTRACE_CTF_IR_VISITOR_H
+
+/*
+ * BabelTrace - CTF IR: Visitor
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * The Common Trace Format (CTF) Specification is available at
+ * http://www.efficios.com/ctf
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bt_ctf_ir_element;
+
+enum bt_ctf_ir_type {
+ BT_CTF_IR_TYPE_UNKNOWN = -1,
+ BT_CTF_IR_TYPE_TRACE = 0,
+ BT_CTF_IR_TYPE_STREAM_CLASS = 1,
+ BT_CTF_IR_TYPE_STREAM = 2,
+ BT_CTF_IR_TYPE_EVENT_CLASS = 3,
+ BT_CTF_IR_TYPE_EVENT = 4,
+ BT_CTF_IR_TYPE_NR,
+};
+
+typedef int (*bt_ctf_ir_visitor)(struct bt_ctf_ir_element *element,
+ void *data);
+
+/*
+ * bt_ctf_ir_element_get_type: get an IR element's type.
+ *
+ * Get an IR element's type.
+ *
+ * @param element Element instance.
+ *
+ * Returns one of #bt_ctf_ir_type.
+ */
+enum bt_ctf_ir_type bt_ctf_ir_element_get_type(
+ struct bt_ctf_ir_element *element);
+
+/*
+ * bt_ctf_ir_element_get_element: get an IR element's value.
+ *
+ * Get an IR element's value.
+ *
+ * @param element Element instance.
+ *
+ * Returns a CTF-IR type. Use #bt_ctf_ir_type to determine the
+ * concrete type of the value returned.
+ */
+void *bt_ctf_ir_element_get_element(struct bt_ctf_ir_element *element);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_CTF_IR_VISITOR_H */
/** End of stream packet notification, see packet.h */
BT_NOTIFICATION_TYPE_END_PACKET = 3,
+ /** New trace notification, see model.h */
+ BT_NOTIFICATION_TYPE_NEW_TRACE = 4,
+
+ /** New stream class notification, see model.h */
+ BT_NOTIFICATION_TYPE_NEW_STREAM_CLASS = 5,
+
+ /** New event class notification, see model.h */
+ BT_NOTIFICATION_TYPE_NEW_EVENT_CLASS = 6,
+
/** End of trace notification, see eot.h */
- BT_NOTIFICATION_TYPE_END_OF_TRACE = 4,
+ BT_NOTIFICATION_TYPE_END_OF_TRACE = 7,
BT_NOTIFICATION_TYPE_NR,
};
--- /dev/null
+#ifndef BABELTRACE_PLUGIN_NOTIFICATION_SCHEMA_H
+#define BABELTRACE_PLUGIN_NOTIFICATION_SCHEMA_H
+
+/*
+ * BabelTrace - Plug-in Schema Change Notification
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bt_notification;
+struct bt_ctf_trace;
+struct bt_ctf_stream_class;
+struct bt_ctf_event_class;
+
+
+/* BT_NOTIFICATION_TYPE_NEW_TRACE */
+/**
+ * Create a new trace notification.
+ *
+ * @param trace The new trace
+ * @returns A new trace notification instance
+ *
+ * @see #bt_notification_type
+ */
+extern struct bt_notification *bt_notification_new_trace_create(
+ struct bt_ctf_trace *trace);
+
+/**
+ * Get a new trace notification's associated trace.
+ *
+ * @param notification New trace notification instance
+ * @returns A trace instance
+ *
+ * @see #bt_ctf_trace
+ */
+extern struct bt_ctf_trace *bt_notification_new_trace_get_trace(
+ struct bt_notification *notification);
+
+
+/* BT_NOTIFICATION_TYPE_NEW_STREAM_CLASS */
+/**
+ * Create a new stream class notification.
+ *
+ * @param trace The event's trace
+ * @returns A new stream class notification instance
+ *
+ * @see #bt_notification_type
+ */
+extern struct bt_notification *bt_notification_new_stream_class_create(
+ struct bt_ctf_stream_class *stream_class);
+
+/**
+ * Get a new stream class notification's associated stream class.
+ *
+ * @param notification New stream class notification instance
+ * @returns A stream class instance
+ *
+ * @see #bt_ctf_stream_class
+ */
+extern struct bt_ctf_trace *bt_notification_new_stream_class_get_stream_class(
+ struct bt_notification *notification);
+
+
+/* BT_NOTIFICATION_TYPE_EVENT_CLASS */
+/**
+ * Create a new trace notification.
+ *
+ * @param trace The event's trace
+ * @returns An event notification instance
+ *
+ * @see #bt_notification_type
+ */
+extern struct bt_notification *bt_notification_new_trace_create(
+ struct bt_ctf_trace *trace);
+
+/**
+ * Get a new trace notification's associated trace.
+ *
+ * @param notification New trace notification instance
+ * @returns A trace instance
+ *
+ * @see #bt_ctf_trace
+ */
+extern struct bt_ctf_trace *bt_notification_new_trace_get_trace(
+ struct bt_notification *notification);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_PLUGIN_NOTIFICATION_SCHEMA_H */