Copy the packet_header in the plugins
[babeltrace.git] / plugins / libctfcopytrace / ctfcopytrace.c
index 894ce2f39f4b7016a4d7f1ee8763f6418bb41240..d3373c1e7c015fe4c068da7f87414e228e0a6491 100644 (file)
@@ -212,7 +212,10 @@ struct bt_ctf_event_class *ctf_copy_event_class(FILE *err,
        struct bt_ctf_event_class *writer_event_class = NULL;
        struct bt_ctf_field_type *context, *payload_type;
        const char *name;
-       int count, i, ret;
+       int ret;
+       int64_t id;
+       enum bt_ctf_event_class_log_level log_level;
+       const char *emf_uri;
 
        name = bt_ctf_event_class_get_name(event_class);
        if (!name) {
@@ -228,31 +231,39 @@ struct bt_ctf_event_class *ctf_copy_event_class(FILE *err,
                goto end;
        }
 
-       count = bt_ctf_event_class_get_attribute_count(event_class);
-       for (i = 0; i < count; i++) {
-               const char *attr_name;
-               struct bt_value *attr_value;
-               int ret;
+       id = bt_ctf_event_class_get_id(event_class);
+       if (id < 0) {
+               fprintf(err, "[error] %s in %s:%d\n", __func__,
+                               __FILE__, __LINE__);
+               goto error;
+       }
 
-               attr_name = bt_ctf_event_class_get_attribute_name_by_index(
-                       event_class, i);
-               if (!attr_name) {
-                       fprintf(err, "[error] %s in %s:%d\n", __func__,
-                                       __FILE__, __LINE__);
-                       goto error;
-               }
-               attr_value = bt_ctf_event_class_get_attribute_value_by_index(
-                       event_class, i);
-               if (!attr_value) {
-                       fprintf(err, "[error] %s in %s:%d\n", __func__,
-                                       __FILE__, __LINE__);
-                       goto error;
-               }
+       ret = bt_ctf_event_class_set_id(writer_event_class, id);
+       if (ret) {
+               fprintf(err, "[error] %s in %s:%d\n", __func__,
+                               __FILE__, __LINE__);
+               goto error;
+       }
 
-               ret = bt_ctf_event_class_set_attribute(writer_event_class,
-                               attr_name, attr_value);
-               BT_PUT(attr_value);
-               if (ret < 0) {
+       log_level = bt_ctf_event_class_get_log_level(event_class);
+       if (log_level < 0) {
+               fprintf(err, "[error] %s in %s:%d\n", __func__,
+                               __FILE__, __LINE__);
+               goto error;
+       }
+
+       ret = bt_ctf_event_class_set_log_level(writer_event_class, log_level);
+       if (ret) {
+               fprintf(err, "[error] %s in %s:%d\n", __func__,
+                               __FILE__, __LINE__);
+               goto error;
+       }
+
+       emf_uri = bt_ctf_event_class_get_emf_uri(event_class);
+       if (emf_uri) {
+               ret = bt_ctf_event_class_set_emf_uri(writer_event_class,
+                       emf_uri);
+               if (ret) {
                        fprintf(err, "[error] %s in %s:%d\n", __func__,
                                        __FILE__, __LINE__);
                        goto error;
@@ -379,7 +390,7 @@ struct bt_ctf_stream_class *ctf_copy_stream_class(FILE *err,
                name = NULL;
        }
 
-       writer_stream_class = bt_ctf_stream_class_create(name);
+       writer_stream_class = bt_ctf_stream_class_create_empty(name);
        if (!writer_stream_class) {
                fprintf(err, "[error] %s in %s:%d\n",
                                __func__, __FILE__, __LINE__);
@@ -387,20 +398,16 @@ struct bt_ctf_stream_class *ctf_copy_stream_class(FILE *err,
        }
 
        type = bt_ctf_stream_class_get_packet_context_type(stream_class);
-       if (!type) {
-               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
-                               __LINE__);
-               goto error;
-       }
-
-       ret_int = bt_ctf_stream_class_set_packet_context_type(
-                       writer_stream_class, type);
-       if (ret_int < 0) {
-               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
-                               __LINE__);
-               goto error;
+       if (type) {
+               ret_int = bt_ctf_stream_class_set_packet_context_type(
+                               writer_stream_class, type);
+               if (ret_int < 0) {
+                       fprintf(err, "[error] %s in %s:%d\n", __func__,
+                                       __FILE__, __LINE__);
+                       goto error;
+               }
+               BT_PUT(type);
        }
-       BT_PUT(type);
 
        type = bt_ctf_stream_class_get_event_header_type(stream_class);
        if (!type) {
@@ -460,165 +467,150 @@ end:
 }
 
 BT_HIDDEN
-enum bt_component_status ctf_copy_packet_context_field(FILE *err,
-               struct bt_ctf_field *field, const char *field_name,
-               struct bt_ctf_field *writer_packet_context,
-               struct bt_ctf_field_type *writer_packet_context_type)
+int ctf_stream_copy_packet_header(FILE *err, struct bt_ctf_packet *packet,
+               struct bt_ctf_stream *writer_stream)
 {
-       enum bt_component_status ret;
-       struct bt_ctf_field *writer_field = NULL;
-       struct bt_ctf_field_type *field_type = NULL;
-       int int_ret;
-       uint64_t value;
+       struct bt_ctf_field *packet_header = NULL, *writer_packet_header = NULL;
+       int ret = 0;
 
-       field_type = bt_ctf_field_get_type(field);
-       if (!field_type) {
-               ret = BT_COMPONENT_STATUS_ERROR;
-               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
-                               __LINE__);
+       packet_header = bt_ctf_packet_get_header(packet);
+       if (!packet_header) {
                goto end;
        }
-       /*
-        * Only support for integers for now.
-        */
-       if (bt_ctf_field_type_get_type_id(field_type) != BT_CTF_FIELD_TYPE_ID_INTEGER) {
-               fprintf(err, "[error] Unsupported packet context field type\n");
-               ret = BT_COMPONENT_STATUS_ERROR;
+
+       writer_packet_header = bt_ctf_field_copy(packet_header);
+       if (!writer_packet_header) {
+               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
+                               __LINE__);
                goto error;
        }
-       BT_PUT(field_type);
 
-       writer_field = bt_ctf_field_structure_get_field_by_name(
-               writer_packet_context, field_name);
-       if (!writer_field) {
-               ret = BT_COMPONENT_STATUS_ERROR;
+       ret = bt_ctf_stream_set_packet_header(writer_stream,
+                       writer_packet_header);
+       if (ret) {
                fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
                                __LINE__);
+               goto error;
+       }
+
+       goto end;
+
+error:
+       ret = -1;
+end:
+       bt_put(writer_packet_header);
+       bt_put(packet_header);
+       return ret;
+}
+
+BT_HIDDEN
+int ctf_packet_copy_header(FILE *err, struct bt_ctf_packet *packet,
+               struct bt_ctf_packet *writer_packet)
+{
+       struct bt_ctf_field *packet_header = NULL, *writer_packet_header = NULL;
+       int ret = 0;
+
+       packet_header = bt_ctf_packet_get_header(packet);
+       if (!packet_header) {
                goto end;
        }
 
-       int_ret = bt_ctf_field_unsigned_integer_get_value(field, &value);
-       if (int_ret < 0) {
-               fprintf(err, "[error] Wrong packet_context field type\n");
+       writer_packet_header = bt_ctf_field_copy(packet_header);
+       if (!writer_packet_header) {
                fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
                                __LINE__);
-               ret = BT_COMPONENT_STATUS_ERROR;
-               goto end;
+               goto error;
        }
 
-       int_ret = bt_ctf_field_unsigned_integer_set_value(writer_field, value);
-       if (int_ret < 0) {
-               ret = BT_COMPONENT_STATUS_ERROR;
+       ret = bt_ctf_packet_set_header(writer_packet, writer_packet_header);
+       if (ret) {
                fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
                                __LINE__);
-               goto end;
+               goto error;
        }
 
-       ret = BT_COMPONENT_STATUS_OK;
-
        goto end;
 
 error:
-       bt_put(field_type);
+       ret = -1;
 end:
-       bt_put(writer_field);
+       bt_put(packet_header);
+       bt_put(writer_packet_header);
        return ret;
 }
 
 BT_HIDDEN
-struct bt_ctf_field *ctf_copy_packet_context(FILE *err,
-               struct bt_ctf_packet *packet,
+int ctf_stream_copy_packet_context(FILE *err, struct bt_ctf_packet *packet,
                struct bt_ctf_stream *writer_stream)
 {
-       enum bt_component_status ret;
        struct bt_ctf_field *packet_context = NULL, *writer_packet_context = NULL;
-       struct bt_ctf_field_type *struct_type = NULL, *writer_packet_context_type = NULL;
-       struct bt_ctf_stream_class *writer_stream_class = NULL;
-       struct bt_ctf_field *field = NULL;
-       struct bt_ctf_field_type *field_type = NULL;
-       int nr_fields, i;
+       int ret = 0;
 
        packet_context = bt_ctf_packet_get_context(packet);
        if (!packet_context) {
                goto end;
        }
 
-       writer_stream_class = bt_ctf_stream_get_class(writer_stream);
-       if (!writer_stream_class) {
+       writer_packet_context = bt_ctf_field_copy(packet_context);
+       if (!writer_packet_context) {
                fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
                                __LINE__);
                goto error;
        }
 
-       writer_packet_context_type = bt_ctf_stream_class_get_packet_context_type(
-                       writer_stream_class);
-       BT_PUT(writer_stream_class);
-       if (!writer_packet_context_type) {
+       ret = bt_ctf_stream_set_packet_context(writer_stream,
+                       writer_packet_context);
+       if (ret) {
                fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
                                __LINE__);
                goto error;
        }
 
-       struct_type = bt_ctf_field_get_type(packet_context);
-       if (!struct_type) {
-               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
-                               __LINE__);
-               goto error;
+       goto end;
+
+error:
+       ret = -1;
+end:
+       bt_put(packet_context);
+       bt_put(writer_packet_context);
+       return ret;
+}
+
+BT_HIDDEN
+int ctf_packet_copy_context(FILE *err, struct bt_ctf_packet *packet,
+               struct bt_ctf_stream *writer_stream,
+               struct bt_ctf_packet *writer_packet)
+{
+       struct bt_ctf_field *packet_context = NULL, *writer_packet_context = NULL;
+       int ret = 0;
+
+       packet_context = bt_ctf_packet_get_context(packet);
+       if (!packet_context) {
+               goto end;
        }
 
-       writer_packet_context = bt_ctf_field_create(writer_packet_context_type);
+       writer_packet_context = bt_ctf_field_copy(packet_context);
        if (!writer_packet_context) {
                fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
                                __LINE__);
                goto error;
        }
 
-       nr_fields = bt_ctf_field_type_structure_get_field_count(struct_type);
-       for (i = 0; i < nr_fields; i++) {
-               const char *field_name;
-
-               field = bt_ctf_field_structure_get_field_by_index(
-                               packet_context, i);
-               if (!field) {
-                       fprintf(err, "[error] %s in %s:%d\n", __func__,
-                                       __FILE__, __LINE__);
-                       goto error;
-               }
-               if (bt_ctf_field_type_structure_get_field_by_index(struct_type,
-                                       &field_name, &field_type, i) < 0) {
-                       fprintf(err, "[error] %s in %s:%d\n", __func__,
-                                       __FILE__, __LINE__);
-                       goto error;
-               }
-
-               if (bt_ctf_field_type_get_type_id(field_type) != BT_CTF_FIELD_TYPE_ID_INTEGER) {
-                       fprintf(err, "[error] Unexpected packet context field type\n");
-                       goto error;
-               }
-
-               ret = ctf_copy_packet_context_field(err, field, field_name,
-                               writer_packet_context, writer_packet_context_type);
-               BT_PUT(field_type);
-               BT_PUT(field);
-               if (ret != BT_COMPONENT_STATUS_OK) {
-                       fprintf(err, "[error] %s in %s:%d\n", __func__,
-                                       __FILE__, __LINE__);
-                       goto error;
-               }
+       ret = bt_ctf_packet_set_context(writer_packet, writer_packet_context);
+       if (ret) {
+               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__,
+                               __LINE__);
+               goto error;
        }
 
        goto end;
 
 error:
-       BT_PUT(writer_packet_context);
+       ret = -1;
 end:
-       bt_put(field);
-       bt_put(field_type);
-       bt_put(struct_type);
-       bt_put(writer_packet_context_type);
-       bt_put(writer_stream_class);
+       bt_put(writer_packet_context);
        bt_put(packet_context);
-       return writer_packet_context;
+       return ret;
 }
 
 BT_HIDDEN
@@ -894,7 +886,7 @@ enum bt_component_status ctf_copy_trace(FILE *err, struct bt_ctf_trace *trace,
                }
        }
 
-       header_type = bt_ctf_trace_get_packet_header_type(writer_trace);
+       header_type = bt_ctf_trace_get_packet_header_type(trace);
        if (header_type) {
                int_ret = bt_ctf_trace_set_packet_header_type(writer_trace, header_type);
                BT_PUT(header_type);
This page took 0.028857 seconds and 4 git commands to generate.