2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 #define BT_LOG_TAG "NOTIF-DISCARDED"
24 #include <babeltrace/lib-logging-internal.h>
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>
37 void bt_notification_discarded_elements_destroy(struct bt_object
*obj
)
39 struct bt_notification_discarded_elements
*notification
=
40 (struct bt_notification_discarded_elements
*) obj
;
42 BT_LOGD("Destroying discarded elements notification: addr=%p",
44 BT_LOGD_STR("Putting stream.");
45 bt_put(notification
->stream
);
46 BT_LOGD_STR("Putting beginning clock value.");
47 bt_put(notification
->begin_clock_value
);
48 BT_LOGD_STR("Putting end clock value.");
49 bt_put(notification
->end_clock_value
);
54 struct bt_notification
*bt_notification_discarded_elements_create(
55 enum bt_notification_type type
,
56 struct bt_ctf_stream
*stream
,
57 struct bt_ctf_clock_value
*begin_clock_value
,
58 struct bt_ctf_clock_value
*end_clock_value
,
61 struct bt_notification_discarded_elements
*notification
;
62 struct bt_notification
*ret_notif
= NULL
;
65 BT_LOGW_STR("Invalid parameter: stream is NULL.");
68 BT_LOGD("Creating discarded elements notification object: "
69 "type=%s, stream-addr=%p, stream-name=\"%s\", "
70 "begin-clock-value-addr=%p, end-clock-value-addr=%p, "
72 bt_notification_type_string(type
), stream
,
73 bt_ctf_stream_get_name(stream
), begin_clock_value
,
74 end_clock_value
, count
);
75 notification
= g_new0(struct bt_notification_discarded_elements
, 1);
77 BT_LOGE_STR("Failed to allocate one discarded elements notification.");
81 bt_notification_init(¬ification
->parent
, type
,
82 bt_notification_discarded_elements_destroy
);
83 ret_notif
= ¬ification
->parent
;
84 notification
->stream
= bt_get(stream
);
85 notification
->begin_clock_value
= bt_get(begin_clock_value
);
86 notification
->end_clock_value
= bt_get(end_clock_value
);
87 notification
->count
= (int64_t) count
;
88 BT_LOGD("Created discarded elements notification object: "
89 "type=%s, stream-addr=%p, stream-name=\"%s\", "
90 "begin-clock-value-addr=%p, end-clock-value-addr=%p, "
91 "count=%" PRIu64
", addr=%p",
92 bt_notification_type_string(type
), stream
,
93 bt_ctf_stream_get_name(stream
), begin_clock_value
,
94 end_clock_value
, count
, ret_notif
);
105 struct bt_ctf_clock_value
*
106 bt_notification_discarded_elements_get_begin_clock_value(
107 enum bt_notification_type type
,
108 struct bt_notification
*notification
)
110 struct bt_ctf_clock_value
*clock_value
= NULL
;
111 struct bt_notification_discarded_elements
*discarded_elems_notif
;
114 BT_LOGW_STR("Invalid parameter: notification is NULL.");
118 if (bt_notification_get_type(notification
) !=
119 BT_NOTIFICATION_TYPE_DISCARDED_EVENTS
) {
120 BT_LOGW("Invalid parameter: notification has not the expected type: "
121 "addr%p, expected-type=%s, notif-type=%s",
122 notification
, bt_notification_type_string(type
),
123 bt_notification_type_string(
124 bt_notification_get_type(notification
)));
128 discarded_elems_notif
= container_of(notification
,
129 struct bt_notification_discarded_elements
, parent
);
130 clock_value
= bt_get(discarded_elems_notif
->begin_clock_value
);
137 struct bt_ctf_clock_value
*
138 bt_notification_discarded_elements_get_end_clock_value(
139 enum bt_notification_type type
,
140 struct bt_notification
*notification
)
142 struct bt_ctf_clock_value
*clock_value
= NULL
;
143 struct bt_notification_discarded_elements
*discarded_elems_notif
;
146 BT_LOGW_STR("Invalid parameter: notification is NULL.");
150 if (bt_notification_get_type(notification
) !=
151 BT_NOTIFICATION_TYPE_DISCARDED_EVENTS
) {
152 BT_LOGW("Invalid parameter: notification has not the expected type: "
153 "addr%p, expected-type=%s, notif-type=%s",
154 notification
, bt_notification_type_string(type
),
155 bt_notification_type_string(
156 bt_notification_get_type(notification
)));
160 discarded_elems_notif
= container_of(notification
,
161 struct bt_notification_discarded_elements
, parent
);
162 clock_value
= bt_get(discarded_elems_notif
->end_clock_value
);
169 int64_t bt_notification_discarded_elements_get_count(
170 enum bt_notification_type type
,
171 struct bt_notification
*notification
)
173 int64_t count
= (int64_t) -1;
174 struct bt_notification_discarded_elements
*discarded_elems_notif
;
177 BT_LOGW_STR("Invalid parameter: notification is NULL.");
181 if (bt_notification_get_type(notification
) !=
182 BT_NOTIFICATION_TYPE_DISCARDED_EVENTS
) {
183 BT_LOGW("Invalid parameter: notification has not the expected type: "
184 "addr%p, expected-type=%s, notif-type=%s",
185 notification
, bt_notification_type_string(type
),
186 bt_notification_type_string(
187 bt_notification_get_type(notification
)));
191 discarded_elems_notif
= container_of(notification
,
192 struct bt_notification_discarded_elements
, parent
);
193 count
= discarded_elems_notif
->count
;
200 struct bt_ctf_stream
*bt_notification_discarded_elements_get_stream(
201 enum bt_notification_type type
,
202 struct bt_notification
*notification
)
204 struct bt_ctf_stream
*stream
= NULL
;
205 struct bt_notification_discarded_elements
*discarded_elems_notif
;
208 BT_LOGW_STR("Invalid parameter: notification is NULL.");
212 if (bt_notification_get_type(notification
) !=
213 BT_NOTIFICATION_TYPE_DISCARDED_EVENTS
) {
214 BT_LOGW("Invalid parameter: notification has not the expected type: "
215 "addr%p, expected-type=%s, notif-type=%s",
216 notification
, bt_notification_type_string(type
),
217 bt_notification_type_string(
218 bt_notification_get_type(notification
)));
222 discarded_elems_notif
= container_of(notification
,
223 struct bt_notification_discarded_elements
, parent
);
224 stream
= bt_get(discarded_elems_notif
->stream
);