lib: update copyrights
[babeltrace.git] / lib / graph / notification / inactivity.c
1 /*
2 * Copyright 2017-2018 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
23 #define BT_LOG_TAG "NOTIF-INACTIVITY"
24 #include <babeltrace/lib-logging-internal.h>
25
26 #include <babeltrace/object-internal.h>
27 #include <babeltrace/compiler-internal.h>
28 #include <babeltrace/trace-ir/clock-class.h>
29 #include <babeltrace/trace-ir/clock-value-internal.h>
30 #include <babeltrace/graph/notification-internal.h>
31 #include <babeltrace/graph/notification-inactivity-const.h>
32 #include <babeltrace/graph/notification-inactivity.h>
33 #include <babeltrace/graph/notification-inactivity-internal.h>
34 #include <babeltrace/assert-pre-internal.h>
35 #include <babeltrace/object.h>
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
43 BT_LIB_LOGD("Destroying inactivity notification: %!+n", notification);
44
45 if (notification->default_cv) {
46 bt_clock_value_recycle(notification->default_cv);
47 }
48
49 g_free(notification);
50 }
51
52 struct bt_notification *bt_notification_inactivity_create(
53 struct bt_self_notification_iterator *self_notif_iter,
54 struct bt_clock_class *default_clock_class)
55 {
56 struct bt_self_component_port_input_notification_iterator *notif_iter =
57 (void *) self_notif_iter;
58 struct bt_notification_inactivity *notification;
59 struct bt_notification *ret_notif = NULL;
60
61 BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
62 BT_ASSERT_PRE_NON_NULL(default_clock_class, "Default clock class");
63 BT_LIB_LOGD("Creating inactivity notification object: "
64 "%![iter-]+i, %![default-cc-]+K", notif_iter,
65 default_clock_class);
66 notification = g_new0(struct bt_notification_inactivity, 1);
67 if (!notification) {
68 BT_LOGE_STR("Failed to allocate one inactivity notification.");
69 goto error;
70 }
71 bt_notification_init(&notification->parent,
72 BT_NOTIFICATION_TYPE_INACTIVITY,
73 bt_notification_inactivity_destroy, NULL);
74 ret_notif = &notification->parent;
75 notification->default_cv = bt_clock_value_create(default_clock_class);
76 if (!notification->default_cv) {
77 goto error;
78 }
79
80 BT_LIB_LOGD("Created inactivity notification object: %!+n", ret_notif);
81 goto end;
82
83 error:
84 BT_OBJECT_PUT_REF_AND_RESET(ret_notif);
85
86 end:
87 return (void *) ret_notif;
88 }
89
90 void bt_notification_inactivity_set_default_clock_value(
91 struct bt_notification *notif, uint64_t value_cycles)
92 {
93 struct bt_notification_inactivity *inactivity = (void *) notif;
94
95 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
96 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY);
97 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
98 bt_clock_value_set_value_inline(inactivity->default_cv, value_cycles);
99 BT_LIB_LOGV("Set inactivity notification's default clock value: "
100 "%![notif-]+n, value=%" PRIu64, notif, value_cycles);
101 }
102
103 const struct bt_clock_value *
104 bt_notification_inactivity_borrow_default_clock_value_const(
105 const struct bt_notification *notif)
106 {
107 struct bt_notification_inactivity *inactivity = (void *) notif;
108
109 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
110 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY);
111 return inactivity->default_cv;
112 }
This page took 0.035013 seconds and 4 git commands to generate.