Split CTF IR and CTF writer APIs and implementations
[babeltrace.git] / lib / graph / notification / stream.c
CommitLineData
043e2020
JG
1/*
2 * Babeltrace Plug-in Stream-related Notifications
3 *
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
6 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
90bd5941
PP
27#define BT_LOG_TAG "NOTIF-STREAM"
28#include <babeltrace/lib-logging-internal.h>
29
3d9990ac 30#include <babeltrace/compiler-internal.h>
3230ee6b 31#include <babeltrace/ctf-ir/stream-internal.h>
9d408fca 32#include <babeltrace/ctf-ir/stream-class.h>
b2e0c907 33#include <babeltrace/graph/notification-stream-internal.h>
f6ccaed9
PP
34#include <babeltrace/assert-internal.h>
35#include <babeltrace/assert-pre-internal.h>
90bd5941 36#include <inttypes.h>
043e2020
JG
37
38static
39void bt_notification_stream_end_destroy(struct bt_object *obj)
40{
41 struct bt_notification_stream_end *notification =
42 (struct bt_notification_stream_end *) obj;
43
90bd5941
PP
44 BT_LOGD("Destroying stream end notification: addr=%p",
45 notification);
46 BT_LOGD_STR("Putting stream.");
043e2020
JG
47 BT_PUT(notification->stream);
48 g_free(notification);
49}
50
51struct bt_notification *bt_notification_stream_end_create(
50842bdc 52 struct bt_stream *stream)
043e2020
JG
53{
54 struct bt_notification_stream_end *notification;
50842bdc 55 struct bt_stream_class *stream_class;
043e2020 56
f6ccaed9 57 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
3dca2276 58 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 59 BT_ASSERT(stream_class);
90bd5941
PP
60 BT_LOGD("Creating stream end notification object: "
61 "stream-addr=%p, stream-name=\"%s\", "
62 "stream-class-addr=%p, stream-class-name=\"%s\", "
63 "stream-class-id=%" PRId64,
50842bdc 64 stream, bt_stream_get_name(stream),
90bd5941 65 stream_class,
50842bdc
PP
66 bt_stream_class_get_name(stream_class),
67 bt_stream_class_get_id(stream_class));
043e2020 68 notification = g_new0(struct bt_notification_stream_end, 1);
90bd5941
PP
69 if (!notification) {
70 BT_LOGE_STR("Failed to allocate one stream end notification.");
71 goto error;
72 }
73
043e2020
JG
74 bt_notification_init(&notification->parent,
75 BT_NOTIFICATION_TYPE_STREAM_END,
76 bt_notification_stream_end_destroy);
77 notification->stream = bt_get(stream);
90bd5941
PP
78 BT_LOGD("Created stream end notification object: "
79 "stream-addr=%p, stream-name=\"%s\", "
80 "stream-class-addr=%p, stream-class-name=\"%s\", "
81 "stream-class-id=%" PRId64 ", addr=%p",
50842bdc 82 stream, bt_stream_get_name(stream),
90bd5941 83 stream_class,
50842bdc
PP
84 bt_stream_class_get_name(stream_class),
85 bt_stream_class_get_id(stream_class), notification);
043e2020
JG
86 return &notification->parent;
87error:
88 return NULL;
89}
90
50842bdc 91struct bt_stream *bt_notification_stream_end_get_stream(
043e2020
JG
92 struct bt_notification *notification)
93{
94 struct bt_notification_stream_end *stream_end;
95
f6ccaed9
PP
96 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
97 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
98 BT_NOTIFICATION_TYPE_STREAM_END);
043e2020
JG
99 stream_end = container_of(notification,
100 struct bt_notification_stream_end, parent);
f6ccaed9 101 return bt_get(stream_end->stream);
043e2020 102}
3230ee6b
PP
103
104static
105void bt_notification_stream_begin_destroy(struct bt_object *obj)
106{
107 struct bt_notification_stream_begin *notification =
108 (struct bt_notification_stream_begin *) obj;
109
90bd5941
PP
110 BT_LOGD("Destroying stream beginning notification: addr=%p",
111 notification);
112 BT_LOGD_STR("Putting stream.");
3230ee6b
PP
113 BT_PUT(notification->stream);
114 g_free(notification);
115}
116
117struct bt_notification *bt_notification_stream_begin_create(
50842bdc 118 struct bt_stream *stream)
3230ee6b
PP
119{
120 struct bt_notification_stream_begin *notification;
50842bdc 121 struct bt_stream_class *stream_class;
3230ee6b 122
f6ccaed9 123 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
3dca2276 124 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 125 BT_ASSERT(stream_class);
90bd5941
PP
126 BT_LOGD("Creating stream beginning notification object: "
127 "stream-addr=%p, stream-name=\"%s\", "
128 "stream-class-addr=%p, stream-class-name=\"%s\", "
129 "stream-class-id=%" PRId64,
50842bdc 130 stream, bt_stream_get_name(stream),
90bd5941 131 stream_class,
50842bdc
PP
132 bt_stream_class_get_name(stream_class),
133 bt_stream_class_get_id(stream_class));
3230ee6b 134 notification = g_new0(struct bt_notification_stream_begin, 1);
90bd5941
PP
135 if (!notification) {
136 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
137 goto error;
138 }
139
3230ee6b
PP
140 bt_notification_init(&notification->parent,
141 BT_NOTIFICATION_TYPE_STREAM_BEGIN,
142 bt_notification_stream_begin_destroy);
143 notification->stream = bt_get(stream);
90bd5941
PP
144 BT_LOGD("Created stream beginning notification object: "
145 "stream-addr=%p, stream-name=\"%s\", "
146 "stream-class-addr=%p, stream-class-name=\"%s\", "
147 "stream-class-id=%" PRId64 ", addr=%p",
50842bdc 148 stream, bt_stream_get_name(stream),
90bd5941 149 stream_class,
50842bdc
PP
150 bt_stream_class_get_name(stream_class),
151 bt_stream_class_get_id(stream_class), notification);
3230ee6b
PP
152 return &notification->parent;
153error:
154 return NULL;
155}
156
50842bdc 157struct bt_stream *bt_notification_stream_begin_get_stream(
3230ee6b
PP
158 struct bt_notification *notification)
159{
160 struct bt_notification_stream_begin *stream_begin;
161
f6ccaed9
PP
162 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
163 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
164 BT_NOTIFICATION_TYPE_STREAM_BEGIN);
3230ee6b
PP
165 stream_begin = container_of(notification,
166 struct bt_notification_stream_begin, parent);
f6ccaed9 167 return bt_get(stream_begin->stream);
3230ee6b 168}
This page took 0.043845 seconds and 4 git commands to generate.