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 | ||
e8892093 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> |
8b45963b | 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> | |
03e18d5d | 32 | #include <babeltrace/graph/private-connection-private-notification-iterator.h> |
8b45963b | 33 | #include <babeltrace/assert-pre-internal.h> |
ece3fb0f PP |
34 | |
35 | static | |
36 | void bt_notification_inactivity_destroy(struct bt_object *obj) | |
37 | { | |
38 | struct bt_notification_inactivity *notification = | |
39 | (struct bt_notification_inactivity *) obj; | |
40 | ||
e8892093 | 41 | BT_LOGD("Destroying inactivity notification: addr=%p", notification); |
8fc063a2 | 42 | bt_clock_value_set_finalize(¬ification->cv_set); |
ece3fb0f PP |
43 | g_free(notification); |
44 | } | |
45 | ||
46 | struct bt_notification *bt_notification_inactivity_create( | |
03e18d5d | 47 | struct bt_private_connection_private_notification_iterator *notif_iter) |
ece3fb0f PP |
48 | { |
49 | struct bt_notification_inactivity *notification; | |
50 | struct bt_notification *ret_notif = NULL; | |
8fc063a2 | 51 | int ret; |
ece3fb0f | 52 | |
8fc063a2 | 53 | BT_LOGD_STR("Creating inactivity notification object."); |
ece3fb0f PP |
54 | notification = g_new0(struct bt_notification_inactivity, 1); |
55 | if (!notification) { | |
e8892093 | 56 | BT_LOGE_STR("Failed to allocate one inactivity notification."); |
ece3fb0f PP |
57 | goto error; |
58 | } | |
59 | bt_notification_init(¬ification->parent, | |
e8892093 | 60 | BT_NOTIFICATION_TYPE_INACTIVITY, |
f7c3ac09 | 61 | bt_notification_inactivity_destroy, NULL); |
ece3fb0f | 62 | ret_notif = ¬ification->parent; |
8fc063a2 PP |
63 | ret = bt_clock_value_set_initialize(¬ification->cv_set); |
64 | if (ret) { | |
ece3fb0f PP |
65 | goto error; |
66 | } | |
67 | ||
8fc063a2 PP |
68 | BT_LOGD("Created inactivity notification object: addr=%p", |
69 | ret_notif); | |
ece3fb0f PP |
70 | goto end; |
71 | ||
72 | error: | |
73 | BT_PUT(ret_notif); | |
74 | ||
75 | end: | |
76 | return ret_notif; | |
77 | } | |
78 | ||
8fc063a2 PP |
79 | int bt_notification_inactivity_set_clock_value(struct bt_notification *notif, |
80 | struct bt_clock_class *clock_class, uint64_t raw_value, | |
81 | bt_bool is_default) | |
ece3fb0f | 82 | { |
8fc063a2 | 83 | struct bt_notification_inactivity *inactivity = (void *) notif; |
ece3fb0f | 84 | |
8fc063a2 PP |
85 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); |
86 | BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); | |
87 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); | |
88 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY); | |
89 | BT_ASSERT_PRE(is_default, | |
90 | "You can only set a default clock value as of this version."); | |
91 | return bt_clock_value_set_set_clock_value(&inactivity->cv_set, | |
92 | clock_class, raw_value, is_default); | |
ece3fb0f PP |
93 | } |
94 | ||
8fc063a2 PP |
95 | struct bt_clock_value *bt_notification_inactivity_borrow_default_clock_value( |
96 | struct bt_notification *notif) | |
ece3fb0f | 97 | { |
8fc063a2 PP |
98 | struct bt_notification_inactivity *inactivity = (void *) notif; |
99 | struct bt_clock_value *clock_value = NULL; | |
100 | ||
101 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
102 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY); | |
103 | clock_value = inactivity->cv_set.default_cv; | |
104 | if (!clock_value) { | |
105 | BT_LIB_LOGV("No default clock value: %![notif-]+n", notif); | |
106 | } | |
ece3fb0f | 107 | |
8fc063a2 | 108 | return clock_value; |
8b45963b | 109 | } |