lib: use object pool for event and packet notifications
[babeltrace.git] / lib / graph / notification / discarded-elements.c
CommitLineData
2ec84d26
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>
f6ccaed9 33#include <babeltrace/assert-pre-internal.h>
2ec84d26
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(
5c563278 56 struct bt_graph *graph,
2ec84d26 57 enum bt_notification_type type,
50842bdc
PP
58 struct bt_stream *stream,
59 struct bt_clock_value *begin_clock_value,
60 struct bt_clock_value *end_clock_value,
2ec84d26
PP
61 uint64_t count)
62{
63 struct bt_notification_discarded_elements *notification;
64 struct bt_notification *ret_notif = NULL;
65
f6ccaed9 66 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
2ec84d26
PP
67 BT_LOGD("Creating discarded elements notification object: "
68 "type=%s, stream-addr=%p, stream-name=\"%s\", "
69 "begin-clock-value-addr=%p, end-clock-value-addr=%p, "
70 "count=%" PRIu64,
71 bt_notification_type_string(type), stream,
50842bdc 72 bt_stream_get_name(stream), begin_clock_value,
2ec84d26
PP
73 end_clock_value, count);
74 notification = g_new0(struct bt_notification_discarded_elements, 1);
75 if (!notification) {
76 BT_LOGE_STR("Failed to allocate one discarded elements notification.");
77 goto error;
78 }
79
80 bt_notification_init(&notification->parent, type,
5c563278 81 bt_notification_discarded_elements_destroy, NULL);
2ec84d26
PP
82 ret_notif = &notification->parent;
83 notification->stream = bt_get(stream);
84 notification->begin_clock_value = bt_get(begin_clock_value);
85 notification->end_clock_value = bt_get(end_clock_value);
86 notification->count = (int64_t) count;
87 BT_LOGD("Created discarded elements notification object: "
88 "type=%s, stream-addr=%p, stream-name=\"%s\", "
89 "begin-clock-value-addr=%p, end-clock-value-addr=%p, "
90 "count=%" PRIu64 ", addr=%p",
91 bt_notification_type_string(type), stream,
50842bdc 92 bt_stream_get_name(stream), begin_clock_value,
2ec84d26
PP
93 end_clock_value, count, ret_notif);
94 goto end;
95
96error:
97 BT_PUT(ret_notif);
98
99end:
100 return ret_notif;
101}
102
103BT_HIDDEN
50842bdc 104struct bt_clock_value *
094ff7c0 105bt_notification_discarded_elements_borrow_begin_clock_value(
2ec84d26
PP
106 enum bt_notification_type type,
107 struct bt_notification *notification)
108{
2ec84d26
PP
109 struct bt_notification_discarded_elements *discarded_elems_notif;
110
f6ccaed9
PP
111 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
112 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
2ec84d26
PP
113 discarded_elems_notif = container_of(notification,
114 struct bt_notification_discarded_elements, parent);
094ff7c0 115 return discarded_elems_notif->begin_clock_value;
2ec84d26
PP
116}
117
118BT_HIDDEN
50842bdc 119struct bt_clock_value *
094ff7c0 120bt_notification_discarded_elements_borrow_end_clock_value(
2ec84d26
PP
121 enum bt_notification_type type,
122 struct bt_notification *notification)
123{
2ec84d26
PP
124 struct bt_notification_discarded_elements *discarded_elems_notif;
125
f6ccaed9
PP
126 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
127 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
2ec84d26
PP
128 discarded_elems_notif = container_of(notification,
129 struct bt_notification_discarded_elements, parent);
094ff7c0 130 return discarded_elems_notif->end_clock_value;
2ec84d26
PP
131}
132
133BT_HIDDEN
134int64_t bt_notification_discarded_elements_get_count(
135 enum bt_notification_type type,
136 struct bt_notification *notification)
137{
2ec84d26
PP
138 struct bt_notification_discarded_elements *discarded_elems_notif;
139
f6ccaed9
PP
140 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
141 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
2ec84d26
PP
142 discarded_elems_notif = container_of(notification,
143 struct bt_notification_discarded_elements, parent);
f6ccaed9 144 return discarded_elems_notif->count;
2ec84d26
PP
145}
146
147BT_HIDDEN
094ff7c0 148struct bt_stream *bt_notification_discarded_elements_borrow_stream(
2ec84d26
PP
149 enum bt_notification_type type,
150 struct bt_notification *notification)
151{
2ec84d26
PP
152 struct bt_notification_discarded_elements *discarded_elems_notif;
153
f6ccaed9
PP
154 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
155 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
2ec84d26
PP
156 discarded_elems_notif = container_of(notification,
157 struct bt_notification_discarded_elements, parent);
094ff7c0 158 return discarded_elems_notif->stream;
2ec84d26 159}
This page took 0.032854 seconds and 4 git commands to generate.