2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 #include <babeltrace/object-internal.h>
24 #include <babeltrace/compiler.h>
25 #include <babeltrace/ctf-ir/clock-class.h>
26 #include <babeltrace/graph/clock-class-priority-map.h>
27 #include <babeltrace/graph/notification-internal.h>
28 #include <babeltrace/graph/notification-inactivity-internal.h>
31 void bt_notification_inactivity_destroy(struct bt_object
*obj
)
33 struct bt_notification_inactivity
*notification
=
34 (struct bt_notification_inactivity
*) obj
;
36 bt_put(notification
->cc_prio_map
);
38 if (notification
->clock_values
) {
39 g_hash_table_destroy(notification
->clock_values
);
45 struct bt_notification
*bt_notification_inactivity_create(
46 struct bt_clock_class_priority_map
*cc_prio_map
)
48 struct bt_notification_inactivity
*notification
;
49 struct bt_notification
*ret_notif
= NULL
;
55 notification
= g_new0(struct bt_notification_inactivity
, 1);
59 bt_notification_init(¬ification
->parent
,
60 BT_NOTIFICATION_TYPE_INACTIVITY
,
61 bt_notification_inactivity_destroy
);
62 ret_notif
= ¬ification
->parent
;
63 notification
->clock_values
= g_hash_table_new_full(g_direct_hash
,
64 g_direct_equal
, bt_put
, bt_put
);
65 if (!notification
->clock_values
) {
69 notification
->cc_prio_map
= bt_get(cc_prio_map
);
79 extern struct bt_clock_class_priority_map
*
80 bt_notification_inactivity_get_clock_class_priority_map(
81 struct bt_notification
*notification
)
83 struct bt_clock_class_priority_map
*cc_prio_map
= NULL
;
84 struct bt_notification_inactivity
*inactivity_notification
;
86 if (bt_notification_get_type(notification
) !=
87 BT_NOTIFICATION_TYPE_INACTIVITY
) {
91 inactivity_notification
= container_of(notification
,
92 struct bt_notification_inactivity
, parent
);
93 cc_prio_map
= bt_get(inactivity_notification
->cc_prio_map
);
98 struct bt_ctf_clock_value
*bt_notification_inactivity_get_clock_value(
99 struct bt_notification
*notification
,
100 struct bt_ctf_clock_class
*clock_class
)
102 struct bt_ctf_clock_value
*clock_value
= NULL
;
103 struct bt_notification_inactivity
*inactivity_notification
;
105 if (!notification
|| !clock_class
) {
109 if (bt_notification_get_type(notification
) !=
110 BT_NOTIFICATION_TYPE_INACTIVITY
) {
114 inactivity_notification
= container_of(notification
,
115 struct bt_notification_inactivity
, parent
);
116 clock_value
= g_hash_table_lookup(inactivity_notification
->clock_values
,
124 int bt_notification_inactivity_set_clock_value(
125 struct bt_notification
*notification
,
126 struct bt_ctf_clock_value
*clock_value
)
130 struct bt_ctf_clock_class
*clock_class
= NULL
;
131 struct bt_notification_inactivity
*inactivity_notification
;
133 if (!notification
|| !clock_value
|| notification
->frozen
) {
138 if (bt_notification_get_type(notification
) !=
139 BT_NOTIFICATION_TYPE_INACTIVITY
) {
143 inactivity_notification
= container_of(notification
,
144 struct bt_notification_inactivity
, parent
);
145 clock_class
= bt_ctf_clock_value_get_class(clock_value
);
146 ret
= bt_clock_class_priority_map_get_clock_class_priority(
147 inactivity_notification
->cc_prio_map
, clock_class
, &prio
);
150 * Clock value's class is not mapped to a priority
151 * within the scope of this notification.
156 g_hash_table_insert(inactivity_notification
->clock_values
,
157 clock_class
, bt_get(clock_value
));