| 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 |
BDPluginSpec* bd_plugin_spec_copy (BDPluginSpec *spec) { |
| 19 |
if (!spec) |
| 20 |
return NULL; |
| 21 |
|
| 22 |
BDPluginSpec *new_spec = g_new0 (BDPluginSpec, 1); |
| 23 |
|
| 24 |
new_spec->name = spec->name; |
| 25 |
new_spec->so_name = g_strdup (spec->so_name); |
| 26 |
|
| 27 |
return new_spec; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* bd_plugin_spec_free: (skip) |
| 32 |
* @spec: (nullable): %BDPluginSpec to free |
| 33 |
* |
| 34 |
* Frees @spec. |
| 35 |
*/ |
| 36 |
void bd_plugin_spec_free (BDPluginSpec *spec) { |
| 37 |
if (!spec) |
| 38 |
return; |
| 39 |
g_free ((gchar *) spec->so_name); |
| 40 |
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 |
BDPluginSpec* bd_plugin_spec_new (BDPlugin name, const gchar *so_name) { |
| 51 |
BDPluginSpec* ret = g_new0 (BDPluginSpec, 1); |
| 52 |
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 |
ret->so_name = so_name ? g_strdup (so_name) : NULL; |
| 57 |
|
| 58 |
return ret; |
| 59 |
} |
| 60 |
|
| 61 |
GType bd_plugin_spec_get_type (void) { |
| 62 |
static GType type = 0; |
| 63 |
|
| 64 |
if (G_UNLIKELY(type == 0)) { |
| 65 |
type = g_boxed_type_register_static("BDPluginSpec", |
| 66 |
(GBoxedCopyFunc) bd_plugin_spec_copy, |
| 67 |
(GBoxedFreeFunc) bd_plugin_spec_free); |
| 68 |
} |
| 69 |
|
| 70 |
return type; |
| 71 |
} |