lib: Reset libbabeltrace2 to SONANE 0
[babeltrace.git] / include / babeltrace / graph / message-internal.h
CommitLineData
d6e69534
PP
1#ifndef BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H
2#define BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H
3
4/*
5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
6 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
27#include <babeltrace/babeltrace-internal.h>
28#include <babeltrace/object-internal.h>
29#include <babeltrace/assert-internal.h>
30#include <babeltrace/graph/graph.h>
31#include <babeltrace/graph/message-const.h>
32#include <babeltrace/trace-ir/stream.h>
33#include <babeltrace/object-pool-internal.h>
34#include <babeltrace/types.h>
35
36typedef struct bt_stream *(*get_stream_func)(
37 struct bt_message *message);
38
39struct bt_message {
40 struct bt_object base;
41 enum bt_message_type type;
d6e69534
PP
42 bt_bool frozen;
43
44 /* Owned by this; keeps the graph alive while the msg. is alive */
45 struct bt_graph *graph;
46};
47
48#define BT_ASSERT_PRE_MSG_IS_TYPE(_msg, _type) \
49 BT_ASSERT_PRE(((struct bt_message *) (_msg))->type == (_type), \
50 "Message has the wrong type: expected-type=%s, " \
51 "%![msg-]+n", bt_message_type_string(_type), \
52 (_msg))
53
54BT_HIDDEN
55void bt_message_init(struct bt_message *message,
56 enum bt_message_type type,
57 bt_object_release_func release,
58 struct bt_graph *graph);
59
60static inline
61void bt_message_reset(struct bt_message *message)
62{
63 BT_ASSERT(message);
64
65#ifdef BT_DEV_MODE
66 message->frozen = BT_FALSE;
d6e69534
PP
67#endif
68}
69
70static inline
71struct bt_message *bt_message_create_from_pool(
72 struct bt_object_pool *pool, struct bt_graph *graph)
73{
74 struct bt_message *msg = bt_object_pool_create_object(pool);
75
76 if (unlikely(!msg)) {
77#ifdef BT_LIB_LOGE
78 BT_LIB_LOGE("Cannot allocate one message from message pool: "
79 "%![pool-]+o, %![graph-]+g", pool, graph);
80#endif
81 goto error;
82 }
83
84 if (likely(!msg->graph)) {
85 msg->graph = graph;
86 }
87
88 goto end;
89
90error:
91 BT_ASSERT(!msg);
92
93end:
94 return msg;
95}
96
97static inline void _bt_message_freeze(struct bt_message *message)
98{
99 message->frozen = BT_TRUE;
100}
101
102BT_HIDDEN
103void bt_message_unlink_graph(struct bt_message *msg);
104
105#ifdef BT_DEV_MODE
106# define bt_message_freeze _bt_message_freeze
107#else
108# define bt_message_freeze(_x)
109#endif /* BT_DEV_MODE */
110
111static inline
112const char *bt_message_type_string(enum bt_message_type type)
113{
114 switch (type) {
115 case BT_MESSAGE_TYPE_EVENT:
116 return "BT_MESSAGE_TYPE_EVENT";
b9fd9cbb
FD
117 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
118 return "BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY";
d6e69534
PP
119 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
120 return "BT_MESSAGE_TYPE_STREAM_BEGINNING";
121 case BT_MESSAGE_TYPE_STREAM_END:
122 return "BT_MESSAGE_TYPE_STREAM_END";
123 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
124 return "BT_MESSAGE_TYPE_PACKET_BEGINNING";
125 case BT_MESSAGE_TYPE_PACKET_END:
126 return "BT_MESSAGE_TYPE_PACKET_END";
5df26c89
PP
127 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
128 return "BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING";
129 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
130 return "BT_MESSAGE_TYPE_STREAM_ACTIVITY_END";
4c833281
PP
131 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
132 return "BT_MESSAGE_TYPE_DISCARDED_EVENTS";
d6e69534
PP
133 default:
134 return "(unknown)";
135 }
136}
137
138#endif /* BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H */
This page took 0.033448 seconds and 4 git commands to generate.