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> |
ece3fb0f | 28 | #include <babeltrace/ctf-ir/clock-class.h> |
f6ccaed9 | 29 | #include <babeltrace/ctf-ir/clock-value-internal.h> |
ece3fb0f | 30 | #include <babeltrace/graph/clock-class-priority-map.h> |
fe650ea4 | 31 | #include <babeltrace/graph/clock-class-priority-map-internal.h> |
ece3fb0f PP |
32 | #include <babeltrace/graph/notification-internal.h> |
33 | #include <babeltrace/graph/notification-inactivity-internal.h> | |
f6ccaed9 | 34 | #include <babeltrace/assert-pre-internal.h> |
ece3fb0f PP |
35 | |
36 | static | |
37 | void bt_notification_inactivity_destroy(struct bt_object *obj) | |
38 | { | |
39 | struct bt_notification_inactivity *notification = | |
40 | (struct bt_notification_inactivity *) obj; | |
41 | ||
fe30b20b PP |
42 | BT_LOGD("Destroying inactivity notification: addr=%p", notification); |
43 | BT_LOGD_STR("Putting clock class priority map."); | |
ece3fb0f PP |
44 | bt_put(notification->cc_prio_map); |
45 | ||
46 | if (notification->clock_values) { | |
fe30b20b | 47 | BT_LOGD_STR("Putting clock values."); |
ece3fb0f PP |
48 | g_hash_table_destroy(notification->clock_values); |
49 | } | |
50 | ||
51 | g_free(notification); | |
52 | } | |
53 | ||
54 | struct bt_notification *bt_notification_inactivity_create( | |
5c563278 | 55 | struct bt_graph *graph, |
ece3fb0f PP |
56 | struct bt_clock_class_priority_map *cc_prio_map) |
57 | { | |
58 | struct bt_notification_inactivity *notification; | |
59 | struct bt_notification *ret_notif = NULL; | |
312c056a | 60 | uint64_t i; |
ece3fb0f | 61 | |
7acb78a0 PP |
62 | if (cc_prio_map) { |
63 | /* Function's reference, released at the end */ | |
64 | bt_get(cc_prio_map); | |
65 | } else { | |
66 | cc_prio_map = bt_clock_class_priority_map_create(); | |
67 | if (!cc_prio_map) { | |
68 | BT_LOGE_STR("Cannot create empty clock class priority map."); | |
69 | goto error; | |
70 | } | |
ece3fb0f PP |
71 | } |
72 | ||
fe30b20b PP |
73 | BT_LOGD("Creating inactivity notification object: " |
74 | "cc-prio-map-addr=%p", | |
75 | cc_prio_map); | |
ece3fb0f PP |
76 | notification = g_new0(struct bt_notification_inactivity, 1); |
77 | if (!notification) { | |
fe30b20b | 78 | BT_LOGE_STR("Failed to allocate one inactivity notification."); |
ece3fb0f PP |
79 | goto error; |
80 | } | |
81 | bt_notification_init(¬ification->parent, | |
fe30b20b | 82 | BT_NOTIFICATION_TYPE_INACTIVITY, |
5c563278 | 83 | bt_notification_inactivity_destroy, NULL); |
ece3fb0f PP |
84 | ret_notif = ¬ification->parent; |
85 | notification->clock_values = g_hash_table_new_full(g_direct_hash, | |
312c056a | 86 | g_direct_equal, NULL, (GDestroyNotify) bt_clock_value_recycle); |
ece3fb0f | 87 | if (!notification->clock_values) { |
fe30b20b | 88 | BT_LOGE_STR("Failed to allocate a GHashTable."); |
ece3fb0f PP |
89 | goto error; |
90 | } | |
91 | ||
312c056a PP |
92 | for (i = 0; i < cc_prio_map->entries->len; i++) { |
93 | struct bt_clock_value *clock_value; | |
94 | struct bt_clock_class *clock_class = | |
95 | cc_prio_map->entries->pdata[i]; | |
96 | ||
97 | clock_value = bt_clock_value_create(clock_class); | |
98 | if (!clock_value) { | |
99 | BT_LIB_LOGE("Cannot create clock value from clock class: " | |
100 | "%![cc-]+K", clock_class); | |
101 | goto error; | |
102 | } | |
103 | ||
104 | g_hash_table_insert(notification->clock_values, | |
105 | clock_class, clock_value); | |
106 | } | |
107 | ||
ece3fb0f | 108 | notification->cc_prio_map = bt_get(cc_prio_map); |
fe30b20b | 109 | BT_LOGD_STR("Freezing inactivity notification's clock class priority map."); |
fe650ea4 | 110 | bt_clock_class_priority_map_freeze(cc_prio_map); |
fe30b20b PP |
111 | BT_LOGD("Created inactivity notification object: " |
112 | "cc-prio-map-addr=%p, notif-addr=%p", | |
113 | cc_prio_map, ret_notif); | |
ece3fb0f PP |
114 | goto end; |
115 | ||
116 | error: | |
117 | BT_PUT(ret_notif); | |
118 | ||
119 | end: | |
7acb78a0 | 120 | bt_put(cc_prio_map); |
ece3fb0f PP |
121 | return ret_notif; |
122 | } | |
123 | ||
124 | extern struct bt_clock_class_priority_map * | |
094ff7c0 | 125 | bt_notification_inactivity_borrow_clock_class_priority_map( |
ece3fb0f PP |
126 | struct bt_notification *notification) |
127 | { | |
ece3fb0f PP |
128 | struct bt_notification_inactivity *inactivity_notification; |
129 | ||
f6ccaed9 PP |
130 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
131 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
132 | BT_NOTIFICATION_TYPE_INACTIVITY); | |
ece3fb0f PP |
133 | inactivity_notification = container_of(notification, |
134 | struct bt_notification_inactivity, parent); | |
094ff7c0 | 135 | return inactivity_notification->cc_prio_map; |
ece3fb0f PP |
136 | } |
137 | ||
094ff7c0 | 138 | struct bt_clock_value *bt_notification_inactivity_borrow_clock_value( |
ece3fb0f | 139 | struct bt_notification *notification, |
50842bdc | 140 | struct bt_clock_class *clock_class) |
ece3fb0f | 141 | { |
ece3fb0f PP |
142 | struct bt_notification_inactivity *inactivity_notification; |
143 | ||
f6ccaed9 | 144 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
312c056a | 145 | BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); |
f6ccaed9 PP |
146 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, |
147 | BT_NOTIFICATION_TYPE_INACTIVITY); | |
ece3fb0f | 148 | inactivity_notification = container_of(notification, |
fe30b20b | 149 | struct bt_notification_inactivity, parent); |
094ff7c0 PP |
150 | return g_hash_table_lookup( |
151 | inactivity_notification->clock_values, clock_class); | |
f6ccaed9 | 152 | } |