From b6de043b9a9c465bf90cdf9dcee963be08a9e370 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 26 Jan 2017 04:54:47 -0500 Subject: [PATCH] Add plugin (user) version information MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch adds the BT_PLUGIN_VERSION_WITH_ID() and BT_PLUGIN_VERSION() macros to the plugin development API (babeltrace/plugin/plugin-dev.h) for the user to set a custom version (major, minor, patch, extra). You can use the new bt_plugin_get_version() function to retrieve the plugin's version, if set. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- include/babeltrace/plugin/plugin-dev.h | 38 +++++++++++++++++++++ include/babeltrace/plugin/plugin-internal.h | 1 + include/babeltrace/plugin/plugin.h | 4 +++ lib/plugin/plugin.c | 34 ++++++++++++++++++ 4 files changed, 77 insertions(+) diff --git a/include/babeltrace/plugin/plugin-dev.h b/include/babeltrace/plugin/plugin-dev.h index 5224d466..d65ccce5 100644 --- a/include/babeltrace/plugin/plugin-dev.h +++ b/include/babeltrace/plugin/plugin-dev.h @@ -83,6 +83,15 @@ enum __bt_plugin_descriptor_attribute_type { BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_AUTHOR = 2, BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_LICENSE = 3, BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION = 4, + BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_VERSION = 5, +}; + +/* Plugin (user) version */ +struct __bt_plugin_descriptor_version { + uint32_t major; + uint32_t minor; + uint32_t patch; + const char *extra; }; /* Plugin attribute (internal use) */ @@ -112,6 +121,9 @@ struct __bt_plugin_descriptor_attribute { /* BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION */ const char *description; + + /* BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_VERSION */ + struct __bt_plugin_descriptor_version version; } value; } __attribute__((packed)); @@ -309,6 +321,21 @@ struct __bt_plugin_component_class_descriptor_attribute { #define BT_PLUGIN_DESCRIPTION_WITH_ID(_id, _x) \ __BT_PLUGIN_DESCRIPTOR_ATTRIBUTE(description, BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION, _id, _x) +#define __BT_PLUGIN_VERSION_STRUCT_VALUE(_major, _minor, _patch, _extra) \ + {.major = _major, .minor = _minor, .patch = _patch, .extra = _extra,} + +/* + * Defines a version attribute attached to a specific plugin descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _major: Plugin's major version (uint32_t). + * _minor: Plugin's minor version (uint32_t). + * _patch: Plugin's patch version (uint32_t). + * _extra: Plugin's version extra information (C string). + */ +#define BT_PLUGIN_VERSION_WITH_ID(_id, _major, _minor, _patch, _extra) \ + __BT_PLUGIN_DESCRIPTOR_ATTRIBUTE(version, BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_VERSION, _id, __BT_PLUGIN_VERSION_STRUCT_VALUE(_major, _minor, _patch, _extra)) + /* * Declaration of start and stop symbols of component class descriptors * section. @@ -573,6 +600,17 @@ struct __bt_plugin_component_class_descriptor_attribute { */ #define BT_PLUGIN_DESCRIPTION(_x) BT_PLUGIN_DESCRIPTION_WITH_ID(auto, _x) +/* + * Defines a version attribute attached to the automatic plugin + * descriptor. + * + * _major: Plugin's major version (uint32_t). + * _minor: Plugin's minor version (uint32_t). + * _patch: Plugin's patch version (uint32_t). + * _extra: Plugin's version extra information (C string). + */ +#define BT_PLUGIN_VERSION(_major, _minor, _patch, _extra) BT_PLUGIN_VERSION_WITH_ID(auto, _major, _minor, _patch, _extra) + /* * Defines a source component class attached to the automatic plugin * descriptor. Its ID is the same as its name, hence its name must be a diff --git a/include/babeltrace/plugin/plugin-internal.h b/include/babeltrace/plugin/plugin-internal.h index ac021720..4f361d6d 100644 --- a/include/babeltrace/plugin/plugin-internal.h +++ b/include/babeltrace/plugin/plugin-internal.h @@ -60,6 +60,7 @@ struct bt_plugin { const char *license; const char *description; bt_plugin_init_func init; + const struct __bt_plugin_descriptor_version *version; }; #endif /* BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H */ diff --git a/include/babeltrace/plugin/plugin.h b/include/babeltrace/plugin/plugin.h index 1e5bf37b..9bb04f2e 100644 --- a/include/babeltrace/plugin/plugin.h +++ b/include/babeltrace/plugin/plugin.h @@ -98,6 +98,10 @@ extern const char *bt_plugin_get_description(struct bt_plugin *plugin); */ extern const char *bt_plugin_get_path(struct bt_plugin *plugin); +extern enum bt_plugin_status bt_plugin_get_version(struct bt_plugin *plugin, + unsigned int *major, unsigned int *minor, unsigned int *patch, + const char **extra); + extern int bt_plugin_get_component_class_count(struct bt_plugin *plugin); extern struct bt_component_class *bt_plugin_get_component_class( diff --git a/lib/plugin/plugin.c b/lib/plugin/plugin.c index e79db448..707fe4e7 100644 --- a/lib/plugin/plugin.c +++ b/lib/plugin/plugin.c @@ -335,6 +335,9 @@ enum bt_plugin_status bt_plugin_init( case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION: plugin->description = cur_attr->value.description; break; + case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_VERSION: + plugin->version = &cur_attr->value.version; + break; default: printf_verbose("WARNING: Unknown attribute \"%s\" (type %d) for plugin %s\n", cur_attr->type_name, cur_attr->type, @@ -973,6 +976,37 @@ const char *bt_plugin_get_description(struct bt_plugin *plugin) return plugin ? plugin->description : NULL; } +enum bt_plugin_status bt_plugin_get_version(struct bt_plugin *plugin, + unsigned int *major, unsigned int *minor, unsigned int *patch, + const char **extra) +{ + enum bt_plugin_status status = BT_PLUGIN_STATUS_OK; + + if (!plugin || !plugin->version) { + status = BT_PLUGIN_STATUS_ERROR; + goto end; + } + + if (major) { + *major = (unsigned int) plugin->version->major; + } + + if (minor) { + *minor = (unsigned int) plugin->version->minor; + } + + if (patch) { + *patch = (unsigned int) plugin->version->patch; + } + + if (extra) { + *extra = plugin->version->extra; + } + +end: + return status; +} + int bt_plugin_get_component_class_count(struct bt_plugin *plugin) { return plugin ? plugin->comp_classes->len : -1; -- 2.34.1