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-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>
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
);
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
)
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
;
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);
55 BT_LIB_LOGE_APPEND_CAUSE(
56 "Failed to allocate one message iterator "
57 "inactivity message.");
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
);
69 bt_clock_snapshot_set_raw_value(message
->cs
, value_cycles
);
71 BT_LIB_LOGD("Created message iterator inactivity message object: %!+n",
76 BT_OBJECT_PUT_REF_AND_RESET(ret_msg
);
79 return (void *) ret_msg
;
82 extern const struct bt_clock_snapshot
*
83 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(
84 const bt_message
*msg
)
86 struct bt_message_message_iterator_inactivity
*inactivity
= (void *) msg
;
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
;