38 #include <boost/foreach.hpp>
39 #include <boost/algorithm/string/erase.hpp>
43 struct Publisher::Impl
59 count += pub->getNumSubscribers();
94 std::vector<boost::shared_ptr<PublisherPlugin> >
publishers_;
110 impl_->loader_ = loader;
112 std::vector<std::string> blacklist_vec;
113 std::set<std::string> blacklist;
115 for (
size_t i = 0; i < blacklist_vec.size(); ++i)
117 blacklist.insert(blacklist_vec[i]);
120 BOOST_FOREACH(
const std::string& lookup_name, loader->getDeclaredClasses()) {
121 const std::string transport_name = boost::erase_last_copy(lookup_name,
"_pub");
122 if (blacklist.count(transport_name))
129 impl_->publishers_.push_back(pub);
130 pub->advertise(nh,
impl_->base_topic_, queue_size,
rebindCB(connect_cb),
131 rebindCB(disconnect_cb), tracked_object, latch);
133 catch (
const std::runtime_error& e) {
134 ROS_DEBUG(
"Failed to load plugin %s, error string: %s",
135 lookup_name.c_str(), e.what());
139 if (
impl_->publishers_.empty())
140 throw Exception(
"No plugins found! Does `rospack plugins --attrib=plugin "
141 "image_transport` find any packages?");
153 return std::string();
159 ROS_ASSERT_MSG(
false,
"Call to publish() on an invalid image_transport::Publisher");
164 if (pub->getNumSubscribers() > 0)
165 pub->publish(message);
172 ROS_ASSERT_MSG(
false,
"Call to publish() on an invalid image_transport::Publisher");
177 if (pub->getNumSubscribers() > 0)
178 pub->publish(message);
190 Publisher::operator
void*()
const
192 return (
impl_ &&
impl_->isValid()) ? (
void*)1 : (
void*)0;
196 const SingleSubscriberPublisher& plugin_pub,
199 if (
ImplPtr impl = impl_wptr.lock())
200 impl->subscriberCB(plugin_pub, user_cb);