Annotation of embedaddon/strongswan/src/libstrongswan/plugins/plugin_loader.h, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2012-2014 Tobias Brunner
        !             3:  * Copyright (C) 2007 Martin Willi
        !             4:  * HSR Hochschule fuer Technik Rapperswil
        !             5:  *
        !             6:  * This program is free software; you can redistribute it and/or modify it
        !             7:  * under the terms of the GNU General Public License as published by the
        !             8:  * Free Software Foundation; either version 2 of the License, or (at your
        !             9:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
        !            10:  *
        !            11:  * This program is distributed in the hope that it will be useful, but
        !            12:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            13:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        !            14:  * for more details.
        !            15:  */
        !            16: 
        !            17: /**
        !            18:  * @defgroup plugin_loader plugin_loader
        !            19:  * @{ @ingroup plugins
        !            20:  */
        !            21: 
        !            22: #ifndef PLUGIN_LOADER_H_
        !            23: #define PLUGIN_LOADER_H_
        !            24: 
        !            25: typedef struct plugin_loader_t plugin_loader_t;
        !            26: 
        !            27: #include <collections/enumerator.h>
        !            28: #include <utils/debug.h>
        !            29: 
        !            30: /* to avoid circular references we can't include plugin_feature.h */
        !            31: struct plugin_feature_t;
        !            32: 
        !            33: /**
        !            34:  * The plugin_loader loads plugins from a directory and initializes them
        !            35:  */
        !            36: struct plugin_loader_t {
        !            37: 
        !            38:        /**
        !            39:         * Add static plugin features, not loaded via plugins.
        !            40:         *
        !            41:         * Similar to features provided by plugins they are evaluated during load(),
        !            42:         * and unloaded when unload() is called.
        !            43:         *
        !            44:         * If critical is TRUE load() will fail if any of the added features could
        !            45:         * not be loaded.
        !            46:         *
        !            47:         * If a reload callback function is given, it gets invoked for the
        !            48:         * registered feature set when reload() is invoked on the plugin_loader.
        !            49:         *
        !            50:         * @note The name should be unique otherwise a plugin with the same name is
        !            51:         * not loaded.
        !            52:         *
        !            53:         * @param name                  name of the component adding the features
        !            54:         * @param features              array of plugin features
        !            55:         * @param count                 number of features in the array
        !            56:         * @param critical              TRUE if the features are critical
        !            57:         * @param reload                feature reload callback, or NULL
        !            58:         * @param reload_data   user data to pass to reload callback
        !            59:         */
        !            60:        void (*add_static_features) (plugin_loader_t *this, const char *name,
        !            61:                                                                 struct plugin_feature_t *features, int count,
        !            62:                                                                 bool critical, bool (*reload)(void*),
        !            63:                                                                 void *reload_data);
        !            64: 
        !            65:        /**
        !            66:         * Load a list of plugins.
        !            67:         *
        !            68:         * Each plugin in list may have an ending exclamation mark (!) to mark it
        !            69:         * as a critical plugin. If loading a critical plugin fails, plugin loading
        !            70:         * is aborted and FALSE is returned.
        !            71:         *
        !            72:         * Additional paths can be added with add_path(), these will be searched
        !            73:         * for the plugins first, in the order they were added, then the default
        !            74:         * path follows.
        !            75:         *
        !            76:         * If \<ns>.load_modular is enabled (where \<ns> is lib->ns) the plugins to
        !            77:         * load are determined via a load option in their respective plugin config
        !            78:         * section e.g. \<ns>.plugins.\<plugin>.load = <priority|bool>.
        !            79:         * The order is determined by the configured priority.  If two plugins have
        !            80:         * the same priority the order as seen in list is preserved.  Plugins not
        !            81:         * found in list are loaded first, in alphabetical order.
        !            82:         *
        !            83:         * @note Even though this method could be called multiple times this is
        !            84:         * currently not really supported in regards to plugin features and their
        !            85:         * dependencies (in particular soft dependencies).
        !            86:         *
        !            87:         * @param list                  space separated list of plugins to load
        !            88:         * @return                              TRUE if all critical plugins loaded successfully
        !            89:         */
        !            90:        bool (*load)(plugin_loader_t *this, char *list);
        !            91: 
        !            92:        /**
        !            93:         * Add an additional search path for plugins.
        !            94:         *
        !            95:         * These will be searched in the order they were added.
        !            96:         *
        !            97:         * @param path                  path containing loadable plugins
        !            98:         */
        !            99:        void (*add_path)(plugin_loader_t *this, char *path);
        !           100: 
        !           101:        /**
        !           102:         * Reload the configuration of one or multiple plugins.
        !           103:         *
        !           104:         * @param                               space separated plugin names to reload, NULL for all
        !           105:         * @return                              number of plugins that did support reloading
        !           106:         */
        !           107:        u_int (*reload)(plugin_loader_t *this, char *list);
        !           108: 
        !           109:        /**
        !           110:         * Unload all loaded plugins.
        !           111:         */
        !           112:        void (*unload)(plugin_loader_t *this);
        !           113: 
        !           114:        /**
        !           115:         * Create an enumerator over all loaded plugins.
        !           116:         *
        !           117:         * In addition to the plugin, the enumerator optionally provides a list of
        !           118:         * pointers to plugin features currently loaded.
        !           119:         * This list has to be destroyed.
        !           120:         *
        !           121:         * @return                              enumerator over plugin_t*, linked_list_t*
        !           122:         */
        !           123:        enumerator_t* (*create_plugin_enumerator)(plugin_loader_t *this);
        !           124: 
        !           125:        /**
        !           126:         * Check if the given feature is available and loaded.
        !           127:         *
        !           128:         * @param feature               feature to check
        !           129:         * @return                              TRUE if feature available
        !           130:         */
        !           131:        bool (*has_feature)(plugin_loader_t *this, struct plugin_feature_t feature);
        !           132: 
        !           133:        /**
        !           134:         * Get a simple list the names of all loaded plugins.
        !           135:         *
        !           136:         * The function returns internal data, do not free.
        !           137:         *
        !           138:         * @return                              list of the names of all loaded plugins
        !           139:         */
        !           140:        char* (*loaded_plugins)(plugin_loader_t *this);
        !           141: 
        !           142:        /**
        !           143:         * Log status about loaded plugins and features.
        !           144:         *
        !           145:         * @param level                 log level to use
        !           146:         */
        !           147:        void (*status)(plugin_loader_t *this, level_t level);
        !           148: 
        !           149:        /**
        !           150:         * Unload loaded plugins, destroy plugin_loader instance.
        !           151:         */
        !           152:        void (*destroy)(plugin_loader_t *this);
        !           153: };
        !           154: 
        !           155: /**
        !           156:  * Create a plugin_loader instance.
        !           157:  *
        !           158:  * @return                     plugin loader instance
        !           159:  */
        !           160: plugin_loader_t *plugin_loader_create();
        !           161: 
        !           162: /**
        !           163:  * Convenience function to add plugin directories for the given plugins within
        !           164:  * the given base directory according to the conventions in the src/build tree.
        !           165:  *
        !           166:  * @param basedir      base directory
        !           167:  * @param plugins      space separated list of plugins
        !           168:  */
        !           169: void plugin_loader_add_plugindirs(char *basedir, char *plugins);
        !           170: 
        !           171: #ifdef STATIC_PLUGIN_CONSTRUCTORS
        !           172: /**
        !           173:  * Register a plugin constructor in case of static builds.
        !           174:  *
        !           175:  * @param name         name of the plugin
        !           176:  * @param constructor  constructor to register (set to NULL to unregister)
        !           177:  */
        !           178: void plugin_constructor_register(char *name, void *constructor);
        !           179: #endif
        !           180: 
        !           181: #endif /** PLUGIN_LOADER_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>