Commit | Line | Data |
---|---|---|
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> |
56e18c4c PP |
28 | #include <babeltrace/trace-ir/clock-class.h> |
29 | #include <babeltrace/trace-ir/clock-value-internal.h> | |
ece3fb0f | 30 | #include <babeltrace/graph/notification-internal.h> |
e5be10ef | 31 | #include <babeltrace/graph/private-notification-inactivity.h> |
ece3fb0f | 32 | #include <babeltrace/graph/notification-inactivity-internal.h> |
f0010051 | 33 | #include <babeltrace/graph/private-connection-private-notification-iterator.h> |
f6ccaed9 | 34 | #include <babeltrace/assert-pre-internal.h> |
e5be10ef | 35 | #include <babeltrace/object.h> |
ece3fb0f PP |
36 | |
37 | static | |
38 | void bt_notification_inactivity_destroy(struct bt_object *obj) | |
39 | { | |
40 | struct bt_notification_inactivity *notification = | |
41 | (struct bt_notification_inactivity *) obj; | |
42 | ||
fe30b20b | 43 | BT_LOGD("Destroying inactivity notification: addr=%p", notification); |
44c440bc PP |
44 | |
45 | if (notification->default_cv) { | |
46 | bt_clock_value_recycle(notification->default_cv); | |
47 | } | |
48 | ||
ece3fb0f PP |
49 | g_free(notification); |
50 | } | |
51 | ||
e5be10ef | 52 | struct bt_private_notification *bt_private_notification_inactivity_create( |
44c440bc PP |
53 | struct bt_private_connection_private_notification_iterator *notif_iter, |
54 | struct bt_clock_class *default_clock_class) | |
ece3fb0f PP |
55 | { |
56 | struct bt_notification_inactivity *notification; | |
57 | struct bt_notification *ret_notif = NULL; | |
58 | ||
44c440bc PP |
59 | BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); |
60 | BT_ASSERT_PRE_NON_NULL(default_clock_class, "Default clock class"); | |
e22b45d0 | 61 | BT_LOGD_STR("Creating inactivity notification object."); |
ece3fb0f PP |
62 | notification = g_new0(struct bt_notification_inactivity, 1); |
63 | if (!notification) { | |
fe30b20b | 64 | BT_LOGE_STR("Failed to allocate one inactivity notification."); |
ece3fb0f PP |
65 | goto error; |
66 | } | |
67 | bt_notification_init(¬ification->parent, | |
fe30b20b | 68 | BT_NOTIFICATION_TYPE_INACTIVITY, |
5c563278 | 69 | bt_notification_inactivity_destroy, NULL); |
ece3fb0f | 70 | ret_notif = ¬ification->parent; |
44c440bc PP |
71 | notification->default_cv = bt_clock_value_create(default_clock_class); |
72 | if (!notification->default_cv) { | |
ece3fb0f PP |
73 | goto error; |
74 | } | |
75 | ||
e22b45d0 PP |
76 | BT_LOGD("Created inactivity notification object: addr=%p", |
77 | ret_notif); | |
ece3fb0f PP |
78 | goto end; |
79 | ||
80 | error: | |
65300d60 | 81 | BT_OBJECT_PUT_REF_AND_RESET(ret_notif); |
ece3fb0f PP |
82 | |
83 | end: | |
e5be10ef | 84 | return (void *) ret_notif; |
ece3fb0f PP |
85 | } |
86 | ||
e5be10ef PP |
87 | int bt_private_notification_inactivity_set_default_clock_value( |
88 | struct bt_private_notification *priv_notif, | |
89 | uint64_t value_cycles) | |
ece3fb0f | 90 | { |
e5be10ef | 91 | struct bt_notification *notif = (void *) priv_notif; |
e22b45d0 | 92 | struct bt_notification_inactivity *inactivity = (void *) notif; |
ece3fb0f | 93 | |
e22b45d0 | 94 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); |
e22b45d0 | 95 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY); |
44c440bc PP |
96 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); |
97 | bt_clock_value_set_value_inline(inactivity->default_cv, value_cycles); | |
98 | BT_LIB_LOGV("Set inactivity notification's default clock value: " | |
99 | "%![notif-]+n, value=%" PRIu64, notif, value_cycles); | |
100 | return 0; | |
ece3fb0f PP |
101 | } |
102 | ||
e22b45d0 PP |
103 | struct bt_clock_value *bt_notification_inactivity_borrow_default_clock_value( |
104 | struct bt_notification *notif) | |
ece3fb0f | 105 | { |
e22b45d0 | 106 | struct bt_notification_inactivity *inactivity = (void *) notif; |
e22b45d0 PP |
107 | |
108 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
109 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY); | |
44c440bc | 110 | return inactivity->default_cv; |
f6ccaed9 | 111 | } |