Add bt_version_get_*() functions to dynamically get the lib's version
[deliverable/babeltrace.git] / lib / component / notification / inactivity.c
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
23 #include <babeltrace/object-internal.h>
24 #include <babeltrace/compiler.h>
25 #include <babeltrace/ctf-ir/clock-class.h>
26 #include <babeltrace/graph/clock-class-priority-map.h>
27 #include <babeltrace/graph/notification-internal.h>
28 #include <babeltrace/graph/notification-inactivity-internal.h>
29
30 static
31 void bt_notification_inactivity_destroy(struct bt_object *obj)
32 {
33 struct bt_notification_inactivity *notification =
34 (struct bt_notification_inactivity *) obj;
35
36 bt_put(notification->cc_prio_map);
37
38 if (notification->clock_values) {
39 g_hash_table_destroy(notification->clock_values);
40 }
41
42 g_free(notification);
43 }
44
45 struct bt_notification *bt_notification_inactivity_create(
46 struct bt_clock_class_priority_map *cc_prio_map)
47 {
48 struct bt_notification_inactivity *notification;
49 struct bt_notification *ret_notif = NULL;
50
51 if (!cc_prio_map) {
52 goto error;
53 }
54
55 notification = g_new0(struct bt_notification_inactivity, 1);
56 if (!notification) {
57 goto error;
58 }
59 bt_notification_init(&notification->parent,
60 BT_NOTIFICATION_TYPE_INACTIVITY,
61 bt_notification_inactivity_destroy);
62 ret_notif = &notification->parent;
63 notification->clock_values = g_hash_table_new_full(g_direct_hash,
64 g_direct_equal, bt_put, bt_put);
65 if (!notification->clock_values) {
66 goto error;
67 }
68
69 notification->cc_prio_map = bt_get(cc_prio_map);
70 goto end;
71
72 error:
73 BT_PUT(ret_notif);
74
75 end:
76 return ret_notif;
77 }
78
79 extern struct bt_clock_class_priority_map *
80 bt_notification_inactivity_get_clock_class_priority_map(
81 struct bt_notification *notification)
82 {
83 struct bt_clock_class_priority_map *cc_prio_map = NULL;
84 struct bt_notification_inactivity *inactivity_notification;
85
86 if (bt_notification_get_type(notification) !=
87 BT_NOTIFICATION_TYPE_INACTIVITY) {
88 goto end;
89 }
90
91 inactivity_notification = container_of(notification,
92 struct bt_notification_inactivity, parent);
93 cc_prio_map = bt_get(inactivity_notification->cc_prio_map);
94 end:
95 return cc_prio_map;
96 }
97
98 struct bt_ctf_clock_value *bt_notification_inactivity_get_clock_value(
99 struct bt_notification *notification,
100 struct bt_ctf_clock_class *clock_class)
101 {
102 struct bt_ctf_clock_value *clock_value = NULL;
103 struct bt_notification_inactivity *inactivity_notification;
104
105 if (!notification || !clock_class) {
106 goto end;
107 }
108
109 if (bt_notification_get_type(notification) !=
110 BT_NOTIFICATION_TYPE_INACTIVITY) {
111 goto end;
112 }
113
114 inactivity_notification = container_of(notification,
115 struct bt_notification_inactivity, parent);
116 clock_value = g_hash_table_lookup(inactivity_notification->clock_values,
117 clock_class);
118 bt_get(clock_value);
119
120 end:
121 return clock_value;
122 }
123
124 int bt_notification_inactivity_set_clock_value(
125 struct bt_notification *notification,
126 struct bt_ctf_clock_value *clock_value)
127 {
128 int ret = 0;
129 uint64_t prio;
130 struct bt_ctf_clock_class *clock_class = NULL;
131 struct bt_notification_inactivity *inactivity_notification;
132
133 if (!notification || !clock_value || notification->frozen) {
134 ret = -1;
135 goto end;
136 }
137
138 if (bt_notification_get_type(notification) !=
139 BT_NOTIFICATION_TYPE_INACTIVITY) {
140 goto end;
141 }
142
143 inactivity_notification = container_of(notification,
144 struct bt_notification_inactivity, parent);
145 clock_class = bt_ctf_clock_value_get_class(clock_value);
146 ret = bt_clock_class_priority_map_get_clock_class_priority(
147 inactivity_notification->cc_prio_map, clock_class, &prio);
148 if (ret) {
149 /*
150 * Clock value's class is not mapped to a priority
151 * within the scope of this notification.
152 */
153 goto end;
154 }
155
156 g_hash_table_insert(inactivity_notification->clock_values,
157 clock_class, bt_get(clock_value));
158 clock_class = NULL;
159
160 end:
161 bt_put(clock_class);
162 return ret;
163 }
This page took 0.034792 seconds and 5 git commands to generate.