Fix: add missing cases in enum-to-string functions
[babeltrace.git] / src / lib / graph / message / message.h
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
30 typedef struct bt_stream *(*get_stream_func)(
31 struct bt_message *message);
32
33 struct 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 BT_HIDDEN
43 void bt_message_init(struct bt_message *message,
44 enum bt_message_type type,
45 bt_object_release_func release,
46 struct bt_graph *graph);
47
48 static inline
49 void bt_message_reset(struct bt_message *message)
50 {
51 BT_ASSERT_DBG(message);
52
53 #ifdef BT_DEV_MODE
54 message->frozen = BT_FALSE;
55 #endif
56 }
57
58 static inline
59 struct bt_message *bt_message_create_from_pool(
60 struct bt_object_pool *pool, struct bt_graph *graph)
61 {
62 struct bt_message *msg = bt_object_pool_create_object(pool);
63
64 if (G_UNLIKELY(!msg)) {
65 BT_LIB_LOGE_APPEND_CAUSE(
66 "Cannot allocate one message from message pool: "
67 "%![pool-]+o, %![graph-]+g", pool, graph);
68 goto error;
69 }
70
71 if (G_LIKELY(!msg->graph)) {
72 msg->graph = graph;
73 }
74
75 goto end;
76
77 error:
78 BT_ASSERT(!msg);
79
80 end:
81 return msg;
82 }
83
84 static inline void _bt_message_freeze(struct bt_message *message)
85 {
86 message->frozen = BT_TRUE;
87 }
88
89 BT_HIDDEN
90 void bt_message_unlink_graph(struct bt_message *msg);
91
92 #ifdef BT_DEV_MODE
93 # define bt_message_freeze _bt_message_freeze
94 #else
95 # define bt_message_freeze(_x)
96 #endif /* BT_DEV_MODE */
97
98 static inline
99 const char *bt_message_type_string(enum bt_message_type type)
100 {
101 switch (type) {
102 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
103 return "STREAM_BEGINNING";
104 case BT_MESSAGE_TYPE_STREAM_END:
105 return "STREAM_END";
106 case BT_MESSAGE_TYPE_EVENT:
107 return "EVENT";
108 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
109 return "PACKET_BEGINNING";
110 case BT_MESSAGE_TYPE_PACKET_END:
111 return "PACKET_END";
112 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
113 return "DISCARDED_EVENTS";
114 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
115 return "DISCARDED_PACKETS";
116 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
117 return "MESSAGE_ITERATOR_INACTIVITY";
118 }
119
120 bt_common_abort();
121 }
122
123 #endif /* BABELTRACE_GRAPH_MESSAGE_MESSAGE_INTERNAL_H */
This page took 0.032226 seconds and 4 git commands to generate.