9303c650256ddf756693c73a5cbe8d6221602798
[babeltrace.git] / src / lib / graph / message / message-iterator-inactivity.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #define BT_LOG_TAG "LIB/MSG-MSG-ITER-INACTIVITY"
8 #include "lib/logging.h"
9
10 #include "lib/assert-pre.h"
11 #include "lib/object.h"
12 #include "compat/compiler.h"
13 #include <babeltrace2/trace-ir/clock-class.h>
14 #include "lib/trace-ir/clock-snapshot.h"
15 #include "lib/graph/message/message.h"
16 #include <babeltrace2/graph/message.h>
17
18 #include "message-iterator-inactivity.h"
19
20 static
21 void bt_message_message_iterator_inactivity_destroy(struct bt_object *obj)
22 {
23 struct bt_message_message_iterator_inactivity *message =
24 (struct bt_message_message_iterator_inactivity *) obj;
25
26 BT_LIB_LOGD("Destroying message iterator inactivity message: %!+n",
27 message);
28
29 if (message->cs) {
30 bt_clock_snapshot_recycle(message->cs);
31 message->cs = NULL;
32 }
33
34 g_free(message);
35 }
36
37 struct bt_message *bt_message_message_iterator_inactivity_create(
38 struct bt_self_message_iterator *self_msg_iter,
39 const struct bt_clock_class *clock_class,
40 uint64_t value_cycles)
41 {
42 struct bt_message_iterator *msg_iter =
43 (void *) self_msg_iter;
44 struct bt_message_message_iterator_inactivity *message;
45 struct bt_message *ret_msg = NULL;
46
47 BT_ASSERT_PRE_DEV_NO_ERROR();
48 BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator");
49 BT_ASSERT_PRE_NON_NULL(clock_class, "Default clock class");
50 BT_LIB_LOGD("Creating message iterator inactivity message object: "
51 "%![iter-]+i, %![cc-]+K, value=%" PRIu64, msg_iter,
52 clock_class, value_cycles);
53 message = g_new0(struct bt_message_message_iterator_inactivity, 1);
54 if (!message) {
55 BT_LIB_LOGE_APPEND_CAUSE(
56 "Failed to allocate one message iterator "
57 "inactivity message.");
58 goto error;
59 }
60 bt_message_init(&message->parent,
61 BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY,
62 bt_message_message_iterator_inactivity_destroy, NULL);
63 ret_msg = &message->parent;
64 message->cs = bt_clock_snapshot_create(
65 (void *) clock_class);
66 if (!message->cs) {
67 goto error;
68 }
69 bt_clock_snapshot_set_raw_value(message->cs, value_cycles);
70
71 BT_LIB_LOGD("Created message iterator inactivity message object: %!+n",
72 ret_msg);
73 goto end;
74
75 error:
76 BT_OBJECT_PUT_REF_AND_RESET(ret_msg);
77
78 end:
79 return (void *) ret_msg;
80 }
81
82 extern const struct bt_clock_snapshot *
83 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(
84 const bt_message *msg)
85 {
86 struct bt_message_message_iterator_inactivity *inactivity = (void *) msg;
87
88 BT_ASSERT_PRE_DEV_NON_NULL(msg, "Message");
89 BT_ASSERT_PRE_DEV_MSG_IS_TYPE(msg,
90 BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY);
91 return inactivity->cs;
92 }
This page took 0.03207 seconds and 3 git commands to generate.