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 | ||
546a0c4a PP |
27 | #define BT_LOG_TAG "NOTIF-EVENT" |
28 | #include <babeltrace/lib-logging-internal.h> | |
29 | ||
3d9990ac | 30 | #include <babeltrace/compiler-internal.h> |
599faa1c | 31 | #include <babeltrace/ctf-ir/event.h> |
80f00602 | 32 | #include <babeltrace/ctf-ir/event-internal.h> |
d8a36e14 PP |
33 | #include <babeltrace/ctf-ir/event-class-internal.h> |
34 | #include <babeltrace/ctf-ir/stream-class-internal.h> | |
599faa1c PP |
35 | #include <babeltrace/ctf-ir/trace.h> |
36 | #include <babeltrace/graph/clock-class-priority-map.h> | |
fe650ea4 | 37 | #include <babeltrace/graph/clock-class-priority-map-internal.h> |
b2e0c907 | 38 | #include <babeltrace/graph/notification-event-internal.h> |
c55a9f58 | 39 | #include <babeltrace/types.h> |
8b45963b PP |
40 | #include <babeltrace/assert-internal.h> |
41 | #include <babeltrace/assert-pre-internal.h> | |
a68c0f97 | 42 | #include <stdbool.h> |
546a0c4a | 43 | #include <inttypes.h> |
d51202da JG |
44 | |
45 | static | |
46 | void bt_notification_event_destroy(struct bt_object *obj) | |
47 | { | |
48 | struct bt_notification_event *notification = | |
49 | (struct bt_notification_event *) obj; | |
50 | ||
546a0c4a | 51 | BT_LOGD("Destroying event notification: addr=%p", notification); |
a6918753 PP |
52 | BT_LOGD_STR("Recycling event."); |
53 | bt_event_recycle(notification->event); | |
54 | notification->event = NULL; | |
546a0c4a | 55 | BT_LOGD_STR("Putting clock class priority map."); |
599faa1c | 56 | BT_PUT(notification->cc_prio_map); |
d51202da JG |
57 | g_free(notification); |
58 | } | |
59 | ||
8b45963b | 60 | BT_ASSERT_PRE_FUNC |
a6918753 | 61 | static inline bool event_class_has_trace(struct bt_event_class *event_class) |
a68c0f97 | 62 | { |
839d52a5 | 63 | struct bt_stream_class *stream_class; |
a68c0f97 | 64 | |
839d52a5 | 65 | stream_class = bt_event_class_borrow_stream_class(event_class); |
8b45963b | 66 | BT_ASSERT(stream_class); |
839d52a5 | 67 | return bt_stream_class_borrow_trace(stream_class) != NULL; |
a68c0f97 PP |
68 | } |
69 | ||
a6918753 PP |
70 | struct bt_notification *bt_notification_event_create( |
71 | struct bt_event_class *event_class, | |
72 | struct bt_packet *packet, | |
599faa1c | 73 | struct bt_clock_class_priority_map *cc_prio_map) |
d51202da | 74 | { |
80f00602 | 75 | struct bt_notification_event *notification = NULL; |
546a0c4a | 76 | |
a6918753 PP |
77 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); |
78 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); | |
d51202da | 79 | |
81512f1e PP |
80 | if (cc_prio_map) { |
81 | /* Function's reference, released at the end */ | |
82 | bt_get(cc_prio_map); | |
83 | } else { | |
84 | cc_prio_map = bt_clock_class_priority_map_create(); | |
85 | if (!cc_prio_map) { | |
86 | BT_LOGE_STR("Cannot create empty clock class priority map."); | |
87 | goto error; | |
88 | } | |
d51202da JG |
89 | } |
90 | ||
8b45963b | 91 | BT_ASSERT(cc_prio_map); |
546a0c4a | 92 | BT_LOGD("Creating event notification object: " |
a6918753 | 93 | "event-class-addr=%p, " |
546a0c4a PP |
94 | "event-class-name=\"%s\", event-class-id=%" PRId64 ", " |
95 | "cc-prio-map-addr=%p", | |
a6918753 | 96 | event_class, |
839d52a5 PP |
97 | bt_event_class_get_name(event_class), |
98 | bt_event_class_get_id(event_class), cc_prio_map); | |
546a0c4a | 99 | |
a6918753 PP |
100 | BT_ASSERT_PRE(event_class_has_trace(event_class), |
101 | "Event class is not part of a trace: %!+E", event_class); | |
d51202da | 102 | notification = g_new0(struct bt_notification_event, 1); |
24626e8b | 103 | if (!notification) { |
546a0c4a | 104 | BT_LOGE_STR("Failed to allocate one event notification."); |
24626e8b JG |
105 | goto error; |
106 | } | |
546a0c4a PP |
107 | |
108 | bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_EVENT, | |
109 | bt_notification_event_destroy); | |
a6918753 PP |
110 | notification->event = bt_event_create(event_class, packet); |
111 | if (!notification->event) { | |
112 | BT_LIB_LOGE("Cannot create event from event class: " | |
113 | "%![event-class-]+E", event_class); | |
114 | goto error; | |
115 | } | |
116 | ||
599faa1c | 117 | notification->cc_prio_map = bt_get(cc_prio_map); |
546a0c4a | 118 | BT_LOGD_STR("Freezing event notification's clock class priority map."); |
fe650ea4 | 119 | bt_clock_class_priority_map_freeze(notification->cc_prio_map); |
546a0c4a PP |
120 | BT_LOGD("Created event notification object: " |
121 | "event-addr=%p, event-class-addr=%p, " | |
122 | "event-class-name=\"%s\", event-class-id=%" PRId64 ", " | |
123 | "cc-prio-map-addr=%p, notif-addr=%p", | |
a6918753 | 124 | notification->event, event_class, |
839d52a5 PP |
125 | bt_event_class_get_name(event_class), |
126 | bt_event_class_get_id(event_class), cc_prio_map, | |
546a0c4a | 127 | notification); |
3fd45dc7 | 128 | goto end; |
546a0c4a | 129 | |
d51202da | 130 | error: |
3fd45dc7 PP |
131 | BT_PUT(notification); |
132 | ||
133 | end: | |
81512f1e | 134 | bt_put(cc_prio_map); |
3fd45dc7 | 135 | return ¬ification->parent; |
d51202da JG |
136 | } |
137 | ||
5fe68922 | 138 | struct bt_event *bt_notification_event_borrow_event( |
d51202da JG |
139 | struct bt_notification *notification) |
140 | { | |
141 | struct bt_notification_event *event_notification; | |
142 | ||
8b45963b PP |
143 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
144 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, BT_NOTIFICATION_TYPE_EVENT); | |
d51202da JG |
145 | event_notification = container_of(notification, |
146 | struct bt_notification_event, parent); | |
5fe68922 | 147 | return event_notification->event; |
d51202da | 148 | } |
599faa1c PP |
149 | |
150 | extern struct bt_clock_class_priority_map * | |
5fe68922 | 151 | bt_notification_event_borrow_clock_class_priority_map( |
599faa1c PP |
152 | struct bt_notification *notification) |
153 | { | |
599faa1c PP |
154 | struct bt_notification_event *event_notification; |
155 | ||
8b45963b PP |
156 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
157 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, BT_NOTIFICATION_TYPE_EVENT); | |
599faa1c PP |
158 | event_notification = container_of(notification, |
159 | struct bt_notification_event, parent); | |
5fe68922 | 160 | return event_notification->cc_prio_map; |
599faa1c | 161 | } |