lib: merge common CTF IR part with the remaining implementation
[babeltrace.git] / include / babeltrace / ctf-ir / trace-internal.h
index dc0b7069e196f39457049ac66031eea703f411dd..8de7885281a5b91edca154005567795d0cddfc47 100644 (file)
  * SOFTWARE.
  */
 
-#include <babeltrace/ctf-writer/ref-internal.h>
+#include <babeltrace/assert-pre-internal.h>
 #include <babeltrace/ctf-ir/trace.h>
-#include <babeltrace/ctf-ir/event-types.h>
-#include <babeltrace/ctf-ir/event-fields.h>
+#include <babeltrace/ctf-ir/stream-class-internal.h>
+#include <babeltrace/ctf-ir/field-types.h>
+#include <babeltrace/ctf-ir/fields.h>
+#include <babeltrace/ctf-ir/validation-internal.h>
+#include <babeltrace/ctf-ir/attributes-internal.h>
+#include <babeltrace/ctf-ir/clock-class-internal.h>
+#include <babeltrace/object-internal.h>
+#include <babeltrace/object-pool-internal.h>
 #include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/values.h>
+#include <babeltrace/types.h>
 #include <glib.h>
 #include <sys/types.h>
-#include <uuid/uuid.h>
-
-enum field_type_alias {
-       FIELD_TYPE_ALIAS_UINT5_T = 0,
-       FIELD_TYPE_ALIAS_UINT8_T,
-       FIELD_TYPE_ALIAS_UINT16_T,
-       FIELD_TYPE_ALIAS_UINT27_T,
-       FIELD_TYPE_ALIAS_UINT32_T,
-       FIELD_TYPE_ALIAS_UINT64_T,
-       NR_FIELD_TYPE_ALIAS,
-};
+#include <babeltrace/compat/uuid-internal.h>
 
-struct bt_ctf_trace {
-       struct bt_ctf_ref ref_count;
+struct bt_trace {
+       struct bt_object base;
+       GString *name;
        int frozen;
-       uuid_t uuid;
-       int byte_order;
-       GPtrArray *environment; /* Array of pointers to environment_variable */
-       GPtrArray *clocks; /* Array of pointers to bt_ctf_clock */
-       GPtrArray *stream_classes; /* Array of ptrs to bt_ctf_stream_class */
-       GPtrArray *streams; /* Array of ptrs to bt_ctf_stream */
-       struct bt_ctf_field_type *packet_header_type;
-       uint64_t next_stream_id;
-};
+       unsigned char uuid[BABELTRACE_UUID_LEN];
+       bt_bool uuid_set;
+       enum bt_byte_order native_byte_order;
+       struct bt_value *environment;
+       GPtrArray *clock_classes; /* Array of pointers to bt_clock_class */
+       GPtrArray *stream_classes; /* Array of ptrs to bt_stream_class */
+       GPtrArray *streams; /* Array of ptrs to bt_stream */
+       struct bt_field_type *packet_header_field_type;
+       int64_t next_stream_id;
 
-struct environment_variable {
-       GString *name, *value;
-};
+       /*
+        * This flag indicates if the trace is valid. A valid
+        * trace is _always_ frozen.
+        */
+       int valid;
 
-struct metadata_context {
-       GString *string;
-       GString *field_name;
-       unsigned int current_indentation_level;
+       GPtrArray *listeners; /* Array of struct listener_wrapper */
+       GArray *is_static_listeners;
+       bt_bool is_static;
+       bt_bool in_remove_listener;
+
+       /* Pool of `struct bt_field_wrapper *` */
+       struct bt_object_pool packet_header_field_pool;
 };
 
-/* Checks that the string does not contain a reserved keyword */
 BT_HIDDEN
-int validate_identifier(const char *string);
+int bt_trace_object_modification(struct bt_visitor_object *object,
+               void *trace_ptr);
 
 BT_HIDDEN
-const char *get_byte_order_string(int byte_order);
+bt_bool bt_trace_has_clock_class(struct bt_trace *trace,
+               struct bt_clock_class *clock_class);
+
+/**
+@brief User function type to use with bt_trace_add_listener().
+
+@param[in] obj New CTF IR object which is part of the trace
+               class hierarchy.
+@param[in] data        User data.
+
+@prenotnull{obj}
+*/
+typedef void (*bt_listener_cb)(struct bt_visitor_object *obj, void *data);
+
+/**
+@brief Adds the trace class modification listener \p listener to
+       the CTF IR trace class \p trace_class.
+
+Once you add \p listener to \p trace_class, whenever \p trace_class
+is modified, \p listener is called with the new element and with
+\p data (user data).
 
+@param[in] trace_class Trace class to which to add \p listener.
+@param[in] listener    Modification listener function.
+@param[in] data                User data.
+@returns               0 on success, or a negative value on error.
+
+@prenotnull{trace_class}
+@prenotnull{listener}
+@postrefcountsame{trace_class}
+*/
 BT_HIDDEN
-struct bt_ctf_field_type *get_field_type(enum field_type_alias alias);
+int bt_trace_add_listener(struct bt_trace *trace_class,
+               bt_listener_cb listener, void *data);
+
+static inline
+void bt_trace_freeze(struct bt_trace *trace)
+{
+       int i;
+
+       if (trace->frozen) {
+               return;
+       }
+
+       BT_LOGD("Freezing trace: addr=%p, name=\"%s\"",
+               trace, bt_trace_get_name(trace));
+       BT_LOGD_STR("Freezing packet header field type.");
+       bt_field_type_freeze(trace->packet_header_field_type);
+       BT_LOGD_STR("Freezing environment attributes.");
+       bt_attributes_freeze(trace->environment);
+
+       if (trace->clock_classes->len > 0) {
+               BT_LOGD_STR("Freezing clock classes.");
+       }
+
+       for (i = 0; i < trace->clock_classes->len; i++) {
+               struct bt_clock_class *clock_class =
+                       g_ptr_array_index(trace->clock_classes, i);
+
+               bt_clock_class_freeze(clock_class);
+       }
+
+       trace->frozen = 1;
+}
 
 #endif /* BABELTRACE_CTF_IR_TRACE_INTERNAL_H */
This page took 0.024835 seconds and 4 git commands to generate.