Commit | Line | Data |
---|---|---|
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 | ||
27 | #include <babeltrace/compiler.h> | |
599faa1c PP |
28 | #include <babeltrace/ctf-ir/event.h> |
29 | #include <babeltrace/ctf-ir/event-class.h> | |
30 | #include <babeltrace/ctf-ir/stream-class.h> | |
31 | #include <babeltrace/ctf-ir/trace.h> | |
32 | #include <babeltrace/graph/clock-class-priority-map.h> | |
b2e0c907 | 33 | #include <babeltrace/graph/notification-event-internal.h> |
d51202da JG |
34 | |
35 | static | |
36 | void bt_notification_event_destroy(struct bt_object *obj) | |
37 | { | |
38 | struct bt_notification_event *notification = | |
39 | (struct bt_notification_event *) obj; | |
40 | ||
41 | BT_PUT(notification->event); | |
599faa1c | 42 | BT_PUT(notification->cc_prio_map); |
d51202da JG |
43 | g_free(notification); |
44 | } | |
45 | ||
599faa1c PP |
46 | static |
47 | bool validate_clock_classes(struct bt_notification_event *notif) | |
48 | { | |
49 | /* | |
50 | * For each clock class found in the event's trace, get the | |
51 | * event's clock value for this clock class, and if it exists, | |
52 | * make sure that this clock class has a priority in the | |
53 | * notification's clock class priority map. | |
54 | */ | |
55 | bool is_valid = true; | |
56 | int ret; | |
57 | int count; | |
58 | size_t i; | |
59 | struct bt_ctf_event_class *event_class = NULL; | |
60 | struct bt_ctf_stream_class *stream_class = NULL; | |
61 | struct bt_ctf_trace *trace = NULL; | |
62 | uint64_t prio; | |
63 | ||
64 | event_class = bt_ctf_event_get_class(notif->event); | |
65 | assert(event_class); | |
66 | stream_class = bt_ctf_event_class_get_stream_class(event_class); | |
67 | assert(stream_class); | |
68 | trace = bt_ctf_stream_class_get_trace(stream_class); | |
69 | assert(trace); | |
70 | count = bt_ctf_trace_get_clock_class_count(trace); | |
71 | assert(count >= 0); | |
72 | ||
73 | for (i = 0; i < count; i++) { | |
74 | struct bt_ctf_clock_class *clock_class = | |
75 | bt_ctf_trace_get_clock_class(trace, i); | |
76 | ||
77 | assert(clock_class); | |
78 | ret = bt_clock_class_priority_map_get_clock_class_priority( | |
79 | notif->cc_prio_map, clock_class, &prio); | |
80 | bt_put(clock_class); | |
81 | if (ret) { | |
82 | is_valid = false; | |
83 | goto end; | |
84 | } | |
85 | } | |
86 | ||
87 | end: | |
88 | bt_put(trace); | |
89 | bt_put(stream_class); | |
90 | bt_put(event_class); | |
91 | return is_valid; | |
92 | } | |
93 | ||
94 | struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event, | |
95 | struct bt_clock_class_priority_map *cc_prio_map) | |
d51202da JG |
96 | { |
97 | struct bt_notification_event *notification; | |
98 | ||
599faa1c | 99 | if (!event || !cc_prio_map) { |
d51202da JG |
100 | goto error; |
101 | } | |
102 | ||
24626e8b JG |
103 | // FIXME - Validate that the event is associated to a packet |
104 | // and freeze the event. | |
d51202da | 105 | notification = g_new0(struct bt_notification_event, 1); |
24626e8b JG |
106 | if (!notification) { |
107 | goto error; | |
108 | } | |
d51202da JG |
109 | bt_notification_init(¬ification->parent, |
110 | BT_NOTIFICATION_TYPE_EVENT, | |
111 | bt_notification_event_destroy); | |
112 | notification->event = bt_get(event); | |
599faa1c PP |
113 | notification->cc_prio_map = bt_get(cc_prio_map); |
114 | ||
115 | if (!validate_clock_classes(notification)) { | |
116 | bt_put(notification); | |
117 | goto error; | |
118 | } | |
119 | ||
d51202da JG |
120 | return ¬ification->parent; |
121 | error: | |
122 | return NULL; | |
123 | } | |
124 | ||
125 | struct bt_ctf_event *bt_notification_event_get_event( | |
126 | struct bt_notification *notification) | |
127 | { | |
08bfb670 | 128 | struct bt_ctf_event *event = NULL; |
d51202da JG |
129 | struct bt_notification_event *event_notification; |
130 | ||
08bfb670 JG |
131 | if (bt_notification_get_type(notification) != |
132 | BT_NOTIFICATION_TYPE_EVENT) { | |
133 | goto end; | |
134 | } | |
d51202da JG |
135 | event_notification = container_of(notification, |
136 | struct bt_notification_event, parent); | |
08bfb670 JG |
137 | event = bt_get(event_notification->event); |
138 | end: | |
139 | return event; | |
d51202da | 140 | } |
599faa1c PP |
141 | |
142 | extern struct bt_clock_class_priority_map * | |
143 | bt_notification_event_get_clock_class_priority_map( | |
144 | struct bt_notification *notification) | |
145 | { | |
146 | struct bt_clock_class_priority_map *cc_prio_map = NULL; | |
147 | struct bt_notification_event *event_notification; | |
148 | ||
149 | if (bt_notification_get_type(notification) != | |
150 | BT_NOTIFICATION_TYPE_EVENT) { | |
151 | goto end; | |
152 | } | |
153 | ||
154 | event_notification = container_of(notification, | |
155 | struct bt_notification_event, parent); | |
156 | cc_prio_map = bt_get(event_notification->cc_prio_map); | |
157 | end: | |
158 | return cc_prio_map; | |
159 | } |