Visibility hidden by default
[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
91d81473 16#include "common/macros.h"
578e048b
MJ
17#include "lib/object.h"
18#include "common/assert.h"
3fadfbc0 19#include <babeltrace2/graph/graph.h>
43c59509 20#include <babeltrace2/graph/message.h>
3fadfbc0 21#include <babeltrace2/trace-ir/stream.h>
578e048b 22#include "lib/object-pool.h"
3fadfbc0 23#include <babeltrace2/types.h>
d6e69534 24
f137d351
PP
25/* Protection: this file uses BT_LIB_LOG*() macros directly */
26#ifndef BT_LIB_LOG_SUPPORTED
27# error Please include "lib/logging.h" before including this file.
28#endif
29
d6e69534
PP
30typedef struct bt_stream *(*get_stream_func)(
31 struct bt_message *message);
32
33struct bt_message {
34 struct bt_object base;
35 enum bt_message_type type;
d6e69534
PP
36 bt_bool frozen;
37
38 /* Owned by this; keeps the graph alive while the msg. is alive */
39 struct bt_graph *graph;
40};
41
d6e69534
PP
42void bt_message_init(struct bt_message *message,
43 enum bt_message_type type,
44 bt_object_release_func release,
45 struct bt_graph *graph);
46
47static inline
48void bt_message_reset(struct bt_message *message)
49{
98b15851 50 BT_ASSERT_DBG(message);
d6e69534
PP
51
52#ifdef BT_DEV_MODE
53 message->frozen = BT_FALSE;
d6e69534
PP
54#endif
55}
56
57static inline
58struct bt_message *bt_message_create_from_pool(
59 struct bt_object_pool *pool, struct bt_graph *graph)
60{
61 struct bt_message *msg = bt_object_pool_create_object(pool);
62
91d81473 63 if (G_UNLIKELY(!msg)) {
870631a2
PP
64 BT_LIB_LOGE_APPEND_CAUSE(
65 "Cannot allocate one message from message pool: "
d6e69534 66 "%![pool-]+o, %![graph-]+g", pool, graph);
d6e69534
PP
67 goto error;
68 }
69
91d81473 70 if (G_LIKELY(!msg->graph)) {
d6e69534
PP
71 msg->graph = graph;
72 }
73
74 goto end;
75
76error:
77 BT_ASSERT(!msg);
78
79end:
80 return msg;
81}
82
83static inline void _bt_message_freeze(struct bt_message *message)
84{
85 message->frozen = BT_TRUE;
86}
87
d6e69534
PP
88void bt_message_unlink_graph(struct bt_message *msg);
89
90#ifdef BT_DEV_MODE
91# define bt_message_freeze _bt_message_freeze
92#else
93# define bt_message_freeze(_x)
94#endif /* BT_DEV_MODE */
95
d6e69534 96#endif /* BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H */
This page took 0.079401 seconds and 4 git commands to generate.