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