/* * PluginController * * Author: Andrew Salamon * * Copyright (c) 2008 Machine Perception Laboratory * University of California San Diego. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #ifndef __CERT_PLUGINCONTROLLER_H__ #define __CERT_PLUGINCONTROLLER_H__ #include "PluginBase.h" #include "CERT_Config.h" #include #include #include namespace CERT { namespace PluginSteps { /// Known plugin steps extern const std::string unknown; ///< Constant string: MPT_PluginStep_NoStep extern const std::string afterFaces; ///< Constant string: MPT_PluginStep_AfterFaces extern const std::string SVM; ///< Constant string: MPT_PluginStep_SVM extern const std::string Feature; ///< Constant string: MPT_PluginStep_Features extern const std::string PostProcess; ///< Constant string: MPT_PluginStep_PostProcess extern const std::string Output; ///< Constant string: MPT_PluginStep_Output } class FacePlugin; /** The PluginController is responsible for loading plugins and providing access to them. * Usually loading will be done based on a passed in Config object, but plugins could * be created and added manually. */ class PluginController { public: typedef boost::shared_ptr pluginPtr; // typedef std::vector containerType; // Probably ought to be a set rather than a vector typedef std::vector containerType; // Probably ought to be a set rather than a vector public: static PluginController *getPluginController( const std::string &configPath = std::string() ); static std::vector knownPluginTypes(); static void cleanup(); ///< Should be called just before exiting the program. public: PluginController(); PluginController( PluginController &other ); ~PluginController(); bool loadPluginsFromConfig( Config *config ); void addPlugin( PluginBase * ); void removePlugin( PluginBase * ); void removePlugin( const std::string &pluginID ); containerType pluginsForStep( const PluginStep &step, bool enabledOnly = true ); containerType pluginsForSteps( const std::vector &steps, bool enabledOnly = true ); PluginBase *pluginWithID( const std::string &id, bool enabledOnly = true ); ///< May return null. FacePlugin *getFaceDetector(); ///< Will return null if the face plugin is not enabled. /// This method will return any global settings contained in the config object. bool hasSetting( const std::string &name ); std::vector< std::string > getSetting( const std::string &name ); bool hasStringSetting( const std::string &name ); std::string getStringSetting( const std::string &name ); ///< Will be an empty string if it wasn't present. bool hasIntSetting( const std::string &name ); int getIntSetting( const std::string &name ); ///< Will be zero if it wasn't present. bool hasMapSetting( const std::string &name ); ConfigItem::PropertyType getMapSetting( const std::string &name ); std::string getFaceAlignmentMethod(); ///< See FeatureAlignment to convert from string to alignment method enum. static std::vector< std::string > validFaceAlignmentMethods(); private: containerType plugins; FacePlugin *faceDetector; boost::shared_ptr config; }; } // end namespace CERT #endif // __CERT_PLUGINCONTROLLER_H__