Line data Source code
1 : #include <glib.h>
2 : #include <glib-object.h>
3 : #include "plugins.h"
4 :
5 : /**
6 : * SECTION: plugins
7 : * @short_description: functions related to querying plugins
8 : * @title: Plugins
9 : * @include: blockdev.h
10 : */
11 :
12 : /**
13 : * bd_plugin_spec_copy: (skip)
14 : * @spec: (nullable): %BDPluginSpec to copy
15 : *
16 : * Creates a new copy of @spec.
17 : */
18 0 : BDPluginSpec* bd_plugin_spec_copy (BDPluginSpec *spec) {
19 0 : if (!spec)
20 0 : return NULL;
21 :
22 0 : BDPluginSpec *new_spec = g_new0 (BDPluginSpec, 1);
23 :
24 0 : new_spec->name = spec->name;
25 0 : new_spec->so_name = g_strdup (spec->so_name);
26 :
27 0 : return new_spec;
28 : }
29 :
30 : /**
31 : * bd_plugin_spec_free: (skip)
32 : * @spec: (nullable): %BDPluginSpec to free
33 : *
34 : * Frees @spec.
35 : */
36 59 : void bd_plugin_spec_free (BDPluginSpec *spec) {
37 59 : if (!spec)
38 0 : return;
39 59 : g_free ((gchar *) spec->so_name);
40 59 : g_free (spec);
41 : }
42 :
43 : /**
44 : * bd_plugin_spec_new: (constructor)
45 : * @name: %BDPlugin name, e.g. %BD_PLUGIN_LVM
46 : * @so_name: (nullable): SO name of the plugin to load or %NULL for default
47 : *
48 : * Returns: (transfer full): a new plugin spec
49 : */
50 72 : BDPluginSpec* bd_plugin_spec_new (BDPlugin name, const gchar *so_name) {
51 72 : BDPluginSpec* ret = g_new0 (BDPluginSpec, 1);
52 72 : ret->name = name;
53 : /* FIXME: this should be const, but we are already allocating a new string in _copy
54 : * and freeing it in _free
55 : */
56 101 : ret->so_name = so_name ? g_strdup (so_name) : NULL;
57 :
58 72 : return ret;
59 : }
60 :
61 10 : GType bd_plugin_spec_get_type (void) {
62 : static GType type = 0;
63 :
64 10 : if (G_UNLIKELY(type == 0)) {
65 1 : type = g_boxed_type_register_static("BDPluginSpec",
66 : (GBoxedCopyFunc) bd_plugin_spec_copy,
67 : (GBoxedFreeFunc) bd_plugin_spec_free);
68 : }
69 :
70 10 : return type;
71 : }
|