#include <babeltrace/object-internal.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/ctf-ir/clock-class.h>
-#include <babeltrace/graph/clock-class-priority-map.h>
-#include <babeltrace/graph/clock-class-priority-map-internal.h>
+#include <babeltrace/ctf-ir/clock-value-internal.h>
#include <babeltrace/graph/notification-internal.h>
#include <babeltrace/graph/notification-inactivity-internal.h>
+#include <babeltrace/assert-pre-internal.h>
static
void bt_notification_inactivity_destroy(struct bt_object *obj)
(struct bt_notification_inactivity *) obj;
BT_LOGD("Destroying inactivity notification: addr=%p", notification);
- BT_LOGD_STR("Putting clock class priority map.");
- bt_put(notification->cc_prio_map);
-
- if (notification->clock_values) {
- BT_LOGD_STR("Putting clock values.");
- g_hash_table_destroy(notification->clock_values);
- }
-
+ bt_clock_value_set_finalize(¬ification->cv_set);
g_free(notification);
}
struct bt_notification *bt_notification_inactivity_create(
- struct bt_clock_class_priority_map *cc_prio_map)
+ struct bt_graph *graph)
{
struct bt_notification_inactivity *notification;
struct bt_notification *ret_notif = NULL;
+ int ret;
- if (cc_prio_map) {
- /* Function's reference, released at the end */
- bt_get(cc_prio_map);
- } else {
- cc_prio_map = bt_clock_class_priority_map_create();
- if (!cc_prio_map) {
- BT_LOGE_STR("Cannot create empty clock class priority map.");
- goto error;
- }
- }
-
- BT_LOGD("Creating inactivity notification object: "
- "cc-prio-map-addr=%p",
- cc_prio_map);
+ BT_LOGD_STR("Creating inactivity notification object.");
notification = g_new0(struct bt_notification_inactivity, 1);
if (!notification) {
BT_LOGE_STR("Failed to allocate one inactivity notification.");
}
bt_notification_init(¬ification->parent,
BT_NOTIFICATION_TYPE_INACTIVITY,
- bt_notification_inactivity_destroy);
+ bt_notification_inactivity_destroy, NULL);
ret_notif = ¬ification->parent;
- notification->clock_values = g_hash_table_new_full(g_direct_hash,
- g_direct_equal, bt_put, bt_put);
- if (!notification->clock_values) {
- BT_LOGE_STR("Failed to allocate a GHashTable.");
+ ret = bt_clock_value_set_initialize(¬ification->cv_set);
+ if (ret) {
goto error;
}
- notification->cc_prio_map = bt_get(cc_prio_map);
- BT_LOGD_STR("Freezing inactivity notification's clock class priority map.");
- bt_clock_class_priority_map_freeze(cc_prio_map);
- BT_LOGD("Created inactivity notification object: "
- "cc-prio-map-addr=%p, notif-addr=%p",
- cc_prio_map, ret_notif);
+ BT_LOGD("Created inactivity notification object: addr=%p",
+ ret_notif);
goto end;
error:
BT_PUT(ret_notif);
end:
- bt_put(cc_prio_map);
return ret_notif;
}
-extern struct bt_clock_class_priority_map *
-bt_notification_inactivity_get_clock_class_priority_map(
- struct bt_notification *notification)
+int bt_notification_inactivity_set_clock_value(struct bt_notification *notif,
+ struct bt_clock_class *clock_class, uint64_t raw_value,
+ bt_bool is_default)
{
- struct bt_clock_class_priority_map *cc_prio_map = NULL;
- struct bt_notification_inactivity *inactivity_notification;
-
- if (!notification) {
- BT_LOGW_STR("Invalid parameter: notification is NULL.");
- goto end;
- }
-
- if (bt_notification_get_type(notification) !=
- BT_NOTIFICATION_TYPE_INACTIVITY) {
- BT_LOGW("Invalid parameter: notification is not an inactivity notification: "
- "addr%p, notif-type=%s",
- notification, bt_notification_type_string(
- bt_notification_get_type(notification)));
- goto end;
- }
-
- inactivity_notification = container_of(notification,
- struct bt_notification_inactivity, parent);
- cc_prio_map = bt_get(inactivity_notification->cc_prio_map);
-end:
- return cc_prio_map;
+ struct bt_notification_inactivity *inactivity = (void *) notif;
+
+ BT_ASSERT_PRE_NON_NULL(notif, "Notification");
+ BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
+ BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
+ BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY);
+ BT_ASSERT_PRE(is_default,
+ "You can only set a default clock value as of this version.");
+ return bt_clock_value_set_set_clock_value(&inactivity->cv_set,
+ clock_class, raw_value, is_default);
}
-struct bt_clock_value *bt_notification_inactivity_get_clock_value(
- struct bt_notification *notification,
- struct bt_clock_class *clock_class)
+struct bt_clock_value *bt_notification_inactivity_borrow_default_clock_value(
+ struct bt_notification *notif)
{
+ struct bt_notification_inactivity *inactivity = (void *) notif;
struct bt_clock_value *clock_value = NULL;
- struct bt_notification_inactivity *inactivity_notification;
-
- if (!notification) {
- BT_LOGW_STR("Invalid parameter: notification is NULL.");
- goto end;
- }
-
- if (!clock_class) {
- BT_LOGW_STR("Invalid parameter: clock class is NULL.");
- goto end;
- }
-
- if (bt_notification_get_type(notification) !=
- BT_NOTIFICATION_TYPE_INACTIVITY) {
- BT_LOGW("Invalid parameter: notification is not an inactivity notification: "
- "addr%p, notif-type=%s",
- notification, bt_notification_type_string(
- bt_notification_get_type(notification)));
- goto end;
- }
-
- inactivity_notification = container_of(notification,
- struct bt_notification_inactivity, parent);
- clock_value = g_hash_table_lookup(inactivity_notification->clock_values,
- clock_class);
- bt_get(clock_value);
-
-end:
- return clock_value;
-}
-
-int bt_notification_inactivity_set_clock_value(
- struct bt_notification *notification,
- struct bt_clock_value *clock_value)
-{
- int ret = 0;
- uint64_t prio;
- struct bt_clock_class *clock_class = NULL;
- struct bt_notification_inactivity *inactivity_notification;
-
- if (!notification) {
- BT_LOGW_STR("Invalid parameter: notification is NULL.");
- ret = -1;
- goto end;
- }
+ BT_ASSERT_PRE_NON_NULL(notif, "Notification");
+ BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY);
+ clock_value = inactivity->cv_set.default_cv;
if (!clock_value) {
- BT_LOGW_STR("Invalid parameter: clock value is NULL.");
- ret = -1;
- goto end;
+ BT_LIB_LOGV("No default clock value: %![notif-]+n", notif);
}
- if (notification->frozen) {
- BT_LOGW_STR("Invalid parameter: notification is frozen.");
- ret = -1;
- goto end;
- }
-
- if (bt_notification_get_type(notification) !=
- BT_NOTIFICATION_TYPE_INACTIVITY) {
- BT_LOGW("Invalid parameter: notification is not an inactivity notification: "
- "addr%p, notif-type=%s",
- notification, bt_notification_type_string(
- bt_notification_get_type(notification)));
- ret = -1;
- goto end;
- }
-
- inactivity_notification = container_of(notification,
- struct bt_notification_inactivity, parent);
- clock_class = bt_clock_value_get_class(clock_value);
- ret = bt_clock_class_priority_map_get_clock_class_priority(
- inactivity_notification->cc_prio_map, clock_class, &prio);
- if (ret) {
- BT_LOGW("Clock value's class is not mapped to a priority within the scope of the inactivity notification: "
- "notif-addr=%p, cc-prio-map-addr=%p, "
- "clock-class-addr=%p, clock-class-name=\"%s\", "
- "clock-value-addr=%p",
- inactivity_notification,
- inactivity_notification->cc_prio_map,
- clock_class, bt_clock_class_get_name(clock_class),
- clock_value);
- ret = -1;
- goto end;
- }
-
- g_hash_table_insert(inactivity_notification->clock_values,
- clock_class, bt_get(clock_value));
- clock_class = NULL;
- BT_LOGV("Set inactivity notification's clock value: "
- "notif-addr=%p, cc-prio-map-addr=%p, "
- "clock-class-addr=%p, clock-class-name=\"%s\", "
- "clock-value-addr=%p",
- inactivity_notification,
- inactivity_notification->cc_prio_map,
- clock_class, bt_clock_class_get_name(clock_class),
- clock_value);
-
-end:
- bt_put(clock_class);
- return ret;
+ return clock_value;
}