Implement plugin base class
[babeltrace.git] / plugins / ctf / reader.c
1 #include <babeltrace/plugin/plugin-lib.h>
2 #include <babeltrace/plugin/plugin-system.h>
3 #include <glib.h>
4 #include <stdio.h>
5
6 const char *plugin_name = "ctf";
7
8 struct ctf_reader {
9 FILE *err;
10 };
11
12 enum bt_plugin_type bt_plugin_lib_get_type(void)
13 {
14 return BT_PLUGIN_TYPE_SOURCE;
15 }
16
17 const char *bt_plugin_lib_get_format_name(void)
18 {
19 return plugin_name;
20 }
21
22 static
23 void ctf_reader_destroy(struct bt_plugin *plugin)
24 {
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);
37 }
38
39 static
40 struct bt_notification_iterator *ctf_reader_iterator_create(
41 struct bt_plugin *plugin)
42 {
43 return NULL;
44 }
45
46 /* Move this to bt_plugin */
47 static
48 enum bt_plugin_status ctf_reader_set_error_stream(
49 struct bt_plugin *plugin, FILE *stream)
50 {
51 struct ctf_reader *reader;
52 enum bt_plugin_status ret = BT_PLUGIN_STATUS_OK;
53
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;
66 end:
67 return ret;
68 }
69
70 struct 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 }
92 end:
93 return plugin;
94 error:
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.032007 seconds and 5 git commands to generate.