lib: remove clock class priority map, use default clock value
[babeltrace.git] / lib / graph / notification / inactivity.c
CommitLineData
ece3fb0f
PP
1/*
2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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
20 * SOFTWARE.
21 */
22
fe30b20b
PP
23#define BT_LOG_TAG "NOTIF-INACTIVITY"
24#include <babeltrace/lib-logging-internal.h>
25
ece3fb0f 26#include <babeltrace/object-internal.h>
3d9990ac 27#include <babeltrace/compiler-internal.h>
ece3fb0f 28#include <babeltrace/ctf-ir/clock-class.h>
f6ccaed9 29#include <babeltrace/ctf-ir/clock-value-internal.h>
ece3fb0f
PP
30#include <babeltrace/graph/notification-internal.h>
31#include <babeltrace/graph/notification-inactivity-internal.h>
f6ccaed9 32#include <babeltrace/assert-pre-internal.h>
ece3fb0f
PP
33
34static
35void bt_notification_inactivity_destroy(struct bt_object *obj)
36{
37 struct bt_notification_inactivity *notification =
38 (struct bt_notification_inactivity *) obj;
39
fe30b20b 40 BT_LOGD("Destroying inactivity notification: addr=%p", notification);
e22b45d0 41 bt_clock_value_set_finalize(&notification->cv_set);
ece3fb0f
PP
42 g_free(notification);
43}
44
45struct bt_notification *bt_notification_inactivity_create(
e22b45d0 46 struct bt_graph *graph)
ece3fb0f
PP
47{
48 struct bt_notification_inactivity *notification;
49 struct bt_notification *ret_notif = NULL;
e22b45d0 50 int ret;
ece3fb0f 51
e22b45d0 52 BT_LOGD_STR("Creating inactivity notification object.");
ece3fb0f
PP
53 notification = g_new0(struct bt_notification_inactivity, 1);
54 if (!notification) {
fe30b20b 55 BT_LOGE_STR("Failed to allocate one inactivity notification.");
ece3fb0f
PP
56 goto error;
57 }
58 bt_notification_init(&notification->parent,
fe30b20b 59 BT_NOTIFICATION_TYPE_INACTIVITY,
5c563278 60 bt_notification_inactivity_destroy, NULL);
ece3fb0f 61 ret_notif = &notification->parent;
e22b45d0
PP
62 ret = bt_clock_value_set_initialize(&notification->cv_set);
63 if (ret) {
ece3fb0f
PP
64 goto error;
65 }
66
e22b45d0
PP
67 BT_LOGD("Created inactivity notification object: addr=%p",
68 ret_notif);
ece3fb0f
PP
69 goto end;
70
71error:
72 BT_PUT(ret_notif);
73
74end:
75 return ret_notif;
76}
77
e22b45d0
PP
78int bt_notification_inactivity_set_clock_value(struct bt_notification *notif,
79 struct bt_clock_class *clock_class, uint64_t raw_value,
80 bt_bool is_default)
ece3fb0f 81{
e22b45d0 82 struct bt_notification_inactivity *inactivity = (void *) notif;
ece3fb0f 83
e22b45d0
PP
84 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
85 BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
86 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
87 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY);
88 BT_ASSERT_PRE(is_default,
89 "You can only set a default clock value as of this version.");
90 return bt_clock_value_set_set_clock_value(&inactivity->cv_set,
91 clock_class, raw_value, is_default);
ece3fb0f
PP
92}
93
e22b45d0
PP
94struct bt_clock_value *bt_notification_inactivity_borrow_default_clock_value(
95 struct bt_notification *notif)
ece3fb0f 96{
e22b45d0
PP
97 struct bt_notification_inactivity *inactivity = (void *) notif;
98 struct bt_clock_value *clock_value = NULL;
99
100 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
101 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY);
102 clock_value = inactivity->cv_set.default_cv;
103 if (!clock_value) {
104 BT_LIB_LOGV("No default clock value: %![notif-]+n", notif);
105 }
ece3fb0f 106
e22b45d0 107 return clock_value;
f6ccaed9 108}
This page took 0.036886 seconds and 4 git commands to generate.