$search
00001 /*************************************************************************** 00002 tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 PluginLoader.hpp 00003 00004 PluginLoader.hpp - description 00005 ------------------- 00006 begin : Tue September 07 2010 00007 copyright : (C) 2010 The SourceWorks 00008 email : peter@thesourceworks.com 00009 00010 *************************************************************************** 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU General Public * 00013 * License as published by the Free Software Foundation; * 00014 * version 2 of the License. * 00015 * * 00016 * As a special exception, you may use this file as part of a free * 00017 * software library without restriction. Specifically, if other files * 00018 * instantiate templates or use macros or inline functions from this * 00019 * file, or you compile this file and link it with other files to * 00020 * produce an executable, this file does not by itself cause the * 00021 * resulting executable to be covered by the GNU General Public * 00022 * License. This exception does not however invalidate any other * 00023 * reasons why the executable file might be covered by the GNU General * 00024 * Public License. * 00025 * * 00026 * This library is distributed in the hope that it will be useful, * 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00029 * Lesser General Public License for more details. * 00030 * * 00031 * You should have received a copy of the GNU General Public * 00032 * License along with this library; if not, write to the Free Software * 00033 * Foundation, Inc., 59 Temple Place, * 00034 * Suite 330, Boston, MA 02111-1307 USA * 00035 * * 00036 ***************************************************************************/ 00037 00038 00039 #ifndef ORO_PLUGINLOADER_HPP_ 00040 #define ORO_PLUGINLOADER_HPP_ 00041 00042 #include <string> 00043 #include <vector> 00044 #include <boost/shared_ptr.hpp> 00045 00046 #include "../rtt-fwd.hpp" 00047 #include "../rtt-config.h" 00048 #include "../os/Mutex.hpp" 00049 00050 namespace RTT { 00051 namespace plugin { 00068 class RTT_API PluginLoader 00069 { 00074 class LoadedLib{ 00075 public: 00076 LoadedLib(std::string n, std::string short_name, void* h) 00077 : filename(n), shortname(short_name), handle(h), loadPlugin(0), is_typekit(false), is_service(false) 00078 { 00079 } 00083 std::string filename; 00087 std::string shortname; 00091 std::string plugname; 00092 void* handle; 00093 bool (*loadPlugin)(RTT::TaskContext*); 00094 RTT::ServicePtr (*createService)(void); 00095 bool is_typekit, is_service; 00096 }; 00097 00098 std::vector< LoadedLib > loadedLibs; 00099 00103 std::string plugin_path; 00104 00108 mutable os::Mutex listlock; 00109 00119 bool loadInProcess(std::string filename, std::string shortname, std::string kind, bool log_error ); 00129 bool loadPluginInternal( std::string const& name, std::string const& path_list, std::string const& subdir, std::string const& kind ); 00138 bool loadPluginsInternal( std::string const& path_list, std::string const& subdir, std::string const& kind ); 00143 bool isLoadedInternal(std::string name); 00151 bool isCompatiblePlugin(std::string const& filepath); 00152 00153 public: 00154 PluginLoader(); 00155 ~PluginLoader(); 00156 00157 typedef boost::shared_ptr<PluginLoader> shared_ptr; 00163 static boost::shared_ptr<PluginLoader> Instance(); 00164 00169 static void Release(); 00170 00176 bool loadLibrary(std::string const& path); 00177 00187 bool loadTypekits(std::string const& path_list); 00188 00195 bool loadTypekit(std::string const& name, std::string const& path_list); 00196 00204 bool loadPlugins(std::string const& path_list); 00205 00213 bool isLoaded(std::string name); 00214 00222 bool loadPlugin(std::string const& name, std::string const& path_list); 00223 00231 bool loadService(std::string const& servicename, TaskContext* tc); 00232 00237 std::vector<std::string> listServices() const; 00238 00243 std::vector<std::string> listPlugins() const; 00244 00249 std::vector<std::string> listTypekits() const; 00250 00257 std::string getPluginPath() const; 00258 00265 void setPluginPath( std::string const& newpath ); 00266 }; 00267 } 00268 } 00269 00270 00271 #endif /* ORO_PLUGINLOADER_HPP_ */