X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Ffs-sink%2Ffs-sink-stream.c;h=ca61d10ff1c9bbee4cc450bf64178438c06af54a;hb=fe4df857056b4a03898f1031f136359ce733b0f5;hp=a8bf2dc73b848d8c93af460ae3d0daba184b198c;hpb=d9c39b0a4ad9517178899334c0ca89fd20901609;p=babeltrace.git diff --git a/src/plugins/ctf/fs-sink/fs-sink-stream.c b/src/plugins/ctf/fs-sink/fs-sink-stream.c index a8bf2dc7..ca61d10f 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-stream.c +++ b/src/plugins/ctf/fs-sink/fs-sink-stream.c @@ -198,6 +198,34 @@ static int write_field(struct fs_sink_stream *stream, struct fs_sink_ctf_field_class *fc, const bt_field *field); +static inline +int write_bool_field(struct fs_sink_stream *stream, + struct fs_sink_ctf_field_class_int *fc, const bt_field *field) +{ + /* + * CTF 1.8 has no boolean field class type, so this component + * translates this boolean field to an 8-bit unsigned integer + * field which has the value 0 (false) or 1 (true). + */ + return bt_ctfser_write_unsigned_int(&stream->ctfser, + bt_field_bool_get_value(field) ? 1 : 0, + fc->base.base.alignment, fc->base.size, BYTE_ORDER); +} + +static inline +int write_bit_array_field(struct fs_sink_stream *stream, + struct fs_sink_ctf_field_class_bit_array *fc, + const bt_field *field) +{ + /* + * CTF 1.8 has no bit array field class type, so this component + * translates this bit array field to an unsigned integer field. + */ + return bt_ctfser_write_unsigned_int(&stream->ctfser, + bt_field_bit_array_get_value_as_integer(field), + fc->base.alignment, fc->size, BYTE_ORDER); +} + static inline int write_int_field(struct fs_sink_stream *stream, struct fs_sink_ctf_field_class_int *fc, const bt_field *field) @@ -222,12 +250,14 @@ int write_float_field(struct fs_sink_stream *stream, struct fs_sink_ctf_field_class_float *fc, const bt_field *field) { int ret; - double val = bt_field_real_get_value(field); + double val; if (fc->base.size == 32) { + val = (double) bt_field_real_single_precision_get_value(field); ret = bt_ctfser_write_float32(&stream->ctfser, val, fc->base.base.alignment, BYTE_ORDER); } else { + val = bt_field_real_double_precision_get_value(field); ret = bt_ctfser_write_float64(&stream->ctfser, val, fc->base.base.alignment, BYTE_ORDER); } @@ -321,6 +351,40 @@ end: return ret; } +static inline +int write_option_field(struct fs_sink_stream *stream, + struct fs_sink_ctf_field_class_option *fc, + const bt_field *field) +{ + int ret; + const bt_field *content_field = + bt_field_option_borrow_field_const(field); + + ret = bt_ctfser_write_unsigned_int(&stream->ctfser, + content_field ? 1 : 0, 8, 8, BYTE_ORDER); + if (G_UNLIKELY(ret)) { + goto end; + } + + /* + * CTF 1.8 has no option field class type, so this component + * translates the option field class to a variant field class + * where the options are: + * + * * An empty structure field class (field occupies 0 bits). + * * The optional field class itself. + * + * If `content_field` is `NULL`, do not write anything (empty + * structure). + */ + if (content_field) { + ret = write_field(stream, fc->content_fc, content_field); + } + +end: + return ret; +} + static inline int write_variant_field(struct fs_sink_stream *stream, struct fs_sink_ctf_field_class_variant *fc, @@ -354,6 +418,12 @@ int write_field(struct fs_sink_stream *stream, int ret; switch (fc->type) { + case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL: + ret = write_bool_field(stream, (void *) fc, field); + break; + case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY: + ret = write_bit_array_field(stream, (void *) fc, field); + break; case FS_SINK_CTF_FIELD_CLASS_TYPE_INT: ret = write_int_field(stream, (void *) fc, field); break; @@ -372,6 +442,9 @@ int write_field(struct fs_sink_stream *stream, case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE: ret = write_sequence_field(stream, (void *) fc, field); break; + case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION: + ret = write_option_field(stream, (void *) fc, field); + break; case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT: ret = write_variant_field(stream, (void *) fc, field); break;