$search
00001 /* 00002 * Copyright (c) 2009, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 #ifndef RVIZ_PLUGIN_H 00031 #define RVIZ_PLUGIN_H 00032 00033 #include "display_type_info.h" 00034 #include "class_type_info.h" 00035 00036 #include <string> 00037 #include <list> 00038 #include <stdexcept> 00039 00040 #include <boost/shared_ptr.hpp> 00041 #include <boost/signals.hpp> 00042 00043 #include <wx/dynlib.h> 00044 00045 namespace YAML 00046 { 00047 class Node; 00048 } 00049 00050 namespace rviz 00051 { 00052 class VisualizationManager; 00053 class Display; 00054 class DisplayCreator; 00055 typedef boost::shared_ptr<DisplayCreator> DisplayCreatorPtr; 00056 00057 typedef std::map<std::string, std::string> M_string; 00058 00059 class Plugin; 00060 struct PluginStatus 00061 { 00062 PluginStatus(Plugin* p) 00063 : plugin(p) 00064 {} 00065 Plugin* plugin; 00066 }; 00067 typedef boost::signal<void(const PluginStatus&)> PluginStatusSignal; 00068 00069 class PluginParseException : public std::runtime_error 00070 { 00071 public: 00072 PluginParseException(const std::string& file, const std::string& error) 00073 : std::runtime_error("Unable to parse plugin description file [" + file + "]: " + error) 00074 {} 00075 }; 00076 00077 class UnableToLoadLibraryException : public std::runtime_error 00078 { 00079 public: 00080 UnableToLoadLibraryException(const std::string& library_name) 00081 : std::runtime_error("Unable to load library [" + library_name + "]") 00082 {} 00083 }; 00084 00085 class LibraryDoesNotExistException : public std::runtime_error 00086 { 00087 public: 00088 LibraryDoesNotExistException(const std::string& library_name) 00089 : std::runtime_error("Library [" + library_name + "] does not exist on disk") 00090 {} 00091 }; 00092 00093 class NoPluginInitFunctionException : public std::runtime_error 00094 { 00095 public: 00096 NoPluginInitFunctionException(const std::string& library_name) 00097 : std::runtime_error("Library [" + library_name + "] does not have an rvizPluginInit(rviz::TypeRegistry*) function!") 00098 {} 00099 }; 00100 00101 class Plugin 00102 { 00103 public: 00104 Plugin(); 00105 ~Plugin(); 00106 00107 void loadDescription(const std::string& description_path); 00108 00109 void load(); 00110 void unload(); 00111 00112 bool isLoaded(); 00113 bool isAutoLoad(); 00114 void setAutoLoad(bool autoload); 00115 void autoLoad(); 00116 00117 const L_DisplayTypeInfo& getDisplayTypeInfoList() const { return display_info_; } 00118 DisplayTypeInfoPtr getDisplayTypeInfo(const std::string& class_name) const; 00119 DisplayTypeInfoPtr getDisplayTypeInfoByDisplayName(const std::string& display_name) const; 00120 00121 Display* createDisplay(const std::string& class_name, const std::string& name, VisualizationManager* manager); 00122 00123 const std::string& getPackageName() const { return package_name_; } 00124 const std::string& getDescriptionPath() const { return description_path_; } 00125 const std::string& getName() { return name_; } 00126 00127 const std::string& mapDisplayClassName(const std::string& class_name) const; 00128 const std::string& mapDisplayName(const std::string& name) const; 00129 00130 PluginStatusSignal& getLoadingSignal() { return loading_signal_; } 00131 PluginStatusSignal& getLoadedSignal() { return loaded_signal_; } 00132 PluginStatusSignal& getUnloadingSignal() { return unloading_signal_; } 00133 PluginStatusSignal& getUnloadedSignal() { return unloaded_signal_; } 00134 00135 YAML::Node& getDescription() { return *doc_; } 00136 00137 const L_ClassTypeInfo* getClassTypeInfoList(const std::string& base_class) const; 00138 00139 private: 00140 std::string description_path_; 00141 std::string package_name_; 00142 std::string library_path_; 00143 std::string name_; 00144 00145 L_DisplayTypeInfo display_info_; 00146 M_string display_class_mappings_; 00147 M_string display_name_mappings_; 00148 00149 M_ClassTypeInfo class_info_; 00150 00151 wxDynamicLibrary library_; 00152 00153 bool loaded_; 00154 bool auto_load_; 00155 bool auto_load_tried_; 00156 00157 PluginStatusSignal loading_signal_; 00158 PluginStatusSignal loaded_signal_; 00159 PluginStatusSignal unloading_signal_; 00160 PluginStatusSignal unloaded_signal_; 00161 00162 YAML::Node* doc_; 00163 }; 00164 typedef boost::shared_ptr<Plugin> PluginPtr; 00165 typedef std::list<PluginPtr> L_Plugin; 00166 00167 } 00168 00169 #endif // RVIZ_PLUGIN_MANAGER_H 00170