Move to kernel style SPDX license identifiers
[babeltrace.git] / src / lib / graph / message / message.h
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 */
7
8#ifndef BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H
9#define BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H
10
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
16#include "common/macros.h"
17#include "lib/object.h"
18#include "common/assert.h"
19#include <babeltrace2/graph/graph.h>
20#include <babeltrace2/graph/message.h>
21#include <babeltrace2/trace-ir/stream.h>
22#include "lib/object-pool.h"
23#include <babeltrace2/types.h>
24
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
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;
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
42#define _BT_ASSERT_PRE_MSG_IS_TYPE_COND(_msg, _type) \
43 (((struct bt_message *) (_msg))->type == (_type))
44
45#define _BT_ASSERT_PRE_MSG_IS_TYPE_FMT \
46 "Message has the wrong type: expected-type=%s, %![msg-]+n"
47
48#define BT_ASSERT_PRE_MSG_IS_TYPE(_msg, _type) \
49 BT_ASSERT_PRE( \
50 _BT_ASSERT_PRE_MSG_IS_TYPE_COND((_msg), (_type)), \
51 _BT_ASSERT_PRE_MSG_IS_TYPE_FMT, \
52 bt_message_type_string(_type), (_msg))
53
54#define BT_ASSERT_PRE_DEV_MSG_IS_TYPE(_msg, _type) \
55 BT_ASSERT_PRE_DEV( \
56 _BT_ASSERT_PRE_MSG_IS_TYPE_COND((_msg), (_type)), \
57 _BT_ASSERT_PRE_MSG_IS_TYPE_FMT, \
58 bt_message_type_string(_type), (_msg))
59
60BT_HIDDEN
61void bt_message_init(struct bt_message *message,
62 enum bt_message_type type,
63 bt_object_release_func release,
64 struct bt_graph *graph);
65
66static inline
67void bt_message_reset(struct bt_message *message)
68{
69 BT_ASSERT_DBG(message);
70
71#ifdef BT_DEV_MODE
72 message->frozen = BT_FALSE;
73#endif
74}
75
76static inline
77struct bt_message *bt_message_create_from_pool(
78 struct bt_object_pool *pool, struct bt_graph *graph)
79{
80 struct bt_message *msg = bt_object_pool_create_object(pool);
81
82 if (G_UNLIKELY(!msg)) {
83 BT_LIB_LOGE_APPEND_CAUSE(
84 "Cannot allocate one message from message pool: "
85 "%![pool-]+o, %![graph-]+g", pool, graph);
86 goto error;
87 }
88
89 if (G_LIKELY(!msg->graph)) {
90 msg->graph = graph;
91 }
92
93 goto end;
94
95error:
96 BT_ASSERT(!msg);
97
98end:
99 return msg;
100}
101
102static inline void _bt_message_freeze(struct bt_message *message)
103{
104 message->frozen = BT_TRUE;
105}
106
107BT_HIDDEN
108void bt_message_unlink_graph(struct bt_message *msg);
109
110#ifdef BT_DEV_MODE
111# define bt_message_freeze _bt_message_freeze
112#else
113# define bt_message_freeze(_x)
114#endif /* BT_DEV_MODE */
115
116static inline
117const char *bt_message_type_string(enum bt_message_type type)
118{
119 switch (type) {
120 case BT_MESSAGE_TYPE_EVENT:
121 return "EVENT";
122 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
123 return "MESSAGE_ITERATOR_INACTIVITY";
124 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
125 return "STREAM_BEGINNING";
126 case BT_MESSAGE_TYPE_STREAM_END:
127 return "STREAM_END";
128 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
129 return "PACKET_BEGINNING";
130 case BT_MESSAGE_TYPE_PACKET_END:
131 return "PACKET_END";
132 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
133 return "DISCARDED_EVENTS";
134 default:
135 return "(unknown)";
136 }
137}
138
139#endif /* BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H */
This page took 0.023602 seconds and 4 git commands to generate.