lib: rename bt_plugin_create_all_*() -> bt_plugin_find_all_*()
[babeltrace.git] / include / babeltrace / graph / notification-internal.h
CommitLineData
6ac74c0c
PP
1#ifndef BABELTRACE_GRAPH_NOTIFICATION_NOTIFICATION_INTERNAL_H
2#define BABELTRACE_GRAPH_NOTIFICATION_NOTIFICATION_INTERNAL_H
62ed7c30
JG
3
4/*
e2f7325d 5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
62ed7c30
JG
6 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
62ed7c30
JG
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
62ed7c30 27#include <babeltrace/babeltrace-internal.h>
b8a06801 28#include <babeltrace/object-internal.h>
6c677fb5 29#include <babeltrace/assert-internal.h>
5c563278 30#include <babeltrace/graph/graph.h>
0d72b8c3 31#include <babeltrace/graph/notification-const.h>
56e18c4c 32#include <babeltrace/trace-ir/stream.h>
5c563278 33#include <babeltrace/object-pool-internal.h>
c55a9f58 34#include <babeltrace/types.h>
62ed7c30 35
50842bdc 36typedef struct bt_stream *(*get_stream_func)(
cc5236c9
JG
37 struct bt_notification *notification);
38
f7665a2e 39struct bt_notification {
b8a06801 40 struct bt_object base;
f7665a2e 41 enum bt_notification_type type;
f42867e2 42 uint64_t seq_num;
c55a9f58 43 bt_bool frozen;
5c563278
PP
44
45 /* Owned by this; keeps the graph alive while the notif. is alive */
46 struct bt_graph *graph;
62ed7c30
JG
47};
48
f6ccaed9 49#define BT_ASSERT_PRE_NOTIF_IS_TYPE(_notif, _type) \
40f4ba76 50 BT_ASSERT_PRE(((struct bt_notification *) (_notif))->type == (_type), \
f6ccaed9
PP
51 "Notification has the wrong type: expected-type=%s, " \
52 "%![notif-]+n", bt_notification_type_string(_type), \
53 (_notif))
54
78586d8a
JG
55BT_HIDDEN
56void bt_notification_init(struct bt_notification *notification,
57 enum bt_notification_type type,
5c563278
PP
58 bt_object_release_func release,
59 struct bt_graph *graph);
60
61static inline
62void 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
72static inline
73struct 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
6c677fb5 78 if (unlikely(!notif)) {
5c563278
PP
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
6c677fb5 86 if (likely(!notif->graph)) {
5c563278
PP
87 notif->graph = graph;
88 }
89
90 goto end;
91
92error:
6c677fb5 93 BT_ASSERT(!notif);
78586d8a 94
5c563278
PP
95end:
96 return notif;
97}
98
99static inline void _bt_notification_freeze(struct bt_notification *notification)
e7fa96c3 100{
c55a9f58 101 notification->frozen = BT_TRUE;
e7fa96c3
PP
102}
103
5c563278
PP
104BT_HIDDEN
105void 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
5af447e5
PP
113static inline
114const char *bt_notification_type_string(enum bt_notification_type type)
115{
116 switch (type) {
5af447e5
PP
117 case BT_NOTIFICATION_TYPE_EVENT:
118 return "BT_NOTIFICATION_TYPE_EVENT";
119 case BT_NOTIFICATION_TYPE_INACTIVITY:
120 return "BT_NOTIFICATION_TYPE_INACTIVITY";
bb5bb160
PP
121 case BT_NOTIFICATION_TYPE_STREAM_BEGINNING:
122 return "BT_NOTIFICATION_TYPE_STREAM_BEGINNING";
5af447e5
PP
123 case BT_NOTIFICATION_TYPE_STREAM_END:
124 return "BT_NOTIFICATION_TYPE_STREAM_END";
bb5bb160
PP
125 case BT_NOTIFICATION_TYPE_PACKET_BEGINNING:
126 return "BT_NOTIFICATION_TYPE_PACKET_BEGINNING";
5af447e5
PP
127 case BT_NOTIFICATION_TYPE_PACKET_END:
128 return "BT_NOTIFICATION_TYPE_PACKET_END";
129 default:
130 return "(unknown)";
131 }
62ed7c30 132}
62ed7c30 133
6ac74c0c 134#endif /* BABELTRACE_GRAPH_NOTIFICATION_NOTIFICATION_INTERNAL_H */
This page took 0.044388 seconds and 4 git commands to generate.