Decouple component class from plugin subsystem, remove component factory
[babeltrace.git] / include / babeltrace / plugin / plugin-dev.h
CommitLineData
33b34c43
PP
1#ifndef BABELTRACE_PLUGIN_PLUGIN_DEV_H
2#define BABELTRACE_PLUGIN_PLUGIN_DEV_H
3
4/*
5 * BabelTrace - Babeltrace Plug-in System Interface
6 *
7 * This is the header that you need to include for the development of
8 * a Babeltrace plug-in.
9 *
10 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
12 *
13 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining a copy
16 * of this software and associated documentation files (the "Software"), to deal
17 * in the Software without restriction, including without limitation the rights
18 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19 * copies of the Software, and to permit persons to whom the Software is
20 * furnished to do so, subject to the following conditions:
21 *
22 * The above copyright notice and this permission notice shall be included in
23 * all copies or substantial portions of the Software.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#include <babeltrace/plugin/plugin.h>
35#include <babeltrace/component/component-class.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41typedef enum bt_plugin_status (*bt_plugin_init_func)(
42 struct bt_plugin *plugin);
43
44typedef enum bt_plugin_status (*bt_plugin_exit_func)(void);
45
46extern enum bt_plugin_status bt_plugin_add_component_class(
47 struct bt_plugin *plugin,
48 struct bt_component_class *component_class);
49
50#ifdef BT_BUILT_IN_PLUGINS
51/*
52 * Statically-linked plug-in symbol types are stored in separate sections and
53 * which are read using the bt_component_factory interface.
54 */
55# define BT_PLUGIN_INIT(_x) static bt_plugin_init_func __attribute__((section("__bt_plugin_init_funcs"), used)) __bt_plugin_init = (_x)
56# define BT_PLUGIN_EXIT(_x) static bt_plugin_exit_func __attribute__((section("__bt_plugin_exit_funcs"), used)) __bt_plugin_exit = (_x)
57# define BT_PLUGIN_NAME(_x) static const char *__bt_plugin_name __attribute__((section("__bt_plugin_names"), used)) = (_x)
58# define BT_PLUGIN_AUTHOR(_x) static const char *__bt_plugin_author __attribute__((section("__bt_plugin_authors"), used)) = (_x)
59# define BT_PLUGIN_LICENSE(_x) static const char *__bt_plugin_license __attribute__((section("__bt_plugin_licenses"), used)) = (_x)
60# define BT_PLUGIN_DESCRIPTION(_x) static const char *__bt_plugin_description __attribute__((section("__bt_plugin_descriptions"), used)) = (_x)
61#else /* BT_BUILT_IN_PLUGINS */
62# define BT_PLUGIN_INIT(_x) bt_plugin_init_func __bt_plugin_init = (_x)
63# define BT_PLUGIN_EXIT(_x) bt_plugin_exit_func __bt_plugin_exit = (_x)
64# define BT_PLUGIN_NAME(_x) const char __bt_plugin_name[] = (_x)
65# define BT_PLUGIN_AUTHOR(_x) const char __bt_plugin_author[] = (_x)
66# define BT_PLUGIN_LICENSE(_x) const char __bt_plugin_license[] = (_x)
67# define BT_PLUGIN_DESCRIPTION(_x) const char __bt_plugin_description[] = (_x)
68#endif /* BT_BUILT_IN_PLUGINS */
69
70#define BT_PLUGIN_COMPONENT_CLASSES_BEGIN \
71 static enum bt_plugin_status __bt_plugin_init_add_component_classes( \
72 struct bt_plugin *plugin) \
73 { \
74 enum bt_plugin_status status = BT_PLUGIN_STATUS_OK; \
75 struct bt_component_class *component_class = NULL;
76
77#define __BT_PLUGIN_COMPONENT_CLASS_ENTRY_EPILOGUE \
78 if (!component_class) { \
79 status = BT_PLUGIN_STATUS_ERROR; \
80 goto end; \
81 } \
82 status = bt_plugin_add_component_class(plugin, component_class);\
83 bt_put(component_class); \
84 component_class = NULL; \
85 if (status < 0) { \
86 goto end; \
87 }
88
89#define BT_PLUGIN_COMPONENT_CLASS_SOURCE_ENTRY(_name, _description, _init_func) \
90 component_class = bt_component_class_create( \
91 BT_COMPONENT_TYPE_SOURCE, _name, \
92 _description, _init_func); \
93 __BT_PLUGIN_COMPONENT_CLASS_ENTRY_EPILOGUE
94
95#define BT_PLUGIN_COMPONENT_CLASS_SINK_ENTRY(_name, _description, _init_func) \
96 component_class = bt_component_class_create( \
97 BT_COMPONENT_TYPE_SINK, _name, \
98 _description, _init_func); \
99 __BT_PLUGIN_COMPONENT_CLASS_ENTRY_EPILOGUE
100
101#define BT_PLUGIN_COMPONENT_CLASS_FILTER_ENTRY(_name, _description, _init_func) \
102 component_class = bt_component_class_create( \
103 BT_COMPONENT_TYPE_FILTER, _name, \
104 _description, _init_func); \
105 __BT_PLUGIN_COMPONENT_CLASS_ENTRY_EPILOGUE
106
107#define BT_PLUGIN_COMPONENT_CLASSES_END \
108 end: \
109 return status; \
110 } \
111 \
112 static enum bt_plugin_status __bt_plugin_nop_exit(void) { \
113 return BT_PLUGIN_STATUS_OK; \
114 } \
115 \
116 BT_PLUGIN_INIT(__bt_plugin_init_add_component_classes); \
117 BT_PLUGIN_EXIT(__bt_plugin_nop_exit);
118
119#ifdef __cplusplus
120}
121#endif
122
123#endif /* BABELTRACE_PLUGIN_PLUGIN_DEV_H */
This page took 0.027773 seconds and 4 git commands to generate.