intraprocess_publisher_link.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, 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 Willow Garage, Inc. 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 "ros/subscription.h"
38 #include "ros/header.h"
39 #include "ros/connection.h"
41 #include "ros/this_node.h"
42 #include "ros/connection_manager.h"
43 #include "ros/file_log.h"
44 
45 #include <boost/bind.hpp>
46 
47 #include <sstream>
48 
49 namespace ros
50 {
51 
52 IntraProcessPublisherLink::IntraProcessPublisherLink(const SubscriptionPtr& parent, const std::string& xmlrpc_uri, const TransportHints& transport_hints)
53 : PublisherLink(parent, xmlrpc_uri, transport_hints)
54 , dropped_(false)
55 {
56 }
57 
59 {
60 }
61 
63 {
64  publisher_ = publisher;
65 
66  SubscriptionPtr parent = parent_.lock();
67  ROS_ASSERT(parent);
68 
69  Header header;
70  M_stringPtr values = header.getValues();
71  (*values)["callerid"] = this_node::getName();
72  (*values)["topic"] = parent->getName();
73  (*values)["type"] = publisher->getDataType();
74  (*values)["md5sum"] = publisher->getMD5Sum();
75  (*values)["message_definition"] = publisher->getMessageDefinition();
76  (*values)["latching"] = publisher->isLatching() ? "1" : "0";
77  setHeader(header);
78 }
79 
81 {
82  {
83  boost::recursive_mutex::scoped_lock lock(drop_mutex_);
84  if (dropped_)
85  {
86  return;
87  }
88 
89  dropped_ = true;
90  }
91 
92  if (publisher_)
93  {
94  publisher_->drop();
95  publisher_.reset();
96  }
97 
98  if (SubscriptionPtr parent = parent_.lock())
99  {
100  ROSCPP_LOG_DEBUG("Connection to local publisher on topic [%s] dropped", parent->getName().c_str());
101 
102  parent->removePublisherLink(shared_from_this());
103  }
104 }
105 
106 void IntraProcessPublisherLink::handleMessage(const SerializedMessage& m, bool ser, bool nocopy)
107 {
108  boost::recursive_mutex::scoped_lock lock(drop_mutex_);
109  if (dropped_)
110  {
111  return;
112  }
113 
116 
117  SubscriptionPtr parent = parent_.lock();
118 
119  if (parent)
120  {
121  stats_.drops_ += parent->handleMessage(m, ser, nocopy, header_.getValues(), shared_from_this());
122  }
123 }
124 
126 {
127  return std::string("INTRAPROCESS");
128 }
129 
131 {
132  // TODO: Check if we can dump more useful information here
133  return getTransportType();
134 }
135 
136 void IntraProcessPublisherLink::getPublishTypes(bool& ser, bool& nocopy, const std::type_info& ti)
137 {
138  boost::recursive_mutex::scoped_lock lock(drop_mutex_);
139  if (dropped_)
140  {
141  ser = false;
142  nocopy = false;
143  return;
144  }
145 
146  SubscriptionPtr parent = parent_.lock();
147  if (parent)
148  {
149  parent->getPublishTypes(ser, nocopy, ti);
150  }
151  else
152  {
153  ser = true;
154  nocopy = false;
155  }
156 }
157 
158 } // namespace ros
159 
ROSCPP_DECL const std::string & getName()
Returns the name of the current node.
Definition: this_node.cpp:74
Provides a way of specifying network transport hints to ros::NodeHandle::subscribe() and someday ros:...
#define ROSCPP_LOG_DEBUG(...)
Definition: file_log.h:35
M_stringPtr getValues()
const std::string header
#define ROS_ASSERT(cond)


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Feb 28 2022 23:33:27