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-internal.h>
25 #include <babeltrace/ctf-ir/clock-class.h>
26 #include <babeltrace/graph/clock-class-priority-map.h>
27 #include <babeltrace/graph/clock-class-priority-map-internal.h>
28 #include <babeltrace/graph/notification-internal.h>
29 #include <babeltrace/graph/notification-inactivity-internal.h>
32 void bt_notification_inactivity_destroy(struct bt_object
*obj
)
34 struct bt_notification_inactivity
*notification
=
35 (struct bt_notification_inactivity
*) obj
;
37 bt_put(notification
->cc_prio_map
);
39 if (notification
->clock_values
) {
40 g_hash_table_destroy(notification
->clock_values
);
46 struct bt_notification
*bt_notification_inactivity_create(
47 struct bt_clock_class_priority_map
*cc_prio_map
)
49 struct bt_notification_inactivity
*notification
;
50 struct bt_notification
*ret_notif
= NULL
;
56 notification
= g_new0(struct bt_notification_inactivity
, 1);
60 bt_notification_init(¬ification
->parent
,
61 BT_NOTIFICATION_TYPE_INACTIVITY
,
62 bt_notification_inactivity_destroy
);
63 ret_notif
= ¬ification
->parent
;
64 notification
->clock_values
= g_hash_table_new_full(g_direct_hash
,
65 g_direct_equal
, bt_put
, bt_put
);
66 if (!notification
->clock_values
) {
70 notification
->cc_prio_map
= bt_get(cc_prio_map
);
71 bt_clock_class_priority_map_freeze(cc_prio_map
);
81 extern struct bt_clock_class_priority_map
*
82 bt_notification_inactivity_get_clock_class_priority_map(
83 struct bt_notification
*notification
)
85 struct bt_clock_class_priority_map
*cc_prio_map
= NULL
;
86 struct bt_notification_inactivity
*inactivity_notification
;
88 if (bt_notification_get_type(notification
) !=
89 BT_NOTIFICATION_TYPE_INACTIVITY
) {
93 inactivity_notification
= container_of(notification
,
94 struct bt_notification_inactivity
, parent
);
95 cc_prio_map
= bt_get(inactivity_notification
->cc_prio_map
);
100 struct bt_ctf_clock_value
*bt_notification_inactivity_get_clock_value(
101 struct bt_notification
*notification
,
102 struct bt_ctf_clock_class
*clock_class
)
104 struct bt_ctf_clock_value
*clock_value
= NULL
;
105 struct bt_notification_inactivity
*inactivity_notification
;
107 if (!notification
|| !clock_class
) {
111 if (bt_notification_get_type(notification
) !=
112 BT_NOTIFICATION_TYPE_INACTIVITY
) {
116 inactivity_notification
= container_of(notification
,
117 struct bt_notification_inactivity
, parent
);
118 clock_value
= g_hash_table_lookup(inactivity_notification
->clock_values
,
126 int bt_notification_inactivity_set_clock_value(
127 struct bt_notification
*notification
,
128 struct bt_ctf_clock_value
*clock_value
)
132 struct bt_ctf_clock_class
*clock_class
= NULL
;
133 struct bt_notification_inactivity
*inactivity_notification
;
135 if (!notification
|| !clock_value
|| notification
->frozen
) {
140 if (bt_notification_get_type(notification
) !=
141 BT_NOTIFICATION_TYPE_INACTIVITY
) {
145 inactivity_notification
= container_of(notification
,
146 struct bt_notification_inactivity
, parent
);
147 clock_class
= bt_ctf_clock_value_get_class(clock_value
);
148 ret
= bt_clock_class_priority_map_get_clock_class_priority(
149 inactivity_notification
->cc_prio_map
, clock_class
, &prio
);
152 * Clock value's class is not mapped to a priority
153 * within the scope of this notification.
158 g_hash_table_insert(inactivity_notification
->clock_values
,
159 clock_class
, bt_get(clock_value
));