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 }
boost::shared_ptr< void const > VoidConstPtr
Definition: forwards.h:52
boost::shared_ptr< M_string > connection_header_
MessageDeserializer(const SubscriptionCallbackHelperPtr &helper, const SerializedMessage &m, const boost::shared_ptr< M_string > &connection_header)
const std::type_info * type_info
SubscriptionCallbackHelperPtr helper_
boost::shared_array< uint8_t > buf
boost::shared_ptr< void const > message
SerializedMessage serialized_message_
#define ROS_ERROR(...)


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Fri Jun 8 2018 02:54:34