Logging: standardize logging tags
[babeltrace.git] / src / lib / graph / message / stream.c
CommitLineData
b09a5592
PP
1/*
2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
b03487ab 24#define BT_LOG_TAG "LIB/MSG-STREAM"
57952005 25#include "lib/lib-logging.h"
b09a5592 26
57952005
MJ
27#include "lib/assert-pre.h"
28#include "compat/compiler.h"
71c5da58 29#include <babeltrace2/trace-ir/clock-snapshot-const.h>
57952005 30#include "lib/trace-ir/stream.h"
71c5da58 31#include <babeltrace2/trace-ir/stream-class.h>
57952005 32#include "lib/trace-ir/stream-class.h"
71c5da58
MJ
33#include <babeltrace2/graph/message-stream-beginning.h>
34#include <babeltrace2/graph/message-stream-end.h>
35#include <babeltrace2/graph/message-stream-beginning-const.h>
36#include <babeltrace2/graph/message-stream-end-const.h>
57952005 37#include "common/assert.h"
b09a5592
PP
38#include <inttypes.h>
39
57952005
MJ
40#include "stream.h"
41
b09a5592 42static
a1f053a9 43void destroy_stream_message(struct bt_object *obj)
b09a5592 44{
a1f053a9 45 struct bt_message_stream *message = (void *) obj;
b09a5592 46
a1f053a9 47 BT_LIB_LOGD("Destroying stream message: %!+n", message);
b09a5592
PP
48 BT_LIB_LOGD("Putting stream: %!+s", message->stream);
49 BT_OBJECT_PUT_REF_AND_RESET(message->stream);
b09a5592
PP
50 g_free(message);
51}
52
a1f053a9
PP
53static inline
54struct bt_message *create_stream_message(
b09a5592 55 struct bt_self_message_iterator *self_msg_iter,
a1f053a9 56 struct bt_stream *stream, enum bt_message_type type)
b09a5592 57{
a1f053a9 58 struct bt_message_stream *message;
b09a5592
PP
59 struct bt_stream_class *stream_class;
60
61 BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator");
62 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
63 stream_class = bt_stream_borrow_class(stream);
64 BT_ASSERT(stream_class);
a1f053a9
PP
65 BT_LIB_LOGD("Creating stream message object: "
66 "type=%s, %![stream-]+s, %![sc-]+S",
67 bt_message_type_string(type), stream, stream_class);
68 message = g_new0(struct bt_message_stream, 1);
b09a5592 69 if (!message) {
a1f053a9 70 BT_LOGE_STR("Failed to allocate one stream message.");
b09a5592
PP
71 goto error;
72 }
73
a1f053a9
PP
74 bt_message_init(&message->parent, type,
75 destroy_stream_message, NULL);
b09a5592
PP
76 message->stream = stream;
77 bt_object_get_no_null_check(message->stream);
a1f053a9 78 BT_LIB_LOGD("Created stream message object: "
b09a5592
PP
79 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message,
80 stream, stream_class);
81
82 return (void *) &message->parent;
a1f053a9 83
b09a5592
PP
84error:
85 return NULL;
86}
87
a1f053a9
PP
88struct bt_message *bt_message_stream_beginning_create(
89 struct bt_self_message_iterator *self_msg_iter,
6a6975d2 90 const struct bt_stream *stream)
b09a5592 91{
6a6975d2 92 return create_stream_message(self_msg_iter, (void *) stream,
a1f053a9 93 BT_MESSAGE_TYPE_STREAM_BEGINNING);
b09a5592
PP
94}
95
a1f053a9
PP
96struct bt_message *bt_message_stream_end_create(
97 struct bt_self_message_iterator *self_msg_iter,
6a6975d2 98 const struct bt_stream *stream)
b09a5592 99{
6a6975d2 100 return create_stream_message(self_msg_iter, (void *) stream,
a1f053a9 101 BT_MESSAGE_TYPE_STREAM_END);
b09a5592
PP
102}
103
a1f053a9
PP
104static inline
105struct bt_stream *borrow_stream_message_stream(struct bt_message *message)
b09a5592 106{
a1f053a9 107 struct bt_message_stream *stream_msg;
b09a5592 108
a1f053a9
PP
109 BT_ASSERT(message);
110 stream_msg = (void *) message;
111 return stream_msg->stream;
b09a5592
PP
112}
113
a1f053a9
PP
114struct bt_stream *bt_message_stream_beginning_borrow_stream(
115 struct bt_message *message)
b09a5592 116{
a1f053a9
PP
117 BT_ASSERT_PRE_NON_NULL(message, "Message");
118 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_STREAM_BEGINNING);
119 return borrow_stream_message_stream(message);
b09a5592
PP
120}
121
a1f053a9 122struct bt_stream *bt_message_stream_end_borrow_stream(
b09a5592
PP
123 struct bt_message *message)
124{
b09a5592 125 BT_ASSERT_PRE_NON_NULL(message, "Message");
a1f053a9
PP
126 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_STREAM_END);
127 return borrow_stream_message_stream(message);
b09a5592
PP
128}
129
130const struct bt_stream *bt_message_stream_beginning_borrow_stream_const(
131 const struct bt_message *message)
132{
133 return bt_message_stream_beginning_borrow_stream(
134 (void *) message);
135}
a1f053a9
PP
136
137const struct bt_stream *bt_message_stream_end_borrow_stream_const(
138 const struct bt_message *message)
139{
140 return bt_message_stream_end_borrow_stream(
141 (void *) message);
142}
This page took 0.043716 seconds and 4 git commands to generate.