Commit | Line | Data |
---|---|---|
d6e69534 PP |
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 "MSG-INACTIVITY" | |
24 | #include <babeltrace/lib-logging-internal.h> | |
25 | ||
26 | #include <babeltrace/assert-pre-internal.h> | |
27 | #include <babeltrace/object-internal.h> | |
28 | #include <babeltrace/compiler-internal.h> | |
29 | #include <babeltrace/trace-ir/clock-class.h> | |
605e1019 | 30 | #include <babeltrace/trace-ir/clock-snapshot-internal.h> |
d6e69534 PP |
31 | #include <babeltrace/graph/message-internal.h> |
32 | #include <babeltrace/graph/message-inactivity-const.h> | |
33 | #include <babeltrace/graph/message-inactivity.h> | |
34 | #include <babeltrace/graph/message-inactivity-internal.h> | |
35 | ||
36 | static | |
37 | void bt_message_inactivity_destroy(struct bt_object *obj) | |
38 | { | |
39 | struct bt_message_inactivity *message = | |
40 | (struct bt_message_inactivity *) obj; | |
41 | ||
42 | BT_LIB_LOGD("Destroying inactivity message: %!+n", message); | |
43 | ||
605e1019 PP |
44 | if (message->default_cs) { |
45 | bt_clock_snapshot_recycle(message->default_cs); | |
678aa684 | 46 | message->default_cs = NULL; |
d6e69534 PP |
47 | } |
48 | ||
49 | g_free(message); | |
50 | } | |
51 | ||
52 | struct bt_message *bt_message_inactivity_create( | |
53 | struct bt_self_message_iterator *self_msg_iter, | |
54 | struct bt_clock_class *default_clock_class) | |
55 | { | |
56 | struct bt_self_component_port_input_message_iterator *msg_iter = | |
57 | (void *) self_msg_iter; | |
58 | struct bt_message_inactivity *message; | |
59 | struct bt_message *ret_msg = NULL; | |
60 | ||
61 | BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator"); | |
62 | BT_ASSERT_PRE_NON_NULL(default_clock_class, "Default clock class"); | |
63 | BT_LIB_LOGD("Creating inactivity message object: " | |
64 | "%![iter-]+i, %![default-cc-]+K", msg_iter, | |
65 | default_clock_class); | |
66 | message = g_new0(struct bt_message_inactivity, 1); | |
67 | if (!message) { | |
68 | BT_LOGE_STR("Failed to allocate one inactivity message."); | |
69 | goto error; | |
70 | } | |
71 | bt_message_init(&message->parent, | |
72 | BT_MESSAGE_TYPE_INACTIVITY, | |
73 | bt_message_inactivity_destroy, NULL); | |
74 | ret_msg = &message->parent; | |
605e1019 PP |
75 | message->default_cs = bt_clock_snapshot_create(default_clock_class); |
76 | if (!message->default_cs) { | |
d6e69534 PP |
77 | goto error; |
78 | } | |
79 | ||
80 | BT_LIB_LOGD("Created inactivity message object: %!+n", ret_msg); | |
81 | goto end; | |
82 | ||
83 | error: | |
84 | BT_OBJECT_PUT_REF_AND_RESET(ret_msg); | |
85 | ||
86 | end: | |
87 | return (void *) ret_msg; | |
88 | } | |
89 | ||
605e1019 | 90 | void bt_message_inactivity_set_default_clock_snapshot( |
d6e69534 PP |
91 | struct bt_message *msg, uint64_t value_cycles) |
92 | { | |
93 | struct bt_message_inactivity *inactivity = (void *) msg; | |
94 | ||
95 | BT_ASSERT_PRE_NON_NULL(msg, "Message"); | |
96 | BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_INACTIVITY); | |
97 | BT_ASSERT_PRE_HOT(msg, "Message", ": %!+n", msg); | |
f0ebeace | 98 | bt_clock_snapshot_set_raw_value(inactivity->default_cs, value_cycles); |
605e1019 | 99 | BT_LIB_LOGV("Set inactivity message's default clock snapshot: " |
d6e69534 PP |
100 | "%![msg-]+n, value=%" PRIu64, msg, value_cycles); |
101 | } | |
102 | ||
dc68f16d | 103 | extern enum bt_clock_snapshot_state |
605e1019 | 104 | bt_message_inactivity_borrow_default_clock_snapshot_const( |
dc68f16d | 105 | const bt_message *msg, const bt_clock_snapshot **snapshot) |
d6e69534 PP |
106 | { |
107 | struct bt_message_inactivity *inactivity = (void *) msg; | |
108 | ||
109 | BT_ASSERT_PRE_NON_NULL(msg, "Message"); | |
dc68f16d | 110 | BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)"); |
d6e69534 | 111 | BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_INACTIVITY); |
dc68f16d PP |
112 | *snapshot = inactivity->default_cs; |
113 | return BT_CLOCK_SNAPSHOT_STATE_KNOWN; | |
d6e69534 | 114 | } |