Document libbabeltrace2's C API
[babeltrace.git] / src / lib / graph / message / message-iterator-inactivity.c
CommitLineData
b09a5592
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
b03487ab 23#define BT_LOG_TAG "LIB/MSG-MSG-ITER-INACTIVITY"
1633ef46 24#include "lib/logging.h"
b09a5592 25
57952005
MJ
26#include "lib/assert-pre.h"
27#include "lib/object.h"
28#include "compat/compiler.h"
71c5da58 29#include <babeltrace2/trace-ir/clock-class.h>
57952005
MJ
30#include "lib/trace-ir/clock-snapshot.h"
31#include "lib/graph/message/message.h"
7704a0af 32#include <babeltrace2/graph/message.h>
57952005
MJ
33
34#include "message-iterator-inactivity.h"
b09a5592
PP
35
36static
40bf6fd0 37void bt_message_message_iterator_inactivity_destroy(struct bt_object *obj)
b09a5592 38{
40bf6fd0
FD
39 struct bt_message_message_iterator_inactivity *message =
40 (struct bt_message_message_iterator_inactivity *) obj;
b09a5592 41
40bf6fd0 42 BT_LIB_LOGD("Destroying message iterator inactivity message: %!+n",
a684a357 43 message);
b09a5592 44
62988c56
PP
45 if (message->cs) {
46 bt_clock_snapshot_recycle(message->cs);
47 message->cs = NULL;
b09a5592
PP
48 }
49
50 g_free(message);
51}
52
40bf6fd0 53struct bt_message *bt_message_message_iterator_inactivity_create(
b09a5592 54 struct bt_self_message_iterator *self_msg_iter,
62988c56 55 const struct bt_clock_class *clock_class,
b8fae4bb 56 uint64_t value_cycles)
b09a5592 57{
fbd8a4e0 58 struct bt_message_iterator *msg_iter =
b09a5592 59 (void *) self_msg_iter;
40bf6fd0 60 struct bt_message_message_iterator_inactivity *message;
b09a5592
PP
61 struct bt_message *ret_msg = NULL;
62
7c7324d3 63 BT_ASSERT_PRE_DEV_NO_ERROR();
b09a5592 64 BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator");
62988c56 65 BT_ASSERT_PRE_NON_NULL(clock_class, "Default clock class");
40bf6fd0 66 BT_LIB_LOGD("Creating message iterator inactivity message object: "
62988c56
PP
67 "%![iter-]+i, %![cc-]+K, value=%" PRIu64, msg_iter,
68 clock_class, value_cycles);
40bf6fd0 69 message = g_new0(struct bt_message_message_iterator_inactivity, 1);
b09a5592 70 if (!message) {
a8f90e5d
PP
71 BT_LIB_LOGE_APPEND_CAUSE(
72 "Failed to allocate one message iterator "
a684a357 73 "inactivity message.");
b09a5592
PP
74 goto error;
75 }
76 bt_message_init(&message->parent,
40bf6fd0
FD
77 BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY,
78 bt_message_message_iterator_inactivity_destroy, NULL);
b09a5592 79 ret_msg = &message->parent;
62988c56
PP
80 message->cs = bt_clock_snapshot_create(
81 (void *) clock_class);
82 if (!message->cs) {
b09a5592
PP
83 goto error;
84 }
62988c56 85 bt_clock_snapshot_set_raw_value(message->cs, value_cycles);
b09a5592 86
40bf6fd0 87 BT_LIB_LOGD("Created message iterator inactivity message object: %!+n",
a684a357 88 ret_msg);
b09a5592
PP
89 goto end;
90
91error:
92 BT_OBJECT_PUT_REF_AND_RESET(ret_msg);
93
94end:
95 return (void *) ret_msg;
96}
97
11ddb3ef 98extern const struct bt_clock_snapshot *
62988c56 99bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(
11ddb3ef 100 const bt_message *msg)
b09a5592 101{
40bf6fd0 102 struct bt_message_message_iterator_inactivity *inactivity = (void *) msg;
b09a5592 103
fa6cfec3
PP
104 BT_ASSERT_PRE_DEV_NON_NULL(msg, "Message");
105 BT_ASSERT_PRE_DEV_MSG_IS_TYPE(msg,
106 BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY);
62988c56 107 return inactivity->cs;
b09a5592 108}
This page took 0.052072 seconds and 4 git commands to generate.