cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[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-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>
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 BT_EXPORT
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)
42 {
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;
47
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);
55 if (!message) {
56 BT_LIB_LOGE_APPEND_CAUSE(
57 "Failed to allocate one message iterator "
58 "inactivity message.");
59 goto error;
60 }
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);
67 if (!message->cs) {
68 goto error;
69 }
70 bt_clock_snapshot_set_raw_value(message->cs, value_cycles);
71
72 BT_LIB_LOGD("Created message iterator inactivity message object: %!+n",
73 ret_msg);
74 goto end;
75
76 error:
77 BT_OBJECT_PUT_REF_AND_RESET(ret_msg);
78
79 end:
80 return (void *) ret_msg;
81 }
82
83 BT_EXPORT
84 const struct bt_clock_snapshot *
85 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(
86 const bt_message *msg)
87 {
88 struct bt_message_message_iterator_inactivity *inactivity = (void *) msg;
89
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;
95 }
This page took 0.030674 seconds and 4 git commands to generate.