ir: add public bt_ctf_packet object
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 17 Feb 2016 22:07:29 +0000 (17:07 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 19 Feb 2016 23:09:08 +0000 (18:09 -0500)
The purpose of a bt_ctf_packet object is to hold the packet
header and packet context fields.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/Makefile.am
formats/ctf/ir/packet.c [new file with mode: 0644]
include/Makefile.am
include/babeltrace/ctf-ir/packet-internal.h [new file with mode: 0644]
include/babeltrace/ctf-ir/packet.h [new file with mode: 0644]
include/babeltrace/ctf-ir/stream-class-internal.h

index 5b29ff77b94b1edbedd384cb4fb714f4b5746a3c..b9048bc5a23126134eab03199bc1b84bd9415e26 100644 (file)
@@ -10,6 +10,7 @@ libctf_ir_la_SOURCES = \
        fields.c \
        field-types.c \
        field-path.c \
+       packet.c \
        stream.c \
        stream-class.c \
        trace.c \
diff --git a/formats/ctf/ir/packet.c b/formats/ctf/ir/packet.c
new file mode 100644 (file)
index 0000000..76a2f04
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * packet.c
+ *
+ * Babeltrace CTF IR - Stream packet
+ *
+ * Copyright 2016 Philippe Proulx <pproulx@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/fields-internal.h>
+#include <babeltrace/ctf-ir/packet.h>
+#include <babeltrace/ctf-ir/packet-internal.h>
+#include <babeltrace/ctf-ir/trace.h>
+#include <babeltrace/ctf-ir/stream-class-internal.h>
+#include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace/ctf-ir/stream.h>
+#include <babeltrace/ctf-ir/stream-internal.h>
+#include <babeltrace/ctf-ir/trace-internal.h>
+#include <babeltrace/object-internal.h>
+#include <babeltrace/ref.h>
+
+struct bt_ctf_stream *bt_ctf_packet_get_stream(struct bt_ctf_packet *packet)
+{
+       return packet ? bt_get(packet->stream) : NULL;
+}
+
+struct bt_ctf_field *bt_ctf_packet_get_header(
+               struct bt_ctf_packet *packet)
+{
+       return packet ? bt_get(packet->header) : NULL;
+}
+
+int bt_ctf_packet_set_header(struct bt_ctf_packet *packet,
+               struct bt_ctf_field *header)
+{
+       int ret = 0;
+       struct bt_ctf_trace *trace = NULL;
+       struct bt_ctf_stream_class *stream_class = NULL;
+       struct bt_ctf_field_type *header_field_type = NULL;
+       struct bt_ctf_field_type *expected_header_field_type = NULL;
+
+       if (!packet || !header || packet->frozen) {
+               ret = -1;
+               goto end;
+       }
+
+       stream_class = bt_ctf_stream_get_class(packet->stream);
+       assert(stream_class);
+       trace = bt_ctf_stream_class_get_trace(stream_class);
+       assert(trace);
+       header_field_type = bt_ctf_field_get_type(header);
+       assert(header_field_type);
+       expected_header_field_type = bt_ctf_trace_get_packet_header_type(trace);
+
+       if (bt_ctf_field_type_compare(header_field_type,
+                       expected_header_field_type)) {
+               ret = -1;
+               goto end;
+       }
+
+       bt_put(packet->header);
+       packet->header = bt_get(header);
+
+end:
+       BT_PUT(trace);
+       BT_PUT(stream_class);
+       BT_PUT(header_field_type);
+       BT_PUT(expected_header_field_type);
+
+       return ret;
+}
+
+struct bt_ctf_field *bt_ctf_packet_get_context(
+               struct bt_ctf_packet *packet)
+{
+       return packet ? bt_get(packet->context) : NULL;
+}
+
+int bt_ctf_packet_set_context(struct bt_ctf_packet *packet,
+               struct bt_ctf_field *context)
+{
+       int ret = 0;
+       struct bt_ctf_stream_class *stream_class = NULL;
+       struct bt_ctf_field_type *context_field_type = NULL;
+       struct bt_ctf_field_type *expected_context_field_type = NULL;
+
+       if (!packet || !context || packet->frozen) {
+               ret = -1;
+               goto end;
+       }
+
+       stream_class = bt_ctf_stream_get_class(packet->stream);
+       assert(stream_class);
+       context_field_type = bt_ctf_field_get_type(context);
+       assert(context_field_type);
+       expected_context_field_type =
+               bt_ctf_stream_class_get_packet_context_type(stream_class);
+
+       if (bt_ctf_field_type_compare(context_field_type,
+                       expected_context_field_type)) {
+               ret = -1;
+               goto end;
+       }
+
+       bt_put(packet->context);
+       packet->context = bt_get(context);
+
+end:
+       BT_PUT(stream_class);
+       BT_PUT(context_field_type);
+       BT_PUT(expected_context_field_type);
+
+       return ret;
+}
+
+BT_HIDDEN
+void bt_ctf_packet_freeze(struct bt_ctf_packet *packet)
+{
+       if (!packet) {
+               goto end;
+       }
+
+       bt_ctf_field_freeze(packet->header);
+       bt_ctf_field_freeze(packet->context);
+       packet->frozen = 1;
+
+end:
+       return;
+}
+
+static
+void bt_ctf_packet_destroy(struct bt_object *obj)
+{
+       struct bt_ctf_packet *packet;
+
+       packet = container_of(obj, struct bt_ctf_packet, base);
+       bt_put(packet->header);
+       bt_put(packet->context);
+       bt_put(packet->stream);
+       g_free(packet);
+}
+
+extern struct bt_ctf_packet *bt_ctf_packet_create(
+               struct bt_ctf_stream *stream)
+{
+       struct bt_ctf_packet *packet = NULL;
+       struct bt_ctf_stream_class *stream_class = NULL;
+       struct bt_ctf_trace *trace = NULL;
+
+       if (!stream || stream->pos.fd >= 0) {
+               goto end;
+       }
+
+       stream_class = bt_ctf_stream_get_class(stream);
+       assert(stream_class);
+       trace = bt_ctf_stream_class_get_trace(stream_class);
+       assert(trace);
+       packet = g_new0(struct bt_ctf_packet, 1);
+       if (!packet) {
+               goto end;
+       }
+
+       bt_object_init(packet, bt_ctf_packet_destroy);
+       packet->stream = bt_get(stream);
+       packet->header = bt_ctf_field_create(trace->packet_header_type);
+       if (!packet->header) {
+               BT_PUT(packet);
+               goto end;
+       }
+
+       packet->context = bt_ctf_field_create(
+               stream->stream_class->packet_context_type);
+       if (!packet->context) {
+               BT_PUT(packet);
+               goto end;
+       }
+
+end:
+       BT_PUT(trace);
+       BT_PUT(stream_class);
+
+       return packet;
+}
index f022571b95c9e6fb9f1240942c3ea99cc78dc0d9..e7f32eab13e7765793b56c9a8ae0046e881fb353 100644 (file)
@@ -31,6 +31,7 @@ babeltracectfirinclude_HEADERS = \
        babeltrace/ctf-ir/event-class.h \
        babeltrace/ctf-ir/field-path.h \
        babeltrace/ctf-ir/stream.h \
+       babeltrace/ctf-ir/packet.h \
        babeltrace/ctf-ir/stream-class.h \
        babeltrace/ctf-ir/trace.h \
        babeltrace/ctf-ir/utils.h
@@ -67,6 +68,7 @@ noinst_HEADERS = \
        babeltrace/ctf-ir/resolve-internal.h \
        babeltrace/ctf-ir/stream-class-internal.h \
        babeltrace/ctf-ir/stream-internal.h \
+       babeltrace/ctf-ir/packet-internal.h \
        babeltrace/ctf-ir/trace-internal.h \
        babeltrace/ctf-ir/validation-internal.h \
        babeltrace/ctf-writer/functor-internal.h \
diff --git a/include/babeltrace/ctf-ir/packet-internal.h b/include/babeltrace/ctf-ir/packet-internal.h
new file mode 100644 (file)
index 0000000..275524b
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef BABELTRACE_CTF_IR_PACKET_INTERNAL_H
+#define BABELTRACE_CTF_IR_PACKET_INTERNAL_H
+
+/*
+ * Babeltrace - CTF IR: Stream packet internal
+ *
+ * Copyright 2016 Philippe Proulx <pproulx@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/fields.h>
+#include <babeltrace/ctf-ir/stream.h>
+#include <babeltrace/object-internal.h>
+#include <babeltrace/babeltrace-internal.h>
+
+struct bt_ctf_packet {
+       struct bt_object base;
+       struct bt_ctf_field *header;
+       struct bt_ctf_field *context;
+       struct bt_ctf_stream *stream;
+       int frozen;
+};
+
+BT_HIDDEN
+void bt_ctf_packet_freeze(struct bt_ctf_packet *packet);
+
+#endif /* BABELTRACE_CTF_IR_PACKET_INTERNAL_H */
diff --git a/include/babeltrace/ctf-ir/packet.h b/include/babeltrace/ctf-ir/packet.h
new file mode 100644 (file)
index 0000000..40aaab1
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef BABELTRACE_CTF_IR_PACKET_H
+#define BABELTRACE_CTF_IR_PACKET_H
+
+/*
+ * BabelTrace - CTF IR: Stream packet
+ *
+ * Copyright 2016 Philippe Proulx <pproulx@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
+ */
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bt_ctf_stream;
+struct bt_ctf_packet;
+
+extern struct bt_ctf_packet *bt_ctf_packet_create(
+               struct bt_ctf_stream *stream);
+
+extern struct bt_ctf_stream *bt_ctf_packet_get_stream(
+               struct bt_ctf_packet *packet);
+
+extern struct bt_ctf_field *bt_ctf_packet_get_header(
+               struct bt_ctf_packet *packet);
+
+extern int bt_ctf_packet_set_header(
+               struct bt_ctf_packet *packet, struct bt_ctf_field *header);
+
+extern struct bt_ctf_field *bt_ctf_packet_get_context(
+               struct bt_ctf_packet *context);
+
+extern int bt_ctf_packet_set_context(
+               struct bt_ctf_packet *packet, struct bt_ctf_field *context);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_CTF_IR_PACKET_H */
index 453b08515a8be31819a1233f78f6888696211d9a..1bd1ea18c26bfb63c9711c38fa95aefaa5ea8208 100644 (file)
@@ -34,6 +34,7 @@
 #include <babeltrace/object-internal.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/ctf/types.h>
+#include <babeltrace/ctf-ir/trace-internal.h>
 #include <glib.h>
 
 struct bt_ctf_stream_class {
This page took 0.029188 seconds and 4 git commands to generate.