2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
7 #define BT_LOG_TAG "LIB/MSG-MSG-ITER-INACTIVITY"
8 #include "lib/logging.h"
10 #include "lib/assert-cond.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>
18 #include "message-iterator-inactivity.h"
21 void bt_message_message_iterator_inactivity_destroy(struct bt_object
*obj
)
23 struct bt_message_message_iterator_inactivity
*message
=
24 (struct bt_message_message_iterator_inactivity
*) obj
;
26 BT_LIB_LOGD("Destroying message iterator inactivity message: %!+n",
30 bt_clock_snapshot_recycle(message
->cs
);
38 struct bt_message
*bt_message_message_iterator_inactivity_create(
39 struct bt_self_message_iterator
*self_msg_iter
,
40 const struct bt_clock_class
*clock_class
,
41 uint64_t value_cycles
)
43 struct bt_message_iterator
*msg_iter
=
44 (void *) self_msg_iter
;
45 struct bt_message_message_iterator_inactivity
*message
;
46 struct bt_message
*ret_msg
= NULL
;
48 BT_ASSERT_PRE_DEV_NO_ERROR();
49 BT_ASSERT_PRE_MSG_ITER_NON_NULL(msg_iter
);
50 BT_ASSERT_PRE_DEF_CLK_CLS_NON_NULL(clock_class
);
51 BT_LIB_LOGD("Creating message iterator inactivity message object: "
52 "%![iter-]+i, %![cc-]+K, value=%" PRIu64
, msg_iter
,
53 clock_class
, value_cycles
);
54 message
= g_new0(struct bt_message_message_iterator_inactivity
, 1);
56 BT_LIB_LOGE_APPEND_CAUSE(
57 "Failed to allocate one message iterator "
58 "inactivity message.");
61 bt_message_init(&message
->parent
,
62 BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
,
63 bt_message_message_iterator_inactivity_destroy
, NULL
);
64 ret_msg
= &message
->parent
;
65 message
->cs
= bt_clock_snapshot_create(
66 (void *) clock_class
);
70 bt_clock_snapshot_set_raw_value(message
->cs
, value_cycles
);
72 BT_LIB_LOGD("Created message iterator inactivity message object: %!+n",
77 BT_OBJECT_PUT_REF_AND_RESET(ret_msg
);
80 return (void *) ret_msg
;
84 const struct bt_clock_snapshot
*
85 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(
86 const bt_message
*msg
)
88 struct bt_message_message_iterator_inactivity
*inactivity
= (void *) msg
;
90 BT_ASSERT_PRE_DEV_MSG_NON_NULL(msg
);
91 BT_ASSERT_PRE_DEV_MSG_HAS_TYPE("message", msg
,
92 "message-iterator-inactivity",
93 BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
);
94 return inactivity
->cs
;