Implement plugin base class
[babeltrace.git] / plugins / ctf / reader.c
CommitLineData
bfd20a42
JG
1#include <babeltrace/plugin/plugin-lib.h>
2#include <babeltrace/plugin/plugin-system.h>
3#include <glib.h>
4#include <stdio.h>
5
6const char *plugin_name = "ctf";
7
8struct ctf_reader {
9 FILE *err;
10};
11
12enum bt_plugin_type bt_plugin_lib_get_type(void)
4c1456f0
JG
13{
14 return BT_PLUGIN_TYPE_SOURCE;
15}
16
bfd20a42 17const char *bt_plugin_lib_get_format_name(void)
4c1456f0 18{
bfd20a42 19 return plugin_name;
4c1456f0
JG
20}
21
bfd20a42
JG
22static
23void ctf_reader_destroy(struct bt_plugin *plugin)
4c1456f0 24{
bfd20a42
JG
25 struct ctf_reader *reader;
26
27 if (!plugin) {
28 return;
29 }
30
31 reader = bt_plugin_get_private_data(plugin);
32 if (!reader) {
33 return;
34 }
35
36 g_free(reader);
4c1456f0
JG
37}
38
bfd20a42
JG
39static
40struct bt_notification_iterator *ctf_reader_iterator_create(
41 struct bt_plugin *plugin)
4c1456f0 42{
bfd20a42 43 return NULL;
4c1456f0
JG
44}
45
bfd20a42
JG
46/* Move this to bt_plugin */
47static
48enum bt_plugin_status ctf_reader_set_error_stream(
49 struct bt_plugin *plugin, FILE *stream)
4c1456f0 50{
bfd20a42
JG
51 struct ctf_reader *reader;
52 enum bt_plugin_status ret = BT_PLUGIN_STATUS_OK;
4c1456f0 53
bfd20a42
JG
54 if (!plugin) {
55 ret = BT_PLUGIN_STATUS_INVAL;
56 goto end;
57 }
58
59 reader = bt_plugin_get_private_data(plugin);
60 if (!reader) {
61 ret = BT_PLUGIN_STATUS_ERROR;
62 goto end;
63 }
64
65 reader->stream = stream;
66end:
67 return ret;
4c1456f0
JG
68}
69
bfd20a42
JG
70struct bt_plugin *bt_plugin_lib_create(struct bt_object *params)
71{
72 enum bt_plugin_status ret;
73 struct bt_plugin *plugin = NULL;
74 struct ctf_reader *reader = g_new0(struct ctf_reader, 1);
75
76 if (!reader) {
77 goto error;
78 }
79
80 plugin = bt_plugin_source_create(plugin_name, reader,
81 ctf_reader_destroy, ctf_reader_iterator_create);
82 if (!plugin) {
83 goto error;
84 }
85 reader = NULL;
86
87 ret = bt_plugin_set_error_stream_cb(plugin,
88 ctf_reader_set_error_stream);
89 if (ret != BT_PLUGIN_STATUS_OK) {
90 goto error;
91 }
92end:
93 return plugin;
94error:
95 if (reader) {
96 ctf_reader_destroy(reader);
97 }
98 if (plugin) {
99 bt_plugin_put(plugin);
100 plugin = NULL;
101 }
102 goto end;
103}
This page took 0.026381 seconds and 4 git commands to generate.