Add plugin (user) version information
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 26 Jan 2017 09:54:47 +0000 (04:54 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:37 +0000 (12:57 -0400)
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 <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/plugin/plugin-dev.h
include/babeltrace/plugin/plugin-internal.h
include/babeltrace/plugin/plugin.h
lib/plugin/plugin.c

index 5224d466b607d0d8e6442abbe2b4ef15efb0d05d..d65ccce5d07ced2f67e69d3aa4b98374b80e9ab8 100644 (file)
@@ -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
index ac0217207bcfca61f068df44cc083d43f151afbc..4f361d6d6d2931285565f81fe64cb637581f43e0 100644 (file)
@@ -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 */
index 1e5bf37b5e0f74b24d032b9fc5c89a0d0d820e18..9bb04f2e6b126284d4fdab48498e7b4a4f59ceba 100644 (file)
@@ -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(
index e79db448e2296e0ebce278e4c15ffa67294deb55..707fe4e74595646702aa7f6f4ed7c6f703973d2c 100644 (file)
@@ -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;
This page took 0.02785 seconds and 4 git commands to generate.