Commit | Line | Data |
---|---|---|
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> | |
33 | #include <stdint.h> | |
34 | #include <inttypes.h> | |
35 | ||
36 | static | |
37 | void bt_notification_discarded_elements_destroy(struct bt_object *obj) | |
38 | { | |
39 | struct bt_notification_discarded_elements *notification = | |
40 | (struct bt_notification_discarded_elements *) obj; | |
41 | ||
42 | BT_LOGD("Destroying discarded elements notification: addr=%p", | |
43 | notification); | |
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); | |
50 | g_free(notification); | |
51 | } | |
52 | ||
53 | BT_HIDDEN | |
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, | |
59 | uint64_t count) | |
60 | { | |
61 | struct bt_notification_discarded_elements *notification; | |
62 | struct bt_notification *ret_notif = NULL; | |
63 | ||
64 | if (!stream) { | |
65 | BT_LOGW_STR("Invalid parameter: stream is NULL."); | |
66 | } | |
67 | ||
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, " | |
71 | "count=%" PRIu64, | |
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); | |
76 | if (!notification) { | |
77 | BT_LOGE_STR("Failed to allocate one discarded elements notification."); | |
78 | goto error; | |
79 | } | |
80 | ||
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); | |
95 | goto end; | |
96 | ||
97 | error: | |
98 | BT_PUT(ret_notif); | |
99 | ||
100 | end: | |
101 | return ret_notif; | |
102 | } | |
103 | ||
104 | BT_HIDDEN | |
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) | |
109 | { | |
110 | struct bt_ctf_clock_value *clock_value = NULL; | |
111 | struct bt_notification_discarded_elements *discarded_elems_notif; | |
112 | ||
113 | if (!notification) { | |
114 | BT_LOGW_STR("Invalid parameter: notification is NULL."); | |
115 | goto end; | |
116 | } | |
117 | ||
126215b4 | 118 | if (bt_notification_get_type(notification) != type) { |
2ec84d26 PP |
119 | BT_LOGW("Invalid parameter: notification has not the expected type: " |
120 | "addr%p, expected-type=%s, notif-type=%s", | |
121 | notification, bt_notification_type_string(type), | |
122 | bt_notification_type_string( | |
123 | bt_notification_get_type(notification))); | |
124 | goto end; | |
125 | } | |
126 | ||
127 | discarded_elems_notif = container_of(notification, | |
128 | struct bt_notification_discarded_elements, parent); | |
129 | clock_value = bt_get(discarded_elems_notif->begin_clock_value); | |
130 | ||
131 | end: | |
132 | return clock_value; | |
133 | } | |
134 | ||
135 | BT_HIDDEN | |
136 | struct bt_ctf_clock_value * | |
137 | bt_notification_discarded_elements_get_end_clock_value( | |
138 | enum bt_notification_type type, | |
139 | struct bt_notification *notification) | |
140 | { | |
141 | struct bt_ctf_clock_value *clock_value = NULL; | |
142 | struct bt_notification_discarded_elements *discarded_elems_notif; | |
143 | ||
144 | if (!notification) { | |
145 | BT_LOGW_STR("Invalid parameter: notification is NULL."); | |
146 | goto end; | |
147 | } | |
148 | ||
126215b4 | 149 | if (bt_notification_get_type(notification) != type) { |
2ec84d26 PP |
150 | BT_LOGW("Invalid parameter: notification has not the expected type: " |
151 | "addr%p, expected-type=%s, notif-type=%s", | |
152 | notification, bt_notification_type_string(type), | |
153 | bt_notification_type_string( | |
154 | bt_notification_get_type(notification))); | |
155 | goto end; | |
156 | } | |
157 | ||
158 | discarded_elems_notif = container_of(notification, | |
159 | struct bt_notification_discarded_elements, parent); | |
160 | clock_value = bt_get(discarded_elems_notif->end_clock_value); | |
161 | ||
162 | end: | |
163 | return clock_value; | |
164 | } | |
165 | ||
166 | BT_HIDDEN | |
167 | int64_t bt_notification_discarded_elements_get_count( | |
168 | enum bt_notification_type type, | |
169 | struct bt_notification *notification) | |
170 | { | |
171 | int64_t count = (int64_t) -1; | |
172 | struct bt_notification_discarded_elements *discarded_elems_notif; | |
173 | ||
174 | if (!notification) { | |
175 | BT_LOGW_STR("Invalid parameter: notification is NULL."); | |
176 | goto end; | |
177 | } | |
178 | ||
126215b4 | 179 | if (bt_notification_get_type(notification) != type) { |
2ec84d26 PP |
180 | BT_LOGW("Invalid parameter: notification has not the expected type: " |
181 | "addr%p, expected-type=%s, notif-type=%s", | |
182 | notification, bt_notification_type_string(type), | |
183 | bt_notification_type_string( | |
184 | bt_notification_get_type(notification))); | |
185 | goto end; | |
186 | } | |
187 | ||
188 | discarded_elems_notif = container_of(notification, | |
189 | struct bt_notification_discarded_elements, parent); | |
190 | count = discarded_elems_notif->count; | |
191 | ||
192 | end: | |
193 | return count; | |
194 | } | |
195 | ||
196 | BT_HIDDEN | |
197 | struct bt_ctf_stream *bt_notification_discarded_elements_get_stream( | |
198 | enum bt_notification_type type, | |
199 | struct bt_notification *notification) | |
200 | { | |
201 | struct bt_ctf_stream *stream = NULL; | |
202 | struct bt_notification_discarded_elements *discarded_elems_notif; | |
203 | ||
204 | if (!notification) { | |
205 | BT_LOGW_STR("Invalid parameter: notification is NULL."); | |
206 | goto end; | |
207 | } | |
208 | ||
126215b4 | 209 | if (bt_notification_get_type(notification) != type) { |
2ec84d26 PP |
210 | BT_LOGW("Invalid parameter: notification has not the expected type: " |
211 | "addr%p, expected-type=%s, notif-type=%s", | |
212 | notification, bt_notification_type_string(type), | |
213 | bt_notification_type_string( | |
214 | bt_notification_get_type(notification))); | |
215 | goto end; | |
216 | } | |
217 | ||
218 | discarded_elems_notif = container_of(notification, | |
219 | struct bt_notification_discarded_elements, parent); | |
220 | stream = bt_get(discarded_elems_notif->stream); | |
221 | ||
222 | end: | |
223 | return stream; | |
224 | } |