Build system: build reader plug-in stub
[babeltrace.git] / plugins / plugin.c
index e857381d3d1a9894230e6d25e933ec96090da0e1..1f5a6bbde3cc3fbb569ac912d2362804512a0fb2 100644 (file)
  * SOFTWARE.
  */
 
+#include <babeltrace/plugin/plugin-internal.h>
+#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/compiler.h>
+
+static void bt_plugin_destroy(struct bt_ctf_ref *ref);
+
 const char *bt_plugin_get_name(struct bt_plugin *plugin)
 {
        const char *ret = NULL;
@@ -97,5 +103,71 @@ void bt_plugin_put(struct bt_plugin *plugin)
                return;
        }
 
-       bt_ctf_ref_put(&plugin->ref_count);
+       bt_ctf_ref_put(&plugin->ref_count, bt_plugin_destroy);
+}
+
+BT_HIDDEN
+enum bt_plugin_status bt_plugin_init(struct bt_plugin *plugin, const char *name,
+               void *user_data, bt_plugin_destroy_cb user_destroy_func,
+               enum bt_plugin_type plugin_type,
+               bt_plugin_destroy_cb plugin_destroy)
+{
+       enum bt_plugin_status ret = BT_PLUGIN_STATUS_OK;
+
+       if (!plugin || !name || name[0] == '\0' ||
+               !user_destroy_func || !user_data || !plugin_destroy) {
+               ret = BT_PLUGIN_STATUS_INVAL;
+               goto end;
+       }
+
+       bt_ctf_ref_init(&plugin->ref_count);
+       plugin->type = plugin_type;
+       plugin->user_data = user_data;
+       plugin->user_data_destroy = user_destroy_func;
+       plugin->destroy = plugin_destroy;
+
+       plugin->name = g_string_new(name);
+       if (!plugin->name) {
+               ret = BT_PLUGIN_STATUS_NOMEM;
+               goto end;
+       }
+end:
+       return ret;
+}
+
+void *bt_plugin_get_private_data(struct bt_plugin *plugin)
+{
+        void *ret = NULL;
+
+       if (!plugin) {
+               goto end;
+       }
+
+       ret = plugin->user_data;
+end:
+       return ret;
+}
+
+static
+void bt_plugin_destroy(struct bt_ctf_ref *ref)
+{
+       struct bt_plugin *plugin = NULL;
+
+       if (!ref) {
+               return;
+       }
+
+       plugin = container_of(ref, struct bt_plugin, ref_count);
+
+       /**
+        * Destroy user data, base and source/filter/sink last since
+        * it will deallocate the plugin.
+        */
+       assert(plugin->user_data_destroy);
+       plugin->user_data_destroy(plugin->user_data);
+
+       g_string_free(plugin->name, TRUE);
+
+       assert(plugin->destroy);
+       plugin->destroy(plugin);
 }
This page took 0.024682 seconds and 4 git commands to generate.