lib: rename bt_plugin_create_all_*() -> bt_plugin_find_all_*()
[babeltrace.git] / include / babeltrace / graph / notification-internal.h
1 #ifndef BABELTRACE_GRAPH_NOTIFICATION_NOTIFICATION_INTERNAL_H
2 #define BABELTRACE_GRAPH_NOTIFICATION_NOTIFICATION_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/notification-const.h>
32 #include <babeltrace/trace-ir/stream.h>
33 #include <babeltrace/object-pool-internal.h>
34 #include <babeltrace/types.h>
35
36 typedef struct bt_stream *(*get_stream_func)(
37 struct bt_notification *notification);
38
39 struct bt_notification {
40 struct bt_object base;
41 enum bt_notification_type type;
42 uint64_t seq_num;
43 bt_bool frozen;
44
45 /* Owned by this; keeps the graph alive while the notif. is alive */
46 struct bt_graph *graph;
47 };
48
49 #define BT_ASSERT_PRE_NOTIF_IS_TYPE(_notif, _type) \
50 BT_ASSERT_PRE(((struct bt_notification *) (_notif))->type == (_type), \
51 "Notification has the wrong type: expected-type=%s, " \
52 "%![notif-]+n", bt_notification_type_string(_type), \
53 (_notif))
54
55 BT_HIDDEN
56 void bt_notification_init(struct bt_notification *notification,
57 enum bt_notification_type type,
58 bt_object_release_func release,
59 struct bt_graph *graph);
60
61 static inline
62 void bt_notification_reset(struct bt_notification *notification)
63 {
64 BT_ASSERT(notification);
65
66 #ifdef BT_DEV_MODE
67 notification->frozen = BT_FALSE;
68 notification->seq_num = UINT64_C(-1);
69 #endif
70 }
71
72 static inline
73 struct bt_notification *bt_notification_create_from_pool(
74 struct bt_object_pool *pool, struct bt_graph *graph)
75 {
76 struct bt_notification *notif = bt_object_pool_create_object(pool);
77
78 if (unlikely(!notif)) {
79 #ifdef BT_LIB_LOGE
80 BT_LIB_LOGE("Cannot allocate one notification from notification pool: "
81 "%![pool-]+o, %![graph-]+g", pool, graph);
82 #endif
83 goto error;
84 }
85
86 if (likely(!notif->graph)) {
87 notif->graph = graph;
88 }
89
90 goto end;
91
92 error:
93 BT_ASSERT(!notif);
94
95 end:
96 return notif;
97 }
98
99 static inline void _bt_notification_freeze(struct bt_notification *notification)
100 {
101 notification->frozen = BT_TRUE;
102 }
103
104 BT_HIDDEN
105 void bt_notification_unlink_graph(struct bt_notification *notif);
106
107 #ifdef BT_DEV_MODE
108 # define bt_notification_freeze _bt_notification_freeze
109 #else
110 # define bt_notification_freeze(_x)
111 #endif /* BT_DEV_MODE */
112
113 static inline
114 const char *bt_notification_type_string(enum bt_notification_type type)
115 {
116 switch (type) {
117 case BT_NOTIFICATION_TYPE_EVENT:
118 return "BT_NOTIFICATION_TYPE_EVENT";
119 case BT_NOTIFICATION_TYPE_INACTIVITY:
120 return "BT_NOTIFICATION_TYPE_INACTIVITY";
121 case BT_NOTIFICATION_TYPE_STREAM_BEGINNING:
122 return "BT_NOTIFICATION_TYPE_STREAM_BEGINNING";
123 case BT_NOTIFICATION_TYPE_STREAM_END:
124 return "BT_NOTIFICATION_TYPE_STREAM_END";
125 case BT_NOTIFICATION_TYPE_PACKET_BEGINNING:
126 return "BT_NOTIFICATION_TYPE_PACKET_BEGINNING";
127 case BT_NOTIFICATION_TYPE_PACKET_END:
128 return "BT_NOTIFICATION_TYPE_PACKET_END";
129 default:
130 return "(unknown)";
131 }
132 }
133
134 #endif /* BABELTRACE_GRAPH_NOTIFICATION_NOTIFICATION_INTERNAL_H */
This page took 0.032307 seconds and 4 git commands to generate.