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 #define BT_LOG_TAG "NOTIF-INACTIVITY"
24 #include <babeltrace/lib-logging-internal.h>
26 #include <babeltrace/object-internal.h>
27 #include <babeltrace/compiler-internal.h>
28 #include <babeltrace/ctf-ir/clock-class.h>
29 #include <babeltrace/graph/clock-class-priority-map.h>
30 #include <babeltrace/graph/clock-class-priority-map-internal.h>
31 #include <babeltrace/graph/notification-internal.h>
32 #include <babeltrace/graph/notification-inactivity-internal.h>
35 void bt_notification_inactivity_destroy(struct bt_object
*obj
)
37 struct bt_notification_inactivity
*notification
=
38 (struct bt_notification_inactivity
*) obj
;
40 BT_LOGD("Destroying inactivity notification: addr=%p", notification
);
41 BT_LOGD_STR("Putting clock class priority map.");
42 bt_put(notification
->cc_prio_map
);
44 if (notification
->clock_values
) {
45 BT_LOGD_STR("Putting clock values.");
46 g_hash_table_destroy(notification
->clock_values
);
52 struct bt_notification
*bt_notification_inactivity_create(
53 struct bt_clock_class_priority_map
*cc_prio_map
)
55 struct bt_notification_inactivity
*notification
;
56 struct bt_notification
*ret_notif
= NULL
;
59 BT_LOGW_STR("Invalid parameter: clock class priority map is NULL.");
63 BT_LOGD("Creating inactivity notification object: "
64 "cc-prio-map-addr=%p",
66 notification
= g_new0(struct bt_notification_inactivity
, 1);
68 BT_LOGE_STR("Failed to allocate one inactivity notification.");
71 bt_notification_init(¬ification
->parent
,
72 BT_NOTIFICATION_TYPE_INACTIVITY
,
73 bt_notification_inactivity_destroy
);
74 ret_notif
= ¬ification
->parent
;
75 notification
->clock_values
= g_hash_table_new_full(g_direct_hash
,
76 g_direct_equal
, bt_put
, bt_put
);
77 if (!notification
->clock_values
) {
78 BT_LOGE_STR("Failed to allocate a GHashTable.");
82 notification
->cc_prio_map
= bt_get(cc_prio_map
);
83 BT_LOGD_STR("Freezing inactivity notification's clock class priority map.");
84 bt_clock_class_priority_map_freeze(cc_prio_map
);
85 BT_LOGD("Created inactivity notification object: "
86 "cc-prio-map-addr=%p, notif-addr=%p",
87 cc_prio_map
, ret_notif
);
97 extern struct bt_clock_class_priority_map
*
98 bt_notification_inactivity_get_clock_class_priority_map(
99 struct bt_notification
*notification
)
101 struct bt_clock_class_priority_map
*cc_prio_map
= NULL
;
102 struct bt_notification_inactivity
*inactivity_notification
;
105 BT_LOGW_STR("Invalid parameter: notification is NULL.");
109 if (bt_notification_get_type(notification
) !=
110 BT_NOTIFICATION_TYPE_INACTIVITY
) {
111 BT_LOGW("Invalid parameter: notification is not an inactivity notification: "
112 "addr%p, notif-type=%s",
113 notification
, bt_notification_type_string(
114 bt_notification_get_type(notification
)));
118 inactivity_notification
= container_of(notification
,
119 struct bt_notification_inactivity
, parent
);
120 cc_prio_map
= bt_get(inactivity_notification
->cc_prio_map
);
125 struct bt_ctf_clock_value
*bt_notification_inactivity_get_clock_value(
126 struct bt_notification
*notification
,
127 struct bt_ctf_clock_class
*clock_class
)
129 struct bt_ctf_clock_value
*clock_value
= NULL
;
130 struct bt_notification_inactivity
*inactivity_notification
;
133 BT_LOGW_STR("Invalid parameter: notification is NULL.");
138 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
142 if (bt_notification_get_type(notification
) !=
143 BT_NOTIFICATION_TYPE_INACTIVITY
) {
144 BT_LOGW("Invalid parameter: notification is not an inactivity notification: "
145 "addr%p, notif-type=%s",
146 notification
, bt_notification_type_string(
147 bt_notification_get_type(notification
)));
151 inactivity_notification
= container_of(notification
,
152 struct bt_notification_inactivity
, parent
);
153 clock_value
= g_hash_table_lookup(inactivity_notification
->clock_values
,
161 int bt_notification_inactivity_set_clock_value(
162 struct bt_notification
*notification
,
163 struct bt_ctf_clock_value
*clock_value
)
167 struct bt_ctf_clock_class
*clock_class
= NULL
;
168 struct bt_notification_inactivity
*inactivity_notification
;
171 BT_LOGW_STR("Invalid parameter: notification is NULL.");
177 BT_LOGW_STR("Invalid parameter: clock value is NULL.");
182 if (notification
->frozen
) {
183 BT_LOGW_STR("Invalid parameter: notification is frozen.");
188 if (bt_notification_get_type(notification
) !=
189 BT_NOTIFICATION_TYPE_INACTIVITY
) {
190 BT_LOGW("Invalid parameter: notification is not an inactivity notification: "
191 "addr%p, notif-type=%s",
192 notification
, bt_notification_type_string(
193 bt_notification_get_type(notification
)));
197 inactivity_notification
= container_of(notification
,
198 struct bt_notification_inactivity
, parent
);
199 clock_class
= bt_ctf_clock_value_get_class(clock_value
);
200 ret
= bt_clock_class_priority_map_get_clock_class_priority(
201 inactivity_notification
->cc_prio_map
, clock_class
, &prio
);
203 BT_LOGW("Clock value's class is not mapped to a priority within the scope of the inactivity notification: "
204 "notif-addr=%p, cc-prio-map-addr=%p, "
205 "clock-class-addr=%p, clock-class-name=\"%s\", "
206 "clock-value-addr=%p",
207 inactivity_notification
,
208 inactivity_notification
->cc_prio_map
,
209 clock_class
, bt_ctf_clock_class_get_name(clock_class
),
214 g_hash_table_insert(inactivity_notification
->clock_values
,
215 clock_class
, bt_get(clock_value
));
217 BT_LOGV("Set inactivity notification's clock value: "
218 "notif-addr=%p, cc-prio-map-addr=%p, "
219 "clock-class-addr=%p, clock-class-name=\"%s\", "
220 "clock-value-addr=%p",
221 inactivity_notification
,
222 inactivity_notification
->cc_prio_map
,
223 clock_class
, bt_ctf_clock_class_get_name(clock_class
),