list_transports.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2009, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
37 #include <pluginlib/class_loader.h>
38 #include <boost/foreach.hpp>
39 #include <boost/algorithm/string/erase.hpp>
40 #include <map>
41 
42 using namespace image_transport;
43 using namespace pluginlib;
44 
46 
48 struct TransportDesc
49 {
50  TransportDesc()
51  : pub_status(DOES_NOT_EXIST), sub_status(DOES_NOT_EXIST)
52  {}
53 
54  std::string package_name;
55  std::string pub_name;
56  PluginStatus pub_status;
57  std::string sub_name;
58  PluginStatus sub_status;
59 };
61 
62 int main(int argc, char** argv)
63 {
64  ClassLoader<PublisherPlugin> pub_loader("image_transport", "image_transport::PublisherPlugin");
65  ClassLoader<SubscriberPlugin> sub_loader("image_transport", "image_transport::SubscriberPlugin");
66  typedef std::map<std::string, TransportDesc> StatusMap;
67  StatusMap transports;
68 
69  BOOST_FOREACH(const std::string& lookup_name, pub_loader.getDeclaredClasses()) {
70  std::string transport_name = boost::erase_last_copy(lookup_name, "_pub");
71  transports[transport_name].pub_name = lookup_name;
72  transports[transport_name].package_name = pub_loader.getClassPackage(lookup_name);
73  try {
74  boost::shared_ptr<PublisherPlugin> pub = pub_loader.createInstance(lookup_name);
75  transports[transport_name].pub_status = SUCCESS;
76  }
77  catch (const LibraryLoadException& e) {
78  transports[transport_name].pub_status = LIB_LOAD_FAILURE;
79  }
80  catch (const CreateClassException& e) {
81  transports[transport_name].pub_status = CREATE_FAILURE;
82  }
83  }
84 
85  BOOST_FOREACH(const std::string& lookup_name, sub_loader.getDeclaredClasses()) {
86  std::string transport_name = boost::erase_last_copy(lookup_name, "_sub");
87  transports[transport_name].sub_name = lookup_name;
88  transports[transport_name].package_name = sub_loader.getClassPackage(lookup_name);
89  try {
90  boost::shared_ptr<SubscriberPlugin> sub = sub_loader.createInstance(lookup_name);
91  transports[transport_name].sub_status = SUCCESS;
92  }
93  catch (const LibraryLoadException& e) {
94  transports[transport_name].sub_status = LIB_LOAD_FAILURE;
95  }
96  catch (const CreateClassException& e) {
97  transports[transport_name].sub_status = CREATE_FAILURE;
98  }
99  }
100 
101  bool problem_package = false;
102  printf("Declared transports:\n");
103  BOOST_FOREACH(const StatusMap::value_type& value, transports) {
104  const TransportDesc& td = value.second;
105  printf("%s", value.first.c_str());
106  if ((td.pub_status == CREATE_FAILURE || td.pub_status == LIB_LOAD_FAILURE) ||
107  (td.sub_status == CREATE_FAILURE || td.sub_status == LIB_LOAD_FAILURE)) {
108  printf(" (*): Not available. Try 'catkin_make --pkg %s'.", td.package_name.c_str());
109  problem_package = true;
110  }
111  printf("\n");
112  }
113 #if 0
114  if (problem_package)
115  printf("(*) \n");
116 #endif
117 
118  printf("\nDetails:\n");
119  BOOST_FOREACH(const StatusMap::value_type& value, transports) {
120  const TransportDesc& td = value.second;
121  printf("----------\n");
122  printf("\"%s\"\n", value.first.c_str());
123  if (td.pub_status == CREATE_FAILURE || td.sub_status == CREATE_FAILURE) {
124  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");
125  }
126  else if (td.pub_status == LIB_LOAD_FAILURE || td.sub_status == LIB_LOAD_FAILURE) {
127  printf("*** Plugins are not built. ***\n");
128  }
129  printf(" - Provided by package: %s\n", td.package_name.c_str());
130  if (td.pub_status == DOES_NOT_EXIST)
131  printf(" - No publisher provided\n");
132  else
133  printf(" - Publisher: %s\n", pub_loader.getClassDescription(td.pub_name).c_str());
134  if (td.sub_status == DOES_NOT_EXIST)
135  printf(" - No subscriber provided\n");
136  else
137  printf(" - Subscriber: %s\n", sub_loader.getClassDescription(td.sub_name).c_str());
138  }
139 
140  return 0;
141 }
virtual std::string getClassDescription(const std::string &lookup_name)
boost::shared_ptr< T > createInstance(const std::string &lookup_name)
int main(int argc, char **argv)
virtual std::string getClassPackage(const std::string &lookup_name)
std::vector< std::string > getDeclaredClasses()
PluginStatus


image_transport
Author(s): Patrick Mihelich
autogenerated on Mon Feb 28 2022 22:31:45