message_deserializer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, Willow Garage, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the names of Willow Garage, Inc. nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 
31 #include <ros/console.h>
32 
33 namespace ros
34 {
35 
37 : helper_(helper)
38 , serialized_message_(m)
39 , connection_header_(connection_header)
40 {
41  if (serialized_message_.message && *serialized_message_.type_info != helper->getTypeInfo())
42  {
44  }
45 }
46 
48 {
49  boost::mutex::scoped_lock lock(mutex_);
50 
51  if (msg_)
52  {
53  return msg_;
54  }
55 
57  {
59  return msg_;
60  }
61 
63  {
64  // If the buffer has been reset it means we tried to deserialize and failed
65  return VoidConstPtr();
66  }
67 
68  try
69  {
74  msg_ = helper_->deserialize(params);
75  }
76  catch (std::exception& e)
77  {
78  ROS_ERROR("Exception thrown when deserializing message of length [%d] from [%s]: %s", (uint32_t)serialized_message_.num_bytes, (*connection_header_)["callerid"].c_str(), e.what());
79  }
80 
81  serialized_message_.buf.reset();
82 
83  return msg_;
84 }
85 
86 }
message_deserializer.h
ros::SerializedMessage
ros::SerializedMessage::message_start
uint8_t * message_start
boost::shared_ptr< SubscriptionCallbackHelper >
ros::MessageDeserializer::MessageDeserializer
MessageDeserializer(const SubscriptionCallbackHelperPtr &helper, const SerializedMessage &m, const boost::shared_ptr< M_string > &connection_header)
Definition: message_deserializer.cpp:36
ros::SubscriptionCallbackHelperDeserializeParams::buffer
uint8_t * buffer
Definition: subscription_callback_helper.h:54
ros
ros::SerializedMessage::message
boost::shared_ptr< void const > message
subscription_callback_helper.h
ros::MessageDeserializer::helper_
SubscriptionCallbackHelperPtr helper_
Definition: message_deserializer.h:54
ros::SubscriptionCallbackHelperDeserializeParams::length
uint32_t length
Definition: subscription_callback_helper.h:55
ros::MessageDeserializer::mutex_
boost::mutex mutex_
Definition: message_deserializer.h:58
console.h
ros::MessageDeserializer::deserialize
VoidConstPtr deserialize()
Definition: message_deserializer.cpp:47
ros::MessageDeserializer::connection_header_
boost::shared_ptr< M_string > connection_header_
Definition: message_deserializer.h:56
ros::VoidConstPtr
boost::shared_ptr< void const > VoidConstPtr
Definition: forwards.h:52
ros::SerializedMessage::num_bytes
size_t num_bytes
ros::SubscriptionCallbackHelperDeserializeParams
Definition: subscription_callback_helper.h:52
ros::SerializedMessage::type_info
const std::type_info * type_info
ROS_ERROR
#define ROS_ERROR(...)
ros::MessageDeserializer::serialized_message_
SerializedMessage serialized_message_
Definition: message_deserializer.h:55
ros::SubscriptionCallbackHelperDeserializeParams::connection_header
boost::shared_ptr< M_string > connection_header
Definition: subscription_callback_helper.h:56
ros::MessageDeserializer::msg_
VoidConstPtr msg_
Definition: message_deserializer.h:59
ros::SerializedMessage::buf
boost::shared_array< uint8_t > buf


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Sat Oct 17 2020 19:28:47