lib/ctf-ir/stream.c: add logging
[babeltrace.git] / lib / graph / notification / event.c
CommitLineData
d51202da
JG
1/*
2 * Babeltrace Plug-in Event Notification
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
3d9990ac 27#include <babeltrace/compiler-internal.h>
599faa1c 28#include <babeltrace/ctf-ir/event.h>
80f00602 29#include <babeltrace/ctf-ir/event-internal.h>
d8a36e14
PP
30#include <babeltrace/ctf-ir/event-class-internal.h>
31#include <babeltrace/ctf-ir/stream-class-internal.h>
599faa1c
PP
32#include <babeltrace/ctf-ir/trace.h>
33#include <babeltrace/graph/clock-class-priority-map.h>
fe650ea4 34#include <babeltrace/graph/clock-class-priority-map-internal.h>
b2e0c907 35#include <babeltrace/graph/notification-event-internal.h>
c55a9f58 36#include <babeltrace/types.h>
d51202da
JG
37
38static
39void bt_notification_event_destroy(struct bt_object *obj)
40{
41 struct bt_notification_event *notification =
42 (struct bt_notification_event *) obj;
43
44 BT_PUT(notification->event);
599faa1c 45 BT_PUT(notification->cc_prio_map);
d51202da
JG
46 g_free(notification);
47}
48
599faa1c 49static
c55a9f58 50bt_bool validate_clock_classes(struct bt_notification_event *notif)
599faa1c
PP
51{
52 /*
d8a36e14
PP
53 * For each clock class found in the notification's clock class
54 * priority map, make sure the event has a clock value set for
55 * this clock class. Also make sure that those clock classes
56 * are part of the trace to which the event belongs.
599faa1c 57 */
c55a9f58 58 bt_bool is_valid = BT_TRUE;
d8a36e14
PP
59 int trace_cc_count;
60 int cc_prio_map_cc_count;
61 size_t cc_prio_map_cc_i, trace_cc_i;
599faa1c
PP
62 struct bt_ctf_event_class *event_class = NULL;
63 struct bt_ctf_stream_class *stream_class = NULL;
64 struct bt_ctf_trace *trace = NULL;
599faa1c 65
d8a36e14 66 event_class = bt_ctf_event_borrow_event_class(notif->event);
599faa1c 67 assert(event_class);
d8a36e14 68 stream_class = bt_ctf_event_class_borrow_stream_class(event_class);
599faa1c 69 assert(stream_class);
d8a36e14 70 trace = bt_ctf_stream_class_borrow_trace(stream_class);
599faa1c 71 assert(trace);
d8a36e14
PP
72 trace_cc_count = bt_ctf_trace_get_clock_class_count(trace);
73 assert(trace_cc_count >= 0);
74 cc_prio_map_cc_count =
75 bt_clock_class_priority_map_get_clock_class_count(
76 notif->cc_prio_map);
77 assert(cc_prio_map_cc_count >= 0);
599faa1c 78
d8a36e14
PP
79 for (cc_prio_map_cc_i = 0; cc_prio_map_cc_i < cc_prio_map_cc_count;
80 cc_prio_map_cc_i++) {
599faa1c 81 struct bt_ctf_clock_class *clock_class =
9ac68eb1 82 bt_clock_class_priority_map_get_clock_class_by_index(
d8a36e14
PP
83 notif->cc_prio_map, cc_prio_map_cc_i);
84 struct bt_ctf_clock_value *clock_value;
c55a9f58 85 bt_bool found_in_trace = BT_FALSE;
599faa1c
PP
86
87 assert(clock_class);
d8a36e14
PP
88 clock_value = bt_ctf_event_get_clock_value(notif->event,
89 clock_class);
90 if (!clock_value) {
c55a9f58 91 is_valid = BT_FALSE;
d8a36e14
PP
92 goto end;
93 }
94
95 bt_put(clock_value);
96
97 for (trace_cc_i = 0; trace_cc_i < trace_cc_count;
98 trace_cc_i++) {
99 struct bt_ctf_clock_class *trace_clock_class =
9ac68eb1
PP
100 bt_ctf_trace_get_clock_class_by_index(trace,
101 trace_cc_i);
d8a36e14
PP
102
103 assert(trace_clock_class);
104
105 if (trace_clock_class == clock_class) {
c55a9f58 106 found_in_trace = BT_TRUE;
d8a36e14
PP
107 break;
108 }
109 }
110
599faa1c 111 bt_put(clock_class);
d8a36e14
PP
112
113 if (!found_in_trace) {
c55a9f58 114 is_valid = BT_FALSE;
599faa1c
PP
115 goto end;
116 }
117 }
118
119end:
599faa1c
PP
120 return is_valid;
121}
122
123struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event,
124 struct bt_clock_class_priority_map *cc_prio_map)
d51202da 125{
80f00602 126 struct bt_notification_event *notification = NULL;
d51202da 127
599faa1c 128 if (!event || !cc_prio_map) {
d51202da
JG
129 goto error;
130 }
131
80f00602
PP
132 if (!bt_ctf_event_borrow_packet(event)) {
133 goto error;
134 }
135
d51202da 136 notification = g_new0(struct bt_notification_event, 1);
24626e8b
JG
137 if (!notification) {
138 goto error;
139 }
d51202da
JG
140 bt_notification_init(&notification->parent,
141 BT_NOTIFICATION_TYPE_EVENT,
142 bt_notification_event_destroy);
143 notification->event = bt_get(event);
599faa1c 144 notification->cc_prio_map = bt_get(cc_prio_map);
599faa1c 145 if (!validate_clock_classes(notification)) {
599faa1c
PP
146 goto error;
147 }
148
80f00602 149 bt_ctf_event_freeze(notification->event);
fe650ea4 150 bt_clock_class_priority_map_freeze(notification->cc_prio_map);
d51202da
JG
151 return &notification->parent;
152error:
80f00602 153 bt_put(notification);
d51202da
JG
154 return NULL;
155}
156
157struct bt_ctf_event *bt_notification_event_get_event(
158 struct bt_notification *notification)
159{
08bfb670 160 struct bt_ctf_event *event = NULL;
d51202da
JG
161 struct bt_notification_event *event_notification;
162
08bfb670
JG
163 if (bt_notification_get_type(notification) !=
164 BT_NOTIFICATION_TYPE_EVENT) {
165 goto end;
166 }
d51202da
JG
167 event_notification = container_of(notification,
168 struct bt_notification_event, parent);
08bfb670
JG
169 event = bt_get(event_notification->event);
170end:
171 return event;
d51202da 172}
599faa1c
PP
173
174extern struct bt_clock_class_priority_map *
175bt_notification_event_get_clock_class_priority_map(
176 struct bt_notification *notification)
177{
178 struct bt_clock_class_priority_map *cc_prio_map = NULL;
179 struct bt_notification_event *event_notification;
180
181 if (bt_notification_get_type(notification) !=
182 BT_NOTIFICATION_TYPE_EVENT) {
183 goto end;
184 }
185
186 event_notification = container_of(notification,
187 struct bt_notification_event, parent);
188 cc_prio_map = bt_get(event_notification->cc_prio_map);
189end:
190 return cc_prio_map;
191}
This page took 0.050329 seconds and 4 git commands to generate.