lib: rename "notification" -> "message"
[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;
42 uint64_t seq_num;
43 bt_bool frozen;
44
45 /* Owned by this; keeps the graph alive while the msg. is alive */
46 struct bt_graph *graph;
47};
48
49#define BT_ASSERT_PRE_MSG_IS_TYPE(_msg, _type) \
50 BT_ASSERT_PRE(((struct bt_message *) (_msg))->type == (_type), \
51 "Message has the wrong type: expected-type=%s, " \
52 "%![msg-]+n", bt_message_type_string(_type), \
53 (_msg))
54
55BT_HIDDEN
56void bt_message_init(struct bt_message *message,
57 enum bt_message_type type,
58 bt_object_release_func release,
59 struct bt_graph *graph);
60
61static inline
62void bt_message_reset(struct bt_message *message)
63{
64 BT_ASSERT(message);
65
66#ifdef BT_DEV_MODE
67 message->frozen = BT_FALSE;
68 message->seq_num = UINT64_C(-1);
69#endif
70}
71
72static inline
73struct bt_message *bt_message_create_from_pool(
74 struct bt_object_pool *pool, struct bt_graph *graph)
75{
76 struct bt_message *msg = bt_object_pool_create_object(pool);
77
78 if (unlikely(!msg)) {
79#ifdef BT_LIB_LOGE
80 BT_LIB_LOGE("Cannot allocate one message from message pool: "
81 "%![pool-]+o, %![graph-]+g", pool, graph);
82#endif
83 goto error;
84 }
85
86 if (likely(!msg->graph)) {
87 msg->graph = graph;
88 }
89
90 goto end;
91
92error:
93 BT_ASSERT(!msg);
94
95end:
96 return msg;
97}
98
99static inline void _bt_message_freeze(struct bt_message *message)
100{
101 message->frozen = BT_TRUE;
102}
103
104BT_HIDDEN
105void bt_message_unlink_graph(struct bt_message *msg);
106
107#ifdef BT_DEV_MODE
108# define bt_message_freeze _bt_message_freeze
109#else
110# define bt_message_freeze(_x)
111#endif /* BT_DEV_MODE */
112
113static inline
114const char *bt_message_type_string(enum bt_message_type type)
115{
116 switch (type) {
117 case BT_MESSAGE_TYPE_EVENT:
118 return "BT_MESSAGE_TYPE_EVENT";
119 case BT_MESSAGE_TYPE_INACTIVITY:
120 return "BT_MESSAGE_TYPE_INACTIVITY";
121 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
122 return "BT_MESSAGE_TYPE_STREAM_BEGINNING";
123 case BT_MESSAGE_TYPE_STREAM_END:
124 return "BT_MESSAGE_TYPE_STREAM_END";
125 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
126 return "BT_MESSAGE_TYPE_PACKET_BEGINNING";
127 case BT_MESSAGE_TYPE_PACKET_END:
128 return "BT_MESSAGE_TYPE_PACKET_END";
129 default:
130 return "(unknown)";
131 }
132}
133
134#endif /* BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H */
This page took 0.030918 seconds and 4 git commands to generate.