cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / lib / graph / message / message.h
CommitLineData
d6e69534 1/*
0235b0db
MJ
2 * SPDX-License-Identifier: MIT
3 *
d6e69534
PP
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
d6e69534
PP
6 */
7
0235b0db
MJ
8#ifndef BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H
9#define BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H
10
870631a2
PP
11/* Protection: this file uses BT_LIB_LOG*() macros directly */
12#ifndef BT_LIB_LOG_SUPPORTED
13# error Please include "lib/logging.h" before including this file.
14#endif
15
578e048b
MJ
16#include "lib/object.h"
17#include "common/assert.h"
3fadfbc0 18#include <babeltrace2/graph/graph.h>
43c59509 19#include <babeltrace2/graph/message.h>
3fadfbc0 20#include <babeltrace2/trace-ir/stream.h>
578e048b 21#include "lib/object-pool.h"
3fadfbc0 22#include <babeltrace2/types.h>
d6e69534 23
f137d351
PP
24/* Protection: this file uses BT_LIB_LOG*() macros directly */
25#ifndef BT_LIB_LOG_SUPPORTED
26# error Please include "lib/logging.h" before including this file.
27#endif
28
d6e69534
PP
29typedef struct bt_stream *(*get_stream_func)(
30 struct bt_message *message);
31
32struct bt_message {
33 struct bt_object base;
34 enum bt_message_type type;
d6e69534
PP
35 bt_bool frozen;
36
37 /* Owned by this; keeps the graph alive while the msg. is alive */
38 struct bt_graph *graph;
39};
40
d6e69534
PP
41void bt_message_init(struct bt_message *message,
42 enum bt_message_type type,
43 bt_object_release_func release,
44 struct bt_graph *graph);
45
46static inline
47void bt_message_reset(struct bt_message *message)
48{
98b15851 49 BT_ASSERT_DBG(message);
d6e69534
PP
50
51#ifdef BT_DEV_MODE
52 message->frozen = BT_FALSE;
d6e69534
PP
53#endif
54}
55
56static inline
57struct bt_message *bt_message_create_from_pool(
58 struct bt_object_pool *pool, struct bt_graph *graph)
59{
60 struct bt_message *msg = bt_object_pool_create_object(pool);
61
91d81473 62 if (G_UNLIKELY(!msg)) {
870631a2
PP
63 BT_LIB_LOGE_APPEND_CAUSE(
64 "Cannot allocate one message from message pool: "
d6e69534 65 "%![pool-]+o, %![graph-]+g", pool, graph);
d6e69534
PP
66 goto error;
67 }
68
91d81473 69 if (G_LIKELY(!msg->graph)) {
d6e69534
PP
70 msg->graph = graph;
71 }
72
73 goto end;
74
75error:
76 BT_ASSERT(!msg);
77
78end:
79 return msg;
80}
81
82static inline void _bt_message_freeze(struct bt_message *message)
83{
84 message->frozen = BT_TRUE;
85}
86
d6e69534
PP
87void bt_message_unlink_graph(struct bt_message *msg);
88
89#ifdef BT_DEV_MODE
90# define bt_message_freeze _bt_message_freeze
91#else
92# define bt_message_freeze(_x)
93#endif /* BT_DEV_MODE */
94
d6e69534 95#endif /* BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H */
This page took 0.089296 seconds and 4 git commands to generate.