Replace assert() -> BT_ASSERT() and some preconditions with BT_ASSERT_PRE()
[babeltrace.git] / lib / graph / notification / discarded-elements.c
CommitLineData
b04a393b
PP
1/*
2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#define BT_LOG_TAG "NOTIF-DISCARDED"
24#include <babeltrace/lib-logging-internal.h>
25
26#include <babeltrace/object-internal.h>
27#include <babeltrace/compiler-internal.h>
28#include <babeltrace/ctf-ir/clock-class.h>
29#include <babeltrace/graph/clock-class-priority-map.h>
30#include <babeltrace/graph/clock-class-priority-map-internal.h>
31#include <babeltrace/graph/notification-internal.h>
32#include <babeltrace/graph/notification-discarded-elements-internal.h>
8b45963b 33#include <babeltrace/assert-pre-internal.h>
b04a393b
PP
34#include <stdint.h>
35#include <inttypes.h>
36
37static
38void bt_notification_discarded_elements_destroy(struct bt_object *obj)
39{
40 struct bt_notification_discarded_elements *notification =
41 (struct bt_notification_discarded_elements *) obj;
42
43 BT_LOGD("Destroying discarded elements notification: addr=%p",
44 notification);
45 BT_LOGD_STR("Putting stream.");
46 bt_put(notification->stream);
47 BT_LOGD_STR("Putting beginning clock value.");
48 bt_put(notification->begin_clock_value);
49 BT_LOGD_STR("Putting end clock value.");
50 bt_put(notification->end_clock_value);
51 g_free(notification);
52}
53
54BT_HIDDEN
55struct bt_notification *bt_notification_discarded_elements_create(
56 enum bt_notification_type type,
839d52a5
PP
57 struct bt_stream *stream,
58 struct bt_clock_value *begin_clock_value,
59 struct bt_clock_value *end_clock_value,
b04a393b
PP
60 uint64_t count)
61{
62 struct bt_notification_discarded_elements *notification;
63 struct bt_notification *ret_notif = NULL;
64
8b45963b 65 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
b04a393b
PP
66 BT_LOGD("Creating discarded elements notification object: "
67 "type=%s, stream-addr=%p, stream-name=\"%s\", "
68 "begin-clock-value-addr=%p, end-clock-value-addr=%p, "
69 "count=%" PRIu64,
70 bt_notification_type_string(type), stream,
839d52a5 71 bt_stream_get_name(stream), begin_clock_value,
b04a393b
PP
72 end_clock_value, count);
73 notification = g_new0(struct bt_notification_discarded_elements, 1);
74 if (!notification) {
75 BT_LOGE_STR("Failed to allocate one discarded elements notification.");
76 goto error;
77 }
78
79 bt_notification_init(&notification->parent, type,
80 bt_notification_discarded_elements_destroy);
81 ret_notif = &notification->parent;
82 notification->stream = bt_get(stream);
83 notification->begin_clock_value = bt_get(begin_clock_value);
84 notification->end_clock_value = bt_get(end_clock_value);
85 notification->count = (int64_t) count;
86 BT_LOGD("Created discarded elements notification object: "
87 "type=%s, stream-addr=%p, stream-name=\"%s\", "
88 "begin-clock-value-addr=%p, end-clock-value-addr=%p, "
89 "count=%" PRIu64 ", addr=%p",
90 bt_notification_type_string(type), stream,
839d52a5 91 bt_stream_get_name(stream), begin_clock_value,
b04a393b
PP
92 end_clock_value, count, ret_notif);
93 goto end;
94
95error:
96 BT_PUT(ret_notif);
97
98end:
99 return ret_notif;
100}
101
102BT_HIDDEN
839d52a5 103struct bt_clock_value *
b04a393b
PP
104bt_notification_discarded_elements_get_begin_clock_value(
105 enum bt_notification_type type,
106 struct bt_notification *notification)
107{
b04a393b
PP
108 struct bt_notification_discarded_elements *discarded_elems_notif;
109
8b45963b
PP
110 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
111 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
b04a393b
PP
112 discarded_elems_notif = container_of(notification,
113 struct bt_notification_discarded_elements, parent);
8b45963b 114 return bt_get(discarded_elems_notif->begin_clock_value);
b04a393b
PP
115}
116
117BT_HIDDEN
839d52a5 118struct bt_clock_value *
b04a393b
PP
119bt_notification_discarded_elements_get_end_clock_value(
120 enum bt_notification_type type,
121 struct bt_notification *notification)
122{
b04a393b
PP
123 struct bt_notification_discarded_elements *discarded_elems_notif;
124
8b45963b
PP
125 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
126 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
b04a393b
PP
127 discarded_elems_notif = container_of(notification,
128 struct bt_notification_discarded_elements, parent);
8b45963b 129 return bt_get(discarded_elems_notif->end_clock_value);
b04a393b
PP
130}
131
132BT_HIDDEN
133int64_t bt_notification_discarded_elements_get_count(
134 enum bt_notification_type type,
135 struct bt_notification *notification)
136{
b04a393b
PP
137 struct bt_notification_discarded_elements *discarded_elems_notif;
138
8b45963b
PP
139 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
140 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
b04a393b
PP
141 discarded_elems_notif = container_of(notification,
142 struct bt_notification_discarded_elements, parent);
8b45963b 143 return discarded_elems_notif->count;
b04a393b
PP
144}
145
146BT_HIDDEN
839d52a5 147struct bt_stream *bt_notification_discarded_elements_get_stream(
b04a393b
PP
148 enum bt_notification_type type,
149 struct bt_notification *notification)
150{
b04a393b
PP
151 struct bt_notification_discarded_elements *discarded_elems_notif;
152
8b45963b
PP
153 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
154 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
b04a393b
PP
155 discarded_elems_notif = container_of(notification,
156 struct bt_notification_discarded_elements, parent);
8b45963b 157 return bt_get(discarded_elems_notif->stream);
b04a393b 158}
This page took 0.046735 seconds and 4 git commands to generate.