00001 #include "image_transport/publisher_plugin.h" 00002 #include "image_transport/subscriber_plugin.h" 00003 #include <pluginlib/class_loader.h> 00004 #include <boost/foreach.hpp> 00005 #include <boost/algorithm/string/erase.hpp> 00006 #include <map> 00007 00008 using namespace image_transport; 00009 using namespace pluginlib; 00010 00011 enum PluginStatus {SUCCESS, CREATE_FAILURE, LIB_LOAD_FAILURE, DOES_NOT_EXIST}; 00012 00014 struct TransportDesc 00015 { 00016 TransportDesc() 00017 : pub_status(DOES_NOT_EXIST), sub_status(DOES_NOT_EXIST) 00018 {} 00019 00020 std::string package_name; 00021 std::string pub_name; 00022 PluginStatus pub_status; 00023 std::string sub_name; 00024 PluginStatus sub_status; 00025 }; 00027 00028 int main(int argc, char** argv) 00029 { 00030 ClassLoader<PublisherPlugin> pub_loader("image_transport", "image_transport::PublisherPlugin"); 00031 ClassLoader<SubscriberPlugin> sub_loader("image_transport", "image_transport::SubscriberPlugin"); 00032 typedef std::map<std::string, TransportDesc> StatusMap; 00033 StatusMap transports; 00034 00035 BOOST_FOREACH(const std::string& lookup_name, pub_loader.getDeclaredClasses()) { 00036 std::string transport_name = boost::erase_last_copy(lookup_name, "_pub"); 00037 transports[transport_name].pub_name = lookup_name; 00038 transports[transport_name].package_name = pub_loader.getClassPackage(lookup_name); 00039 try { 00040 PublisherPlugin* pub = pub_loader.createClassInstance(lookup_name); 00041 transports[transport_name].pub_status = SUCCESS; 00042 delete pub; 00043 } 00044 catch (const LibraryLoadException& e) { 00045 transports[transport_name].pub_status = LIB_LOAD_FAILURE; 00046 } 00047 catch (const CreateClassException& e) { 00048 transports[transport_name].pub_status = CREATE_FAILURE; 00049 } 00050 } 00051 00052 BOOST_FOREACH(const std::string& lookup_name, sub_loader.getDeclaredClasses()) { 00053 std::string transport_name = boost::erase_last_copy(lookup_name, "_sub"); 00054 transports[transport_name].sub_name = lookup_name; 00055 transports[transport_name].package_name = sub_loader.getClassPackage(lookup_name); 00056 try { 00057 SubscriberPlugin* sub = sub_loader.createClassInstance(lookup_name); 00058 transports[transport_name].sub_status = SUCCESS; 00059 delete sub; 00060 } 00061 catch (const LibraryLoadException& e) { 00062 transports[transport_name].sub_status = LIB_LOAD_FAILURE; 00063 } 00064 catch (const CreateClassException& e) { 00065 transports[transport_name].sub_status = CREATE_FAILURE; 00066 } 00067 } 00068 00069 bool problem_package = false; 00070 printf("Declared transports:\n"); 00071 BOOST_FOREACH(const StatusMap::value_type& value, transports) { 00072 const TransportDesc& td = value.second; 00073 printf("%s", value.first.c_str()); 00074 if ((td.pub_status == CREATE_FAILURE || td.pub_status == LIB_LOAD_FAILURE) || 00075 (td.sub_status == CREATE_FAILURE || td.sub_status == LIB_LOAD_FAILURE)) { 00076 printf(" (*): Not available. Try 'rosmake %s'.", td.package_name.c_str()); 00077 problem_package = true; 00078 } 00079 printf("\n"); 00080 } 00081 #if 0 00082 if (problem_package) 00083 printf("(*) \n"); 00084 #endif 00085 00086 printf("\nDetails:\n"); 00087 BOOST_FOREACH(const StatusMap::value_type& value, transports) { 00088 const TransportDesc& td = value.second; 00089 printf("----------\n"); 00090 printf("\"%s\"\n", value.first.c_str()); 00091 if (td.pub_status == CREATE_FAILURE || td.sub_status == CREATE_FAILURE) { 00092 printf("*** Plugins are built, but could not be loaded. The package may need to be rebuilt or may not be compatible with this release of image_common. ***\n"); 00093 } 00094 else if (td.pub_status == LIB_LOAD_FAILURE || td.sub_status == LIB_LOAD_FAILURE) { 00095 printf("*** Plugins are not built. ***\n"); 00096 } 00097 printf(" - Provided by package: %s\n", td.package_name.c_str()); 00098 if (td.pub_status == DOES_NOT_EXIST) 00099 printf(" - No publisher provided\n"); 00100 else 00101 printf(" - Publisher: %s\n", pub_loader.getClassDescription(td.pub_name).c_str()); 00102 if (td.sub_status == DOES_NOT_EXIST) 00103 printf(" - No subscriber provided\n"); 00104 else 00105 printf(" - Subscriber: %s\n", sub_loader.getClassDescription(td.sub_name).c_str()); 00106 } 00107 00108 return 0; 00109 }