attr: Use plugin features to register attribute provider
authorTobias Brunner <tobias@strongswan.org>
Fri, 7 Jun 2013 16:52:33 +0000 (18:52 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 11 Jun 2013 09:18:18 +0000 (11:18 +0200)
src/libhydra/plugins/attr/attr_plugin.c

index cb14495..7d719d0 100644 (file)
@@ -42,6 +42,36 @@ METHOD(plugin_t, get_name, char*,
        return "attr";
 }
 
+/**
+ * Register provider
+ */
+static bool plugin_cb(private_attr_plugin_t *this,
+                                         plugin_feature_t *feature, bool reg, void *cb_data)
+{
+       if (reg)
+       {
+               hydra->attributes->add_provider(hydra->attributes,
+                                                                               &this->provider->provider);
+       }
+       else
+       {
+               hydra->attributes->remove_provider(hydra->attributes,
+                                                                                  &this->provider->provider);
+       }
+       return TRUE;
+}
+
+METHOD(plugin_t, get_features, int,
+       private_attr_plugin_t *this, plugin_feature_t *features[])
+{
+       static plugin_feature_t f[] = {
+               PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
+                       PLUGIN_PROVIDE(CUSTOM, "attr"),
+       };
+       *features = f;
+       return countof(f);
+}
+
 METHOD(plugin_t, reload, bool,
        private_attr_plugin_t *this)
 {
@@ -52,7 +82,6 @@ METHOD(plugin_t, reload, bool,
 METHOD(plugin_t, destroy, void,
        private_attr_plugin_t *this)
 {
-       hydra->attributes->remove_provider(hydra->attributes, &this->provider->provider);
        this->provider->destroy(this->provider);
        free(this);
 }
@@ -68,13 +97,13 @@ plugin_t *attr_plugin_create()
                .public = {
                        .plugin = {
                                .get_name = _get_name,
+                               .get_features = _get_features,
                                .reload = _reload,
                                .destroy = _destroy,
                        },
                },
                .provider = attr_provider_create(),
        );
-       hydra->attributes->add_provider(hydra->attributes, &this->provider->provider);
 
        return &this->public.plugin;
 }