Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "image_transport/publisher_plugin.h"
00036 #include "image_transport/subscriber_plugin.h"
00037 #include <pluginlib/class_loader.h>
00038 #include <boost/foreach.hpp>
00039 #include <boost/algorithm/string/erase.hpp>
00040 #include <map>
00041
00042 using namespace image_transport;
00043 using namespace pluginlib;
00044
00045 enum PluginStatus {SUCCESS, CREATE_FAILURE, LIB_LOAD_FAILURE, DOES_NOT_EXIST};
00046
00048 struct TransportDesc
00049 {
00050 TransportDesc()
00051 : pub_status(DOES_NOT_EXIST), sub_status(DOES_NOT_EXIST)
00052 {}
00053
00054 std::string package_name;
00055 std::string pub_name;
00056 PluginStatus pub_status;
00057 std::string sub_name;
00058 PluginStatus sub_status;
00059 };
00061
00062 int main(int argc, char** argv)
00063 {
00064 ClassLoader<PublisherPlugin> pub_loader("image_transport", "image_transport::PublisherPlugin");
00065 ClassLoader<SubscriberPlugin> sub_loader("image_transport", "image_transport::SubscriberPlugin");
00066 typedef std::map<std::string, TransportDesc> StatusMap;
00067 StatusMap transports;
00068
00069 BOOST_FOREACH(const std::string& lookup_name, pub_loader.getDeclaredClasses()) {
00070 std::string transport_name = boost::erase_last_copy(lookup_name, "_pub");
00071 transports[transport_name].pub_name = lookup_name;
00072 transports[transport_name].package_name = pub_loader.getClassPackage(lookup_name);
00073 try {
00074 boost::shared_ptr<PublisherPlugin> pub = pub_loader.createInstance(lookup_name);
00075 transports[transport_name].pub_status = SUCCESS;
00076 }
00077 catch (const LibraryLoadException& e) {
00078 transports[transport_name].pub_status = LIB_LOAD_FAILURE;
00079 }
00080 catch (const CreateClassException& e) {
00081 transports[transport_name].pub_status = CREATE_FAILURE;
00082 }
00083 }
00084
00085 BOOST_FOREACH(const std::string& lookup_name, sub_loader.getDeclaredClasses()) {
00086 std::string transport_name = boost::erase_last_copy(lookup_name, "_sub");
00087 transports[transport_name].sub_name = lookup_name;
00088 transports[transport_name].package_name = sub_loader.getClassPackage(lookup_name);
00089 try {
00090 boost::shared_ptr<SubscriberPlugin> sub = sub_loader.createInstance(lookup_name);
00091 transports[transport_name].sub_status = SUCCESS;
00092 }
00093 catch (const LibraryLoadException& e) {
00094 transports[transport_name].sub_status = LIB_LOAD_FAILURE;
00095 }
00096 catch (const CreateClassException& e) {
00097 transports[transport_name].sub_status = CREATE_FAILURE;
00098 }
00099 }
00100
00101 bool problem_package = false;
00102 printf("Declared transports:\n");
00103 BOOST_FOREACH(const StatusMap::value_type& value, transports) {
00104 const TransportDesc& td = value.second;
00105 printf("%s", value.first.c_str());
00106 if ((td.pub_status == CREATE_FAILURE || td.pub_status == LIB_LOAD_FAILURE) ||
00107 (td.sub_status == CREATE_FAILURE || td.sub_status == LIB_LOAD_FAILURE)) {
00108 printf(" (*): Not available. Try 'catkin_make --pkg %s'.", td.package_name.c_str());
00109 problem_package = true;
00110 }
00111 printf("\n");
00112 }
00113 #if 0
00114 if (problem_package)
00115 printf("(*) \n");
00116 #endif
00117
00118 printf("\nDetails:\n");
00119 BOOST_FOREACH(const StatusMap::value_type& value, transports) {
00120 const TransportDesc& td = value.second;
00121 printf("----------\n");
00122 printf("\"%s\"\n", value.first.c_str());
00123 if (td.pub_status == CREATE_FAILURE || td.sub_status == CREATE_FAILURE) {
00124 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");
00125 }
00126 else if (td.pub_status == LIB_LOAD_FAILURE || td.sub_status == LIB_LOAD_FAILURE) {
00127 printf("*** Plugins are not built. ***\n");
00128 }
00129 printf(" - Provided by package: %s\n", td.package_name.c_str());
00130 if (td.pub_status == DOES_NOT_EXIST)
00131 printf(" - No publisher provided\n");
00132 else
00133 printf(" - Publisher: %s\n", pub_loader.getClassDescription(td.pub_name).c_str());
00134 if (td.sub_status == DOES_NOT_EXIST)
00135 printf(" - No subscriber provided\n");
00136 else
00137 printf(" - Subscriber: %s\n", sub_loader.getClassDescription(td.sub_name).c_str());
00138 }
00139
00140 return 0;
00141 }