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 /* Function's reference, released at the end */
62 cc_prio_map
= bt_clock_class_priority_map_create();
64 BT_LOGE_STR("Cannot create empty clock class priority map.");
69 BT_LOGD("Creating inactivity notification object: "
70 "cc-prio-map-addr=%p",
72 notification
= g_new0(struct bt_notification_inactivity
, 1);
74 BT_LOGE_STR("Failed to allocate one inactivity notification.");
77 bt_notification_init(¬ification
->parent
,
78 BT_NOTIFICATION_TYPE_INACTIVITY
,
79 bt_notification_inactivity_destroy
);
80 ret_notif
= ¬ification
->parent
;
81 notification
->clock_values
= g_hash_table_new_full(g_direct_hash
,
82 g_direct_equal
, bt_put
, bt_put
);
83 if (!notification
->clock_values
) {
84 BT_LOGE_STR("Failed to allocate a GHashTable.");
88 notification
->cc_prio_map
= bt_get(cc_prio_map
);
89 BT_LOGD_STR("Freezing inactivity notification's clock class priority map.");
90 bt_clock_class_priority_map_freeze(cc_prio_map
);
91 BT_LOGD("Created inactivity notification object: "
92 "cc-prio-map-addr=%p, notif-addr=%p",
93 cc_prio_map
, ret_notif
);
104 extern struct bt_clock_class_priority_map
*
105 bt_notification_inactivity_get_clock_class_priority_map(
106 struct bt_notification
*notification
)
108 struct bt_clock_class_priority_map
*cc_prio_map
= NULL
;
109 struct bt_notification_inactivity
*inactivity_notification
;
112 BT_LOGW_STR("Invalid parameter: notification is NULL.");
116 if (bt_notification_get_type(notification
) !=
117 BT_NOTIFICATION_TYPE_INACTIVITY
) {
118 BT_LOGW("Invalid parameter: notification is not an inactivity notification: "
119 "addr%p, notif-type=%s",
120 notification
, bt_notification_type_string(
121 bt_notification_get_type(notification
)));
125 inactivity_notification
= container_of(notification
,
126 struct bt_notification_inactivity
, parent
);
127 cc_prio_map
= bt_get(inactivity_notification
->cc_prio_map
);
132 struct bt_clock_value
*bt_notification_inactivity_get_clock_value(
133 struct bt_notification
*notification
,
134 struct bt_clock_class
*clock_class
)
136 struct bt_clock_value
*clock_value
= NULL
;
137 struct bt_notification_inactivity
*inactivity_notification
;
140 BT_LOGW_STR("Invalid parameter: notification is NULL.");
145 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
149 if (bt_notification_get_type(notification
) !=
150 BT_NOTIFICATION_TYPE_INACTIVITY
) {
151 BT_LOGW("Invalid parameter: notification is not an inactivity notification: "
152 "addr%p, notif-type=%s",
153 notification
, bt_notification_type_string(
154 bt_notification_get_type(notification
)));
158 inactivity_notification
= container_of(notification
,
159 struct bt_notification_inactivity
, parent
);
160 clock_value
= g_hash_table_lookup(inactivity_notification
->clock_values
,
168 int bt_notification_inactivity_set_clock_value(
169 struct bt_notification
*notification
,
170 struct bt_clock_value
*clock_value
)
174 struct bt_clock_class
*clock_class
= NULL
;
175 struct bt_notification_inactivity
*inactivity_notification
;
178 BT_LOGW_STR("Invalid parameter: notification is NULL.");
184 BT_LOGW_STR("Invalid parameter: clock value is NULL.");
189 if (notification
->frozen
) {
190 BT_LOGW_STR("Invalid parameter: notification is frozen.");
195 if (bt_notification_get_type(notification
) !=
196 BT_NOTIFICATION_TYPE_INACTIVITY
) {
197 BT_LOGW("Invalid parameter: notification is not an inactivity notification: "
198 "addr%p, notif-type=%s",
199 notification
, bt_notification_type_string(
200 bt_notification_get_type(notification
)));
205 inactivity_notification
= container_of(notification
,
206 struct bt_notification_inactivity
, parent
);
207 clock_class
= bt_clock_value_get_class(clock_value
);
208 ret
= bt_clock_class_priority_map_get_clock_class_priority(
209 inactivity_notification
->cc_prio_map
, clock_class
, &prio
);
211 BT_LOGW("Clock value's class is not mapped to a priority within the scope of the inactivity notification: "
212 "notif-addr=%p, cc-prio-map-addr=%p, "
213 "clock-class-addr=%p, clock-class-name=\"%s\", "
214 "clock-value-addr=%p",
215 inactivity_notification
,
216 inactivity_notification
->cc_prio_map
,
217 clock_class
, bt_clock_class_get_name(clock_class
),
223 g_hash_table_insert(inactivity_notification
->clock_values
,
224 clock_class
, bt_get(clock_value
));
226 BT_LOGV("Set inactivity notification's clock value: "
227 "notif-addr=%p, cc-prio-map-addr=%p, "
228 "clock-class-addr=%p, clock-class-name=\"%s\", "
229 "clock-value-addr=%p",
230 inactivity_notification
,
231 inactivity_notification
->cc_prio_map
,
232 clock_class
, bt_clock_class_get_name(clock_class
),